From 5bb23f6f5f8fed81f1166a15344e44afa7fbb480 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 17 Dec 2024 02:18:56 +0300 Subject: [PATCH] Check if db is writable on oauth authorization pages --- .../oauth2_authorizations_controller.rb | 2 ++ .../oauth2_authorizations_controller_test.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/controllers/oauth2_authorizations_controller.rb b/app/controllers/oauth2_authorizations_controller.rb index 415ab2775..9f86e8b18 100644 --- a/app/controllers/oauth2_authorizations_controller.rb +++ b/app/controllers/oauth2_authorizations_controller.rb @@ -7,4 +7,6 @@ class Oauth2AuthorizationsController < Doorkeeper::AuthorizationsController allow_all_form_action :only => :new authorize_resource :class => false + + before_action :check_database_writable end diff --git a/test/controllers/oauth2_authorizations_controller_test.rb b/test/controllers/oauth2_authorizations_controller_test.rb index 854f7cde5..012bfd7f4 100644 --- a/test/controllers/oauth2_authorizations_controller_test.rb +++ b/test/controllers/oauth2_authorizations_controller_test.rb @@ -102,6 +102,20 @@ class Oauth2AuthorizationsControllerTest < ActionDispatch::IntegrationTest 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") -- 2.39.5