Commit 54849afc authored by Stan Hu's avatar Stan Hu

Handle SSH keys that have multiple spaces between each marker

Notice what happens when a user adds a key with a space in between:

```
irb(main):004:0> 'ssh-rsa  foobar'.split(/ /)
=> ["ssh-rsa", "", "foobar"]
```

This would cause gitlab-shell to receive a blank argument for the actual
key, leading to users unable to login.
parent ced322c5
---
title: Handle SSH keys that have multiple spaces between each marker
merge_request:
author:
...@@ -35,7 +35,7 @@ module Gitlab ...@@ -35,7 +35,7 @@ module Gitlab
end end
def strip_key(key) def strip_key(key)
key.split(/ /)[0, 2].join(' ') key.split(/[ ]+/)[0, 2].join(' ')
end end
private private
......
...@@ -69,6 +69,15 @@ describe Gitlab::Shell, lib: true do ...@@ -69,6 +69,15 @@ describe Gitlab::Shell, lib: true do
expect(io).to have_received(:puts).with("key-42\tssh-rsa foo") expect(io).to have_received(:puts).with("key-42\tssh-rsa foo")
end end
it 'handles multiple spaces in the key' do
io = spy(:io)
adder = described_class.new(io)
adder.add_key('key-42', "ssh-rsa foo")
expect(io).to have_received(:puts).with("key-42\tssh-rsa foo")
end
it 'raises an exception if the key contains a tab' do it 'raises an exception if the key contains a tab' do
expect do expect do
described_class.new(StringIO.new).add_key('key-42', "ssh-rsa\tfoobar") described_class.new(StringIO.new).add_key('key-42', "ssh-rsa\tfoobar")
......
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