diff options
author | Rubén Dávila <ruben@gitlab.com> | 2018-02-15 09:50:19 -0500 |
---|---|---|
committer | Rubén Dávila <ruben@gitlab.com> | 2018-02-15 09:50:19 -0500 |
commit | 75fd83245450216b0aeec9993455802764eaf87b (patch) | |
tree | 8892a4c9e970d5a6d3bd767c8788bce93734388a /spec/lib | |
parent | 1bbce21f644809532454101adaa49039711cf86b (diff) | |
download | gitlab-ce-75fd83245450216b0aeec9993455802764eaf87b.tar.gz |
Revert "Merge branch 'rd-43185-revert-sanitize-extra-blank-spaces-used-when-uploading-a-ssh-key' into 'master'"
This reverts commit e607fd796657afd214b8f25201919d3e33b3f35f.
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/ssh_public_key_spec.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ssh_public_key_spec.rb b/spec/lib/gitlab/ssh_public_key_spec.rb index 93d538141ce..c15e29774b6 100644 --- a/spec/lib/gitlab/ssh_public_key_spec.rb +++ b/spec/lib/gitlab/ssh_public_key_spec.rb @@ -37,6 +37,41 @@ describe Gitlab::SSHPublicKey, lib: true do end end + describe '.sanitize(key_content)' do + let(:content) { build(:key).key } + + context 'when key has blank space characters' do + it 'removes the extra blank space characters' do + unsanitized = content.insert(100, "\n") + .insert(40, "\r\n") + .insert(30, ' ') + + sanitized = described_class.sanitize(unsanitized) + _, body = sanitized.split + + expect(sanitized).not_to eq(unsanitized) + expect(body).not_to match(/\s/) + end + end + + context "when key doesn't have blank space characters" do + it "doesn't modify the content" do + sanitized = described_class.sanitize(content) + + expect(sanitized).to eq(content) + end + end + + context "when key is invalid" do + it 'returns the original content' do + unsanitized = "ssh-foo any content==" + sanitized = described_class.sanitize(unsanitized) + + expect(sanitized).to eq(unsanitized) + end + end + end + describe '#valid?' do subject { public_key } |