diff --git a/app/models/key.rb b/app/models/key.rb index 64441ea54eb..edb0bcd61fd 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -45,7 +45,7 @@ class Key < ActiveRecord::Base file.close file.unlink # deletes the temp file end - errors.add(:key, "can't be fingerprinted") if fingerprint_output.match("failed") + errors.add(:key, "can't be fingerprinted") if $?.exitstatus != 0 end def set_identifier diff --git a/features/steps/profile/profile_ssh_keys.rb b/features/steps/profile/profile_ssh_keys.rb index 8ae1fa91025..fbb92077f0a 100644 --- a/features/steps/profile/profile_ssh_keys.rb +++ b/features/steps/profile/profile_ssh_keys.rb @@ -43,6 +43,6 @@ class ProfileSshKeys < Spinach::FeatureSteps end And 'I have ssh key "ssh-rsa Work"' do - create(:key, :user => @user, :title => "ssh-rsa Work", :key => "jfKLJDFKSFJSHFJssh-rsa Work") + create(:key, :user => @user, :title => "ssh-rsa Work", :key => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+L3TbFegm3k8QjejSwemk4HhlRh+DuN679Pc5ckqE/MPhVtE/+kZQDYCTB284GiT2aIoGzmZ8ee9TkaoejAsBwlA+Wz2Q3vhz65X6sMgalRwpdJx8kSEUYV8ZPV3MZvPo8KdNg993o4jL6G36GDW4BPIyO6FPZhfsawdf6liVD0Xo5kibIK7B9VoE178cdLQtLpS2YolRwf5yy6XR6hbbBGQR+6xrGOdP16eGZDb1CE2bMvvJijjloFqPscGktWOqW+nfh5txwFfBzlfARDTBsS8WZtg3Yoj1kn33kPsWRlgHfNutFRAIynDuDdQzQq8tTtVwm+Yi75RfcPHW8y3P Work") end end diff --git a/spec/factories.rb b/spec/factories.rb index d2e9f48c47b..17dbc796d8f 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -148,6 +148,12 @@ FactoryGirl.define do "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa ++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=" end end + + factory :invalid_key do + key do + "ssh-rsa this_is_invalid_key==" + end + end end factory :milestone do diff --git a/spec/factories_spec.rb b/spec/factories_spec.rb index 5ee7354688a..8360477d8fe 100644 --- a/spec/factories_spec.rb +++ b/spec/factories_spec.rb @@ -1,6 +1,9 @@ require 'spec_helper' -INVALID_FACTORIES = [:key_with_a_space_in_the_middle] +INVALID_FACTORIES = [ + :key_with_a_space_in_the_middle, + :invalid_key, +] FactoryGirl.factories.map(&:name).each do |factory_name| next if INVALID_FACTORIES.include?(factory_name) diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb index 94b952cf932..a9ab2f05a34 100644 --- a/spec/models/key_spec.rb +++ b/spec/models/key_spec.rb @@ -73,8 +73,12 @@ describe Key do build(:key, user: user).should be_valid end - it "rejects the unfingerprintable key" do + it "rejects the unfingerprintable key (contains space in middle)" do build(:key_with_a_space_in_the_middle).should_not be_valid end + + it "rejects the unfingerprintable key (not a key)" do + build(:invalid_key).should_not be_valid + end end end