Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Disable internal login if direct provider not enabled

Oliver Günther59fd5e91a76a
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 8e8fe437c22..3fe1143f991 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -40,6 +40,7 @@ class AccountController < ApplicationController
before_action :apply_csp_appends, only: %i[login]
before_action :disable_api
before_action :check_auth_source_sso_failure, only: :auth_source_sso_failed
+ before_action :check_internal_login_enabled, only: :internal_login
layout 'no_menu'
@@ -532,4 +533,8 @@ class AccountController < ApplicationController
append_content_security_policy_directives(appends)
end
+
+ def check_internal_login_enabled
+ render_404 unless omniauth_direct_login?
+ end
end
diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rb
index 361eb8d426f..6b436990512 100644
--- a/spec/controllers/account_controller_spec.rb
+++ b/spec/controllers/account_controller_spec.rb
@@ -98,6 +98,33 @@ describe AccountController,
end
end
+ describe 'GET #internal_login' do
+ context 'when direct login enabled', with_config: { omniauth_direct_login_provider: 'some_provider' } do
+ it 'allows to login internally using a special route' do
+ get :internal_login
+
+ expect(response).to redirect_to '/login'
+ expect(session[:internal_login]).to be true
+ end
+
+ it 'allows to login internally using a session flag' do
+ session[:internal_login] = true
+ get :login
+
+ expect(response).to render_template 'login'
+ end
+ end
+
+ context 'when direct login disabled' do
+ it 'allows to login internally using a special route' do
+ get :internal_login
+
+ expect(response.status).to eq 404
+ expect(session[:internal_login]).not_to be_present
+ end
+ end
+ end
+
context 'POST #login' do
shared_let(:admin) { create(:admin) }
@@ -295,7 +322,7 @@ describe AccountController,
let(:user) { build_stubbed(:user, login: 'bob', identity_url: 'saml:foo') }
let(:slo_callback) { nil }
let(:sso_provider) do
- { name: 'saml', single_sign_out_callback: slo_callback }
+ { name: 'saml', single_sign_out_callback: slo_callback }
end
before do
@@ -453,20 +480,6 @@ describe AccountController,
expect(response).to redirect_to '/auth/some_provider'
end
-
- it 'allows to login internally using a special route' do
- get :internal_login
-
- expect(response).to redirect_to '/login'
- expect(session[:internal_login]).to be true
- end
-
- it 'allows to login internally using a session flag' do
- session[:internal_login] = true
- get :login
-
- expect(response).to render_template 'login'
- end
end
describe 'POST' do
@@ -819,8 +832,8 @@ describe AccountController,
it 'preserves the back url' do
expect(response).to redirect_to(
- '/login?back_url=https%3A%2F%2Fexample.net%2Fsome_back_url'
- )
+ '/login?back_url=https%3A%2F%2Fexample.net%2Fsome_back_url'
+ )
end
it 'calls the user_registered callback' do