diff options
author | Alexis Reigel <mail@koffeinfrei.org> | 2017-02-22 12:49:17 +0100 |
---|---|---|
committer | Alexis Reigel <mail@koffeinfrei.org> | 2017-07-27 15:40:40 +0200 |
commit | fbf1fd1a204a24aef2b80473ec64a520ed2a2dfc (patch) | |
tree | eb1656bf0a16ab379b1ac1a5cd8cf86bf771b0c1 /spec/models | |
parent | 28bb5e3d53a585b1fb958d1d91622da0a038bea8 (diff) | |
download | gitlab-ce-fbf1fd1a204a24aef2b80473ec64a520ed2a2dfc.tar.gz |
add gpg key model
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/gpg_key_spec.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/models/gpg_key_spec.rb b/spec/models/gpg_key_spec.rb new file mode 100644 index 00000000000..02623c52fa6 --- /dev/null +++ b/spec/models/gpg_key_spec.rb @@ -0,0 +1,41 @@ +require 'rails_helper' + +describe GpgKey do + describe "associations" do + it { is_expected.to belong_to(:user) } + end + + describe "validation" do + it { is_expected.to validate_presence_of(:fingerprint) } + + it { is_expected.to validate_presence_of(:key) } + it { is_expected.to validate_uniqueness_of(:key) } + it { is_expected.to allow_value("-----BEGIN PGP PUBLIC KEY BLOCK-----\nkey").for(:key) } + it { is_expected.not_to allow_value("-----BEGIN PGP PUBLIC KEY BLOCK-----\nkey\n-----BEGIN PGP PUBLIC KEY BLOCK-----").for(:key) } + it { is_expected.not_to allow_value('BEGIN PGP').for(:key) } + end + + context 'callbacks' do + describe 'extract_fingerprint' do + it 'extracts the fingerprint from the gpg key', :gpg do + gpg_key = described_class.new(key: GpgHelpers.public_key) + gpg_key.valid? + expect(gpg_key.fingerprint).to eq '4F4840A503964251CF7D7F5DC728AF10972E97C0' + end + end + end + + describe '#key=' do + it 'strips white spaces' do + key = <<~KEY.strip + -----BEGIN PGP PUBLIC KEY BLOCK----- + Version: GnuPG v1 + + mQENBFMOSOgBCADFCYxmnXFbrDhfvlf03Q/bQuT+nZu46BFGbo7XkUjDowFXJQhP + -----END PGP PUBLIC KEY BLOCK----- + KEY + + expect(described_class.new(key: " #{key} ").key).to eq(key) + end + end +end |