diff options
author | Nikita Verkhovin <vernik91@gmail.com> | 2015-07-11 21:18:56 +0300 |
---|---|---|
committer | Nikita Verkhovin <vernik91@gmail.com> | 2015-07-11 21:18:56 +0300 |
commit | 562d78a65a5d6d9ebd593b0fe20d1cbc187bc570 (patch) | |
tree | 15f20b791111333213ed972865cca57c38e9a3f3 | |
parent | dc6aa1d34a3f78a757d829eb8cd050fa381cef99 (diff) |
Add error message for SSH key linebreaks
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/models/key.rb | 1 | ||||
-rw-r--r-- | spec/models/key_spec.rb | 8 |
3 files changed, 9 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG index 56f6a48cc51..7fc52d175f1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -43,6 +43,7 @@ v 7.13.0 (unreleased) - Redesign project page. Show README as default instead of activity. Move project activity to separate page - Make left menu more hierarchical and less contextual by adding back item at top - A fork can’t have a visibility level that is greater than the original project. + - 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 |