Skip to content

Commit

Permalink
Auto merge of rubygems#1605 - djberg96:cert_check, r=segiddins
Browse files Browse the repository at this point in the history
Raise an explicit error if Signer#sign is called with no certs

# Description:

This PR addresses an unfriendly error message that I brought up in rubygems#1413. It now explicitly raises an error if no certs are found. I also added a test for it.
______________

I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).
  • Loading branch information
homu committed Apr 29, 2016
2 parents 9c11011 + fff6e78 commit 487dfed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rubygems/security/signer.rb
Expand Up @@ -102,6 +102,8 @@ def load_cert_chain # :nodoc:
def sign data
return unless @key

raise Gem::Security::Exception, 'no certs provided' if @cert_chain.empty?

if @cert_chain.length == 1 and @cert_chain.last.not_after < Time.now then
re_sign_key
end
Expand Down
8 changes: 8 additions & 0 deletions test/rubygems/test_gem_security_signer.rb
Expand Up @@ -205,5 +205,13 @@ def test_sign_wrong_key
end
end

def test_sign_no_certs
signer = Gem::Security::Signer.new ALTERNATE_KEY, []

assert_raises Gem::Security::Exception do
signer.sign 'hello'
end
end

end if defined?(OpenSSL::SSL)

0 comments on commit 487dfed

Please sign in to comment.