summaryrefslogtreecommitdiff
path: root/spec/services/keys/revoke_service_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-24 15:07:34 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-24 15:07:34 +0000
commitdf9890e9a702e2f12bbc8f022b916ca72820a292 (patch)
tree26ff255cfb6843fe963fcafea9ee70121ee5e913 /spec/services/keys/revoke_service_spec.rb
parent17c1c66eefd05243dd8ed2c8fd49d17ab1a52522 (diff)
downloadgitlab-ce-df9890e9a702e2f12bbc8f022b916ca72820a292.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/keys/revoke_service_spec.rb')
-rw-r--r--spec/services/keys/revoke_service_spec.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/services/keys/revoke_service_spec.rb b/spec/services/keys/revoke_service_spec.rb
new file mode 100644
index 00000000000..ec07701b4b7
--- /dev/null
+++ b/spec/services/keys/revoke_service_spec.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Keys::RevokeService, feature_category: :source_code_management do
+ let(:user) { create(:user) }
+
+ subject(:service) { described_class.new(user) }
+
+ it 'destroys a key' do
+ key = create(:key)
+
+ expect { service.execute(key) }.to change { key.persisted? }.from(true).to(false)
+ end
+
+ it 'unverifies associated signatures' do
+ key = create(:key)
+ signature = create(:ssh_signature, key: key)
+
+ expect do
+ service.execute(key)
+ end.to change { signature.reload.key }.from(key).to(nil)
+ .and change { signature.reload.verification_status }.from('verified').to('revoked_key')
+ end
+
+ it 'does not unverifies signatures if destroy fails' do
+ key = create(:key)
+ signature = create(:ssh_signature, key: key)
+
+ expect(key).to receive(:destroy).and_return(false)
+
+ expect { service.execute(key) }.not_to change { signature.reload.verification_status }
+ expect(key).to be_persisted
+ end
+
+ context 'when revoke_ssh_signatures disabled' do
+ before do
+ stub_feature_flags(revoke_ssh_signatures: false)
+ end
+
+ it 'does not unverifies signatures' do
+ key = create(:key)
+ signature = create(:ssh_signature, key: key)
+
+ expect { service.execute(key) }.not_to change { signature.reload.verification_status }
+ end
+ end
+end