diff options
Diffstat (limited to 'test/rubygems/test_gem_commands_cert_command.rb')
-rw-r--r-- | test/rubygems/test_gem_commands_cert_command.rb | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/test/rubygems/test_gem_commands_cert_command.rb b/test/rubygems/test_gem_commands_cert_command.rb index 3d9bbeb1df..97c081e110 100644 --- a/test/rubygems/test_gem_commands_cert_command.rb +++ b/test/rubygems/test_gem_commands_cert_command.rb @@ -159,7 +159,7 @@ Added '/CN=alternate/DC=example' @cmd.handle_options %W[ --build nobody@example.com --days 26 - ] + ] @build_ui = Gem::MockGemUi.new "#{passphrase}\n#{passphrase}" @@ -615,6 +615,37 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis assert_equal '', @ui.error end + def test_execute_re_sign_with_cert_expiration_length_days + gem_path = File.join Gem.user_home, ".gem" + Dir.mkdir gem_path + + path = File.join @tempdir, 'cert.pem' + Gem::Security.write EXPIRED_PUBLIC_CERT, path, 0600 + + assert_equal '/CN=nobody/DC=example', EXPIRED_PUBLIC_CERT.issuer.to_s + + tmp_expired_cert_file = File.join(Dir.tmpdir, File.basename(EXPIRED_PUBLIC_CERT_FILE)) + File.write(tmp_expired_cert_file, File.read(EXPIRED_PUBLIC_CERT_FILE)) + + @cmd.handle_options %W[ + --private-key #{PRIVATE_KEY_FILE} + --certificate #{tmp_expired_cert_file} + --re-sign + ] + + Gem.configuration.cert_expiration_length_days = 28 + + use_ui @ui do + @cmd.execute + end + + re_signed_cert = OpenSSL::X509::Certificate.new(File.read(tmp_expired_cert_file)) + cert_days_to_expire = (re_signed_cert.not_after - re_signed_cert.not_before).to_i / (24 * 60 * 60) + + assert_equal(28, cert_days_to_expire) + assert_equal '', @ui.error + end + def test_handle_options @cmd.handle_options %W[ --add #{PUBLIC_CERT_FILE} |