summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2016-09-16 11:43:05 +0200
committerJacob Vosmaer <jacob@gitlab.com>2016-09-16 11:49:11 +0200
commit67ec96e3e0ea9d25356ed3de0be12c0d92ed6d16 (patch)
treee470e02d29c3b67fd372c8efed473ca1d466fa85 /spec/lib
parent82b8cc5d66655605091b1fa089b6a3e946bd536d (diff)
downloadgitlab-ce-67ec96e3e0ea9d25356ed3de0be12c0d92ed6d16.tar.gz
Strip comments before sending keys to gitlab-shell
Avoid issues with text encoding by not sending out non-7-bit ASCII text. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/22167
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/backend/shell_spec.rb32
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