diff options
author | Nick Thomas <nick@gitlab.com> | 2019-05-01 11:17:14 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-05-01 11:17:14 +0000 |
commit | 805bdd0d333a047b5fb92a4feb075a7db95cba56 (patch) | |
tree | f4503cddeaa9b22dd0a63362b5bed6b196b090ae | |
parent | 344cc6b443e08ec5648fcf8a3035e46bb404fd6a (diff) | |
parent | a9e6eb77f053798596cdce189dd7ad181c014f44 (diff) | |
download | gitlab-shell-805bdd0d333a047b5fb92a4feb075a7db95cba56.tar.gz |
Merge branch 'master' into 'master'
Print keys in list-keys command
See merge request gitlab-org/gitlab-shell!198
-rw-r--r-- | lib/gitlab_keys.rb | 2 | ||||
-rw-r--r-- | spec/gitlab_keys_spec.rb | 20 |
2 files changed, 13 insertions, 9 deletions
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb index 0600a18..85ca797 100644 --- a/lib/gitlab_keys.rb +++ b/lib/gitlab_keys.rb @@ -99,7 +99,7 @@ class GitlabKeys # rubocop:disable Metrics/ClassLength matches = /^command=\".+?\s+(.+?)\".+?(?:ssh|ecdsa)-.*?\s(.+)\s*.*\n*$/.match(line) keys << "#{matches[1]} #{matches[2]}\n" unless matches.nil? end - keys + puts keys end def list_key_ids diff --git a/spec/gitlab_keys_spec.rb b/spec/gitlab_keys_spec.rb index f86d00d..86128f6 100644 --- a/spec/gitlab_keys_spec.rb +++ b/spec/gitlab_keys_spec.rb @@ -95,16 +95,20 @@ describe GitlabKeys do end end - describe :list_keys do - let(:gitlab_keys) do - build_gitlab_keys('add-key', 'key-741', 'ssh-rsa AAAAB3NzaDAxx2E') + describe ':list_keys' do + let(:gitlab_keys) { build_gitlab_keys('list_keys') } + let(:key_data) { "%s\n%s\n" % [described_class.key_line('key-741', 'ssh-rsa AAAAB3NzaDAxx2E'), described_class.key_line('key-742', 'ssh-rsa AAAAB3NzaDAxx2E')] } + let(:key_output) { "key-741 AAAAB3NzaDAxx2E\nkey-742 AAAAB3NzaDAxx2E\n" } + + before do + create_authorized_keys_fixture( + existing_content: + key_data + ) end - it 'adds a key and lists it' do - create_authorized_keys_fixture - gitlab_keys.send :add_key - auth_line1 = 'key-741 AAAAB3NzaDAxx2E' - expect(gitlab_keys.send(:list_keys)).to eq("#{auth_line1}\n") + it 'outputs the keys with IDs, separated by newlines' do + expect { gitlab_keys.send(:list_keys) }.to output(key_output).to_stdout end end |