]> git.openstreetmap.org Git - rails.git/commitdiff
Check if db is writable on oauth authorization pages
authorAnton Khorev <tony29@yandex.ru>
Mon, 16 Dec 2024 23:18:56 +0000 (02:18 +0300)
committerAnton Khorev <tony29@yandex.ru>
Mon, 16 Dec 2024 23:18:56 +0000 (02:18 +0300)
app/controllers/oauth2_authorizations_controller.rb
test/controllers/oauth2_authorizations_controller_test.rb

index 415ab2775c12f248e90598bde7e2495078e126f9..9f86e8b184e711bce1e3429be2bd96a2d016c578 100644 (file)
@@ -7,4 +7,6 @@ class Oauth2AuthorizationsController < Doorkeeper::AuthorizationsController
   allow_all_form_action :only => :new
 
   authorize_resource :class => false
   allow_all_form_action :only => :new
 
   authorize_resource :class => false
+
+  before_action :check_database_writable
 end
 end
index 854f7cde5c717ef4c4e91ff19ee4633ed0557476..012bfd7f470877ebd340c2cdec4ec1cb5d4eb206 100644 (file)
@@ -102,6 +102,20 @@ class Oauth2AuthorizationsControllerTest < ActionDispatch::IntegrationTest
     assert_select "p", "The requested scope is invalid, unknown, or malformed."
   end
 
     assert_select "p", "The requested scope is invalid, unknown, or malformed."
   end
 
+  def test_new_db_readonly
+    application = create(:oauth_application, :scopes => "write_api")
+
+    session_for(create(:user))
+
+    with_settings(:status => "database_readonly") do
+      get oauth_authorization_path(:client_id => application.uid,
+                                   :redirect_uri => application.redirect_uri,
+                                   :response_type => "code",
+                                   :scope => "write_api")
+      assert_redirected_to offline_path
+    end
+  end
+
   def test_create
     application = create(:oauth_application, :scopes => "write_api")
 
   def test_create
     application = create(:oauth_application, :scopes => "write_api")