summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-07-13 09:33:55 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-07-13 09:33:55 +0000
commit00053c805c9c83baca25b83919f89b024c51d7c8 (patch)
tree4afb25c2ae87c81cbe76ca9797c6d3e65a43e3df
parent98291295a782b5fdf74e0b4742a35857054facbb (diff)
parent562d78a65a5d6d9ebd593b0fe20d1cbc187bc570 (diff)
downloadgitlab-ce-00053c805c9c83baca25b83919f89b024c51d7c8.tar.gz
Merge branch 'ssh-key-linebreaks' into 'master'
Add error message for SSH key linebreaks Solves this [request](http://feedback.gitlab.com/forums/176466-general/suggestions/5653544-check-for-linebreaks-in-ssh-key). See merge request !672
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/key.rb1
-rw-r--r--spec/models/key_spec.rb8
3 files changed, 9 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 93983c63593..97d4671bd0d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -46,6 +46,7 @@ v 7.13.0 (unreleased)
- A fork can’t have a visibility level that is greater than the original project.
- Faster code search in repository and wiki. Fixes search page timeout for big repositories
- Allow administrators to disable 2FA for a specific user
+ - Add error message for SSH key linebreaks
v 7.12.2
- Correctly show anonymous authorized applications under Profile > Applications.
diff --git a/app/models/key.rb b/app/models/key.rb
index bbc28678177..2dcae059c0e 100644
--- a/app/models/key.rb
+++ b/app/models/key.rb
@@ -24,6 +24,7 @@ class Key < ActiveRecord::Base
validates :title, presence: true, length: { within: 0..255 }
validates :key, presence: true, length: { within: 0..5000 }, format: { with: /\A(ssh|ecdsa)-.*\Z/ }, uniqueness: true
+ validates :key, format: { without: /\n|\r/, message: 'should be a single line' }
validates :fingerprint, uniqueness: true, presence: { message: 'cannot be generated' }
delegate :name, :email, to: :user, prefix: true
diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb
index fbb9e162952..456bf221d62 100644
--- a/spec/models/key_spec.rb
+++ b/spec/models/key_spec.rb
@@ -63,7 +63,7 @@ describe Key do
key = build(:key)
# Not always the middle, but close enough
- key.key = key.key[0..100] + ' ' + key.key[100..-1]
+ key.key = key.key[0..100] + ' ' + key.key[101..-1]
expect(key).not_to be_valid
end
@@ -71,6 +71,12 @@ describe Key do
it 'rejects the unfingerprintable key (not a key)' do
expect(build(:key, key: 'ssh-rsa an-invalid-key==')).not_to be_valid
end
+
+ it 'rejects the multiple line key' do
+ key = build(:key)
+ key.key.gsub!(' ', "\n")
+ expect(key).not_to be_valid
+ end
end
context 'callbacks' do