diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-04 21:09:40 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-04 21:09:40 +0300 |
commit | fe448fa0fc6b02fd5c70da8f784476a9d27d70da (patch) | |
tree | 0f51541f1a7892e4edbd54fa7ffcc5712f7d0bbe /spec/requests | |
parent | 99373ac711072bf8f3ea7c020cd240b73dbc2ba3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/ci/jobs_spec.rb | 64 | ||||
-rw-r--r-- | spec/requests/api/graphql/packages/helm_spec.rb | 59 |
2 files changed, 91 insertions, 32 deletions
diff --git a/spec/requests/api/ci/jobs_spec.rb b/spec/requests/api/ci/jobs_spec.rb index a1a0086d96b..580f3d9e92d 100644 --- a/spec/requests/api/ci/jobs_spec.rb +++ b/spec/requests/api/ci/jobs_spec.rb @@ -177,11 +177,16 @@ RSpec.describe API::Ci::Jobs do end describe 'GET /job/allowed_agents' do - let_it_be(:group_authorization) { create(:agent_group_authorization) } - let_it_be(:associated_agent) { create(:cluster_agent, project: project) } + let_it_be(:group) { create(:group) } + let_it_be(:group_agent) { create(:cluster_agent, project: create(:project, group: group)) } + let_it_be(:group_authorization) { create(:agent_group_authorization, agent: group_agent, group: group) } + let_it_be(:project_agent) { create(:cluster_agent, project: project) } - let(:implicit_authorization) { Clusters::Agents::ImplicitAuthorization.new(agent: associated_agent) } - let(:authorizations_finder) { double(execute: [implicit_authorization, group_authorization]) } + before(:all) do + project.update!(group: group_authorization.group) + end + + let(:implicit_authorization) { Clusters::Agents::ImplicitAuthorization.new(agent: project_agent) } let(:headers) { { API::Ci::Helpers::Runner::JOB_TOKEN_HEADER => job.token } } let(:job) { create(:ci_build, :artifacts, pipeline: pipeline, user: api_user, status: job_status) } @@ -193,44 +198,22 @@ RSpec.describe API::Ci::Jobs do end before do - allow(Clusters::AgentAuthorizationsFinder).to receive(:new).with(project).and_return(authorizations_finder) - subject end context 'when token is valid and user is authorized' do - it 'returns agent info', :aggregate_failures do - expect(response).to have_gitlab_http_status(:ok) - - expect(json_response.dig('job', 'id')).to eq(job.id) - expect(json_response.dig('pipeline', 'id')).to eq(job.pipeline_id) - expect(json_response.dig('project', 'id')).to eq(job.project_id) - expect(json_response.dig('user', 'username')).to eq(api_user.username) - expect(json_response['allowed_agents']).to match_array([ - { - 'id' => implicit_authorization.agent_id, - 'config_project' => hash_including('id' => implicit_authorization.agent.project_id), - 'configuration' => implicit_authorization.config - }, - { - 'id' => group_authorization.agent_id, - 'config_project' => hash_including('id' => group_authorization.agent.project_id), - 'configuration' => group_authorization.config - } - ]) - end - - context 'when passing the token as params' do - let(:headers) { {} } - let(:params) { { job_token: job.token } } - + shared_examples_for 'valid allowed_agents request' do it 'returns agent info', :aggregate_failures do expect(response).to have_gitlab_http_status(:ok) expect(json_response.dig('job', 'id')).to eq(job.id) expect(json_response.dig('pipeline', 'id')).to eq(job.pipeline_id) expect(json_response.dig('project', 'id')).to eq(job.project_id) + expect(json_response.dig('project', 'groups')).to match_array([{ 'id' => group_authorization.group.id }]) + expect(json_response.dig('user', 'id')).to eq(api_user.id) expect(json_response.dig('user', 'username')).to eq(api_user.username) + expect(json_response.dig('user', 'roles_in_project')).to match_array %w(guest reporter developer) + expect(json_response).not_to include('environment') expect(json_response['allowed_agents']).to match_array([ { 'id' => implicit_authorization.agent_id, @@ -239,12 +222,29 @@ RSpec.describe API::Ci::Jobs do }, { 'id' => group_authorization.agent_id, - 'config_project' => a_hash_including('id' => group_authorization.agent.project_id), + 'config_project' => hash_including('id' => group_authorization.agent.project_id), 'configuration' => group_authorization.config } ]) end end + + it_behaves_like 'valid allowed_agents request' + + context 'when deployment' do + let(:job) { create(:ci_build, :artifacts, :with_deployment, environment: 'production', pipeline: pipeline, user: api_user, status: job_status) } + + it 'includes environment slug' do + expect(json_response.dig('environment', 'slug')).to eq('production') + end + end + + context 'when passing the token as params' do + let(:headers) { {} } + let(:params) { { job_token: job.token } } + + it_behaves_like 'valid allowed_agents request' + end end context 'when user is anonymous' do diff --git a/spec/requests/api/graphql/packages/helm_spec.rb b/spec/requests/api/graphql/packages/helm_spec.rb new file mode 100644 index 00000000000..397096f70db --- /dev/null +++ b/spec/requests/api/graphql/packages/helm_spec.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe 'helm package details' do + include GraphqlHelpers + include_context 'package details setup' + + let_it_be(:package) { create(:helm_package, project: project) } + + let(:package_files_metadata) {query_graphql_fragment('HelmFileMetadata')} + + let(:query) do + graphql_query_for(:package, { id: package_global_id }, <<~FIELDS) + #{all_graphql_fields_for('PackageDetailsType', max_depth: depth, excluded: excluded)} + packageFiles { + nodes { + #{package_files} + fileMetadata { + #{package_files_metadata} + } + } + } + FIELDS + end + + subject { post_graphql(query, current_user: user) } + + before do + subject + end + + it_behaves_like 'a package detail' + it_behaves_like 'a package with files' + + it 'has the correct file metadata' do + expect(first_file_response_metadata).to include( + 'channel' => first_file.helm_file_metadatum.channel + ) + expect(first_file_response_metadata['metadata']).to include( + 'name' => first_file.helm_file_metadatum.metadata['name'], + 'home' => first_file.helm_file_metadatum.metadata['home'], + 'sources' => first_file.helm_file_metadatum.metadata['sources'], + 'version' => first_file.helm_file_metadatum.metadata['version'], + 'description' => first_file.helm_file_metadatum.metadata['description'], + 'keywords' => first_file.helm_file_metadatum.metadata['keywords'], + 'maintainers' => first_file.helm_file_metadatum.metadata['maintainers'], + 'icon' => first_file.helm_file_metadatum.metadata['icon'], + 'apiVersion' => first_file.helm_file_metadatum.metadata['apiVersion'], + 'condition' => first_file.helm_file_metadatum.metadata['condition'], + 'tags' => first_file.helm_file_metadatum.metadata['tags'], + 'appVersion' => first_file.helm_file_metadatum.metadata['appVersion'], + 'deprecated' => first_file.helm_file_metadatum.metadata['deprecated'], + 'annotations' => first_file.helm_file_metadatum.metadata['annotations'], + 'kubeVersion' => first_file.helm_file_metadatum.metadata['kubeVersion'], + 'dependencies' => first_file.helm_file_metadatum.metadata['dependencies'], + 'type' => first_file.helm_file_metadatum.metadata['type'] + ) + end +end |