Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-07 03:09:12 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-07 03:09:12 +0300
commit6168721025dd8e98caeb2bf6844273e6690eaf69 (patch)
tree8c4fb20d793669e488a739bc9951dab8b363eed4 /spec/workers
parenta89cb5cbdd832d4d9e80517973aceda6bc0a3856 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers')
-rw-r--r--spec/workers/create_commit_signature_worker_spec.rb (renamed from spec/workers/create_gpg_signature_worker_spec.rb)45
1 files changed, 43 insertions, 2 deletions
diff --git a/spec/workers/create_gpg_signature_worker_spec.rb b/spec/workers/create_commit_signature_worker_spec.rb
index 2504a6474db..d7235fcd907 100644
--- a/spec/workers/create_gpg_signature_worker_spec.rb
+++ b/spec/workers/create_commit_signature_worker_spec.rb
@@ -2,13 +2,14 @@
require 'spec_helper'
-describe CreateGpgSignatureWorker do
+describe CreateCommitSignatureWorker do
let(:project) { create(:project, :repository) }
let(:commits) { project.repository.commits('HEAD', limit: 3).commits }
let(:commit_shas) { commits.map(&:id) }
let(:gpg_commit) { instance_double(Gitlab::Gpg::Commit) }
+ let(:x509_commit) { instance_double(Gitlab::X509::Commit) }
- context 'when GpgKey is found' do
+ context 'when a signature is found' do
before do
allow(Project).to receive(:find_by).with(id: project.id).and_return(project)
allow(project).to receive(:commits_by).with(oids: commit_shas).and_return(commits)
@@ -18,6 +19,7 @@ describe CreateGpgSignatureWorker do
it 'calls Gitlab::Gpg::Commit#signature' do
commits.each do |commit|
+ allow(commit).to receive(:signature_type).and_return(:PGP)
expect(Gitlab::Gpg::Commit).to receive(:new).with(commit).and_return(gpg_commit).once
end
@@ -31,13 +33,46 @@ describe CreateGpgSignatureWorker do
allow(Gitlab::Gpg::Commit).to receive(:new).and_return(gpg_commit)
allow(Gitlab::Gpg::Commit).to receive(:new).with(commits.first).and_raise(StandardError)
+ allow(commits[1]).to receive(:signature_type).and_return(:PGP)
+ allow(commits[2]).to receive(:signature_type).and_return(:PGP)
+
expect(gpg_commit).to receive(:signature).twice
subject
end
+
+ it 'calls Gitlab::X509::Commit#signature' do
+ commits.each do |commit|
+ allow(commit).to receive(:signature_type).and_return(:X509)
+ expect(Gitlab::X509::Commit).to receive(:new).with(commit).and_return(x509_commit).once
+ end
+
+ expect(x509_commit).to receive(:signature).exactly(commits.size).times
+
+ subject
+ end
+
+ it 'can recover from exception and continue the X509 signature process' do
+ allow(x509_commit).to receive(:signature)
+ allow(Gitlab::X509::Commit).to receive(:new).and_return(x509_commit)
+ allow(Gitlab::X509::Commit).to receive(:new).with(commits.first).and_raise(StandardError)
+
+ allow(commits[1]).to receive(:signature_type).and_return(:X509)
+ allow(commits[2]).to receive(:signature_type).and_return(:X509)
+
+ expect(x509_commit).to receive(:signature).twice
+
+ subject
+ end
end
context 'handles when a string is passed in for the commit SHA' do
+ before do
+ allow(Project).to receive(:find_by).with(id: project.id).and_return(project)
+ allow(project).to receive(:commits_by).with(oids: Array(commit_shas.first)).and_return(commits)
+ allow(commits.first).to receive(:signature_type).and_return(:PGP)
+ end
+
it 'creates a signature once' do
allow(Gitlab::Gpg::Commit).to receive(:new).with(commits.first).and_return(gpg_commit)
@@ -67,5 +102,11 @@ describe CreateGpgSignatureWorker do
described_class.new.perform(commit_shas, nonexisting_project_id)
end
+
+ it 'does not call Gitlab::X509::Commit#signature' do
+ expect_any_instance_of(Gitlab::X509::Commit).not_to receive(:signature)
+
+ described_class.new.perform(commit_shas, nonexisting_project_id)
+ end
end
end