diff options
Diffstat (limited to 'spec/support/shared_examples/requests')
9 files changed, 33 insertions, 31 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 index 017e6274cb0..59e641e2af6 100644 --- a/spec/support/shared_examples/requests/access_tokens_controller_shared_examples.rb +++ b/spec/support/shared_examples/requests/access_tokens_controller_shared_examples.rb @@ -2,18 +2,13 @@ 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) + token_entities = assigns(:active_resource_access_tokens) + expect(token_entities.length).to eq(1) + expect(token_entities[0][:name]).to eq(active_resource_access_token.name) end it 'lists all available scopes' do @@ -21,15 +16,6 @@ RSpec.shared_examples 'GET resource access tokens available' do 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 @@ -37,10 +23,13 @@ RSpec.shared_examples 'POST resource access tokens available' do PersonalAccessToken.order(:created_at).last end - it 'returns success message' do + it 'renders JSON with a token' do subject - expect(flash[:notice]).to match('Your new access token has been created.') + parsed_body = Gitlab::Json.parse(response.body) + expect(parsed_body['new_token']).not_to be_blank + expect(parsed_body['errors']).to be_blank + expect(response).to have_gitlab_http_status(:success) end it 'creates resource access token' do @@ -59,12 +48,6 @@ RSpec.shared_examples 'POST resource access tokens available' do 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) } @@ -87,10 +70,13 @@ RSpec.shared_examples 'POST resource access tokens available' do expect { subject }.not_to change { User.count } end - it 'shows a failure alert' do + it 'renders JSON with an error' do subject - expect(flash[:alert]).to match("Failed to create new access token: Failed!") + parsed_body = Gitlab::Json.parse(response.body) + expect(parsed_body['new_token']).to be_blank + expect(parsed_body['errors']).to contain_exactly('Failed!') + expect(response).to have_gitlab_http_status(:unprocessable_entity) 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 de7032450a5..14a83d2889b 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 @@ -24,7 +24,7 @@ RSpec.shared_examples 'Debian packages upload request' do |status, body = nil| if status == :created it 'creates package files', :aggregate_failures do expect(::Packages::Debian::FindOrCreateIncomingService).to receive(:new).with(container, user).and_call_original - expect(::Packages::Debian::CreatePackageFileService).to receive(:new).with(be_a(Packages::Package), be_an(Hash)).and_call_original + expect(::Packages::Debian::CreatePackageFileService).to receive(:new).with(package: be_a(Packages::Package), current_user: be_an(User), params: be_an(Hash)).and_call_original if file_name.end_with? '.changes' expect(::Packages::Debian::ProcessChangesWorker).to receive(:perform_async) diff --git a/spec/support/shared_examples/requests/api/helm_packages_shared_examples.rb b/spec/support/shared_examples/requests/api/helm_packages_shared_examples.rb index 06ed0448b50..8bf6b162508 100644 --- a/spec/support/shared_examples/requests/api/helm_packages_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/helm_packages_shared_examples.rb @@ -247,6 +247,15 @@ RSpec.shared_examples 'handling helm chart index requests' do end end + context 'with access to package registry for everyone' do + before do + project.update!(visibility: Gitlab::VisibilityLevel::PRIVATE) + project.project_feature.update!(package_registry_access_level: ProjectFeature::PUBLIC) + end + + it_behaves_like 'process helm service index request', :anonymous, :success + end + context 'when an invalid token is passed' do let(:headers) { basic_auth_header(user.username, 'wrong') } diff --git a/spec/support/shared_examples/requests/api/hooks_shared_examples.rb b/spec/support/shared_examples/requests/api/hooks_shared_examples.rb index 013945bd578..d666a754d9f 100644 --- a/spec/support/shared_examples/requests/api/hooks_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/hooks_shared_examples.rb @@ -134,6 +134,7 @@ RSpec.shared_examples 'web-hook API endpoints' do |prefix| context 'the hook is backed-off' do before do + WebHook::FAILURE_THRESHOLD.times { hook.backoff! } hook.backoff! end diff --git a/spec/support/shared_examples/requests/api/issuable_update_shared_examples.rb b/spec/support/shared_examples/requests/api/issuable_update_shared_examples.rb index a3378d4619b..1045a92f332 100644 --- a/spec/support/shared_examples/requests/api/issuable_update_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/issuable_update_shared_examples.rb @@ -20,7 +20,7 @@ RSpec.shared_examples 'issuable update endpoint' do end it 'updates the issuable with labels param as array' do - stub_const("Gitlab::QueryLimiting::Transaction::THRESHOLD", 110) + allow(Gitlab::QueryLimiting::Transaction).to receive(:threshold).and_return(110) params = { labels: ['label1', 'label2', 'foo, bar', '&,?'] } diff --git a/spec/support/shared_examples/requests/api/npm_packages_shared_examples.rb b/spec/support/shared_examples/requests/api/npm_packages_shared_examples.rb index b651ffc8996..85ac2b5e1ea 100644 --- a/spec/support/shared_examples/requests/api/npm_packages_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/npm_packages_shared_examples.rb @@ -260,7 +260,11 @@ RSpec.shared_examples 'handling get metadata requests' do |scope: :project| project.send("add_#{user_role}", user) if user_role project.update!(visibility: visibility.to_s) package.update!(name: package_name) unless package_name == 'non-existing-package' - allow_fetch_application_setting(attribute: "npm_package_requests_forwarding", return_value: request_forward) + if scope == :instance + allow_fetch_application_setting(attribute: "npm_package_requests_forwarding", return_value: request_forward) + else + allow_fetch_cascade_application_setting(attribute: "npm_package_requests_forwarding", return_value: request_forward) + end end example_name = "#{params[:expected_result]} metadata request" diff --git a/spec/support/shared_examples/requests/api/npm_packages_tags_shared_examples.rb b/spec/support/shared_examples/requests/api/npm_packages_tags_shared_examples.rb index 86b6975bf9f..1d79a61fbb0 100644 --- a/spec/support/shared_examples/requests/api/npm_packages_tags_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/npm_packages_tags_shared_examples.rb @@ -14,6 +14,7 @@ RSpec.shared_examples 'accept package tags request' do |status:| before do allow_fetch_application_setting(attribute: "npm_package_requests_forwarding", return_value: false) + allow_fetch_cascade_application_setting(attribute: "npm_package_requests_forwarding", return_value: false) end context 'with valid package name' do diff --git a/spec/support/shared_examples/requests/api/pypi_packages_shared_examples.rb b/spec/support/shared_examples/requests/api/pypi_packages_shared_examples.rb index f411b5699a9..11e19d8d067 100644 --- a/spec/support/shared_examples/requests/api/pypi_packages_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/pypi_packages_shared_examples.rb @@ -291,7 +291,7 @@ RSpec.shared_examples 'pypi simple API endpoint' do end before do - allow_fetch_application_setting(attribute: "pypi_package_requests_forwarding", return_value: forward) + allow_fetch_cascade_application_setting(attribute: "pypi_package_requests_forwarding", return_value: forward) end it_behaves_like params[:shared_examples_name], :reporter, params[:expected_status] diff --git a/spec/support/shared_examples/requests/projects/google_cloud/google_oauth2_token_examples.rb b/spec/support/shared_examples/requests/projects/google_cloud/google_oauth2_token_examples.rb index 379327be0db..e2e2658d803 100644 --- a/spec/support/shared_examples/requests/projects/google_cloud/google_oauth2_token_examples.rb +++ b/spec/support/shared_examples/requests/projects/google_cloud/google_oauth2_token_examples.rb @@ -18,6 +18,7 @@ RSpec.shared_examples 'requires valid Google Oauth2 token' do allow_next_instance_of(GoogleApi::CloudPlatform::Client) do |client| allow(client).to receive(:validate_token).and_return(true) allow(client).to receive(:list_projects).and_return(mock_gcp_projects) if mock_gcp_projects + allow(client).to receive(:create_cloudsql_instance) end allow_next_instance_of(BranchesFinder) do |finder| |