diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-04-05 07:50:50 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-04-05 07:50:50 +0000 |
commit | d4d95ad32fb1f47ecb4b6d0e8d9885dba0222453 (patch) | |
tree | c6445dd307a28b453a2f1d7df46d0bb13443da10 | |
parent | 2316774d06e531224035b43e9dcc157f53e368c5 (diff) | |
parent | 54849afc6c94fbc16b0b320741cadafb272deb9d (diff) | |
download | gitlab-ce-d4d95ad32fb1f47ecb4b6d0e8d9885dba0222453.tar.gz |
Merge branch 'sh-fix-ssh-keys-with-spaces' into 'master'
Handle SSH keys that have multiple spaces between each marker
See merge request !10466
-rw-r--r-- | changelogs/unreleased/sh-fix-ssh-keys-with-spaces.yml | 4 | ||||
-rw-r--r-- | lib/gitlab/shell.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/backend/shell_spec.rb | 9 |
3 files changed, 14 insertions, 1 deletions
diff --git a/changelogs/unreleased/sh-fix-ssh-keys-with-spaces.yml b/changelogs/unreleased/sh-fix-ssh-keys-with-spaces.yml new file mode 100644 index 00000000000..fe75d7e1156 --- /dev/null +++ b/changelogs/unreleased/sh-fix-ssh-keys-with-spaces.yml @@ -0,0 +1,4 @@ +--- +title: Handle SSH keys that have multiple spaces between each marker +merge_request: +author: diff --git a/lib/gitlab/shell.rb b/lib/gitlab/shell.rb index b631ef11ce7..36a871e5bbc 100644 --- a/lib/gitlab/shell.rb +++ b/lib/gitlab/shell.rb @@ -35,7 +35,7 @@ module Gitlab end def strip_key(key) - key.split(/ /)[0, 2].join(' ') + key.split(/[ ]+/)[0, 2].join(' ') end private diff --git a/spec/lib/gitlab/backend/shell_spec.rb b/spec/lib/gitlab/backend/shell_spec.rb index 4b08a02ec73..6675d26734e 100644 --- a/spec/lib/gitlab/backend/shell_spec.rb +++ b/spec/lib/gitlab/backend/shell_spec.rb @@ -69,6 +69,15 @@ describe Gitlab::Shell, lib: true do expect(io).to have_received(:puts).with("key-42\tssh-rsa foo") 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 expect do described_class.new(StringIO.new).add_key('key-42', "ssh-rsa\tfoobar") |