diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 09:16:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 09:16:11 +0000 |
commit | edaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch) | |
tree | 11f143effbfeba52329fb7afbd05e6e2a3790241 /spec/support/shared_examples/requests | |
parent | d8a5691316400a0f7ec4f83832698f1988eb27c1 (diff) | |
download | gitlab-ce-edaa33dee2ff2f7ea3fac488d41558eb5f86d68c.tar.gz |
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'spec/support/shared_examples/requests')
4 files changed, 163 insertions, 1 deletions
diff --git a/spec/support/shared_examples/requests/access_tokens_controller_shared_examples.rb b/spec/support/shared_examples/requests/access_tokens_controller_shared_examples.rb new file mode 100644 index 00000000000..6cd871d354c --- /dev/null +++ b/spec/support/shared_examples/requests/access_tokens_controller_shared_examples.rb @@ -0,0 +1,138 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'GET resource access tokens available' do + let_it_be(:active_resource_access_token) { create(:personal_access_token, user: bot_user) } + let_it_be(:inactive_resource_access_token) { create(:personal_access_token, :revoked, user: bot_user) } + + it 'retrieves active resource access tokens' do + subject + + expect(assigns(:active_resource_access_tokens)).to contain_exactly(active_resource_access_token) + end + + it 'retrieves inactive resource access tokens' do + subject + + expect(assigns(:inactive_resource_access_tokens)).to contain_exactly(inactive_resource_access_token) + end + + it 'lists all available scopes' do + subject + + expect(assigns(:scopes)).to eq(Gitlab::Auth.resource_bot_scopes) + end + + it 'retrieves newly created personal access token value' do + token_value = 'random-value' + allow(PersonalAccessToken).to receive(:redis_getdel).with("#{user.id}:#{resource.id}").and_return(token_value) + + subject + + expect(assigns(:new_resource_access_token)).to eq(token_value) + end +end + +RSpec.shared_examples 'POST resource access tokens available' do + def created_token + PersonalAccessToken.order(:created_at).last + end + + it 'returns success message' do + subject + + expect(flash[:notice]).to match('Your new access token has been created.') + end + + it 'creates resource access token' do + access_level = access_token_params[:access_level] || Gitlab::Access::MAINTAINER + subject + + expect(created_token.name).to eq(access_token_params[:name]) + expect(created_token.scopes).to eq(access_token_params[:scopes]) + expect(created_token.expires_at).to eq(access_token_params[:expires_at]) + expect(resource.member(created_token.user).access_level).to eq(access_level) + end + + it 'creates project bot user' do + subject + + expect(created_token.user).to be_project_bot + end + + it 'stores newly created token redis store' do + expect(PersonalAccessToken).to receive(:redis_store!) + + subject + end + + it { expect { subject }.to change { User.count }.by(1) } + it { expect { subject }.to change { PersonalAccessToken.count }.by(1) } + + context 'when unsuccessful' do + before do + allow_next_instance_of(ResourceAccessTokens::CreateService) do |service| + allow(service).to receive(:execute).and_return ServiceResponse.error(message: 'Failed!') + end + end + + it 'does not create the token' do + expect { subject }.not_to change { PersonalAccessToken.count } + end + + it 'does not add the project bot as a member' do + expect { subject }.not_to change { Member.count } + end + + it 'does not create the project bot user' do + expect { subject }.not_to change { User.count } + end + + it 'shows a failure alert' do + subject + + expect(flash[:alert]).to match("Failed to create new access token: Failed!") + end + end +end + +RSpec.shared_examples 'PUT resource access tokens available' do + it 'calls delete user worker' do + expect(DeleteUserWorker).to receive(:perform_async).with(user.id, bot_user.id, skip_authorization: true) + + subject + end + + it 'removes membership of bot user' do + subject + + expect(resource.reload.bots).not_to include(bot_user) + end + + it 'converts issuables of the bot user to ghost user' do + issue = create(:issue, author: bot_user) + + subject + + expect(issue.reload.author.ghost?).to be true + end + + it 'deletes project bot user' do + subject + + expect(User.exists?(bot_user.id)).to be_falsy + end + + context 'when unsuccessful' do + before do + allow_next_instance_of(ResourceAccessTokens::RevokeService) do |service| + allow(service).to receive(:execute).and_return ServiceResponse.error(message: 'Failed!') + end + end + + it 'shows a failure alert' do + subject + + expect(flash[:alert]).to include("Could not revoke access token") + end + end +end diff --git a/spec/support/shared_examples/requests/api/debian_packages_shared_examples.rb b/spec/support/shared_examples/requests/api/debian_packages_shared_examples.rb index 2fd5e6a5f91..9f96cb2a164 100644 --- a/spec/support/shared_examples/requests/api/debian_packages_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/debian_packages_shared_examples.rb @@ -40,7 +40,6 @@ RSpec.shared_examples 'Debian packages upload request' do |status, body = nil| expect(response.body).to match(body) end end - it_behaves_like 'a package tracking event', described_class.name, 'push_package' else it "returns #{status}#{and_body}", :aggregate_failures do subject diff --git a/spec/support/shared_examples/requests/api/graphql/packages/package_details_shared_examples.rb b/spec/support/shared_examples/requests/api/graphql/packages/package_details_shared_examples.rb index d576a5874fd..9385706d991 100644 --- a/spec/support/shared_examples/requests/api/graphql/packages/package_details_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/graphql/packages/package_details_shared_examples.rb @@ -38,4 +38,28 @@ RSpec.shared_examples 'a package with files' do 'fileSha256' => first_file.file_sha256 ) end + + context 'with package files pending destruction' do + let_it_be(:package_file_pending_destruction) { create(:package_file, :pending_destruction, package: package) } + + let(:response_package_file_ids) { package_files_response.map { |pf| pf['id'] } } + + it 'does not return them' do + expect(package.reload.package_files).to include(package_file_pending_destruction) + + expect(response_package_file_ids).not_to include(package_file_pending_destruction.to_global_id.to_s) + end + + context 'with packages_installable_package_files disabled' do + before(:context) do + stub_feature_flags(packages_installable_package_files: false) + end + + it 'returns them' do + expect(package.reload.package_files).to include(package_file_pending_destruction) + + expect(response_package_file_ids).to include(package_file_pending_destruction.to_global_id.to_s) + end + end + end end diff --git a/spec/support/shared_examples/requests/api/nuget_endpoints_shared_examples.rb b/spec/support/shared_examples/requests/api/nuget_endpoints_shared_examples.rb index db70bc75c63..290bf58fb6b 100644 --- a/spec/support/shared_examples/requests/api/nuget_endpoints_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/nuget_endpoints_shared_examples.rb @@ -221,6 +221,7 @@ RSpec.shared_examples 'handling nuget search requests' do |anonymous_requests_ex let_it_be(:packages_c) { create_list(:nuget_package, 5, name: 'Dummy.PackageC', project: project) } let_it_be(:package_d) { create(:nuget_package, name: 'Dummy.PackageD', version: '5.0.5-alpha', project: project) } let_it_be(:package_e) { create(:nuget_package, name: 'Foo.BarE', project: project) } + let(:search_term) { 'uMmy' } let(:take) { 26 } let(:skip) { 0 } |