summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/pipelines_controller_spec.rb66
-rw-r--r--spec/features/discussion_comments/merge_request_spec.rb3
-rw-r--r--spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb3
-rw-r--r--spec/frontend/snippets/components/snippet_title_spec.js4
-rw-r--r--spec/lib/api/entities/release_spec.rb32
-rw-r--r--spec/lib/gitlab/authorized_keys_spec.rb4
-rw-r--r--spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb83
-rw-r--r--spec/lib/gitlab/shell_spec.rb224
-rw-r--r--spec/migrations/migrate_merge_request_mentions_to_db_spec.rb31
-rw-r--r--spec/models/ci/build_spec.rb23
-rw-r--r--spec/models/key_spec.rb49
-rw-r--r--spec/policies/project_policy_spec.rb2
-rw-r--r--spec/requests/api/deploy_tokens_spec.rb71
-rw-r--r--spec/requests/api/releases_spec.rb25
-rw-r--r--spec/requests/api/users_spec.rb24
-rw-r--r--spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb7
-rw-r--r--spec/workers/authorized_keys_worker_spec.rb55
-rw-r--r--spec/workers/gitlab_shell_worker_spec.rb33
18 files changed, 452 insertions, 287 deletions
diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb
index 71bb256cee9..3ddfdd478a3 100644
--- a/spec/controllers/projects/pipelines_controller_spec.rb
+++ b/spec/controllers/projects/pipelines_controller_spec.rb
@@ -10,6 +10,7 @@ describe Projects::PipelinesController do
let(:feature) { ProjectFeature::ENABLED }
before do
+ allow(Sidekiq.logger).to receive(:info)
stub_not_protect_default_branch
project.add_developer(user)
project.project_feature.update(builds_access_level: feature)
@@ -583,6 +584,71 @@ describe Projects::PipelinesController do
end
end
+ describe 'POST create' do
+ let(:project) { create(:project, :public, :repository) }
+
+ before do
+ project.add_developer(user)
+ project.project_feature.update(builds_access_level: feature)
+ end
+
+ context 'with a valid .gitlab-ci.yml file' do
+ before do
+ stub_ci_pipeline_yaml_file(YAML.dump({
+ test: {
+ stage: 'test',
+ script: 'echo'
+ }
+ }))
+ end
+
+ shared_examples 'creates a pipeline' do
+ it do
+ expect { post_request }.to change { project.ci_pipelines.count }.by(1)
+
+ pipeline = project.ci_pipelines.last
+ expected_redirect_path = Gitlab::Routing.url_helpers.project_pipeline_path(project, pipeline)
+ expect(pipeline).to be_pending
+ expect(response).to redirect_to(expected_redirect_path)
+ end
+ end
+
+ it_behaves_like 'creates a pipeline'
+
+ context 'when latest commit contains [ci skip]' do
+ before do
+ project.repository.create_file(user, 'new-file.txt', 'A new file',
+ message: '[skip ci] This is a test',
+ branch_name: 'master')
+ end
+
+ it_behaves_like 'creates a pipeline'
+ end
+ end
+
+ context 'with an invalid .gitlab-ci.yml file' do
+ before do
+ stub_ci_pipeline_yaml_file('invalid yaml file')
+ end
+
+ it 'does not persist a pipeline' do
+ expect { post_request }.not_to change { project.ci_pipelines.count }
+
+ expect(response).to have_gitlab_http_status(:ok)
+ end
+ end
+
+ def post_request
+ post :create, params: {
+ namespace_id: project.namespace,
+ project_id: project,
+ pipeline: {
+ ref: 'master'
+ }
+ }
+ end
+ end
+
describe 'POST retry.json' do
let!(:pipeline) { create(:ci_pipeline, :failed, project: project) }
let!(:build) { create(:ci_build, :failed, pipeline: pipeline) }
diff --git a/spec/features/discussion_comments/merge_request_spec.rb b/spec/features/discussion_comments/merge_request_spec.rb
index 96184593655..c5457522c8e 100644
--- a/spec/features/discussion_comments/merge_request_spec.rb
+++ b/spec/features/discussion_comments/merge_request_spec.rb
@@ -12,6 +12,9 @@ describe 'Thread Comments Merge Request', :js do
sign_in(user)
visit project_merge_request_path(project, merge_request)
+
+ # Wait for MR widget to load
+ wait_for_requests
end
it_behaves_like 'thread comments', 'merge request'
diff --git a/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb b/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb
index 38a31d3bbd9..b8a5a4036a5 100644
--- a/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb
+++ b/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb
@@ -568,5 +568,8 @@ describe 'Merge request > User resolves diff notes and threads', :js do
def visit_merge_request(mr = nil)
mr ||= merge_request
visit project_merge_request_path(mr.project, mr)
+
+ # Wait for MR widget to load
+ wait_for_requests
end
end
diff --git a/spec/frontend/snippets/components/snippet_title_spec.js b/spec/frontend/snippets/components/snippet_title_spec.js
index a7efa4ae341..b49b2008610 100644
--- a/spec/frontend/snippets/components/snippet_title_spec.js
+++ b/spec/frontend/snippets/components/snippet_title_spec.js
@@ -6,10 +6,12 @@ describe('Snippet header component', () => {
let wrapper;
const title = 'The property of Thor';
const description = 'Do not touch this hammer';
+ const descriptionHtml = `<h2>${description}</h2>`;
const snippet = {
snippet: {
title,
description,
+ descriptionHtml,
},
};
@@ -35,7 +37,7 @@ describe('Snippet header component', () => {
it('renders snippets title and description', () => {
createComponent();
expect(wrapper.text().trim()).toContain(title);
- expect(wrapper.text().trim()).toContain(description);
+ expect(wrapper.find('.js-snippet-description').element.innerHTML).toBe(descriptionHtml);
});
it('does not render recent changes time stamp if there were no updates', () => {
diff --git a/spec/lib/api/entities/release_spec.rb b/spec/lib/api/entities/release_spec.rb
index 729a69347cb..f0bbaa35efe 100644
--- a/spec/lib/api/entities/release_spec.rb
+++ b/spec/lib/api/entities/release_spec.rb
@@ -4,13 +4,14 @@ require 'spec_helper'
describe API::Entities::Release do
let_it_be(:project) { create(:project) }
- let_it_be(:release) { create(:release, :with_evidence, project: project) }
- let(:user) { create(:user) }
+ let_it_be(:user) { create(:user) }
let(:entity) { described_class.new(release, current_user: user) }
- subject { entity.as_json }
-
describe 'evidence' do
+ let(:release) { create(:release, :with_evidence, project: project) }
+
+ subject { entity.as_json }
+
context 'when the current user can download code' do
it 'exposes the evidence sha and the json path' do
allow(Ability).to receive(:allowed?).and_call_original
@@ -37,4 +38,27 @@ describe API::Entities::Release do
end
end
end
+
+ describe 'description_html' do
+ let(:issue) { create(:issue, :confidential, project: project) }
+ let(:issue_path) { Gitlab::Routing.url_helpers.project_issue_path(project, issue) }
+ let(:issue_title) { 'title="%s"' % issue.title }
+ let(:release) { create(:release, project: project, description: "Now shipping #{issue.to_reference}") }
+
+ subject(:description_html) { entity.as_json[:description_html] }
+
+ it 'renders special references if current user has access' do
+ project.add_reporter(user)
+
+ expect(description_html).to include(issue_path)
+ expect(description_html).to include(issue_title)
+ end
+
+ it 'does not render special references if current user has no access' do
+ project.add_guest(user)
+
+ expect(description_html).not_to include(issue_path)
+ expect(description_html).not_to include(issue_title)
+ end
+ end
end
diff --git a/spec/lib/gitlab/authorized_keys_spec.rb b/spec/lib/gitlab/authorized_keys_spec.rb
index adf36cf1050..d89eb9ef114 100644
--- a/spec/lib/gitlab/authorized_keys_spec.rb
+++ b/spec/lib/gitlab/authorized_keys_spec.rb
@@ -162,10 +162,10 @@ describe Gitlab::AuthorizedKeys do
end
end
- describe '#rm_key' do
+ describe '#remove_key' do
let(:key) { 'key-741' }
- subject { authorized_keys.rm_key(key) }
+ subject { authorized_keys.remove_key(key) }
context 'authorized_keys file exists' do
let(:other_line) { "command=\"#{Gitlab.config.gitlab_shell.path}/bin/gitlab-shell key-742\",options ssh-rsa AAAAB3NzaDAxx2E" }
diff --git a/spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb b/spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb
new file mode 100644
index 00000000000..42e446c07c1
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb
@@ -0,0 +1,83 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require './db/post_migrate/20200211155539_migrate_merge_request_mentions_to_db'
+
+describe Gitlab::BackgroundMigration::UserMentions::CreateResourceUserMention, schema: 20200211155539 do
+ include MigrationsHelpers
+
+ context 'when migrating data' do
+ let(:users) { table(:users) }
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+ let(:notes) { table(:notes) }
+
+ let(:author) { users.create!(email: 'author@example.com', notification_email: 'author@example.com', name: 'author', username: 'author', projects_limit: 10, state: 'active') }
+ let(:member) { users.create!(email: 'member@example.com', notification_email: 'member@example.com', name: 'member', username: 'member', projects_limit: 10, state: 'active') }
+ let(:admin) { users.create!(email: 'administrator@example.com', notification_email: 'administrator@example.com', name: 'administrator', username: 'administrator', admin: 1, projects_limit: 10, state: 'active') }
+ let(:john_doe) { users.create!(email: 'john_doe@example.com', notification_email: 'john_doe@example.com', name: 'john_doe', username: 'john_doe', projects_limit: 10, state: 'active') }
+ let(:skipped) { users.create!(email: 'skipped@example.com', notification_email: 'skipped@example.com', name: 'skipped', username: 'skipped', projects_limit: 10, state: 'active') }
+
+ let(:mentioned_users) { [author, member, admin, john_doe, skipped] }
+ let(:mentioned_users_refs) { mentioned_users.map { |u| "@#{u.username}" }.join(' ') }
+
+ let(:group) { namespaces.create!(name: 'test1', path: 'test1', runners_token: 'my-token1', project_creation_level: 1, visibility_level: 20, type: 'Group') }
+ let(:inaccessible_group) { namespaces.create!(name: 'test2', path: 'test2', runners_token: 'my-token2', project_creation_level: 1, visibility_level: 0, type: 'Group') }
+ let(:project) { projects.create!(name: 'gitlab1', path: 'gitlab1', namespace_id: group.id, visibility_level: 0) }
+
+ let(:mentioned_groups) { [group, inaccessible_group] }
+ let(:group_mentions) { [group, inaccessible_group].map { |gr| "@#{gr.path}" }.join(' ') }
+ let(:description_mentions) { "description with mentions #{mentioned_users_refs} and #{group_mentions}" }
+
+ before do
+ # build personal namespaces and routes for users
+ mentioned_users.each { |u| u.becomes(User).save! }
+
+ # build namespaces and routes for groups
+ mentioned_groups.each do |gr|
+ gr.name += '-org'
+ gr.path += '-org'
+ gr.becomes(Namespace).save!
+ end
+ end
+
+ context 'migrate merge request mentions' do
+ let(:merge_requests) { table(:merge_requests) }
+ let(:merge_request_user_mentions) { table(:merge_request_user_mentions) }
+
+ let!(:mr1) do
+ merge_requests.create!(
+ title: "title 1", state_id: 1, target_branch: 'feature1', source_branch: 'master',
+ source_project_id: project.id, target_project_id: project.id, author_id: author.id,
+ description: description_mentions
+ )
+ end
+
+ let!(:mr2) do
+ merge_requests.create!(
+ title: "title 2", state_id: 1, target_branch: 'feature2', source_branch: 'master',
+ source_project_id: project.id, target_project_id: project.id, author_id: author.id,
+ description: 'some description'
+ )
+ end
+
+ let!(:mr3) do
+ merge_requests.create!(
+ title: "title 3", state_id: 1, target_branch: 'feature3', source_branch: 'master',
+ source_project_id: project.id, target_project_id: project.id, author_id: author.id,
+ description: 'description with an email@example.com and some other @ char here.')
+ end
+
+ let(:user_mentions) { merge_request_user_mentions }
+ let(:resource) { merge_request }
+
+ it_behaves_like 'resource mentions migration', MigrateMergeRequestMentionsToDb, MergeRequest
+ end
+ end
+
+ context 'checks no_quote_columns' do
+ it 'has correct no_quote_columns' do
+ expect(Gitlab::BackgroundMigration::UserMentions::Models::MergeRequest.no_quote_columns).to match([:note_id, :merge_request_id])
+ end
+ end
+end
diff --git a/spec/lib/gitlab/shell_spec.rb b/spec/lib/gitlab/shell_spec.rb
index 19ffb6440be..280d4fba5a2 100644
--- a/spec/lib/gitlab/shell_spec.rb
+++ b/spec/lib/gitlab/shell_spec.rb
@@ -9,14 +9,11 @@ describe Gitlab::Shell do
let(:gitlab_shell) { described_class.new }
let(:popen_vars) { { 'GIT_TERMINAL_PROMPT' => ENV['GIT_TERMINAL_PROMPT'] } }
let(:timeout) { Gitlab.config.gitlab_shell.git_timeout }
- let(:gitlab_authorized_keys) { double }
before do
allow(Project).to receive(:find).and_return(project)
end
- it { is_expected.to respond_to :add_key }
- it { is_expected.to respond_to :remove_key }
it { is_expected.to respond_to :create_repository }
it { is_expected.to respond_to :remove_repository }
it { is_expected.to respond_to :fork_repository }
@@ -49,227 +46,6 @@ describe Gitlab::Shell do
end
end
- describe '#add_key' do
- context 'when authorized_keys_enabled is true' do
- it 'calls Gitlab::AuthorizedKeys#add_key with id and key' do
- expect(Gitlab::AuthorizedKeys).to receive(:new).and_return(gitlab_authorized_keys)
-
- expect(gitlab_authorized_keys)
- .to receive(:add_key)
- .with('key-123', 'ssh-rsa foobar')
-
- gitlab_shell.add_key('key-123', 'ssh-rsa foobar')
- end
- end
-
- context 'when authorized_keys_enabled is false' do
- before do
- stub_application_setting(authorized_keys_enabled: false)
- end
-
- it 'does nothing' do
- expect(Gitlab::AuthorizedKeys).not_to receive(:new)
-
- gitlab_shell.add_key('key-123', 'ssh-rsa foobar trailing garbage')
- end
- end
-
- context 'when authorized_keys_enabled is nil' do
- before do
- stub_application_setting(authorized_keys_enabled: nil)
- end
-
- it 'calls Gitlab::AuthorizedKeys#add_key with id and key' do
- expect(Gitlab::AuthorizedKeys).to receive(:new).and_return(gitlab_authorized_keys)
-
- expect(gitlab_authorized_keys)
- .to receive(:add_key)
- .with('key-123', 'ssh-rsa foobar')
-
- gitlab_shell.add_key('key-123', 'ssh-rsa foobar')
- end
- end
- end
-
- describe '#batch_add_keys' do
- let(:keys) { [double(shell_id: 'key-123', key: 'ssh-rsa foobar')] }
-
- context 'when authorized_keys_enabled is true' do
- it 'calls Gitlab::AuthorizedKeys#batch_add_keys with keys to be added' do
- expect(Gitlab::AuthorizedKeys).to receive(:new).and_return(gitlab_authorized_keys)
-
- expect(gitlab_authorized_keys)
- .to receive(:batch_add_keys)
- .with(keys)
-
- gitlab_shell.batch_add_keys(keys)
- end
- end
-
- context 'when authorized_keys_enabled is false' do
- before do
- stub_application_setting(authorized_keys_enabled: false)
- end
-
- it 'does nothing' do
- expect(Gitlab::AuthorizedKeys).not_to receive(:new)
-
- gitlab_shell.batch_add_keys(keys)
- end
- end
-
- context 'when authorized_keys_enabled is nil' do
- before do
- stub_application_setting(authorized_keys_enabled: nil)
- end
-
- it 'calls Gitlab::AuthorizedKeys#batch_add_keys with keys to be added' do
- expect(Gitlab::AuthorizedKeys).to receive(:new).and_return(gitlab_authorized_keys)
-
- expect(gitlab_authorized_keys)
- .to receive(:batch_add_keys)
- .with(keys)
-
- gitlab_shell.batch_add_keys(keys)
- end
- end
- end
-
- describe '#remove_key' do
- context 'when authorized_keys_enabled is true' do
- it 'calls Gitlab::AuthorizedKeys#rm_key with the key to be removed' do
- expect(Gitlab::AuthorizedKeys).to receive(:new).and_return(gitlab_authorized_keys)
- expect(gitlab_authorized_keys).to receive(:rm_key).with('key-123')
-
- gitlab_shell.remove_key('key-123')
- end
- end
-
- context 'when authorized_keys_enabled is false' do
- before do
- stub_application_setting(authorized_keys_enabled: false)
- end
-
- it 'does nothing' do
- expect(Gitlab::AuthorizedKeys).not_to receive(:new)
-
- gitlab_shell.remove_key('key-123')
- end
- end
-
- context 'when authorized_keys_enabled is nil' do
- before do
- stub_application_setting(authorized_keys_enabled: nil)
- end
-
- it 'calls Gitlab::AuthorizedKeys#rm_key with the key to be removed' do
- expect(Gitlab::AuthorizedKeys).to receive(:new).and_return(gitlab_authorized_keys)
- expect(gitlab_authorized_keys).to receive(:rm_key).with('key-123')
-
- gitlab_shell.remove_key('key-123')
- end
- end
- end
-
- describe '#remove_all_keys' do
- context 'when authorized_keys_enabled is true' do
- it 'calls Gitlab::AuthorizedKeys#clear' do
- expect(Gitlab::AuthorizedKeys).to receive(:new).and_return(gitlab_authorized_keys)
- expect(gitlab_authorized_keys).to receive(:clear)
-
- gitlab_shell.remove_all_keys
- end
- end
-
- context 'when authorized_keys_enabled is false' do
- before do
- stub_application_setting(authorized_keys_enabled: false)
- end
-
- it 'does nothing' do
- expect(Gitlab::AuthorizedKeys).not_to receive(:new)
-
- gitlab_shell.remove_all_keys
- end
- end
-
- context 'when authorized_keys_enabled is nil' do
- before do
- stub_application_setting(authorized_keys_enabled: nil)
- end
-
- it 'calls Gitlab::AuthorizedKeys#clear' do
- expect(Gitlab::AuthorizedKeys).to receive(:new).and_return(gitlab_authorized_keys)
- expect(gitlab_authorized_keys).to receive(:clear)
-
- gitlab_shell.remove_all_keys
- end
- end
- end
-
- describe '#remove_keys_not_found_in_db' do
- context 'when keys are in the file that are not in the DB' do
- before do
- gitlab_shell.remove_all_keys
- gitlab_shell.add_key('key-1234', 'ssh-rsa ASDFASDF')
- gitlab_shell.add_key('key-9876', 'ssh-rsa ASDFASDF')
- @another_key = create(:key) # this one IS in the DB
- end
-
- it 'removes the keys' do
- expect(gitlab_shell).to receive(:remove_key).with('key-1234')
- expect(gitlab_shell).to receive(:remove_key).with('key-9876')
- expect(gitlab_shell).not_to receive(:remove_key).with("key-#{@another_key.id}")
-
- gitlab_shell.remove_keys_not_found_in_db
- end
- end
-
- context 'when keys there are duplicate keys in the file that are not in the DB' do
- before do
- gitlab_shell.remove_all_keys
- gitlab_shell.add_key('key-1234', 'ssh-rsa ASDFASDF')
- gitlab_shell.add_key('key-1234', 'ssh-rsa ASDFASDF')
- end
-
- it 'removes the keys' do
- expect(gitlab_shell).to receive(:remove_key).with('key-1234')
-
- gitlab_shell.remove_keys_not_found_in_db
- end
- end
-
- context 'when keys there are duplicate keys in the file that ARE in the DB' do
- before do
- gitlab_shell.remove_all_keys
- @key = create(:key)
- gitlab_shell.add_key(@key.shell_id, @key.key)
- end
-
- it 'does not remove the key' do
- expect(gitlab_shell).not_to receive(:remove_key).with("key-#{@key.id}")
-
- gitlab_shell.remove_keys_not_found_in_db
- end
- end
-
- unless ENV['CI'] # Skip in CI, it takes 1 minute
- context 'when the first batch can be skipped, but the next batch has keys that are not in the DB' do
- before do
- gitlab_shell.remove_all_keys
- 100.times { |i| create(:key) } # first batch is all in the DB
- gitlab_shell.add_key('key-1234', 'ssh-rsa ASDFASDF')
- end
-
- it 'removes the keys not in the DB' do
- expect(gitlab_shell).to receive(:remove_key).with('key-1234')
-
- gitlab_shell.remove_keys_not_found_in_db
- end
- end
- end
- end
-
describe 'projects commands' do
let(:gitlab_shell_path) { File.expand_path('tmp/tests/gitlab-shell') }
let(:projects_path) { File.join(gitlab_shell_path, 'bin/gitlab-projects') }
diff --git a/spec/migrations/migrate_merge_request_mentions_to_db_spec.rb b/spec/migrations/migrate_merge_request_mentions_to_db_spec.rb
new file mode 100644
index 00000000000..aef8fd6490b
--- /dev/null
+++ b/spec/migrations/migrate_merge_request_mentions_to_db_spec.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20200211155539_migrate_merge_request_mentions_to_db')
+
+describe MigrateMergeRequestMentionsToDb, :migration do
+ let(:users) { table(:users) }
+ let(:projects) { table(:projects) }
+ let(:namespaces) { table(:namespaces) }
+ let(:merge_requests) { table(:merge_requests) }
+ let(:merge_request_user_mentions) { table(:merge_request_user_mentions) }
+
+ let(:user) { users.create!(name: 'root', email: 'root@example.com', username: 'root', projects_limit: 0) }
+ let(:group) { namespaces.create!(name: 'group1', path: 'group1', owner_id: user.id, type: 'Group') }
+ let(:project) { projects.create!(name: 'gitlab1', path: 'gitlab1', namespace_id: group.id, visibility_level: 0) }
+
+ # migrateable resources
+ let(:common_args) { { source_branch: 'master', source_project_id: project.id, target_project_id: project.id, author_id: user.id, description: 'mr description with @root mention' } }
+ let!(:resource1) { merge_requests.create!(common_args.merge(title: "title 1", state_id: 1, target_branch: 'feature1')) }
+ let!(:resource2) { merge_requests.create!(common_args.merge(title: "title 2", state_id: 1, target_branch: 'feature2')) }
+ let!(:resource3) { merge_requests.create!(common_args.merge(title: "title 3", state_id: 1, target_branch: 'feature3')) }
+
+ # non-migrateable resources
+ # this merge request is already migrated, as it has a record in the merge_request_user_mentions table
+ let!(:resource4) { merge_requests.create!(common_args.merge(title: "title 3", state_id: 1, target_branch: 'feature3')) }
+ let!(:user_mention) { merge_request_user_mentions.create!(merge_request_id: resource4.id, mentioned_users_ids: [1]) }
+
+ let!(:resource5) { merge_requests.create!(common_args.merge(title: "title 3", description: 'description with no mention', state_id: 1, target_branch: 'feature3')) }
+
+ it_behaves_like 'schedules resource mentions migration', MergeRequest, false
+end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 757c158e16a..6c77b16f908 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -2542,6 +2542,8 @@ describe Ci::Build do
<<~ROUTEMAP
- source: 'bar/branch-test.txt'
public: '/bar/branches'
+ - source: 'with space/README.md'
+ public: '/README'
ROUTEMAP
end
@@ -2556,10 +2558,27 @@ describe Ci::Build do
let(:environment) { create(:environment, project: merge_request.project, name: "foo-#{project.default_branch}") }
let(:build) { create(:ci_build, pipeline: pipeline, environment: environment.name) }
+ let(:full_urls) do
+ [
+ File.join(environment.external_url, '/bar/branches'),
+ File.join(environment.external_url, '/README')
+ ]
+ end
+
it 'populates CI_MERGE_REQUEST_CHANGED_PAGES_* variables' do
expect(subject).to include(
- { key: 'CI_MERGE_REQUEST_CHANGED_PAGE_PATHS', value: '/bar/branches', public: true, masked: false },
- { key: 'CI_MERGE_REQUEST_CHANGED_PAGE_URLS', value: File.join(environment.external_url, '/bar/branches'), public: true, masked: false }
+ {
+ key: 'CI_MERGE_REQUEST_CHANGED_PAGE_PATHS',
+ value: '/bar/branches,/README',
+ public: true,
+ masked: false
+ },
+ {
+ key: 'CI_MERGE_REQUEST_CHANGED_PAGE_URLS',
+ value: full_urls.join(','),
+ public: true,
+ masked: false
+ }
)
end
diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb
index c9b41c9d82e..8cdedbcdedf 100644
--- a/spec/models/key_spec.rb
+++ b/spec/models/key_spec.rb
@@ -181,16 +181,49 @@ describe Key, :mailer do
end
context 'callbacks' do
- it 'adds new key to authorized_file' do
- key = build(:personal_key, id: 7)
- expect(GitlabShellWorker).to receive(:perform_async).with(:add_key, key.shell_id, key.key)
- key.save!
+ let(:key) { build(:personal_key) }
+
+ context 'authorized keys file is enabled' do
+ before do
+ stub_application_setting(authorized_keys_enabled: true)
+ end
+
+ it 'adds new key to authorized_file' do
+ allow(AuthorizedKeysWorker).to receive(:perform_async)
+
+ key.save!
+
+ # Check after the fact so we have access to Key#id
+ expect(AuthorizedKeysWorker).to have_received(:perform_async).with(:add_key, key.shell_id, key.key)
+ end
+
+ it 'removes key from authorized_file' do
+ key.save!
+
+ expect(AuthorizedKeysWorker).to receive(:perform_async).with(:remove_key, key.shell_id)
+
+ key.destroy
+ end
end
- it 'removes key from authorized_file' do
- key = create(:personal_key)
- expect(GitlabShellWorker).to receive(:perform_async).with(:remove_key, key.shell_id)
- key.destroy
+ context 'authorized_keys file is disabled' do
+ before do
+ stub_application_setting(authorized_keys_enabled: false)
+ end
+
+ it 'does not add the key on creation' do
+ expect(AuthorizedKeysWorker).not_to receive(:perform_async)
+
+ key.save!
+ end
+
+ it 'does not remove the key on destruction' do
+ key.save!
+
+ expect(AuthorizedKeysWorker).not_to receive(:perform_async)
+
+ key.destroy
+ end
end
end
diff --git a/spec/policies/project_policy_spec.rb b/spec/policies/project_policy_spec.rb
index 5f22208a3ac..e7d49377b78 100644
--- a/spec/policies/project_policy_spec.rb
+++ b/spec/policies/project_policy_spec.rb
@@ -52,7 +52,7 @@ describe ProjectPolicy do
admin_snippet admin_project_member admin_note admin_wiki admin_project
admin_commit_status admin_build admin_container_image
admin_pipeline admin_environment admin_deployment destroy_release add_cluster
- daily_statistics read_deploy_token create_deploy_token
+ daily_statistics read_deploy_token create_deploy_token destroy_deploy_token
]
end
diff --git a/spec/requests/api/deploy_tokens_spec.rb b/spec/requests/api/deploy_tokens_spec.rb
index fa46b8017cb..fa20635056f 100644
--- a/spec/requests/api/deploy_tokens_spec.rb
+++ b/spec/requests/api/deploy_tokens_spec.rb
@@ -148,21 +148,21 @@ describe API::DeployTokens do
end
end
- describe 'DELETE /groups/:id/deploy_tokens/:token_id' do
+ describe 'DELETE /projects/:id/deploy_tokens/:token_id' do
subject do
- delete api("/groups/#{group.id}/deploy_tokens/#{group_deploy_token.id}", user)
+ delete api("/projects/#{project.id}/deploy_tokens/#{deploy_token.id}", user)
response
end
context 'when unauthenticated' do
let(:user) { nil }
- it { is_expected.to have_gitlab_http_status(:forbidden) }
+ it { is_expected.to have_gitlab_http_status(:not_found) }
end
context 'when authenticated as non-admin user' do
before do
- group.add_developer(user)
+ project.add_developer(user)
end
it { is_expected.to have_gitlab_http_status(:forbidden) }
@@ -170,26 +170,26 @@ describe API::DeployTokens do
context 'when authenticated as maintainer' do
before do
- group.add_maintainer(user)
+ project.add_maintainer(user)
end
- it 'deletes the deploy token' do
- expect { subject }.to change { group.deploy_tokens.count }.by(-1)
+ it { is_expected.to have_gitlab_http_status(:no_content) }
- expect(group.deploy_tokens).to be_empty
+ it 'deletes the deploy token' do
+ expect { subject }.to change { project.deploy_tokens.count }.by(-1)
end
context 'invalid request' do
it 'returns not found with invalid group id' do
- delete api("/groups/bad_id/deploy_tokens/#{group_deploy_token.id}", user)
+ delete api("/projects/bad_id/deploy_tokens/#{group_deploy_token.id}", user)
expect(response).to have_gitlab_http_status(:not_found)
end
- it 'returns not found with invalid deploy token id' do
- delete api("/groups/#{group.id}/deploy_tokens/bad_id", user)
+ it 'returns bad_request with invalid token id' do
+ delete api("/projects/#{project.id}/deploy_tokens/123abc", user)
- expect(response).to have_gitlab_http_status(:not_found)
+ expect(response).to have_gitlab_http_status(:bad_request)
end
end
end
@@ -262,4 +262,51 @@ describe API::DeployTokens do
it_behaves_like 'creating a deploy token', :group, :forbidden
end
end
+
+ describe 'DELETE /groups/:id/deploy_tokens/:token_id' do
+ subject do
+ delete api("/groups/#{group.id}/deploy_tokens/#{group_deploy_token.id}", user)
+ response
+ end
+
+ context 'when unauthenticated' do
+ let(:user) { nil }
+
+ it { is_expected.to have_gitlab_http_status(:forbidden) }
+ end
+
+ context 'when authenticated as non-admin user' do
+ before do
+ group.add_developer(user)
+ end
+
+ it { is_expected.to have_gitlab_http_status(:forbidden) }
+ end
+
+ context 'when authenticated as maintainer' do
+ before do
+ group.add_maintainer(user)
+ end
+
+ it 'deletes the deploy token' do
+ expect { subject }.to change { group.deploy_tokens.count }.by(-1)
+
+ expect(group.deploy_tokens).to be_empty
+ end
+
+ context 'invalid request' do
+ it 'returns bad request with invalid group id' do
+ delete api("/groups/bad_id/deploy_tokens/#{group_deploy_token.id}", user)
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+
+ it 'returns not found with invalid deploy token id' do
+ delete api("/groups/#{group.id}/deploy_tokens/bad_id", user)
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+ end
+ end
end
diff --git a/spec/requests/api/releases_spec.rb b/spec/requests/api/releases_spec.rb
index 5de8d5aa3ff..4eb6e87c254 100644
--- a/spec/requests/api/releases_spec.rb
+++ b/spec/requests/api/releases_spec.rb
@@ -233,31 +233,6 @@ describe API::Releases do
.to match_array(release.sources.map(&:url))
end
- context "when release description contains confidential issue's link" do
- let(:confidential_issue) do
- create(:issue,
- :confidential,
- project: project,
- title: 'A vulnerability')
- end
-
- let!(:release) do
- create(:release,
- project: project,
- tag: 'v0.1',
- sha: commit.id,
- author: maintainer,
- description: "This is confidential #{confidential_issue.to_reference}")
- end
-
- it "does not expose confidential issue's title" do
- get api("/projects/#{project.id}/releases/v0.1", maintainer)
-
- expect(json_response['description_html']).to include(confidential_issue.to_reference)
- expect(json_response['description_html']).not_to include('A vulnerability')
- end
- end
-
context 'when release has link asset' do
let!(:link) do
create(:release_link,
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index 4a89069cbec..7d63a031666 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -330,6 +330,14 @@ describe API::Users, :do_not_mock_admin_mode do
expect(json_response.keys).not_to include 'last_sign_in_ip'
end
+ it "does not contain plan or trial data" do
+ get api("/users/#{user.id}", user)
+
+ expect(response).to match_response_schema('public_api/v4/user/basic')
+ expect(json_response.keys).not_to include 'plan'
+ expect(json_response.keys).not_to include 'trial'
+ end
+
context 'when job title is present' do
let(:job_title) { 'Fullstack Engineer' }
@@ -367,6 +375,22 @@ describe API::Users, :do_not_mock_admin_mode do
expect(json_response['highest_role']).to be(0)
end
+ if Gitlab.ee?
+ it 'does not include values for plan or trial' do
+ get api("/users/#{user.id}", admin)
+
+ expect(response).to match_response_schema('public_api/v4/user/basic')
+ end
+ else
+ it 'does not include plan or trial data' do
+ get api("/users/#{user.id}", admin)
+
+ expect(response).to match_response_schema('public_api/v4/user/basic')
+ expect(json_response.keys).not_to include 'plan'
+ expect(json_response.keys).not_to include 'trial'
+ end
+ end
+
context 'when user has not logged in' do
it 'does not include the sign in IPs' do
get api("/users/#{user.id}", admin)
diff --git a/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb
index 8f5bfdacc3a..a3f0c84bd1f 100644
--- a/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb
+++ b/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb
@@ -80,10 +80,11 @@ shared_examples 'schedules resource mentions migration' do |resource_class, is_f
migration = described_class::MIGRATION
join = described_class::JOIN
conditions = described_class::QUERY_CONDITIONS
+ delay = described_class::DELAY
- expect(migration).to be_scheduled_delayed_migration(2.minutes, resource_class.name, join, conditions, is_for_notes, resource1.id, resource1.id)
- expect(migration).to be_scheduled_delayed_migration(4.minutes, resource_class.name, join, conditions, is_for_notes, resource2.id, resource2.id)
- expect(migration).to be_scheduled_delayed_migration(6.minutes, resource_class.name, join, conditions, is_for_notes, resource3.id, resource3.id)
+ expect(migration).to be_scheduled_delayed_migration(1 * delay, resource_class.name, join, conditions, is_for_notes, resource1.id, resource1.id)
+ expect(migration).to be_scheduled_delayed_migration(2 * delay, resource_class.name, join, conditions, is_for_notes, resource2.id, resource2.id)
+ expect(migration).to be_scheduled_delayed_migration(3 * delay, resource_class.name, join, conditions, is_for_notes, resource3.id, resource3.id)
expect(BackgroundMigrationWorker.jobs.size).to eq 3
end
end
diff --git a/spec/workers/authorized_keys_worker_spec.rb b/spec/workers/authorized_keys_worker_spec.rb
new file mode 100644
index 00000000000..2aaa6fb2ddf
--- /dev/null
+++ b/spec/workers/authorized_keys_worker_spec.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe AuthorizedKeysWorker do
+ let(:worker) { described_class.new }
+
+ describe '#perform' do
+ context 'authorized_keys is enabled' do
+ before do
+ stub_application_setting(authorized_keys_enabled: true)
+ end
+
+ describe '#add_key' do
+ it 'delegates to Gitlab::AuthorizedKeys' do
+ expect_next_instance_of(Gitlab::AuthorizedKeys) do |instance|
+ expect(instance).to receive(:add_key).with('foo', 'bar')
+ end
+
+ worker.perform(:add_key, 'foo', 'bar')
+ end
+ end
+
+ describe '#remove_key' do
+ it 'delegates to Gitlab::AuthorizedKeys' do
+ expect_next_instance_of(Gitlab::AuthorizedKeys) do |instance|
+ expect(instance).to receive(:remove_key).with('foo', 'bar')
+ end
+
+ worker.perform(:remove_key, 'foo', 'bar')
+ end
+ end
+
+ describe 'all other commands' do
+ it 'does nothing' do
+ expect(Gitlab::AuthorizedKeys).not_to receive(:new)
+
+ worker.perform(:foo, 'bar', 'baz')
+ end
+ end
+ end
+
+ context 'authorized_keys is disabled' do
+ before do
+ stub_application_setting(authorized_keys_enabled: false)
+ end
+
+ it 'does nothing' do
+ expect(Gitlab::AuthorizedKeys).not_to receive(:new)
+
+ worker.perform(:add_key, 'foo', 'bar')
+ end
+ end
+ end
+end
diff --git a/spec/workers/gitlab_shell_worker_spec.rb b/spec/workers/gitlab_shell_worker_spec.rb
index 5dedf5be9fa..f5884e5e8f8 100644
--- a/spec/workers/gitlab_shell_worker_spec.rb
+++ b/spec/workers/gitlab_shell_worker_spec.rb
@@ -5,12 +5,35 @@ require 'spec_helper'
describe GitlabShellWorker do
let(:worker) { described_class.new }
- describe '#perform with add_key' do
- it 'calls add_key on Gitlab::Shell' do
- expect_next_instance_of(Gitlab::Shell) do |instance|
- expect(instance).to receive(:add_key).with('foo', 'bar')
+ describe '#perform' do
+ describe '#add_key' do
+ it 'delegates to Gitlab::AuthorizedKeys' do
+ expect_next_instance_of(Gitlab::AuthorizedKeys) do |instance|
+ expect(instance).to receive(:add_key).with('foo', 'bar')
+ end
+
+ worker.perform(:add_key, 'foo', 'bar')
+ end
+ end
+
+ describe '#remove_key' do
+ it 'delegates to Gitlab::AuthorizedKeys' do
+ expect_next_instance_of(Gitlab::AuthorizedKeys) do |instance|
+ expect(instance).to receive(:remove_key).with('foo', 'bar')
+ end
+
+ worker.perform(:remove_key, 'foo', 'bar')
+ end
+ end
+
+ describe 'all other commands' do
+ it 'delegates them to Gitlab::Shell' do
+ expect_next_instance_of(Gitlab::Shell) do |instance|
+ expect(instance).to receive(:foo).with('bar', 'baz')
+ end
+
+ worker.perform(:foo, 'bar', 'baz')
end
- worker.perform(:add_key, 'foo', 'bar')
end
end
end