Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorIan Baum <ibaum@gitlab.com>2018-02-12 22:05:31 +0300
committerIan Baum <ibaum@gitlab.com>2018-02-12 22:06:57 +0300
commite607fd796657afd214b8f25201919d3e33b3f35f (patch)
treea15d22d1963efdfd168f30b5a385fad68d9aa1ec /spec
parent769f732111a4479e540eeb61eff9f609fb683a2d (diff)
Merge branch 'rd-43185-revert-sanitize-extra-blank-spaces-used-when-uploading-a-ssh-key' into 'master'
Revert "Merge branch 'rd-40552-gitlab-should-check-if-keys-are-valid-before-saving' into 'master'" See merge request gitlab-org/gitlab-ce!17062
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/keys.rb4
-rw-r--r--spec/lib/gitlab/ssh_public_key_spec.rb35
-rw-r--r--spec/models/key_spec.rb51
3 files changed, 7 insertions, 83 deletions
diff --git a/spec/factories/keys.rb b/spec/factories/keys.rb
index 23a98a899f1..f0c43f3d6f5 100644
--- a/spec/factories/keys.rb
+++ b/spec/factories/keys.rb
@@ -5,10 +5,6 @@ FactoryBot.define do
title
key { Spec::Support::Helpers::KeyGeneratorHelper.new(1024).generate + ' dummy@gitlab.com' }
- factory :key_without_comment do
- key { Spec::Support::Helpers::KeyGeneratorHelper.new(1024).generate }
- end
-
factory :deploy_key, class: 'DeployKey'
factory :personal_key do
diff --git a/spec/lib/gitlab/ssh_public_key_spec.rb b/spec/lib/gitlab/ssh_public_key_spec.rb
index c15e29774b6..93d538141ce 100644
--- a/spec/lib/gitlab/ssh_public_key_spec.rb
+++ b/spec/lib/gitlab/ssh_public_key_spec.rb
@@ -37,41 +37,6 @@ 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 }
diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb
index bf5703ac986..7398fd25aa8 100644
--- a/spec/models/key_spec.rb
+++ b/spec/models/key_spec.rb
@@ -72,52 +72,15 @@ describe Key, :mailer do
expect(build(:key)).to be_valid
end
- it 'rejects the unfingerprintable key (not a key)' do
- expect(build(:key, key: 'ssh-rsa an-invalid-key==')).not_to be_valid
- end
-
- where(:factory, :chars, :expected_sections) do
- [
- [:key, ["\n", "\r\n"], 3],
- [:key, [' ', ' '], 3],
- [:key_without_comment, [' ', ' '], 2]
- ]
- end
-
- with_them do
- let!(:key) { create(factory) }
- let!(:original_fingerprint) { key.fingerprint }
-
- it 'accepts a key with blank space characters after stripping them' do
- modified_key = key.key.insert(100, chars.first).insert(40, chars.last)
- _, content = modified_key.split
-
- key.update!(key: modified_key)
-
- expect(key).to be_valid
- expect(key.key.split.size).to eq(expected_sections)
-
- expect(content).not_to match(/\s/)
- expect(original_fingerprint).to eq(key.fingerprint)
- end
- end
- end
-
- context 'validate size' do
- where(:key_content, :result) do
- [
- [Spec::Support::Helpers::KeyGeneratorHelper.new(512).generate, false],
- [Spec::Support::Helpers::KeyGeneratorHelper.new(8192).generate, false],
- [Spec::Support::Helpers::KeyGeneratorHelper.new(1024).generate, true]
- ]
+ it 'accepts a key with newline charecters after stripping them' do
+ key = build(:key)
+ key.key = key.key.insert(100, "\n")
+ key.key = key.key.insert(40, "\r\n")
+ expect(key).to be_valid
end
- with_them do
- it 'validates the size of the key' do
- key = build(:key, key: key_content)
-
- expect(key.valid?).to eq(result)
- end
+ it 'rejects the unfingerprintable key (not a key)' do
+ expect(build(:key, key: 'ssh-rsa an-invalid-key==')).not_to be_valid
end
end