summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2017-10-03 18:31:16 +0100
committerNick Thomas <nick@gitlab.com>2017-10-03 18:45:01 +0100
commiteaa1ce4fbed93cc1af95e96c3ff435ff0ec59863 (patch)
treef52709fb1bf64191a8e2889fe43e0a8e5bf7a2fd
parent66dd045e6af591c370143c21ae98f36d439cd87e (diff)
downloadgitlab-ce-eaa1ce4fbed93cc1af95e96c3ff435ff0ec59863.tar.gz
Ensure key fingerprints are generated correctly when modified
-rw-r--r--app/models/key.rb1
-rw-r--r--spec/models/key_spec.rb10
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