File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
lib/travis/model/repository
spec/travis/model/repository/settings Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ class EnvVar < Travis::Settings::Model
17
17
end
18
18
19
19
class SshKey < Travis ::Settings ::Model
20
+ class NotAPrivateKeyError < StandardError ; end
21
+
20
22
attribute :description , String
21
23
attribute :value , Travis ::Settings ::EncryptedValue
22
24
attribute :repository_id , Integer
@@ -25,9 +27,10 @@ class SshKey < Travis::Settings::Model
25
27
validate :validate_correctness
26
28
27
29
def validate_correctness
28
- OpenSSL ::PKey ::RSA . new ( value . decrypt )
29
- rescue OpenSSL ::PKey ::RSAError
30
- errors . add ( :value , :not_private_key )
30
+ key = OpenSSL ::PKey ::RSA . new ( value . decrypt )
31
+ raise NotAPrivateKeyError unless key . private?
32
+ rescue OpenSSL ::PKey ::RSAError , NotAPrivateKeyError
33
+ errors . add ( :value , :not_a_private_key )
31
34
end
32
35
end
33
36
Original file line number Diff line number Diff line change 40
40
ssh_key . value = 'foo'
41
41
ssh_key . should_not be_valid
42
42
43
- ssh_key . errors [ :value ] . should == [ :not_private_key ]
43
+ ssh_key . errors [ :value ] . should == [ :not_a_private_key ]
44
+ end
45
+
46
+ it 'allows only private key' do
47
+ public_key = OpenSSL ::PKey ::RSA . new ( private_key ) . public_key . to_s
48
+ ssh_key = described_class . new ( value : public_key )
49
+
50
+ ssh_key . should_not be_valid
51
+ ssh_key . errors [ :value ] . should == [ :not_a_private_key ]
44
52
end
45
53
end
You can’t perform that action at this time.
0 commit comments