From 6fd88b8cbba62d1af4e249cee455a30df0eb0b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kantoj=C3=A4rvi?= Date: Fri, 15 Feb 2013 11:16:21 +0200 Subject: [PATCH 1/3] Fix ssh key fingerprinting test to use exitcode --- app/models/key.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/key.rb b/app/models/key.rb index 895e8d6cb9c..580b8b73284 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 From 27f4cf75422d2995fdd403ee9562ab30afe85536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kantoj=C3=A4rvi?= Date: Fri, 15 Feb 2013 11:31:05 +0200 Subject: [PATCH 2/3] Tests to validate that invalid keys are rejected --- spec/factories.rb | 6 ++++++ spec/factories_spec.rb | 5 ++++- spec/models/key_spec.rb | 6 +++++- 3 files changed, 15 insertions(+), 2 deletions(-) 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 From c20be05a8075217db5ec2c0f6b6a6072b422268f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kantoj=C3=A4rvi?= Date: Sun, 17 Feb 2013 19:38:45 +0200 Subject: [PATCH 3/3] Fix ssh key test by adding valid ssh key --- features/steps/profile/profile_ssh_keys.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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