diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-10-04 08:06:49 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-10-04 08:06:49 +0000 |
commit | f0b4fe2fc2c1e89e67b236b640f8fe31aa37e73a (patch) | |
tree | 5a5358c8e5e15d74284ee8c34d0ddbaab3b6a6c5 | |
parent | c958c201b72577eb01662cc1dac0f253e3d3e6db (diff) | |
parent | eaa1ce4fbed93cc1af95e96c3ff435ff0ec59863 (diff) | |
download | gitlab-ce-f0b4fe2fc2c1e89e67b236b640f8fe31aa37e73a.tar.gz |
Merge branch 'fix-ssh-key-mutation' into 'master'
Ensure key fingerprints are generated correctly when modified
See merge request gitlab-org/gitlab-ce!14663
-rw-r--r-- | app/models/key.rb | 1 | ||||
-rw-r--r-- | spec/models/key_spec.rb | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/app/models/key.rb b/app/models/key.rb index 0c41e34d969..f119b15c737 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -34,6 +34,7 @@ class Key < ActiveRecord::Base value&.delete!("\n\r") value.strip! unless value.blank? write_attribute(:key, value) + @public_key = nil end def publishable_key diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb index 8eabc4ca72f..81c2057e175 100644 --- a/spec/models/key_spec.rb +++ b/spec/models/key_spec.rb @@ -155,5 +155,15 @@ describe Key, :mailer do it 'strips white spaces' do expect(described_class.new(key: " #{valid_key} ").key).to eq(valid_key) end + + it 'invalidates the public_key attribute' do + key = build(:key) + + original = key.public_key + key.key = valid_key + + expect(original.key_text).not_to be_nil + expect(key.public_key.key_text).to eq(valid_key) + end end end |