debian-mirror-gitlab/spec/lib/gitlab/x509/commit_spec.rb

59 lines
2 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::X509::Commit do
2022-08-13 15:12:31 +05:30
let(:commit_sha) { '189a6c924013fc3fe40d6f1ec1dc20214183bc97' }
let(:user) { create(:user, email: X509Helpers::User1.certificate_email) }
let(:project) { create(:project, :repository, path: X509Helpers::User1.path, creator: user) }
let(:commit) { project.commit_by(oid: commit_sha ) }
let(:signature) { Gitlab::X509::Commit.new(commit).signature }
let(:store) { OpenSSL::X509::Store.new }
let(:certificate) { OpenSSL::X509::Certificate.new(X509Helpers::User1.trust_cert) }
2020-03-13 15:44:24 +05:30
2022-08-13 15:12:31 +05:30
before do
store.add_cert(certificate) if certificate
allow(OpenSSL::X509::Store).to receive(:new).and_return(store)
end
2020-03-13 15:44:24 +05:30
2022-08-13 15:12:31 +05:30
describe '#signature' do
context 'returns the cached signature' do
2020-04-22 19:07:51 +05:30
it 'on second call' do
allow_any_instance_of(described_class).to receive(:new).and_call_original
expect_any_instance_of(described_class).to receive(:create_cached_signature!).and_call_original
2020-03-13 15:44:24 +05:30
signature
# consecutive call
2020-04-22 19:07:51 +05:30
expect(described_class).not_to receive(:create_cached_signature!).and_call_original
2020-03-13 15:44:24 +05:30
signature
end
end
context 'unsigned commit' do
2022-08-13 15:12:31 +05:30
let(:project) { create :project, :repository, path: X509Helpers::User1.path }
let(:commit_sha) { X509Helpers::User1.commit }
let(:commit) { create :commit, project: project, sha: commit_sha }
2020-03-13 15:44:24 +05:30
it 'returns nil' do
2020-04-22 19:07:51 +05:30
expect(signature).to be_nil
2020-03-28 13:19:24 +05:30
end
end
2020-03-13 15:44:24 +05:30
end
2022-08-13 15:12:31 +05:30
describe '#update_signature!' do
let(:certificate) { nil }
it 'updates verification status' do
signature
cert = OpenSSL::X509::Certificate.new(X509Helpers::User1.trust_cert)
store.add_cert(cert)
stored_signature = CommitSignatures::X509CommitSignature.find_by_commit_sha(commit_sha)
expect { described_class.new(commit).update_signature!(stored_signature) }.to(
change { signature.reload.verification_status }.from('unverified').to('verified')
)
end
end
2020-03-13 15:44:24 +05:30
end