Commit 00053c80 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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
parents 98291295 562d78a6
...@@ -46,6 +46,7 @@ v 7.13.0 (unreleased) ...@@ -46,6 +46,7 @@ v 7.13.0 (unreleased)
- A fork can’t have a visibility level that is greater than the original project. - 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 - Faster code search in repository and wiki. Fixes search page timeout for big repositories
- Allow administrators to disable 2FA for a specific user - Allow administrators to disable 2FA for a specific user
- Add error message for SSH key linebreaks
v 7.12.2 v 7.12.2
- Correctly show anonymous authorized applications under Profile > Applications. - Correctly show anonymous authorized applications under Profile > Applications.
......
...@@ -24,6 +24,7 @@ class Key < ActiveRecord::Base ...@@ -24,6 +24,7 @@ class Key < ActiveRecord::Base
validates :title, presence: true, length: { within: 0..255 } 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, 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' } validates :fingerprint, uniqueness: true, presence: { message: 'cannot be generated' }
delegate :name, :email, to: :user, prefix: true delegate :name, :email, to: :user, prefix: true
......
...@@ -63,7 +63,7 @@ describe Key do ...@@ -63,7 +63,7 @@ describe Key do
key = build(:key) key = build(:key)
# Not always the middle, but close enough # 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 expect(key).not_to be_valid
end end
...@@ -71,6 +71,12 @@ describe Key do ...@@ -71,6 +71,12 @@ describe Key do
it 'rejects the unfingerprintable key (not a key)' do it 'rejects the unfingerprintable key (not a key)' do
expect(build(:key, key: 'ssh-rsa an-invalid-key==')).not_to be_valid expect(build(:key, key: 'ssh-rsa an-invalid-key==')).not_to be_valid
end end
it 'rejects the multiple line key' do
key = build(:key)
key.key.gsub!(' ', "\n")
expect(key).not_to be_valid
end
end end
context 'callbacks' do context 'callbacks' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment