diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2013-07-17 17:16:34 +0400 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2013-07-17 17:17:18 +0400 |
commit | aa0473d0eb581a1c4d20be22c53ec4002a3801e0 (patch) | |
tree | f023019df0fb50d7047f70c75abd6f956ed697ab /app/models | |
parent | 656d800f8c72bc6bb97700b7289a2d5eebc4e42f (diff) |
Validate fingerprint uniqueness
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/key.rb | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/app/models/key.rb b/app/models/key.rb index f5fc141985e..902a7c59116 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -21,11 +21,11 @@ class Key < ActiveRecord::Base attr_accessible :key, :title - before_validation :strip_white_space + before_validation :strip_white_space, :generate_fingerpint validates :title, presence: true, length: { within: 0..255 } validates :key, presence: true, length: { within: 0..5000 }, format: { with: /\A(ssh|ecdsa)-.*\Z/ }, uniqueness: true - validate :fingerprintable_key + validates :fingerprint, uniqueness: true, presence: { message: 'cannot be generated' } delegate :name, :email, to: :user, prefix: true @@ -33,15 +33,6 @@ class Key < ActiveRecord::Base self.key = key.strip unless key.blank? end - def fingerprintable_key - return true unless key # Don't test if there is no key. - - unless generate_fingerpint - errors.add(:key, "can't be fingerprinted") - false - end - end - # projects that has this key def projects user.authorized_projects @@ -54,6 +45,9 @@ class Key < ActiveRecord::Base private def generate_fingerpint + self.fingerprint = nil + return unless key.present? + cmd_status = 0 cmd_output = '' Tempfile.open('gitlab_key_file') do |file| @@ -66,9 +60,6 @@ class Key < ActiveRecord::Base cmd_output.gsub /([\d\h]{2}:)+[\d\h]{2}/ do |match| self.fingerprint = match end - true - else - false end end end |