diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-04 10:03:30 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-04 10:03:30 +0000 |
commit | d35df0ad158c14cb28f583f4b26c4196ef23a3f7 (patch) | |
tree | 5a1992758772519104eacb5de2c231721876541c /spec | |
parent | 3c51da6f5782e53123a7ed5af98ba0828cbfa49f (diff) | |
download | gitlab-ce-d35df0ad158c14cb28f583f4b26c4196ef23a3f7.tar.gz |
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/deploy_keys_controller_spec.rb | 16 | ||||
-rw-r--r-- | spec/features/projects/deploy_keys_spec.rb | 2 | ||||
-rw-r--r-- | spec/features/projects/settings/ci_cd_settings_spec.rb | 97 | ||||
-rw-r--r-- | spec/features/projects/settings/repository_settings_spec.rb | 83 | ||||
-rw-r--r-- | spec/features/projects/settings/user_interacts_with_deploy_keys_spec.rb | 4 | ||||
-rw-r--r-- | spec/frontend/repository/components/table/row_spec.js | 2 | ||||
-rw-r--r-- | spec/frontend/repository/log_tree_spec.js | 28 | ||||
-rw-r--r-- | spec/frontend/repository/router_spec.js | 13 | ||||
-rw-r--r-- | spec/helpers/explore_helper_spec.rb | 19 | ||||
-rw-r--r-- | spec/lib/gitlab/visibility_level_spec.rb | 24 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 10 | ||||
-rw-r--r-- | spec/services/discussions/capture_diff_note_position_service_spec.rb | 23 | ||||
-rw-r--r-- | spec/services/projects/create_service_spec.rb | 1 |
13 files changed, 173 insertions, 149 deletions
diff --git a/spec/controllers/projects/deploy_keys_controller_spec.rb b/spec/controllers/projects/deploy_keys_controller_spec.rb index a6bbe6bd012..1b2b326b6e9 100644 --- a/spec/controllers/projects/deploy_keys_controller_spec.rb +++ b/spec/controllers/projects/deploy_keys_controller_spec.rb @@ -19,10 +19,10 @@ describe Projects::DeployKeysController do end context 'when html requested' do - it 'redirects to project ci / cd settings with the correct anchor' do + it 'redirects to project settings with the correct anchor' do get :index, params: params - expect(response).to redirect_to(project_settings_ci_cd_path(project, anchor: 'js-deploy-keys-settings')) + expect(response).to redirect_to(project_settings_repository_path(project, anchor: 'js-deploy-keys-settings')) end end @@ -87,13 +87,13 @@ describe Projects::DeployKeysController do it 'creates a new deploy key for the project' do expect { post :create, params: create_params }.to change(project.deploy_keys, :count).by(1) - expect(response).to redirect_to(project_settings_ci_cd_path(project, anchor: 'js-deploy-keys-settings')) + expect(response).to redirect_to(project_settings_repository_path(project, anchor: 'js-deploy-keys-settings')) end it 'redirects to project settings with the correct anchor' do post :create, params: create_params - expect(response).to redirect_to(project_settings_ci_cd_path(project, anchor: 'js-deploy-keys-settings')) + expect(response).to redirect_to(project_settings_repository_path(project, anchor: 'js-deploy-keys-settings')) end context 'when the deploy key is invalid' do @@ -153,7 +153,7 @@ describe Projects::DeployKeysController do expect(DeployKeysProject.where(project_id: project.id, deploy_key_id: deploy_key.id).count).to eq(1) expect(response).to have_gitlab_http_status(:found) - expect(response).to redirect_to(namespace_project_settings_ci_cd_path(anchor: 'js-deploy-keys-settings')) + expect(response).to redirect_to(namespace_project_settings_repository_path(anchor: 'js-deploy-keys-settings')) end it 'returns 404' do @@ -175,7 +175,7 @@ describe Projects::DeployKeysController do expect(DeployKeysProject.where(project_id: project.id, deploy_key_id: deploy_key.id).count).to eq(1) expect(response).to have_gitlab_http_status(:found) - expect(response).to redirect_to(namespace_project_settings_ci_cd_path(anchor: 'js-deploy-keys-settings')) + expect(response).to redirect_to(namespace_project_settings_repository_path(anchor: 'js-deploy-keys-settings')) end end end @@ -216,7 +216,7 @@ describe Projects::DeployKeysController do put :disable, params: { id: deploy_key.id, namespace_id: project.namespace, project_id: project } expect(response).to have_gitlab_http_status(:found) - expect(response).to redirect_to(namespace_project_settings_ci_cd_path(anchor: 'js-deploy-keys-settings')) + expect(response).to redirect_to(namespace_project_settings_repository_path(anchor: 'js-deploy-keys-settings')) expect { DeployKey.find(deploy_key.id) }.to raise_error(ActiveRecord::RecordNotFound) end @@ -239,7 +239,7 @@ describe Projects::DeployKeysController do end.to change { DeployKey.count }.by(-1) expect(response).to have_gitlab_http_status(:found) - expect(response).to redirect_to(namespace_project_settings_ci_cd_path(anchor: 'js-deploy-keys-settings')) + expect(response).to redirect_to(namespace_project_settings_repository_path(anchor: 'js-deploy-keys-settings')) expect { DeployKey.find(deploy_key.id) }.to raise_error(ActiveRecord::RecordNotFound) end diff --git a/spec/features/projects/deploy_keys_spec.rb b/spec/features/projects/deploy_keys_spec.rb index 03b7c54faf6..687b6461f05 100644 --- a/spec/features/projects/deploy_keys_spec.rb +++ b/spec/features/projects/deploy_keys_spec.rb @@ -17,7 +17,7 @@ describe 'Project deploy keys', :js do end it 'removes association between project and deploy key' do - visit project_settings_ci_cd_path(project) + visit project_settings_repository_path(project) page.within(find('.qa-deploy-keys-settings')) do expect(page).to have_selector('.deploy-key', count: 1) diff --git a/spec/features/projects/settings/ci_cd_settings_spec.rb b/spec/features/projects/settings/ci_cd_settings_spec.rb deleted file mode 100644 index ed65dcd85ab..00000000000 --- a/spec/features/projects/settings/ci_cd_settings_spec.rb +++ /dev/null @@ -1,97 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'Projects > Settings > CI / CD settings' do - let_it_be(:project) { create(:project_empty_repo) } - let_it_be(:user) { create(:user) } - let_it_be(:role) { :maintainer } - - context 'Deploy Keys', :js do - let_it_be(:private_deploy_key) { create(:deploy_key, title: 'private_deploy_key', public: false) } - let_it_be(:public_deploy_key) { create(:another_deploy_key, title: 'public_deploy_key', public: true) } - let(:new_ssh_key) { attributes_for(:key)[:key] } - - before do - project.add_role(user, role) - sign_in(user) - end - - it 'get list of keys' do - project.deploy_keys << private_deploy_key - project.deploy_keys << public_deploy_key - - visit project_settings_ci_cd_path(project) - - expect(page).to have_content('private_deploy_key') - expect(page).to have_content('public_deploy_key') - end - - it 'add a new deploy key' do - visit project_settings_ci_cd_path(project) - - fill_in 'deploy_key_title', with: 'new_deploy_key' - fill_in 'deploy_key_key', with: new_ssh_key - check 'deploy_key_deploy_keys_projects_attributes_0_can_push' - click_button 'Add key' - - expect(page).to have_content('new_deploy_key') - expect(page).to have_content('Write access allowed') - end - - it 'edit an existing deploy key' do - project.deploy_keys << private_deploy_key - visit project_settings_ci_cd_path(project) - - find('.deploy-key', text: private_deploy_key.title).find('.ic-pencil').click - - fill_in 'deploy_key_title', with: 'updated_deploy_key' - check 'deploy_key_deploy_keys_projects_attributes_0_can_push' - click_button 'Save changes' - - expect(page).to have_content('updated_deploy_key') - expect(page).to have_content('Write access allowed') - end - - it 'edit an existing public deploy key to be writable' do - project.deploy_keys << public_deploy_key - visit project_settings_ci_cd_path(project) - - find('.deploy-key', text: public_deploy_key.title).find('.ic-pencil').click - - check 'deploy_key_deploy_keys_projects_attributes_0_can_push' - click_button 'Save changes' - - expect(page).to have_content('public_deploy_key') - expect(page).to have_content('Write access allowed') - end - - it 'edit a deploy key from projects user has access to' do - project2 = create(:project_empty_repo) - project2.add_role(user, role) - project2.deploy_keys << private_deploy_key - - visit project_settings_ci_cd_path(project) - - find('.js-deployKeys-tab-available_project_keys').click - - find('.deploy-key', text: private_deploy_key.title).find('.ic-pencil').click - - fill_in 'deploy_key_title', with: 'updated_deploy_key' - click_button 'Save changes' - - find('.js-deployKeys-tab-available_project_keys').click - - expect(page).to have_content('updated_deploy_key') - end - - it 'remove an existing deploy key' do - project.deploy_keys << private_deploy_key - visit project_settings_ci_cd_path(project) - - accept_confirm { find('.deploy-key', text: private_deploy_key.title).find('.ic-remove').click } - - expect(page).not_to have_content(private_deploy_key.title) - end - end -end diff --git a/spec/features/projects/settings/repository_settings_spec.rb b/spec/features/projects/settings/repository_settings_spec.rb index 0fd153f0518..2fb6c71384f 100644 --- a/spec/features/projects/settings/repository_settings_spec.rb +++ b/spec/features/projects/settings/repository_settings_spec.rb @@ -39,6 +39,89 @@ describe 'Projects > Settings > Repository settings' do end end + context 'Deploy Keys', :js do + let_it_be(:private_deploy_key) { create(:deploy_key, title: 'private_deploy_key', public: false) } + let_it_be(:public_deploy_key) { create(:another_deploy_key, title: 'public_deploy_key', public: true) } + let(:new_ssh_key) { attributes_for(:key)[:key] } + + it 'get list of keys' do + project.deploy_keys << private_deploy_key + project.deploy_keys << public_deploy_key + + visit project_settings_repository_path(project) + + expect(page).to have_content('private_deploy_key') + expect(page).to have_content('public_deploy_key') + end + + it 'add a new deploy key' do + visit project_settings_repository_path(project) + + fill_in 'deploy_key_title', with: 'new_deploy_key' + fill_in 'deploy_key_key', with: new_ssh_key + check 'deploy_key_deploy_keys_projects_attributes_0_can_push' + click_button 'Add key' + + expect(page).to have_content('new_deploy_key') + expect(page).to have_content('Write access allowed') + end + + it 'edit an existing deploy key' do + project.deploy_keys << private_deploy_key + visit project_settings_repository_path(project) + + find('.deploy-key', text: private_deploy_key.title).find('.ic-pencil').click + + fill_in 'deploy_key_title', with: 'updated_deploy_key' + check 'deploy_key_deploy_keys_projects_attributes_0_can_push' + click_button 'Save changes' + + expect(page).to have_content('updated_deploy_key') + expect(page).to have_content('Write access allowed') + end + + it 'edit an existing public deploy key to be writable' do + project.deploy_keys << public_deploy_key + visit project_settings_repository_path(project) + + find('.deploy-key', text: public_deploy_key.title).find('.ic-pencil').click + + check 'deploy_key_deploy_keys_projects_attributes_0_can_push' + click_button 'Save changes' + + expect(page).to have_content('public_deploy_key') + expect(page).to have_content('Write access allowed') + end + + it 'edit a deploy key from projects user has access to' do + project2 = create(:project_empty_repo) + project2.add_role(user, role) + project2.deploy_keys << private_deploy_key + + visit project_settings_repository_path(project) + + find('.js-deployKeys-tab-available_project_keys').click + + find('.deploy-key', text: private_deploy_key.title).find('.ic-pencil').click + + fill_in 'deploy_key_title', with: 'updated_deploy_key' + click_button 'Save changes' + + find('.js-deployKeys-tab-available_project_keys').click + + expect(page).to have_content('updated_deploy_key') + end + + it 'remove an existing deploy key' do + project.deploy_keys << private_deploy_key + visit project_settings_repository_path(project) + + accept_confirm { find('.deploy-key', text: private_deploy_key.title).find('.ic-remove').click } + + expect(page).not_to have_content(private_deploy_key.title) + end + end + context 'remote mirror settings' do before do visit project_settings_repository_path(project) diff --git a/spec/features/projects/settings/user_interacts_with_deploy_keys_spec.rb b/spec/features/projects/settings/user_interacts_with_deploy_keys_spec.rb index ac7788ba1fa..cd9299150b2 100644 --- a/spec/features/projects/settings/user_interacts_with_deploy_keys_spec.rb +++ b/spec/features/projects/settings/user_interacts_with_deploy_keys_spec.rb @@ -20,7 +20,7 @@ describe "User interacts with deploy keys", :js do click_button("Enable") expect(page).not_to have_selector(".fa-spinner") - expect(current_path).to eq(project_settings_ci_cd_path(project)) + expect(current_path).to eq(project_settings_repository_path(project)) find(".js-deployKeys-tab-enabled_keys").click @@ -96,7 +96,7 @@ describe "User interacts with deploy keys", :js do click_button("Add key") - expect(current_path).to eq(project_settings_ci_cd_path(project)) + expect(current_path).to eq(project_settings_repository_path(project)) page.within(".deploy-keys") do expect(page).to have_content(DEPLOY_KEY_TITLE) diff --git a/spec/frontend/repository/components/table/row_spec.js b/spec/frontend/repository/components/table/row_spec.js index cb2193e1d9a..800a7e586a8 100644 --- a/spec/frontend/repository/components/table/row_spec.js +++ b/spec/frontend/repository/components/table/row_spec.js @@ -26,7 +26,7 @@ function factory(propsData = {}) { }, }); - vm.setData({ ref: 'master' }); + vm.setData({ escapedRef: 'master' }); } describe('Repository table row component', () => { diff --git a/spec/frontend/repository/log_tree_spec.js b/spec/frontend/repository/log_tree_spec.js index 8da2f39f71f..5637d0be957 100644 --- a/spec/frontend/repository/log_tree_spec.js +++ b/spec/frontend/repository/log_tree_spec.js @@ -53,7 +53,7 @@ describe('fetchLogsTree', () => { client = { readQuery: () => ({ projectPath: 'gitlab-org/gitlab-foss', - ref: 'master', + escapedRef: 'master', commits: [], }), writeQuery: jest.fn(), @@ -86,16 +86,18 @@ describe('fetchLogsTree', () => { it('calls entry resolver', () => fetchLogsTree(client, '', '0', resolver).then(() => { - expect(resolver.resolve).toHaveBeenCalledWith({ - __typename: 'LogTreeCommit', - commitPath: 'https://test.com', - committedDate: '2019-01-01', - fileName: 'index.js', - filePath: '/index.js', - message: 'testing message', - sha: '123', - type: 'blob', - }); + expect(resolver.resolve).toHaveBeenCalledWith( + expect.objectContaining({ + __typename: 'LogTreeCommit', + commitPath: 'https://test.com', + committedDate: '2019-01-01', + fileName: 'index.js', + filePath: '/index.js', + message: 'testing message', + sha: '123', + type: 'blob', + }), + ); })); it('writes query to client', () => @@ -104,7 +106,7 @@ describe('fetchLogsTree', () => { query: expect.anything(), data: { commits: [ - { + expect.objectContaining({ __typename: 'LogTreeCommit', commitPath: 'https://test.com', committedDate: '2019-01-01', @@ -113,7 +115,7 @@ describe('fetchLogsTree', () => { message: 'testing message', sha: '123', type: 'blob', - }, + }), ], }, }); diff --git a/spec/frontend/repository/router_spec.js b/spec/frontend/repository/router_spec.js index 6944b23558a..f2f3dda41d9 100644 --- a/spec/frontend/repository/router_spec.js +++ b/spec/frontend/repository/router_spec.js @@ -4,13 +4,12 @@ import createRouter from '~/repository/router'; describe('Repository router spec', () => { it.each` - path | branch | component | componentName - ${'/'} | ${'master'} | ${IndexPage} | ${'IndexPage'} - ${'/tree/master'} | ${'master'} | ${TreePage} | ${'TreePage'} - ${'/-/tree/master'} | ${'master'} | ${TreePage} | ${'TreePage'} - ${'/-/tree/master/app/assets'} | ${'master'} | ${TreePage} | ${'TreePage'} - ${'/-/tree/feature/test-%23/app/assets'} | ${'feature/test-#'} | ${TreePage} | ${'TreePage'} - ${'/-/tree/123/app/assets'} | ${'master'} | ${null} | ${'null'} + path | branch | component | componentName + ${'/'} | ${'master'} | ${IndexPage} | ${'IndexPage'} + ${'/tree/master'} | ${'master'} | ${TreePage} | ${'TreePage'} + ${'/-/tree/master'} | ${'master'} | ${TreePage} | ${'TreePage'} + ${'/-/tree/master/app/assets'} | ${'master'} | ${TreePage} | ${'TreePage'} + ${'/-/tree/123/app/assets'} | ${'master'} | ${null} | ${'null'} `('sets component as $componentName for path "$path"', ({ path, component, branch }) => { const router = createRouter('', branch); diff --git a/spec/helpers/explore_helper_spec.rb b/spec/helpers/explore_helper_spec.rb index f8240dd3a4c..1a6af3be055 100644 --- a/spec/helpers/explore_helper_spec.rb +++ b/spec/helpers/explore_helper_spec.rb @@ -19,23 +19,10 @@ describe ExploreHelper do end describe '#public_visibility_restricted?' do - using RSpec::Parameterized::TableSyntax + it 'delegates to Gitlab::VisibilityLevel' do + expect(Gitlab::VisibilityLevel).to receive(:public_visibility_restricted?).and_call_original - where(:visibility_levels, :expected_status) do - nil | nil - [Gitlab::VisibilityLevel::PRIVATE] | false - [Gitlab::VisibilityLevel::PRIVATE, Gitlab::VisibilityLevel::INTERNAL] | false - [Gitlab::VisibilityLevel::PUBLIC] | true - end - - with_them do - before do - stub_application_setting(restricted_visibility_levels: visibility_levels) - end - - it 'returns the expected status' do - expect(helper.public_visibility_restricted?).to eq(expected_status) - end + helper.public_visibility_restricted? end end end diff --git a/spec/lib/gitlab/visibility_level_spec.rb b/spec/lib/gitlab/visibility_level_spec.rb index 16a05af2216..a249b3a235e 100644 --- a/spec/lib/gitlab/visibility_level_spec.rb +++ b/spec/lib/gitlab/visibility_level_spec.rb @@ -96,6 +96,30 @@ describe Gitlab::VisibilityLevel do end end + describe '.restricted_level?, .non_restricted_level?, and .public_level_restricted?' do + using RSpec::Parameterized::TableSyntax + + where(:visibility_levels, :expected_status) do + nil | false + [Gitlab::VisibilityLevel::PRIVATE] | false + [Gitlab::VisibilityLevel::PRIVATE, Gitlab::VisibilityLevel::INTERNAL] | false + [Gitlab::VisibilityLevel::PUBLIC] | true + [Gitlab::VisibilityLevel::PUBLIC, Gitlab::VisibilityLevel::INTERNAL] | true + end + + with_them do + before do + stub_application_setting(restricted_visibility_levels: visibility_levels) + end + + it 'returns the expected status' do + expect(described_class.restricted_level?(Gitlab::VisibilityLevel::PUBLIC)).to eq(expected_status) + expect(described_class.non_restricted_level?(Gitlab::VisibilityLevel::PUBLIC)).to eq(!expected_status) + expect(described_class.public_visibility_restricted?).to eq(expected_status) + end + end + end + describe '#visibility_level_decreased?' do let(:project) { create(:project, :internal) } diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index bdaecea2089..a4f3fa518c6 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2350,6 +2350,16 @@ describe Ci::Build do end end + context 'when CI_JOB_JWT generation fails' do + it 'CI_JOB_JWT is not included' do + expect(Gitlab::Ci::Jwt).to receive(:for_build).and_raise(OpenSSL::PKey::RSAError, 'Neither PUB key nor PRIV key: not enough data') + expect(Gitlab::ErrorTracking).to receive(:track_exception) + + expect { subject }.not_to raise_error + expect(subject.pluck(:key)).not_to include('CI_JOB_JWT') + end + end + describe 'variables ordering' do context 'when variables hierarchy is stubbed' do let(:build_pre_var) { { key: 'build', value: 'value', public: true, masked: false } } diff --git a/spec/services/discussions/capture_diff_note_position_service_spec.rb b/spec/services/discussions/capture_diff_note_position_service_spec.rb index fced2eb7fce..bc71e170e92 100644 --- a/spec/services/discussions/capture_diff_note_position_service_spec.rb +++ b/spec/services/discussions/capture_diff_note_position_service_spec.rb @@ -3,10 +3,11 @@ require 'spec_helper' describe Discussions::CaptureDiffNotePositionService do + subject { described_class.new(note.noteable, paths) } + context 'image note on diff' do let!(:note) { create(:image_diff_note_on_merge_request) } - - subject { described_class.new(note.noteable, ['files/images/any_image.png']) } + let(:paths) { ['files/images/any_image.png'] } it 'is note affected by the service' do expect(Gitlab::Diff::PositionTracer).not_to receive(:new) @@ -18,8 +19,7 @@ describe Discussions::CaptureDiffNotePositionService do context 'when empty paths are passed as a param' do let!(:note) { create(:diff_note_on_merge_request) } - - subject { described_class.new(note.noteable, []) } + let(:paths) { [] } it 'does not calculate positons' do expect(Gitlab::Diff::PositionTracer).not_to receive(:new) @@ -28,4 +28,19 @@ describe Discussions::CaptureDiffNotePositionService do expect(note.diff_note_positions).to be_empty end end + + context 'when position tracer returned nil position' do + let!(:note) { create(:diff_note_on_merge_request) } + let(:paths) { ['files/any_file.txt'] } + + it 'does not create diff note position' do + expect(note.noteable).to receive(:merge_ref_head).and_return(double.as_null_object) + expect_next_instance_of(Gitlab::Diff::PositionTracer) do |tracer| + expect(tracer).to receive(:trace).and_return({ position: nil }) + end + + expect(subject.execute(note.discussion)).to eq(nil) + expect(note.diff_note_positions).to be_empty + end + end end diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb index 3c9914e2a89..1feea27eebc 100644 --- a/spec/services/projects/create_service_spec.rb +++ b/spec/services/projects/create_service_spec.rb @@ -348,6 +348,7 @@ describe Projects::CreateService, '#execute' do project = create_project(user, opts) expect(project.services.count).to eq 1 + expect(project.errors).to be_empty end end |