Commit 27f4cf75422d2995fdd403ee9562ab30afe85536

Authored by Jaakko Kantojärvi
1 parent 6fd88b8c

Tests to validate that invalid keys are rejected

spec/factories.rb
... ... @@ -148,6 +148,12 @@ FactoryGirl.define do
148 148 "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa ++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
149 149 end
150 150 end
  151 +
  152 + factory :invalid_key do
  153 + key do
  154 + "ssh-rsa this_is_invalid_key=="
  155 + end
  156 + end
151 157 end
152 158  
153 159 factory :milestone do
... ...
spec/factories_spec.rb
1 1 require 'spec_helper'
2 2  
3   -INVALID_FACTORIES = [:key_with_a_space_in_the_middle]
  3 +INVALID_FACTORIES = [
  4 + :key_with_a_space_in_the_middle,
  5 + :invalid_key,
  6 +]
4 7  
5 8 FactoryGirl.factories.map(&:name).each do |factory_name|
6 9 next if INVALID_FACTORIES.include?(factory_name)
... ...
spec/models/key_spec.rb
... ... @@ -73,8 +73,12 @@ describe Key do
73 73 build(:key, user: user).should be_valid
74 74 end
75 75  
76   - it "rejects the unfingerprintable key" do
  76 + it "rejects the unfingerprintable key (contains space in middle)" do
77 77 build(:key_with_a_space_in_the_middle).should_not be_valid
78 78 end
  79 +
  80 + it "rejects the unfingerprintable key (not a key)" do
  81 + build(:invalid_key).should_not be_valid
  82 + end
79 83 end
80 84 end
... ...