From 469a50879c1085ec77c95d650b7f135fee2c9e13 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 8 Jan 2021 00:32:37 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-7-stable-ee --- spec/controllers/projects/jobs_controller_spec.rb | 24 +++++--- spec/features/projects/container_registry_spec.rb | 16 ++++++ spec/features/projects/jobs_spec.rb | 4 +- .../security/project/internal_access_spec.rb | 2 +- .../security/project/private_access_spec.rb | 2 +- .../security/project/public_access_spec.rb | 2 +- .../graphql/container_repository_details.json | 4 +- spec/frontend/jobs/store/actions_spec.js | 66 ---------------------- spec/frontend/jobs/store/mutations_spec.js | 1 - .../components/details_page/tags_list_row_spec.js | 14 +++-- spec/frontend/registry/explorer/mock_data.js | 4 +- spec/lib/gitlab/database/migration_helpers_spec.rb | 11 ++-- spec/lib/gitlab/kubernetes/helm/pod_spec.rb | 2 +- spec/models/environment_spec.rb | 14 +++++ spec/policies/project_policy_spec.rb | 34 ----------- .../container_repository_details_spec.rb | 50 +++++++++++++++- .../canary_ingress/update_service_spec.rb | 6 ++ .../lib/container_registry/tags_shared_context.rb | 9 +++ 18 files changed, 138 insertions(+), 127 deletions(-) create mode 100644 spec/support/shared_contexts/lib/container_registry/tags_shared_context.rb (limited to 'spec') diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb index 3309b15b276..eb5e62f3d44 100644 --- a/spec/controllers/projects/jobs_controller_spec.rb +++ b/spec/controllers/projects/jobs_controller_spec.rb @@ -700,10 +700,22 @@ RSpec.describe Projects::JobsController, :clean_gitlab_redis_shared_state do expect(json_response['lines']).to eq [{ 'content' => [{ 'text' => 'BUILD TRACE' }], 'offset' => 0 }] end - it 'sets being-watched flag for the job' do - expect(response).to have_gitlab_http_status(:ok) + context 'when job is running' do + let(:job) { create(:ci_build, :trace_live, :running, pipeline: pipeline) } + + it 'sets being-watched flag for the job' do + expect(response).to have_gitlab_http_status(:ok) + + expect(job.trace.being_watched?).to be(true) + end + end - expect(job.trace.being_watched?).to be(true) + context 'when job is not running' do + it 'does not set being-watched flag for the job' do + expect(response).to have_gitlab_http_status(:ok) + + expect(job.trace.being_watched?).to be(false) + end end end @@ -711,11 +723,7 @@ RSpec.describe Projects::JobsController, :clean_gitlab_redis_shared_state do let(:job) { create(:ci_build, pipeline: pipeline) } it 'returns no traces' do - expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('job/build_trace') - expect(json_response['id']).to eq job.id - expect(json_response['status']).to eq job.status - expect(json_response['lines']).to be_nil + expect(response).to have_gitlab_http_status(:no_content) end end diff --git a/spec/features/projects/container_registry_spec.rb b/spec/features/projects/container_registry_spec.rb index ee453aa7bbf..d0ad6668c07 100644 --- a/spec/features/projects/container_registry_spec.rb +++ b/spec/features/projects/container_registry_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe 'Container Registry', :js do + include_context 'container registry tags' + let(:user) { create(:user) } let(:project) { create(:project) } @@ -99,6 +101,20 @@ RSpec.describe 'Container Registry', :js do expect(page).to have_content '20' end end + + describe 'with a tag missing digest' do + before do + stub_container_registry_tags(repository: %r{my/image}, tags: %w[latest stable]) + stub_next_container_registry_tags_call(:digest, nil) + visit_container_registry_details 'my/image' + end + + it 'renders the tags list correctly' do + expect(page).to have_content('latest') + expect(page).to have_content('stable') + expect(page).to have_content('Digest: N/A') + end + end end describe 'image repo details when image has no name' do diff --git a/spec/features/projects/jobs_spec.rb b/spec/features/projects/jobs_spec.rb index 4edda9febbe..1557a8a2d72 100644 --- a/spec/features/projects/jobs_spec.rb +++ b/spec/features/projects/jobs_spec.rb @@ -1212,9 +1212,11 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do end describe "GET /:project/jobs/:id/trace.json" do + let(:build) { create(:ci_build, :trace_artifact, pipeline: pipeline) } + context "Job from project" do before do - visit trace_project_job_path(project, job, format: :json) + visit trace_project_job_path(project, build, format: :json) end it { expect(page.status_code).to eq(200) } diff --git a/spec/features/security/project/internal_access_spec.rb b/spec/features/security/project/internal_access_spec.rb index cb9f9a6e680..2440b738db3 100644 --- a/spec/features/security/project/internal_access_spec.rb +++ b/spec/features/security/project/internal_access_spec.rb @@ -430,7 +430,7 @@ RSpec.describe "Internal Project Access" do describe 'GET /:project_path/builds/:id/trace' do let(:pipeline) { create(:ci_pipeline, project: project) } - let(:build) { create(:ci_build, pipeline: pipeline) } + let(:build) { create(:ci_build, :trace_artifact, pipeline: pipeline) } subject { trace_project_job_path(project, build.id) } diff --git a/spec/features/security/project/private_access_spec.rb b/spec/features/security/project/private_access_spec.rb index dda218c5de5..9d3109b92e6 100644 --- a/spec/features/security/project/private_access_spec.rb +++ b/spec/features/security/project/private_access_spec.rb @@ -423,7 +423,7 @@ RSpec.describe "Private Project Access" do describe 'GET /:project_path/builds/:id/trace' do let(:pipeline) { create(:ci_pipeline, project: project) } - let(:build) { create(:ci_build, pipeline: pipeline) } + let(:build) { create(:ci_build, :trace_artifact, pipeline: pipeline) } subject { trace_project_job_path(project, build.id) } diff --git a/spec/features/security/project/public_access_spec.rb b/spec/features/security/project/public_access_spec.rb index f2dbab72a48..28a1f1cda7f 100644 --- a/spec/features/security/project/public_access_spec.rb +++ b/spec/features/security/project/public_access_spec.rb @@ -238,7 +238,7 @@ RSpec.describe "Public Project Access" do describe 'GET /:project_path/builds/:id/trace' do let(:pipeline) { create(:ci_pipeline, project: project) } - let(:build) { create(:ci_build, pipeline: pipeline) } + let(:build) { create(:ci_build, :trace_artifact, pipeline: pipeline) } subject { trace_project_job_path(project, build.id) } diff --git a/spec/fixtures/api/schemas/graphql/container_repository_details.json b/spec/fixtures/api/schemas/graphql/container_repository_details.json index 3db91796fc6..3156b6d58d5 100644 --- a/spec/fixtures/api/schemas/graphql/container_repository_details.json +++ b/spec/fixtures/api/schemas/graphql/container_repository_details.json @@ -11,7 +11,7 @@ "type": "array", "items": { "type": "object", - "required": ["name", "path", "location", "digest", "revision", "shortRevision", "totalSize", "createdAt", "canDelete"], + "required": ["name", "path", "location", "canDelete"], "properties": { "name": { "type": "string" @@ -32,7 +32,7 @@ "type": "string" }, "totalSize": { - "type": "integer" + "type": "string" }, "createdAt": { "type": "string" diff --git a/spec/frontend/jobs/store/actions_spec.js b/spec/frontend/jobs/store/actions_spec.js index 26547d12ac7..91bd5521f70 100644 --- a/spec/frontend/jobs/store/actions_spec.js +++ b/spec/frontend/jobs/store/actions_spec.js @@ -27,7 +27,6 @@ import { hideSidebar, showSidebar, toggleSidebar, - triggerManualJob, } from '~/jobs/store/actions'; import state from '~/jobs/store/state'; import * as types from '~/jobs/store/mutation_types'; @@ -159,32 +158,6 @@ describe('Job State actions', () => { ); }); }); - - it('fetchTrace is called only if the job has started or has a trace', done => { - mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, { id: 121212, name: 'karma' }); - - mockedState.job.started = true; - - testAction( - fetchJob, - null, - mockedState, - [], - [ - { - type: 'requestJob', - }, - { - payload: { id: 121212, name: 'karma' }, - type: 'receiveJobSuccess', - }, - { - type: 'fetchTrace', - }, - ], - done, - ); - }); }); describe('receiveJobSuccess', () => { @@ -536,43 +509,4 @@ describe('Job State actions', () => { ); }); }); - - describe('triggerManualJob', () => { - let mock; - - beforeEach(() => { - mock = new MockAdapter(axios); - }); - - afterEach(() => { - mock.restore(); - }); - - it('should dispatch fetchTrace', done => { - const playManualJobEndpoint = `${TEST_HOST}/manual-job/jobs/1000/play`; - - mock.onPost(playManualJobEndpoint).reply(200); - - mockedState.job = { - status: { - action: { - path: playManualJobEndpoint, - }, - }, - }; - - testAction( - triggerManualJob, - [{ id: '1', key: 'test_var', secret_value: 'test_value' }], - mockedState, - [], - [ - { - type: 'fetchTrace', - }, - ], - done, - ); - }); - }); }); diff --git a/spec/frontend/jobs/store/mutations_spec.js b/spec/frontend/jobs/store/mutations_spec.js index a8146ba93eb..608abc8f7c4 100644 --- a/spec/frontend/jobs/store/mutations_spec.js +++ b/spec/frontend/jobs/store/mutations_spec.js @@ -153,7 +153,6 @@ describe('Jobs Store Mutations', () => { mutations[types.SET_TRACE_TIMEOUT](stateCopy, id); expect(stateCopy.traceTimeout).toEqual(id); - expect(stateCopy.isTraceComplete).toBe(false); }); }); diff --git a/spec/frontend/registry/explorer/components/details_page/tags_list_row_spec.js b/spec/frontend/registry/explorer/components/details_page/tags_list_row_spec.js index e1b75636735..94944643e8b 100644 --- a/spec/frontend/registry/explorer/components/details_page/tags_list_row_spec.js +++ b/spec/frontend/registry/explorer/components/details_page/tags_list_row_spec.js @@ -172,25 +172,31 @@ describe('tags list row', () => { }); it('contains the totalSize and layers', () => { - mountComponent({ ...defaultProps, tag: { ...tag, totalSize: 1024, layers: 10 } }); + mountComponent({ ...defaultProps, tag: { ...tag, totalSize: '1024', layers: 10 } }); expect(findSize().text()).toMatchInterpolatedText('1.00 KiB · 10 layers'); }); + it('when totalSize is giantic', () => { + mountComponent({ ...defaultProps, tag: { ...tag, totalSize: '1099511627776', layers: 2 } }); + + expect(findSize().text()).toMatchInterpolatedText('1024.00 GiB · 2 layers'); + }); + it('when totalSize is missing', () => { - mountComponent({ ...defaultProps, tag: { ...tag, totalSize: 0, layers: 10 } }); + mountComponent({ ...defaultProps, tag: { ...tag, totalSize: '0', layers: 10 } }); expect(findSize().text()).toMatchInterpolatedText(`${NOT_AVAILABLE_SIZE} · 10 layers`); }); it('when layers are missing', () => { - mountComponent({ ...defaultProps, tag: { ...tag, totalSize: 1024 } }); + mountComponent({ ...defaultProps, tag: { ...tag, totalSize: '1024' } }); expect(findSize().text()).toMatchInterpolatedText('1.00 KiB'); }); it('when there is 1 layer', () => { - mountComponent({ ...defaultProps, tag: { ...tag, totalSize: 0, layers: 1 } }); + mountComponent({ ...defaultProps, tag: { ...tag, totalSize: '0', layers: 1 } }); expect(findSize().text()).toMatchInterpolatedText(`${NOT_AVAILABLE_SIZE} · 1 layer`); }); diff --git a/spec/frontend/registry/explorer/mock_data.js b/spec/frontend/registry/explorer/mock_data.js index 992d880581a..72a9bff8a47 100644 --- a/spec/frontend/registry/explorer/mock_data.js +++ b/spec/frontend/registry/explorer/mock_data.js @@ -140,7 +140,7 @@ export const tagsMock = [ revision: 'c2613843ab33aabf847965442b13a8b55a56ae28837ce182627c0716eb08c02b', shortRevision: 'c2613843a', createdAt: '2020-11-03T13:29:38+00:00', - totalSize: 105, + totalSize: '1099511627776', canDelete: true, __typename: 'ContainerRepositoryTag', }, @@ -152,7 +152,7 @@ export const tagsMock = [ revision: 'df44e7228f0f255c73e35b6f0699624a615f42746e3e8e2e4b3804a6d6fc3292', shortRevision: 'df44e7228', createdAt: '2020-11-03T13:29:32+00:00', - totalSize: 104, + totalSize: '536870912000', canDelete: true, __typename: 'ContainerRepositoryTag', }, diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index ff6e5437559..a763dc08b73 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -992,7 +992,8 @@ RSpec.describe Gitlab::Database::MigrationHelpers do temp_undo_cleanup_column, type: :string, batch_column_name: :id, - type_cast_function: nil + type_cast_function: nil, + limit: nil ).and_return(true) expect(model).to receive(:rename_column) @@ -1007,7 +1008,7 @@ RSpec.describe Gitlab::Database::MigrationHelpers do model.undo_cleanup_concurrent_column_type_change(:users, :old, :string) end - it 'passes the type_cast_function and batch_column_name' do + it 'passes the type_cast_function, batch_column_name and limit' do expect(model).to receive(:column_exists?).with(:users, :other_batch_column).and_return(true) expect(model).to receive(:check_trigger_permissions!).with(:users) @@ -1017,7 +1018,8 @@ RSpec.describe Gitlab::Database::MigrationHelpers do temp_undo_cleanup_column, type: :string, batch_column_name: :other_batch_column, - type_cast_function: :custom_type_cast_function + type_cast_function: :custom_type_cast_function, + limit: 8 ).and_return(true) expect(model).to receive(:rename_column) @@ -1034,7 +1036,8 @@ RSpec.describe Gitlab::Database::MigrationHelpers do :old, :string, type_cast_function: :custom_type_cast_function, - batch_column_name: :other_batch_column + batch_column_name: :other_batch_column, + limit: 8 ) end diff --git a/spec/lib/gitlab/kubernetes/helm/pod_spec.rb b/spec/lib/gitlab/kubernetes/helm/pod_spec.rb index 6d97790fc8b..e3763977add 100644 --- a/spec/lib/gitlab/kubernetes/helm/pod_spec.rb +++ b/spec/lib/gitlab/kubernetes/helm/pod_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Gitlab::Kubernetes::Helm::Pod do using RSpec::Parameterized::TableSyntax where(:helm_major_version, :expected_helm_version, :expected_command_env) do - 2 | '2.16.9' | [:TILLER_NAMESPACE] + 2 | '2.17.0' | [:TILLER_NAMESPACE] 3 | '3.2.4' | nil end diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index 3e10ea847ba..0c7d8e2969d 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -1547,4 +1547,18 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do end end end + + describe '#clear_all_caches' do + subject { environment.clear_all_caches } + + it 'clears all caches on the environment' do + expect_next_instance_of(Gitlab::EtagCaching::Store) do |store| + expect(store).to receive(:touch).with(environment.etag_cache_key) + end + + expect(environment).to receive(:clear_reactive_cache!) + + subject + end + end end diff --git a/spec/policies/project_policy_spec.rb b/spec/policies/project_policy_spec.rb index 7f6c47d675b..c21d3b0939f 100644 --- a/spec/policies/project_policy_spec.rb +++ b/spec/policies/project_policy_spec.rb @@ -401,40 +401,6 @@ RSpec.describe ProjectPolicy do end end - describe 'bot_log_in' do - let(:bot_user) { create(:user, :project_bot) } - let(:project) { private_project } - - context 'when bot is in project and is not blocked' do - before do - project.add_maintainer(bot_user) - end - - it 'is a valid project bot' do - expect(bot_user.can?(:bot_log_in, project)).to be_truthy - end - end - - context 'when project bot is invalid' do - context 'when bot is not in project' do - it 'is not a valid project bot' do - expect(bot_user.can?(:bot_log_in, project)).to be_falsy - end - end - - context 'when bot user is blocked' do - before do - project.add_maintainer(bot_user) - bot_user.block! - end - - it 'is not a valid project bot' do - expect(bot_user.can?(:bot_log_in, project)).to be_falsy - end - end - end - end - context 'support bot' do let(:current_user) { User.support_bot } diff --git a/spec/requests/api/graphql/container_repository/container_repository_details_spec.rb b/spec/requests/api/graphql/container_repository/container_repository_details_spec.rb index 3c1c63c1670..44f924d8ae5 100644 --- a/spec/requests/api/graphql/container_repository/container_repository_details_spec.rb +++ b/spec/requests/api/graphql/container_repository/container_repository_details_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' RSpec.describe 'container repository details' do + include_context 'container registry tags' using RSpec::Parameterized::TableSyntax include GraphqlHelpers @@ -18,7 +19,7 @@ RSpec.describe 'container repository details' do let(:user) { project.owner } let(:variables) { {} } - let(:tags) { %w(latest tag1 tag2 tag3 tag4 tag5) } + let(:tags) { %w[latest tag1 tag2 tag3 tag4 tag5] } let(:container_repository_global_id) { container_repository.to_global_id.to_s } let(:container_repository_details_response) { graphql_data.dig('containerRepository') } @@ -76,6 +77,37 @@ RSpec.describe 'container repository details' do end end + context 'with a giant size tag' do + let(:tags) { %w[latest] } + let(:giant_size) { 1.terabyte } + let(:tag_sizes_response) { graphql_data_at('containerRepository', 'tags', 'nodes', 'totalSize') } + let(:fields) do + <<~GQL + tags { + nodes { + totalSize + } + } + GQL + end + + let(:query) do + graphql_query_for( + 'containerRepository', + { id: container_repository_global_id }, + fields + ) + end + + it 'returns the expected value as a string' do + stub_next_container_registry_tags_call(:total_size, giant_size) + + subject + + expect(tag_sizes_response.first).to eq(giant_size.to_s) + end + end + context 'limiting the number of tags' do let(:limit) { 2 } let(:tags_response) { container_repository_details_response.dig('tags', 'edges') } @@ -105,4 +137,20 @@ RSpec.describe 'container repository details' do expect(tags_response.size).to eq(limit) end end + + context 'with tags with a manifest containing nil fields' do + let(:tags_response) { container_repository_details_response.dig('tags', 'nodes') } + let(:errors) { container_repository_details_response.dig('errors') } + + %i[digest revision short_revision total_size created_at].each do |nilable_field| + it "returns a list of tags with a nil #{nilable_field}" do + stub_next_container_registry_tags_call(nilable_field, nil) + + subject + + expect(tags_response.size).to eq(tags.size) + expect(graphql_errors).to eq(nil) + end + end + end end diff --git a/spec/services/environments/canary_ingress/update_service_spec.rb b/spec/services/environments/canary_ingress/update_service_spec.rb index 31d6f543817..5ba62e7104c 100644 --- a/spec/services/environments/canary_ingress/update_service_spec.rb +++ b/spec/services/environments/canary_ingress/update_service_spec.rb @@ -117,6 +117,12 @@ RSpec.describe Environments::CanaryIngress::UpdateService, :clean_gitlab_redis_c expect(subject[:status]).to eq(:success) expect(subject[:message]).to be_nil end + + it 'clears all caches' do + expect(environment).to receive(:clear_all_caches) + + subject + end end context 'when patch request does not succeed' do diff --git a/spec/support/shared_contexts/lib/container_registry/tags_shared_context.rb b/spec/support/shared_contexts/lib/container_registry/tags_shared_context.rb new file mode 100644 index 00000000000..e0a746ec741 --- /dev/null +++ b/spec/support/shared_contexts/lib/container_registry/tags_shared_context.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +RSpec.shared_context 'container registry tags' do + def stub_next_container_registry_tags_call(method_name, mock_value) + allow_next_instance_of(ContainerRegistry::Tag) do |tag| + allow(tag).to receive(method_name).and_return(mock_value) + end + end +end -- cgit v1.2.3