diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-10 09:08:56 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-10 09:08:56 +0000 |
commit | b4ded0ba7b4d2cdbed5b1f331cf2083a25ee4d7c (patch) | |
tree | 6694fa9d8f3e226597cc01dfb8e3e07b50ae85b6 /spec/finders | |
parent | 2aaef94c80937d9d188f7b9cbbad2dcd1508c3c1 (diff) | |
download | gitlab-ce-b4ded0ba7b4d2cdbed5b1f331cf2083a25ee4d7c.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/finders')
-rw-r--r-- | spec/finders/keys_finder_spec.rb | 200 |
1 files changed, 95 insertions, 105 deletions
diff --git a/spec/finders/keys_finder_spec.rb b/spec/finders/keys_finder_spec.rb index 7605d066ddf..bae4a542484 100644 --- a/spec/finders/keys_finder_spec.rb +++ b/spec/finders/keys_finder_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe KeysFinder do - subject { described_class.new(user, params).execute } + subject { described_class.new(params).execute } let(:user) { create(:user) } let(:params) { {} } @@ -20,159 +20,149 @@ describe KeysFinder do let!(:key_2) { create(:personal_key, last_used_at: nil, user: user) } let!(:key_3) { create(:personal_key, last_used_at: 2.days.ago) } - context 'with a regular user' do - it 'raises GitLabAccessDeniedError' do - expect { subject }.to raise_error(KeysFinder::GitLabAccessDeniedError) - end - end + context 'key_type' do + let!(:deploy_key) { create(:deploy_key) } - context 'with an admin user' do - let(:user) {create(:admin)} + context 'when `key_type` is `ssh`' do + before do + params[:key_type] = 'ssh' + end + + it 'returns only SSH keys' do + expect(subject).to contain_exactly(key_1, key_2, key_3) + end + end - context 'key_type' do - let!(:deploy_key) { create(:deploy_key) } + context 'when `key_type` is not specified' do + it 'returns all types of keys' do + expect(subject).to contain_exactly(key_1, key_2, key_3, deploy_key) + end + end + end - context 'when `key_type` is `ssh`' do + context 'fingerprint' do + context 'with invalid fingerprint' do + context 'with invalid MD5 fingerprint' do before do - params[:key_type] = 'ssh' + params[:fingerprint] = '11:11:11:11' end - it 'returns only SSH keys' do - expect(subject).to contain_exactly(key_1, key_2, key_3) + it 'raises InvalidFingerprint' do + expect { subject }.to raise_error(KeysFinder::InvalidFingerprint) end end - context 'when `key_type` is not specified' do - it 'returns all types of keys' do - expect(subject).to contain_exactly(key_1, key_2, key_3, deploy_key) + context 'with invalid SHA fingerprint' do + before do + params[:fingerprint] = 'nUhzNyftwAAKs7HufskYTte2g' + end + + it 'raises InvalidFingerprint' do + expect { subject }.to raise_error(KeysFinder::InvalidFingerprint) end end end - context 'fingerprint' do - context 'with invalid fingerprint' do - context 'with invalid MD5 fingerprint' do + context 'with valid fingerprints' do + let!(:deploy_key) do + create(:deploy_key, + user: user, + key: 'ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt1017k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=', + fingerprint: '8a:4a:12:92:0b:50:47:02:d4:5a:8e:a9:44:4e:08:b4', + fingerprint_sha256: '4DPHOVNh53i9dHb5PpY2vjfyf5qniTx1/pBFPoZLDdk') + end + + context 'personal key with valid MD5 params' do + context 'with an existent fingerprint' do before do - params[:fingerprint] = '11:11:11:11' + params[:fingerprint] = 'ba:81:59:68:d7:6c:cd:02:02:bf:6a:9b:55:4e:af:d1' end - it 'raises InvalidFingerprint' do - expect { subject }.to raise_error(KeysFinder::InvalidFingerprint) + it 'returns the key' do + expect(subject).to eq(key_1) + expect(subject.user).to eq(user) end end - context 'with invalid SHA fingerprint' do + context 'deploy key with an existent fingerprint' do before do - params[:fingerprint] = 'nUhzNyftwAAKs7HufskYTte2g' + params[:fingerprint] = '8a:4a:12:92:0b:50:47:02:d4:5a:8e:a9:44:4e:08:b4' end - it 'raises InvalidFingerprint' do - expect { subject }.to raise_error(KeysFinder::InvalidFingerprint) + it 'returns the key' do + expect(subject).to eq(deploy_key) + expect(subject.user).to eq(user) end end - end - - context 'with valid fingerprints' do - let!(:deploy_key) do - create(:deploy_key, - user: user, - key: 'ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt1017k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=', - fingerprint: '8a:4a:12:92:0b:50:47:02:d4:5a:8e:a9:44:4e:08:b4', - fingerprint_sha256: '4DPHOVNh53i9dHb5PpY2vjfyf5qniTx1/pBFPoZLDdk') - end - - context 'personal key with valid MD5 params' do - context 'with an existent fingerprint' do - before do - params[:fingerprint] = 'ba:81:59:68:d7:6c:cd:02:02:bf:6a:9b:55:4e:af:d1' - end - it 'returns the key' do - expect(subject).to eq(key_1) - expect(subject.user).to eq(user) - end + context 'with a non-existent fingerprint' do + before do + params[:fingerprint] = 'bb:81:59:68:d7:6c:cd:02:02:bf:6a:9b:55:4e:af:d2' end - context 'deploy key with an existent fingerprint' do - before do - params[:fingerprint] = '8a:4a:12:92:0b:50:47:02:d4:5a:8e:a9:44:4e:08:b4' - end - - it 'returns the key' do - expect(subject).to eq(deploy_key) - expect(subject.user).to eq(user) - end + it 'returns nil' do + expect(subject).to be_nil end + end + end - context 'with a non-existent fingerprint' do - before do - params[:fingerprint] = 'bb:81:59:68:d7:6c:cd:02:02:bf:6a:9b:55:4e:af:d2' - end + context 'personal key with valid SHA256 params' do + context 'with an existent fingerprint' do + before do + params[:fingerprint] = 'SHA256:nUhzNyftwADy8AH3wFY31tAKs7HufskYTte2aXo/lCg' + end - it 'returns nil' do - expect(subject).to be_nil - end + it 'returns key' do + expect(subject).to eq(key_1) + expect(subject.user).to eq(user) end end - context 'personal key with valid SHA256 params' do - context 'with an existent fingerprint' do - before do - params[:fingerprint] = 'SHA256:nUhzNyftwADy8AH3wFY31tAKs7HufskYTte2aXo/lCg' - end - - it 'returns key' do - expect(subject).to eq(key_1) - expect(subject.user).to eq(user) - end + context 'deploy key with an existent fingerprint' do + before do + params[:fingerprint] = 'SHA256:4DPHOVNh53i9dHb5PpY2vjfyf5qniTx1/pBFPoZLDdk' end - context 'deploy key with an existent fingerprint' do - before do - params[:fingerprint] = 'SHA256:4DPHOVNh53i9dHb5PpY2vjfyf5qniTx1/pBFPoZLDdk' - end - - it 'returns key' do - expect(subject).to eq(deploy_key) - expect(subject.user).to eq(user) - end + it 'returns key' do + expect(subject).to eq(deploy_key) + expect(subject.user).to eq(user) end + end - context 'with a non-existent fingerprint' do - before do - params[:fingerprint] = 'SHA256:xTjuFqftwADy8AH3wFY31tAKs7HufskYTte2aXi/mNp' - end + context 'with a non-existent fingerprint' do + before do + params[:fingerprint] = 'SHA256:xTjuFqftwADy8AH3wFY31tAKs7HufskYTte2aXi/mNp' + end - it 'returns nil' do - expect(subject).to be_nil - end + it 'returns nil' do + expect(subject).to be_nil end end end end + end - context 'user' do - context 'without user' do - it 'contains ssh_keys of all users in the system' do - expect(subject).to contain_exactly(key_1, key_2, key_3) - end + context 'user' do + context 'without user' do + it 'contains ssh_keys of all users in the system' do + expect(subject).to contain_exactly(key_1, key_2, key_3) end + end - context 'with user' do - before do - params[:user] = user - end + context 'with user' do + before do + params[:users] = user + end - it 'contains ssh_keys of only the specified users' do - expect(subject).to contain_exactly(key_1, key_2) - end + it 'contains ssh_keys of only the specified users' do + expect(subject).to contain_exactly(key_1, key_2) end end + end - context 'sort order' do - it 'sorts in last_used_at_desc order' do - expect(subject).to eq([key_3, key_1, key_2]) - end + context 'sort order' do + it 'sorts in last_used_at_desc order' do + expect(subject).to eq([key_3, key_1, key_2]) end end end |