diff options
Diffstat (limited to 'test/rubygems/test_gem_commands_cert_command.rb')
-rw-r--r-- | test/rubygems/test_gem_commands_cert_command.rb | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/test/rubygems/test_gem_commands_cert_command.rb b/test/rubygems/test_gem_commands_cert_command.rb index 3f67513c3f..3d9bbeb1df 100644 --- a/test/rubygems/test_gem_commands_cert_command.rb +++ b/test/rubygems/test_gem_commands_cert_command.rb @@ -9,14 +9,16 @@ end class TestGemCommandsCertCommand < Gem::TestCase ALTERNATE_CERT = load_cert 'alternate' + EXPIRED_PUBLIC_CERT = load_cert 'expired' ALTERNATE_KEY_FILE = key_path 'alternate' PRIVATE_KEY_FILE = key_path 'private' PUBLIC_KEY_FILE = key_path 'public' - ALTERNATE_CERT_FILE = cert_path 'alternate' - CHILD_CERT_FILE = cert_path 'child' - PUBLIC_CERT_FILE = cert_path 'public' + ALTERNATE_CERT_FILE = cert_path 'alternate' + CHILD_CERT_FILE = cert_path 'child' + PUBLIC_CERT_FILE = cert_path 'public' + EXPIRED_PUBLIC_CERT_FILE = cert_path 'expired' def setup super @@ -582,6 +584,37 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis assert_equal expected, @ui.error end + def test_execute_re_sign + 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 + ] + + use_ui @ui do + @cmd.execute + end + + expected_path = File.join(gem_path, "#{File.basename(tmp_expired_cert_file)}.expired") + + assert_match( + /INFO: Your certificate #{tmp_expired_cert_file} has been re-signed\nINFO: Your expired certificate will be located at: #{expected_path}\.[0-9]+/, + @ui.output + ) + assert_equal '', @ui.error + end + def test_handle_options @cmd.handle_options %W[ --add #{PUBLIC_CERT_FILE} |