diff options
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/api_guard/admin_mode_middleware_spec.rb | 35 | ||||
-rw-r--r-- | spec/requests/api/graphql/group_query_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/graphql/mutations/snippets/mark_as_spam_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/groups_spec.rb | 4 | ||||
-rw-r--r-- | spec/requests/api/users_spec.rb | 2 |
5 files changed, 41 insertions, 4 deletions
diff --git a/spec/requests/api/api_guard/admin_mode_middleware_spec.rb b/spec/requests/api/api_guard/admin_mode_middleware_spec.rb new file mode 100644 index 00000000000..8973afe6570 --- /dev/null +++ b/spec/requests/api/api_guard/admin_mode_middleware_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe API::APIGuard::AdminModeMiddleware, :do_not_mock_admin_mode, :request_store do + let(:user) { create(:admin) } + + it 'is loaded' do + expect(API::API.middleware).to include([:use, described_class]) + end + + context 'when there is an exception in the api call' do + let(:app) do + Class.new(API::API) do + get 'willfail' do + raise StandardError.new('oh noes!') + end + end + end + + it 'resets admin mode' do + Gitlab::Auth::CurrentUserMode.bypass_session!(user.id) + + expect(Gitlab::Auth::CurrentUserMode.bypass_session_admin_id).to be(user.id) + expect(Gitlab::Auth::CurrentUserMode).to receive(:reset_bypass_session!).and_call_original + + get api('/willfail') + + expect(response.status).to eq(500) + expect(response.body).to include('oh noes!') + + expect(Gitlab::Auth::CurrentUserMode.bypass_session_admin_id).to be_nil + end + end +end diff --git a/spec/requests/api/graphql/group_query_spec.rb b/spec/requests/api/graphql/group_query_spec.rb index 6e2663fb090..a38d1857076 100644 --- a/spec/requests/api/graphql/group_query_spec.rb +++ b/spec/requests/api/graphql/group_query_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' # Based on spec/requests/api/groups_spec.rb # Should follow closely in order to ensure all situations are covered -describe 'getting group information' do +describe 'getting group information', :do_not_mock_admin_mode do include GraphqlHelpers include UploadHelpers diff --git a/spec/requests/api/graphql/mutations/snippets/mark_as_spam_spec.rb b/spec/requests/api/graphql/mutations/snippets/mark_as_spam_spec.rb index f80a3401134..05e3f7e6806 100644 --- a/spec/requests/api/graphql/mutations/snippets/mark_as_spam_spec.rb +++ b/spec/requests/api/graphql/mutations/snippets/mark_as_spam_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe 'Mark snippet as spam' do +describe 'Mark snippet as spam', :do_not_mock_admin_mode do include GraphqlHelpers let_it_be(:admin) { create(:admin) } diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb index e8499246840..fb564bb398b 100644 --- a/spec/requests/api/groups_spec.rb +++ b/spec/requests/api/groups_spec.rb @@ -545,7 +545,8 @@ describe API::Groups do name: new_group_name, request_access_enabled: true, project_creation_level: "noone", - subgroup_creation_level: "maintainer" + subgroup_creation_level: "maintainer", + default_branch_protection: ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS } expect(response).to have_gitlab_http_status(:ok) @@ -566,6 +567,7 @@ describe API::Groups do expect(json_response['projects'].length).to eq(2) expect(json_response['shared_projects']).to be_an Array expect(json_response['shared_projects'].length).to eq(0) + expect(json_response['default_branch_protection']).to eq(::Gitlab::Access::MAINTAINER_PROJECT_ACCESS) end it 'returns 404 for a non existing group' do diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 12ac601c013..5a302f0528e 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe API::Users do +describe API::Users, :do_not_mock_admin_mode do let(:user) { create(:user, username: 'user.with.dot') } let(:admin) { create(:admin) } let(:key) { create(:key, user: user) } |