debian-mirror-gitlab/spec/models/commit_signatures/x509_commit_signature_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.6 KiB
Ruby
Raw Permalink Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'spec_helper'
2022-01-26 12:08:38 +05:30
RSpec.describe CommitSignatures::X509CommitSignature do
2022-07-23 23:45:48 +05:30
# This commit is seeded from https://gitlab.com/gitlab-org/gitlab-test
# For instructions on how to add more seed data, see the project README
2022-10-11 01:57:18 +05:30
let_it_be(:commit_sha) { '189a6c924013fc3fe40d6f1ec1dc20214183bc97' }
let_it_be(:project) { create(:project, :public, :repository) }
let_it_be(:commit) { create(:commit, project: project, sha: commit_sha) }
let_it_be(:x509_certificate) { create(:x509_certificate) }
2020-03-13 15:44:24 +05:30
2020-05-24 23:13:21 +05:30
let(:attributes) do
{
commit_sha: commit_sha,
project: project,
x509_certificate_id: x509_certificate.id,
verification_status: "verified"
}
end
2022-10-11 01:57:18 +05:30
let(:signature) { create(:x509_commit_signature, commit_sha: commit_sha, x509_certificate: x509_certificate) }
2020-03-13 15:44:24 +05:30
it_behaves_like 'having unique enum values'
2022-07-23 23:45:48 +05:30
it_behaves_like 'commit signature'
2023-03-04 22:38:38 +05:30
it_behaves_like 'signature with type checking', :x509
2020-03-13 15:44:24 +05:30
describe 'validation' do
it { is_expected.to validate_presence_of(:x509_certificate_id) }
end
describe 'associations' do
it { is_expected.to belong_to(:x509_certificate).required }
end
2020-05-24 23:13:21 +05:30
describe '#user' do
context 'if email is assigned to a user' do
let!(:user) { create(:user, email: X509Helpers::User1.certificate_email) }
it 'returns user' do
2023-03-04 22:38:38 +05:30
expect(described_class.safe_create!(attributes).signed_by_user).to eq(user)
2020-05-24 23:13:21 +05:30
end
end
it 'if email is not assigned to a user, return nil' do
2023-03-04 22:38:38 +05:30
expect(described_class.safe_create!(attributes).signed_by_user).to be_nil
2020-05-24 23:13:21 +05:30
end
end
2020-03-13 15:44:24 +05:30
end