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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Convert stubbed account_controller specs into requests
Oliver Günther00c8c550dcbc
diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rbindex da3db97aecd..0b106959222 100644--- a/spec/controllers/account_controller_spec.rb+++ b/spec/controllers/account_controller_spec.rb@@ -218,28 +218,6 @@ RSpec.describe AccountController, :skip_2fa_stage doexpect(response).to redirect_to my_page_pathend- context 'with an auth source',- with_settings: { self_registration: Setting::SelfRegistration.disabled } do- let(:auth_source) { create(:ldap_auth_source) }-- it 'creates the user on the fly' do- allow(LdapAuthSource)- .to(receive(:authenticate))- .and_return(login: 'foo',- firstname: 'Foo',- lastname: 'Smith',- mail: '[email protected]',- ldap_auth_source_id: auth_source.id)- post :login, params: { username: 'foo', password: 'bar' }-- expect(response).to redirect_to home_url(first_time_user: true)- user = User.find_by(login: 'foo')- expect(user).to be_an_instance_of User- expect(user.ldap_auth_source_id).to eq(auth_source.id)- expect(user.current_password).to be_nil- end- end-context 'with a relative url root' doaround do |example|old_relative_url_root = OpenProject::Configuration['rails_relative_url_root']@@ -434,48 +412,6 @@ RSpec.describe AccountController, :skip_2fa_stage doexpect(response).to have_http_status :not_foundendend-- context 'with an auth source',- with_settings: { self_registration: Setting::SelfRegistration.disabled } do- let(:auth_source) { create(:ldap_auth_source) }-- let(:user_attributes) do- {- login: 's.scallywag',- firstname: 'Scarlet',- lastname: 'Scallywag',- mail: '[email protected]',- ldap_auth_source_id: auth_source.id- }- end-- let(:authenticate) { true }-- before do- allow(LdapAuthSource).to receive(:authenticate).and_return(authenticate ? user_attributes : nil)-- # required so that the register view can be rendered- allow_any_instance_of(User).to receive(:change_password_allowed?).and_return(false) # rubocop:disable RSpec/AnyInstance- end-- context 'with user limit reached' do- render_views-- before do- allow(OpenProject::Enterprise).to receive(:user_limit_reached?).and_return(true)-- post :login, params: { username: 'foo', password: 'bar' }- end-- it 'shows the user limit error' do- expect(response.body).to have_text "User limit reached"- end-- it 'renders the register form' do- expect(response.body).to include "/account/register"- end- end- endenddescribe '#login with omniauth_direct_login enabled',@@ -893,36 +829,6 @@ RSpec.describe AccountController, :skip_2fa_stage dowith_settings: { self_registration: Setting::SelfRegistration.disabled } dobefore doallow_any_instance_of(User).to receive(:change_password_allowed?).and_return(false) # rubocop:disable RSpec/AnyInstance- allow(LdapAuthSource).to receive(:authenticate).and_return(login: 'foo',- lastname: 'Smith',- ldap_auth_source_id: 66)- end-- context 'with password login enabled' do- before do- post :login, params: { username: 'foo', password: 'bar' }- end-- it 'registers the user on-the-fly' do- expect(subject).to respond_with :success- expect(response).to render_template :register-- post :register,- params: {- user: {- firstname: 'Foo',- lastname: 'Smith',- mail: '[email protected]'- }- }- expect(response).to redirect_to home_path(first_time_user: true)-- user = User.find_by_login('foo') # rubocop:disable Rails/DynamicFindBy-- expect(user).to be_an_instance_of(User)- expect(user.ldap_auth_source_id).to be 66- expect(user.current_password).to be_nil- endendcontext 'with password login disabled' do@@ -930,16 +836,6 @@ RSpec.describe AccountController, :skip_2fa_stage doallow(OpenProject::Configuration).to receive(:disable_password_login?).and_return(true)end- describe 'login' do- before do- post :login, params: { username: 'foo', password: 'bar' }- end-- it 'is not found' do- expect(response).to have_http_status :not_found- end- end-describe 'registration' dobefore dopost :register,diff --git a/spec/requests/auth/ldap_sso_spec.rb b/spec/requests/auth/ldap_sso_spec.rbindex b6477d4f095..06e7227c2f4 100644--- a/spec/requests/auth/ldap_sso_spec.rb+++ b/spec/requests/auth/ldap_sso_spec.rb@@ -28,74 +28,69 @@require 'spec_helper'-RSpec.describe AuthSourceSSO, :skip_2fa_stage, # Prevent redirects to 2FA stage+RSpec.describe 'LDAP authentication',+ :skip_2fa_stage,+ :skip_csrf,type: :rails_request do- let(:sso_config) do- {- header: "X-Remote-User",- optional: true- }- end-- before do- allow(OpenProject::Configuration)- .to receive(:auth_source_sso)- .and_return(sso_config)- endinclude_context 'with temporary LDAP'+ let(:username) { 'aa729' }+ let(:password) { 'smada' }+ let(:params) { { username:, password: } }++ subject do+ post(signin_path, params:)+ response+ end+context 'when LDAP is onthefly_register' dolet(:onthefly_register) { true }it 'creates the user on the fly' doexpect(User.find_by(login: 'aa729')).to be_nil- expect do- get '/projects', headers: { 'X-Remote-User' => 'aa729' }- end.to change(User.not_builtin, :count).by(1)+ expect { subject }.to change(User.not_builtin.active, :count).by(1)user = User.find_by(login: 'aa729')expect(user).to be_presentexpect(user).to be_activeexpect(session[:user_id]).to eq user.id- expect(session[:user_from_auth_header]).to eq true- expect(response).to redirect_to '/projects'+ expect(subject).to redirect_to '/?first_time_user=true'end- end- context 'when LDAP is not onthefly_register' do- let(:onthefly_register) { false }+ context 'when not all attributes present' do+ let(:attr_mail) { nil }- it 'returns an error when the user does not exist' do- get '/projects', headers: { 'X-Remote-User' => 'nonexistent' }+ it 'does not save the user, but forwards to registration form' do+ expect(User.find_by(login: 'aa729')).to be_nil- expect(response).to redirect_to '/sso'- expect(session[:auth_source_sso_failure]).to be_present+ expect { subject }.not_to change(User.not_builtin.active, :count)+ expect(subject).to render_template 'account/register'+ expect(subject.body).to have_text "Email can't be blank"+ endend- context 'when the user exists, but is outdated' do- let(:user) { create(:user, login: 'ldap_admin', admin: false, ldap_auth_source:) }-- it 'redirects the user to that URL' do- expect(user).not_to be_admin- get '/projects?foo=bar', headers: { 'X-Remote-User' => user.login }- expect(response).to redirect_to '/projects?foo=bar'+ context 'with user limit reached' do+ before do+ allow(OpenProject::Enterprise).to receive(:user_limit_reached?).and_return(true)+ end- user.reload- expect(user).to be_admin+ it 'shows the user limit error' do+ expect(subject.body).to have_text "User limit reached"+ expect(subject.body).to include "/account/register"endend- context 'when the user exists in another auth source that is inaccessible' do- let(:other_ldap) { create(:ldap_auth_source, name: 'other_ldap') }- let(:user) { create(:user, login: 'ldap_admin', admin: false, ldap_auth_source: other_ldap) }-- it 'returns an error when the user does not exist' do- get '/projects', headers: { 'X-Remote-User' => 'nonexistent' }+ context 'with password login disabled' do+ before do+ allow(OpenProject::Configuration).to receive(:disable_password_login?).and_return(true)+ end- expect(response).to redirect_to '/sso'- expect(session[:auth_source_sso_failure]).to be_present+ describe 'login' do+ it 'is not found' do+ expect(subject).to have_http_status :not_found+ endendendenddiff --git a/spec/support/shared/with_test_ldap.rb b/spec/support/shared/with_test_ldap.rbindex 4ebfd693f8e..caa9b02e231 100644--- a/spec/support/shared/with_test_ldap.rb+++ b/spec/support/shared/with_test_ldap.rb@@ -54,12 +54,16 @@ RSpec.shared_context 'with temporary LDAP' doonthefly_register:,filter_string: ldap_filter,attr_login: 'uid',- attr_firstname: 'givenName',- attr_lastname: 'sn',- attr_mail: 'mail',- attr_admin: 'isAdmin')+ attr_firstname:,+ attr_lastname:,+ attr_mail:,+ attr_admin:)endlet(:onthefly_register) { false }let(:ldap_filter) { nil }+ let(:attr_firstname) { 'givenName' }+ let(:attr_lastname) { 'sn' }+ let(:attr_mail) { 'mail' }+ let(:attr_admin) { 'isAdmin' }end