summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-07 15:07:34 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-07 15:07:34 +0000
commitb4028d450087e97f26d4baa23e08396bcbabe3e0 (patch)
treef84a5cbb29e43bab0ba58db1bc5619112c8c482e /spec
parent05f1d5d9813332bdd456cb358517e56168a24224 (diff)
downloadgitlab-ce-b4028d450087e97f26d4baa23e08396bcbabe3e0.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/tree_controller_spec.rb28
-rw-r--r--spec/controllers/projects_controller_spec.rb30
-rw-r--r--spec/features/projects/jobs_spec.rb15
-rw-r--r--spec/fixtures/api/schemas/public_api/v4/service.json22
-rw-r--r--spec/fixtures/api/schemas/public_api/v4/services.json4
-rw-r--r--spec/javascripts/sidebar/participants_spec.js17
-rw-r--r--spec/lib/gitlab/background_migration/migrate_fingerprint_sha256_within_keys_spec.rb74
-rw-r--r--spec/migrations/update_fingerprint_sha256_within_keys_spec.rb30
-rw-r--r--spec/models/ci/build_spec.rb6
-rw-r--r--spec/requests/api/services_spec.rb31
10 files changed, 257 insertions, 0 deletions
diff --git a/spec/controllers/projects/tree_controller_spec.rb b/spec/controllers/projects/tree_controller_spec.rb
index c0c11db5dd6..7c9abdf700b 100644
--- a/spec/controllers/projects/tree_controller_spec.rb
+++ b/spec/controllers/projects/tree_controller_spec.rb
@@ -89,6 +89,34 @@ describe Projects::TreeController do
end
end
+ describe "GET show" do
+ context 'lfs_blob_ids instance variable' do
+ let(:id) { 'master' }
+
+ context 'with vue tree view enabled' do
+ before do
+ get(:show, params: { namespace_id: project.namespace.to_param, project_id: project, id: id })
+ end
+
+ it 'is not set' do
+ expect(assigns[:lfs_blob_ids]).to be_nil
+ end
+ end
+
+ context 'with vue tree view disabled' do
+ before do
+ stub_feature_flags(vue_file_list: false)
+
+ get(:show, params: { namespace_id: project.namespace.to_param, project_id: project, id: id })
+ end
+
+ it 'is set' do
+ expect(assigns[:lfs_blob_ids]).not_to be_nil
+ end
+ end
+ end
+ end
+
describe 'GET show with whitespace in ref' do
render_views
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index 5259c612bbd..9ae1277de26 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -289,6 +289,36 @@ describe ProjectsController do
.not_to exceed_query_limit(2).for_query(expected_query)
end
end
+
+ context 'lfs_blob_ids instance variable' do
+ let(:project) { create(:project, :public, :repository) }
+
+ before do
+ sign_in(user)
+ end
+
+ context 'with vue tree view enabled' do
+ before do
+ get :show, params: { namespace_id: project.namespace, id: project }
+ end
+
+ it 'is not set' do
+ expect(assigns[:lfs_blob_ids]).to be_nil
+ end
+ end
+
+ context 'with vue tree view disabled' do
+ before do
+ stub_feature_flags(vue_file_list: false)
+
+ get :show, params: { namespace_id: project.namespace, id: project }
+ end
+
+ it 'is set' do
+ expect(assigns[:lfs_blob_ids]).not_to be_nil
+ end
+ end
+ end
end
describe 'GET edit' do
diff --git a/spec/features/projects/jobs_spec.rb b/spec/features/projects/jobs_spec.rb
index 26ba7ae7a29..f9ff076a416 100644
--- a/spec/features/projects/jobs_spec.rb
+++ b/spec/features/projects/jobs_spec.rb
@@ -306,6 +306,21 @@ describe 'Jobs', :clean_gitlab_redis_shared_state do
end
end
+ context 'when job is waiting for resource', :js do
+ let(:job) { create(:ci_build, :waiting_for_resource, pipeline: pipeline, resource_group: resource_group) }
+ let(:resource_group) { create(:ci_resource_group, project: project) }
+
+ before do
+ visit project_job_path(project, job)
+ wait_for_requests
+ end
+
+ it 'shows correct UI components' do
+ expect(page).to have_content("This job is waiting for resource: #{resource_group.key}")
+ expect(page).to have_link("Cancel this job")
+ end
+ end
+
context "Job from other project" do
before do
visit project_job_path(project, job2)
diff --git a/spec/fixtures/api/schemas/public_api/v4/service.json b/spec/fixtures/api/schemas/public_api/v4/service.json
new file mode 100644
index 00000000000..4a91d264961
--- /dev/null
+++ b/spec/fixtures/api/schemas/public_api/v4/service.json
@@ -0,0 +1,22 @@
+{
+ "type": "object",
+ "properties": {
+ "id": { "type": "integer" },
+ "title": { "type": "string" },
+ "created_at": { "type": "date-time" },
+ "updated_at": { "type": "date-time" },
+ "active": { "type": "boolean" },
+ "commit_events": { "type": "boolean" },
+ "push_events": { "type": "boolean" },
+ "issues_events": { "type": "boolean" },
+ "confidential_issues_events": { "type": "boolean" },
+ "merge_requests_events": { "type": "boolean" },
+ "tag_push_events": { "type": "boolean" },
+ "note_events": { "type": "boolean" },
+ "confidential_note_events": { "type": "boolean" },
+ "pipeline_events": { "type": "boolean" },
+ "wiki_page_events": { "type": "boolean" },
+ "job_events": { "type": "boolean" }
+ },
+ "additionalProperties": false
+}
diff --git a/spec/fixtures/api/schemas/public_api/v4/services.json b/spec/fixtures/api/schemas/public_api/v4/services.json
new file mode 100644
index 00000000000..78c59ecfa10
--- /dev/null
+++ b/spec/fixtures/api/schemas/public_api/v4/services.json
@@ -0,0 +1,4 @@
+{
+ "type": "array",
+ "items": { "$ref": "service.json" }
+}
diff --git a/spec/javascripts/sidebar/participants_spec.js b/spec/javascripts/sidebar/participants_spec.js
index 8d8ec5884f6..7e80e86f8ca 100644
--- a/spec/javascripts/sidebar/participants_spec.js
+++ b/spec/javascripts/sidebar/participants_spec.js
@@ -182,4 +182,21 @@ describe('Participants', function() {
expect(vm.$emit).toHaveBeenCalledWith('toggleSidebar');
});
});
+
+ describe('when not showing participants label', () => {
+ beforeEach(() => {
+ vm = mountComponent(Participants, {
+ participants: PARTICIPANT_LIST,
+ showParticipantLabel: false,
+ });
+ });
+
+ it('does not show sidebar collapsed icon', () => {
+ expect(vm.$el.querySelector('.sidebar-collapsed-icon')).not.toBeTruthy();
+ });
+
+ it('does not show participants label title', () => {
+ expect(vm.$el.querySelector('.title')).not.toBeTruthy();
+ });
+ });
});
diff --git a/spec/lib/gitlab/background_migration/migrate_fingerprint_sha256_within_keys_spec.rb b/spec/lib/gitlab/background_migration/migrate_fingerprint_sha256_within_keys_spec.rb
new file mode 100644
index 00000000000..3101e782b8f
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/migrate_fingerprint_sha256_within_keys_spec.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::BackgroundMigration::MigrateFingerprintSha256WithinKeys, :migration, schema: 20200106071113 do
+ subject(:fingerprint_migrator) { described_class.new }
+
+ let(:key_table) { table(:keys) }
+
+ before do
+ generate_fingerprints!
+ end
+
+ it 'correctly creates a sha256 fingerprint for a key' do
+ key_1 = Key.find(1017)
+ key_2 = Key.find(1027)
+
+ expect(key_1.fingerprint_md5).to eq('ba:81:59:68:d7:6c:cd:02:02:bf:6a:9b:55:4e:af:d1')
+ expect(key_1.fingerprint_sha256).to eq(nil)
+
+ expect(key_2.fingerprint_md5).to eq('39:e3:64:a6:24:ea:45:a2:8c:55:2a:e9:4d:4f:1f:b4')
+ expect(key_2.fingerprint_sha256).to eq(nil)
+
+ query_count = ActiveRecord::QueryRecorder.new do
+ fingerprint_migrator.perform(1, 10000)
+ end.count
+
+ expect(query_count).to eq(8)
+
+ key_1.reload
+ key_2.reload
+
+ expect(key_1.fingerprint_md5).to eq('ba:81:59:68:d7:6c:cd:02:02:bf:6a:9b:55:4e:af:d1')
+ expect(key_1.fingerprint_sha256).to eq('nUhzNyftwADy8AH3wFY31tAKs7HufskYTte2aXo/lCg')
+
+ expect(key_2.fingerprint_md5).to eq('39:e3:64:a6:24:ea:45:a2:8c:55:2a:e9:4d:4f:1f:b4')
+ expect(key_2.fingerprint_sha256).to eq('zMNbLekgdjtcgDv8VSC0z5lpdACMG3Q4PUoIz5+H2jM')
+ end
+
+ it 'migrates all keys' do
+ expect(Key.where(fingerprint_sha256: nil).count).to eq(Key.all.count)
+
+ fingerprint_migrator.perform(1, 10000)
+
+ expect(Key.where(fingerprint_sha256: nil).count).to eq(0)
+ end
+
+ def generate_fingerprints!
+ values = ""
+ (1000..2000).to_a.each do |record|
+ key = base_key_for(record)
+ fingerprint = fingerprint_for(key)
+
+ values += "(#{record}, #{record}, 'test-#{record}', '#{key}', '#{fingerprint}'),"
+ end
+
+ update_query = <<~SQL
+ INSERT INTO keys ( id, user_id, title, key, fingerprint )
+ VALUES
+ #{values.chomp(",")};
+ SQL
+
+ ActiveRecord::Base.connection.execute(update_query)
+ end
+
+ def base_key_for(record)
+ 'ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt0000k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0='
+ .gsub("0000", "%04d" % (record - 1)) # generate arbitrary keys with placeholder 0000 within the key above
+ end
+
+ def fingerprint_for(key)
+ Gitlab::SSHPublicKey.new(key).fingerprint("md5")
+ end
+end
diff --git a/spec/migrations/update_fingerprint_sha256_within_keys_spec.rb b/spec/migrations/update_fingerprint_sha256_within_keys_spec.rb
new file mode 100644
index 00000000000..bdb661af904
--- /dev/null
+++ b/spec/migrations/update_fingerprint_sha256_within_keys_spec.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require Rails.root.join('db', 'post_migrate', '20200106071113_update_fingerprint_sha256_within_keys.rb')
+
+describe UpdateFingerprintSha256WithinKeys, :sidekiq, :migration do
+ let(:key_table) { table(:keys) }
+
+ describe '#up' do
+ it 'the BackgroundMigrationWorker will be triggered and fingerprint_sha256 populated' do
+ key_table.create!(
+ id: 1,
+ user_id: 1,
+ title: 'test',
+ key: 'ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt1016k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=',
+ fingerprint: 'ba:81:59:68:d7:6c:cd:02:02:bf:6a:9b:55:4e:af:d1',
+ fingerprint_sha256: nil
+ )
+
+ expect(Key.first.fingerprint_sha256).to eq(nil)
+
+ described_class.new.up
+
+ expect(BackgroundMigrationWorker.jobs.size).to eq(1)
+ expect(BackgroundMigrationWorker.jobs.first["args"][0]).to eq("MigrateFingerprintSha256WithinKeys")
+ expect(BackgroundMigrationWorker.jobs.first["args"][1]).to eq([1, 1])
+ end
+ end
+end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 5fabdd9c6c5..b6006fa9bb7 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -1610,6 +1610,12 @@ describe Ci::Build do
it { is_expected.to be_cancelable }
end
+
+ context 'when build is waiting for resource' do
+ let(:build) { create(:ci_build, :waiting_for_resource) }
+
+ it { is_expected.to be_cancelable }
+ end
end
context 'when build is not cancelable' do
diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb
index 7c7620389b4..26407e8a45e 100644
--- a/spec/requests/api/services_spec.rb
+++ b/spec/requests/api/services_spec.rb
@@ -10,6 +10,37 @@ describe API::Services do
create(:project, creator_id: user.id, namespace: user.namespace)
end
+ describe "GET /projects/:id/services" do
+ it 'returns authentication error when unauthenticated' do
+ get api("/projects/#{project.id}/services")
+
+ expect(response).to have_gitlab_http_status(401)
+ end
+
+ it "returns error when authenticated but user is not a project owner" do
+ project.add_developer(user2)
+ get api("/projects/#{project.id}/services", user2)
+
+ expect(response).to have_gitlab_http_status(403)
+ end
+
+ context 'project with services' do
+ let!(:active_service) { create(:emails_on_push_service, project: project, active: true) }
+ let!(:service) { create(:custom_issue_tracker_service, project: project, active: false) }
+
+ it "returns a list of all active services" do
+ get api("/projects/#{project.id}/services", user)
+
+ aggregate_failures 'expect successful response with all active services' do
+ expect(response).to have_gitlab_http_status(200)
+ expect(json_response).to be_an Array
+ expect(json_response.count).to eq(1)
+ expect(response).to match_response_schema('public_api/v4/services')
+ end
+ end
+ end
+ end
+
Service.available_services_names.each do |service|
describe "PUT /projects/:id/services/#{service.dasherize}" do
include_context service