Commit df3ae4ef authored by Douwe Maan's avatar Douwe Maan

Merge branch 'rs-issue-2970' into 'master'

Normalize space-like characters in keys before output to gitlab-shell

gitlab-shell expects only one tab separator per key, and an SSH key with
a tab character in the comment, for example, would break things.

Closes #2970

See merge request !1552
parents 192dd58d 69b41ba0
...@@ -4,7 +4,8 @@ module Gitlab ...@@ -4,7 +4,8 @@ module Gitlab
class KeyAdder < Struct.new(:io) class KeyAdder < Struct.new(:io)
def add_key(id, key) def add_key(id, key)
io.puts("#{id}\t#{key.strip}") key.gsub!(/[[:space:]]+/, ' ').strip!
io.puts("#{id}\t#{key}")
end end
end end
......
...@@ -15,4 +15,17 @@ describe Gitlab::Shell do ...@@ -15,4 +15,17 @@ describe Gitlab::Shell do
it { is_expected.to respond_to :fork_repository } it { is_expected.to respond_to :fork_repository }
it { expect(gitlab_shell.url_to_repo('diaspora')).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + "diaspora.git") } it { expect(gitlab_shell.url_to_repo('diaspora')).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + "diaspora.git") }
describe Gitlab::Shell::KeyAdder do
describe '#add_key' do
it 'normalizes space characters in the key' do
io = spy
adder = described_class.new(io)
adder.add_key('key-42', "sha-rsa foo\tbar\tbaz")
expect(io).to have_received(:puts).with("key-42\tsha-rsa foo bar baz")
end
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment