diff options
author | Robert Speicher <robert@gitlab.com> | 2016-09-20 05:42:03 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-09-20 05:42:03 +0000 |
commit | 4722c45ea2e3a8503ab057f771ec7367215963a6 (patch) | |
tree | 287f57e697112fa42278667a6cda99c37650c76c /spec | |
parent | 791079e2abeef1d3ebeecc8157bfb02cfdf9b36d (diff) | |
parent | 67ec96e3e0ea9d25356ed3de0be12c0d92ed6d16 (diff) | |
download | gitlab-ce-4722c45ea2e3a8503ab057f771ec7367215963a6.tar.gz |
Merge branch 'strip-key-comments-for-gitlab-shell' into 'master'
Strip comments before sending keys to gitlab-shell
## Why was this MR needed?
https://gitlab.com/gitlab-org/gitlab-ce/issues/22167 encoding issues in comment text.
## What are the relevant issue numbers?
https://gitlab.com/gitlab-org/gitlab-ce/issues/22167
See merge request !6381
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/backend/shell_spec.rb | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/spec/lib/gitlab/backend/shell_spec.rb b/spec/lib/gitlab/backend/shell_spec.rb index 6e5ba211382..07407f212aa 100644 --- a/spec/lib/gitlab/backend/shell_spec.rb +++ b/spec/lib/gitlab/backend/shell_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'stringio' describe Gitlab::Shell, lib: true do let(:project) { double('Project', id: 7, path: 'diaspora') } @@ -44,15 +45,38 @@ describe Gitlab::Shell, lib: true do end end + describe '#add_key' do + it 'removes trailing garbage' do + allow(gitlab_shell).to receive(:gitlab_shell_keys_path).and_return(:gitlab_shell_keys_path) + expect(Gitlab::Utils).to receive(:system_silent).with( + [:gitlab_shell_keys_path, 'add-key', 'key-123', 'ssh-rsa foobar'] + ) + + gitlab_shell.add_key('key-123', 'ssh-rsa foobar trailing garbage') + end + end + describe Gitlab::Shell::KeyAdder, lib: true do describe '#add_key' do - it 'normalizes space characters in the key' do - io = spy + it 'removes trailing garbage' do + io = spy(:io) adder = described_class.new(io) - adder.add_key('key-42', "sha-rsa foo\tbar\tbaz") + adder.add_key('key-42', "ssh-rsa foo bar\tbaz") + + expect(io).to have_received(:puts).with("key-42\tssh-rsa foo") + end + + it 'raises an exception if the key contains a tab' do + expect do + described_class.new(StringIO.new).add_key('key-42', "ssh-rsa\tfoobar") + end.to raise_error(Gitlab::Shell::Error) + end - expect(io).to have_received(:puts).with("key-42\tsha-rsa foo bar baz") + it 'raises an exception if the key contains a newline' do + expect do + described_class.new(StringIO.new).add_key('key-42', "ssh-rsa foobar\nssh-rsa pawned") + end.to raise_error(Gitlab::Shell::Error) end end end |