diff options
Diffstat (limited to 'test/rubygems/test_gem_commands_cert_command.rb')
-rw-r--r-- | test/rubygems/test_gem_commands_cert_command.rb | 323 |
1 files changed, 191 insertions, 132 deletions
diff --git a/test/rubygems/test_gem_commands_cert_command.rb b/test/rubygems/test_gem_commands_cert_command.rb index f722678a19..c173467935 100644 --- a/test/rubygems/test_gem_commands_cert_command.rb +++ b/test/rubygems/test_gem_commands_cert_command.rb @@ -1,27 +1,29 @@ # frozen_string_literal: true -require_relative 'helper' -require 'rubygems/commands/cert_command' + +require_relative "helper" +require "rubygems/commands/cert_command" unless Gem::HAVE_OPENSSL - warn 'Skipping `gem cert` tests. openssl not found.' + warn "Skipping `gem cert` tests. openssl not found." end if Gem.java_platform? - warn 'Skipping `gem cert` tests on jruby.' + warn "Skipping `gem cert` tests on jruby." end class TestGemCommandsCertCommand < Gem::TestCase - ALTERNATE_CERT = load_cert 'alternate' - EXPIRED_PUBLIC_CERT = load_cert 'expired' + 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_KEY_FILE = key_path "alternate" + PRIVATE_KEY_FILE = key_path "private" + PRIVATE_EC_KEY_FILE = key_path "private_ec" + PUBLIC_KEY_FILE = key_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' + 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 @@ -43,9 +45,9 @@ class TestGemCommandsCertCommand < Gem::TestCase @trust_dir.trust_cert PUBLIC_CERT @trust_dir.trust_cert ALTERNATE_CERT - matches = @cmd.certificates_matching '' + matches = @cmd.certificates_matching "" - # HACK OpenSSL::X509::Certificate#== is Object#==, so do this the hard way + # HACK: OpenSSL::X509::Certificate#== is Object#==, so do this the hard way match = matches.next assert_equal ALTERNATE_CERT.to_pem, match.first.to_pem assert_equal @trust_dir.cert_path(ALTERNATE_CERT), match.last @@ -63,7 +65,7 @@ class TestGemCommandsCertCommand < Gem::TestCase @trust_dir.trust_cert PUBLIC_CERT @trust_dir.trust_cert ALTERNATE_CERT - matches = @cmd.certificates_matching 'alternate' + matches = @cmd.certificates_matching "alternate" match = matches.next assert_equal ALTERNATE_CERT.to_pem, match.first.to_pem @@ -90,7 +92,7 @@ class TestGemCommandsCertCommand < Gem::TestCase end def test_execute_add_twice - self.class.cert_path 'alternate' + self.class.cert_path "alternate" @cmd.handle_options %W[ --add #{PUBLIC_CERT_FILE} @@ -111,7 +113,7 @@ Added '/CN=alternate/DC=example' end def test_execute_build - passphrase = 'Foo bar' + passphrase = "Foo bar" @cmd.handle_options %W[--build nobody@example.com] @@ -127,9 +129,9 @@ Added '/CN=alternate/DC=example' output.shift assert_equal "Please repeat the passphrase for your Private Key: ", output.shift - assert_equal "Certificate: #{File.join @tempdir, 'gem-public_cert.pem'}", + assert_equal "Certificate: #{File.join @tempdir, "gem-public_cert.pem"}", output.shift - assert_equal "Private Key: #{File.join @tempdir, 'gem-private_key.pem'}", + assert_equal "Private Key: #{File.join @tempdir, "gem-private_key.pem"}", output.shift assert_equal "Don't forget to move the key file to somewhere private!", @@ -138,12 +140,48 @@ Added '/CN=alternate/DC=example' assert_empty output assert_empty @build_ui.error - assert_path_exist File.join(@tempdir, 'gem-private_key.pem') - assert_path_exist File.join(@tempdir, 'gem-public_cert.pem') + assert_path_exist File.join(@tempdir, "gem-private_key.pem") + assert_path_exist File.join(@tempdir, "gem-public_cert.pem") + end + + def test_execute_build_key_algorithm_ec_key + passphrase = "Foo bar" + + @cmd.handle_options %W[--build nobody@example.com --key-algorithm ec] + + @build_ui = Gem::MockGemUi.new "#{passphrase}\n#{passphrase}" + + use_ui @build_ui do + @cmd.execute + end + + output = @build_ui.output.squeeze("\n").split "\n" + + assert_equal "Passphrase for your Private Key: ", + output.shift + assert_equal "Please repeat the passphrase for your Private Key: ", + output.shift + assert_equal "Certificate: #{File.join @tempdir, "gem-public_cert.pem"}", + output.shift + assert_equal "Private Key: #{File.join @tempdir, "gem-private_key.pem"}", + output.shift + + assert_equal "Don't forget to move the key file to somewhere private!", + output.shift + + assert_empty output + assert_empty @build_ui.error + + assert_path_exist File.join(@tempdir, "gem-private_key.pem") + + cert_path = File.join(@tempdir, "gem-public_cert.pem") + assert_path_exist cert_path + cert = OpenSSL::X509::Certificate.new(File.read(cert_path)) + assert cert.public_key.is_a? OpenSSL::PKey::EC end def test_execute_build_bad_email_address - passphrase = 'Foo bar' + passphrase = "Foo bar" email = "nobody@" @cmd.handle_options %W[--build #{email}] @@ -151,7 +189,6 @@ Added '/CN=alternate/DC=example' @build_ui = Gem::MockGemUi.new "#{passphrase}\n#{passphrase}" use_ui @build_ui do - e = assert_raise Gem::CommandLineError do @cmd.execute end @@ -159,13 +196,13 @@ Added '/CN=alternate/DC=example' assert_equal "Invalid email address #{email}", e.message - assert_path_not_exist File.join(@tempdir, 'gem-private_key.pem') - assert_path_not_exist File.join(@tempdir, 'gem-public_cert.pem') + assert_path_not_exist File.join(@tempdir, "gem-private_key.pem") + assert_path_not_exist File.join(@tempdir, "gem-public_cert.pem") end end def test_execute_build_expiration_days - passphrase = 'Foo bar' + passphrase = "Foo bar" @cmd.handle_options %W[ --build nobody@example.com @@ -184,9 +221,9 @@ Added '/CN=alternate/DC=example' output.shift assert_equal "Please repeat the passphrase for your Private Key: ", output.shift - assert_equal "Certificate: #{File.join @tempdir, 'gem-public_cert.pem'}", + assert_equal "Certificate: #{File.join @tempdir, "gem-public_cert.pem"}", output.shift - assert_equal "Private Key: #{File.join @tempdir, 'gem-private_key.pem'}", + assert_equal "Private Key: #{File.join @tempdir, "gem-private_key.pem"}", output.shift assert_equal "Don't forget to move the key file to somewhere private!", @@ -195,8 +232,8 @@ Added '/CN=alternate/DC=example' assert_empty output assert_empty @build_ui.error - assert_path_exist File.join(@tempdir, 'gem-private_key.pem') - assert_path_exist File.join(@tempdir, 'gem-public_cert.pem') + assert_path_exist File.join(@tempdir, "gem-private_key.pem") + assert_path_exist File.join(@tempdir, "gem-public_cert.pem") pem = File.read("#{@tempdir}/gem-public_cert.pem") cert = OpenSSL::X509::Certificate.new(pem) @@ -206,8 +243,8 @@ Added '/CN=alternate/DC=example' end def test_execute_build_bad_passphrase_confirmation - passphrase = 'Foo bar' - passphrase_confirmation = 'Fu bar' + passphrase = "Foo bar" + passphrase_confirmation = "Fu bar" @cmd.handle_options %W[--build nobody@example.com] @@ -229,11 +266,10 @@ Added '/CN=alternate/DC=example' assert_equal "Passphrase and passphrase confirmation don't match", e.message - end - assert_path_not_exist File.join(@tempdir, 'gem-private_key.pem') - assert_path_not_exist File.join(@tempdir, 'gem-public_cert.pem') + assert_path_not_exist File.join(@tempdir, "gem-private_key.pem") + assert_path_not_exist File.join(@tempdir, "gem-public_cert.pem") end def test_execute_build_key @@ -248,14 +284,14 @@ Added '/CN=alternate/DC=example' output = @ui.output.split "\n" - assert_equal "Certificate: #{File.join @tempdir, 'gem-public_cert.pem'}", + assert_equal "Certificate: #{File.join @tempdir, "gem-public_cert.pem"}", output.shift assert_empty output assert_empty @ui.error - assert_path_exist File.join(@tempdir, 'gem-public_cert.pem') - assert_path_not_exist File.join(@tempdir, 'gem-private_key.pem') + assert_path_exist File.join(@tempdir, "gem-public_cert.pem") + assert_path_not_exist File.join(@tempdir, "gem-private_key.pem") end def test_execute_build_encrypted_key @@ -270,13 +306,35 @@ Added '/CN=alternate/DC=example' output = @ui.output.split "\n" - assert_equal "Certificate: #{File.join @tempdir, 'gem-public_cert.pem'}", + assert_equal "Certificate: #{File.join @tempdir, "gem-public_cert.pem"}", + output.shift + + assert_empty output + assert_empty @ui.error + + assert_path_exist File.join(@tempdir, "gem-public_cert.pem") + end + + def test_execute_build_ec_key + @cmd.handle_options %W[ + --build nobody@example.com + --private-key #{PRIVATE_EC_KEY_FILE} + ] + + use_ui @ui do + @cmd.execute + end + + output = @ui.output.split "\n" + + assert_equal "Certificate: #{File.join @tempdir, "gem-public_cert.pem"}", output.shift assert_empty output assert_empty @ui.error - assert_path_exist File.join(@tempdir, 'gem-public_cert.pem') + assert_path_exist File.join(@tempdir, "gem-public_cert.pem") + assert_path_not_exist File.join(@tempdir, "gem-private_key.pem") end def test_execute_certificate @@ -284,8 +342,8 @@ Added '/CN=alternate/DC=example' @cmd.handle_options %W[--certificate #{PUBLIC_CERT_FILE}] end - assert_equal '', @ui.output - assert_equal '', @ui.error + assert_equal "", @ui.output + assert_equal "", @ui.error assert_equal PUBLIC_CERT.to_pem, @cmd.options[:issuer_cert].to_pem end @@ -324,8 +382,8 @@ Added '/CN=alternate/DC=example' @cmd.send :handle_options, %W[--private-key #{PRIVATE_KEY_FILE}] end - assert_equal '', @ui.output - assert_equal '', @ui.error + assert_equal "", @ui.output + assert_equal "", @ui.error assert_equal PRIVATE_KEY.to_pem, @cmd.options[:key].to_pem end @@ -335,8 +393,8 @@ Added '/CN=alternate/DC=example' @cmd.send :handle_options, %W[--private-key #{ENCRYPTED_PRIVATE_KEY_PATH}] end - assert_equal '', @ui.output - assert_equal '', @ui.error + assert_equal "", @ui.output + assert_equal "", @ui.error assert_equal ENCRYPTED_PRIVATE_KEY.to_pem, @cmd.options[:key].to_pem end @@ -355,7 +413,7 @@ Added '/CN=alternate/DC=example' end assert_equal "Removed '/CN=nobody/DC=example'\n", @ui.output - assert_equal '', @ui.error + assert_equal "", @ui.error assert_path_not_exist cert_path end @@ -382,7 +440,7 @@ Removed '/CN=nobody/DC=example' EXPECTED assert_equal expected, @ui.output - assert_equal '', @ui.error + assert_equal "", @ui.error assert_path_not_exist public_path assert_path_not_exist alternate_path @@ -410,17 +468,17 @@ Removed '/CN=alternate/DC=example' EXPECTED assert_equal expected, @ui.output - assert_equal '', @ui.error + assert_equal "", @ui.error assert_path_not_exist public_path assert_path_not_exist alternate_path end def test_execute_sign - path = File.join @tempdir, 'cert.pem' - Gem::Security.write ALTERNATE_CERT, path, 0600 + path = File.join @tempdir, "cert.pem" + Gem::Security.write ALTERNATE_CERT, path, 0o600 - assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s + assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s @cmd.handle_options %W[ --private-key #{PRIVATE_KEY_FILE} @@ -433,23 +491,23 @@ Removed '/CN=alternate/DC=example' @cmd.execute end - assert_equal '', @ui.output - assert_equal '', @ui.error + assert_equal "", @ui.output + assert_equal "", @ui.error cert = OpenSSL::X509::Certificate.new File.read path - assert_equal '/CN=nobody/DC=example', cert.issuer.to_s + assert_equal "/CN=nobody/DC=example", cert.issuer.to_s - mask = 0100600 & (~File.umask) + mask = 0o100600 & (~File.umask) - assert_equal mask, File.stat(path).mode unless win_platform? + assert_equal mask, File.stat(path).mode unless Gem.win_platform? end def test_execute_sign_encrypted_key - path = File.join @tempdir, 'cert.pem' - Gem::Security.write ALTERNATE_CERT, path, 0600 + path = File.join @tempdir, "cert.pem" + Gem::Security.write ALTERNATE_CERT, path, 0o600 - assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s + assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s @cmd.handle_options %W[ --private-key #{ENCRYPTED_PRIVATE_KEY_PATH} @@ -462,31 +520,31 @@ Removed '/CN=alternate/DC=example' @cmd.execute end - assert_equal '', @ui.output - assert_equal '', @ui.error + assert_equal "", @ui.output + assert_equal "", @ui.error cert = OpenSSL::X509::Certificate.new File.read path - assert_equal '/CN=nobody/DC=example', cert.issuer.to_s + assert_equal "/CN=nobody/DC=example", cert.issuer.to_s - mask = 0100600 & (~File.umask) + mask = 0o100600 & (~File.umask) - assert_equal mask, File.stat(path).mode unless win_platform? + assert_equal mask, File.stat(path).mode unless Gem.win_platform? end def test_execute_sign_default - FileUtils.mkdir_p File.join Gem.user_home, '.gem' + FileUtils.mkdir_p File.join Gem.user_home, ".gem" - private_key_path = File.join Gem.user_home, '.gem', 'gem-private_key.pem' + private_key_path = File.join Gem.user_home, ".gem", "gem-private_key.pem" Gem::Security.write PRIVATE_KEY, private_key_path - public_cert_path = File.join Gem.user_home, '.gem', 'gem-public_cert.pem' + public_cert_path = File.join Gem.user_home, ".gem", "gem-public_cert.pem" Gem::Security.write PUBLIC_CERT, public_cert_path - path = File.join @tempdir, 'cert.pem' - Gem::Security.write ALTERNATE_CERT, path, 0600 + path = File.join @tempdir, "cert.pem" + Gem::Security.write ALTERNATE_CERT, path, 0o600 - assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s + assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s @cmd.handle_options %W[--sign #{path}] @@ -494,31 +552,31 @@ Removed '/CN=alternate/DC=example' @cmd.execute end - assert_equal '', @ui.output - assert_equal '', @ui.error + assert_equal "", @ui.output + assert_equal "", @ui.error cert = OpenSSL::X509::Certificate.new File.read path - assert_equal '/CN=nobody/DC=example', cert.issuer.to_s + assert_equal "/CN=nobody/DC=example", cert.issuer.to_s - mask = 0100600 & (~File.umask) + mask = 0o100600 & (~File.umask) - assert_equal mask, File.stat(path).mode unless win_platform? + assert_equal mask, File.stat(path).mode unless Gem.win_platform? end def test_execute_sign_default_encrypted_key - FileUtils.mkdir_p File.join(Gem.user_home, '.gem') + FileUtils.mkdir_p File.join(Gem.user_home, ".gem") - private_key_path = File.join Gem.user_home, '.gem', 'gem-private_key.pem' - Gem::Security.write ENCRYPTED_PRIVATE_KEY, private_key_path, 0600, PRIVATE_KEY_PASSPHRASE + private_key_path = File.join Gem.user_home, ".gem", "gem-private_key.pem" + Gem::Security.write ENCRYPTED_PRIVATE_KEY, private_key_path, 0o600, PRIVATE_KEY_PASSPHRASE - public_cert_path = File.join Gem.user_home, '.gem', 'gem-public_cert.pem' + public_cert_path = File.join Gem.user_home, ".gem", "gem-public_cert.pem" Gem::Security.write PUBLIC_CERT, public_cert_path - path = File.join @tempdir, 'cert.pem' - Gem::Security.write ALTERNATE_CERT, path, 0600 + path = File.join @tempdir, "cert.pem" + Gem::Security.write ALTERNATE_CERT, path, 0o600 - assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s + assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s @cmd.handle_options %W[--sign #{path}] @@ -526,28 +584,28 @@ Removed '/CN=alternate/DC=example' @cmd.execute end - assert_equal '', @ui.output - assert_equal '', @ui.error + assert_equal "", @ui.output + assert_equal "", @ui.error cert = OpenSSL::X509::Certificate.new File.read path - assert_equal '/CN=nobody/DC=example', cert.issuer.to_s + assert_equal "/CN=nobody/DC=example", cert.issuer.to_s - mask = 0100600 & (~File.umask) + mask = 0o100600 & (~File.umask) - assert_equal mask, File.stat(path).mode unless win_platform? + assert_equal mask, File.stat(path).mode unless Gem.win_platform? end def test_execute_sign_no_cert - FileUtils.mkdir_p File.join Gem.user_home, '.gem' + FileUtils.mkdir_p File.join Gem.user_home, ".gem" - private_key_path = File.join Gem.user_home, '.gem', 'gem-private_key.pem' + private_key_path = File.join Gem.user_home, ".gem", "gem-private_key.pem" Gem::Security.write PRIVATE_KEY, private_key_path - path = File.join @tempdir, 'cert.pem' - Gem::Security.write ALTERNATE_CERT, path, 0600 + path = File.join @tempdir, "cert.pem" + Gem::Security.write ALTERNATE_CERT, path, 0o600 - assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s + assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s @cmd.handle_options %W[--sign #{path}] @@ -557,7 +615,7 @@ Removed '/CN=alternate/DC=example' end end - assert_equal '', @ui.output + assert_equal "", @ui.output expected = <<-EXPECTED ERROR: --certificate not specified and ~/.gem/gem-public_cert.pem does not exist @@ -567,15 +625,15 @@ ERROR: --certificate not specified and ~/.gem/gem-public_cert.pem does not exis end def test_execute_sign_no_key - FileUtils.mkdir_p File.join Gem.user_home, '.gem' + FileUtils.mkdir_p File.join Gem.user_home, ".gem" - public_cert_path = File.join Gem.user_home, '.gem', 'gem-public_cert.pem' + public_cert_path = File.join Gem.user_home, ".gem", "gem-public_cert.pem" Gem::Security.write PUBLIC_CERT, public_cert_path - path = File.join @tempdir, 'cert.pem' - Gem::Security.write ALTERNATE_CERT, path, 0600 + path = File.join @tempdir, "cert.pem" + Gem::Security.write ALTERNATE_CERT, path, 0o600 - assert_equal '/CN=alternate/DC=example', ALTERNATE_CERT.issuer.to_s + assert_equal "/CN=alternate/DC=example", ALTERNATE_CERT.issuer.to_s @cmd.handle_options %W[--sign #{path}] @@ -585,7 +643,7 @@ ERROR: --certificate not specified and ~/.gem/gem-public_cert.pem does not exis end end - assert_equal '', @ui.output + assert_equal "", @ui.output expected = <<-EXPECTED ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exist @@ -598,10 +656,10 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis 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 + path = File.join @tempdir, "cert.pem" + Gem::Security.write EXPIRED_PUBLIC_CERT, path, 0o600 - assert_equal '/CN=nobody/DC=example', EXPIRED_PUBLIC_CERT.issuer.to_s + 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)) @cleanup << tmp_expired_cert_file @@ -619,21 +677,22 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis expected_path = File.join(gem_path, "#{File.basename(tmp_expired_cert_file)}.expired") + assert_include(@ui.output, "INFO: Your certificate #{tmp_expired_cert_file} has been re-signed\n") 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]+/, + /INFO: Your expired certificate will be located at: #{Regexp.quote(expected_path)}\.[0-9]+/, @ui.output ) - assert_equal '', @ui.error + 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 + path = File.join @tempdir, "cert.pem" + Gem::Security.write EXPIRED_PUBLIC_CERT, path, 0o600 - assert_equal '/CN=nobody/DC=example', EXPIRED_PUBLIC_CERT.issuer.to_s + 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)) @cleanup << tmp_expired_cert_file @@ -655,7 +714,7 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis 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 + assert_equal "", @ui.error end def test_handle_options @@ -674,29 +733,29 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis ] assert_equal [PUBLIC_CERT.to_pem, ALTERNATE_CERT.to_pem], - @cmd.options[:add].map {|cert| cert.to_pem } + @cmd.options[:add].map(&:to_pem) assert_equal %w[nobody example], @cmd.options[:remove] assert_equal %w[nobody@example other@example], - @cmd.options[:build].map {|name| name.to_s } + @cmd.options[:build].map(&:to_s) - assert_equal ['', 'example'], @cmd.options[:list] + assert_equal ["", "example"], @cmd.options[:list] end def test_handle_options_add_bad - nonexistent = File.join @tempdir, 'nonexistent' - e = assert_raise OptionParser::InvalidArgument do + nonexistent = File.join @tempdir, "nonexistent" + e = assert_raise Gem::OptionParser::InvalidArgument do @cmd.handle_options %W[--add #{nonexistent}] end assert_equal "invalid argument: --add #{nonexistent}: does not exist", e.message - bad = File.join @tempdir, 'bad' + bad = File.join @tempdir, "bad" FileUtils.touch bad - e = assert_raise OptionParser::InvalidArgument do + e = assert_raise Gem::OptionParser::InvalidArgument do @cmd.handle_options %W[--add #{bad}] end @@ -705,51 +764,51 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis end def test_handle_options_certificate - nonexistent = File.join @tempdir, 'nonexistent' - e = assert_raise OptionParser::InvalidArgument do + nonexistent = File.join @tempdir, "nonexistent" + e = assert_raise Gem::OptionParser::InvalidArgument do @cmd.handle_options %W[--certificate #{nonexistent}] end assert_equal "invalid argument: --certificate #{nonexistent}: does not exist", e.message - bad = File.join @tempdir, 'bad' + bad = File.join @tempdir, "bad" FileUtils.touch bad - e = assert_raise OptionParser::InvalidArgument do + e = assert_raise Gem::OptionParser::InvalidArgument do @cmd.handle_options %W[--certificate #{bad}] end - assert_equal "invalid argument: " + + assert_equal "invalid argument: " \ "--certificate #{bad}: invalid X509 certificate", e.message end def test_handle_options_key_bad - nonexistent = File.join @tempdir, 'nonexistent' - e = assert_raise OptionParser::InvalidArgument do + nonexistent = File.join @tempdir, "nonexistent" + e = assert_raise Gem::OptionParser::InvalidArgument do @cmd.handle_options %W[--private-key #{nonexistent}] end - assert_equal "invalid argument: " + + assert_equal "invalid argument: " \ "--private-key #{nonexistent}: does not exist", e.message - bad = File.join @tempdir, 'bad' + bad = File.join @tempdir, "bad" FileUtils.touch bad - e = assert_raise OptionParser::InvalidArgument do + e = assert_raise Gem::OptionParser::InvalidArgument do @cmd.handle_options %W[--private-key #{bad}] end - assert_equal "invalid argument: --private-key #{bad}: invalid RSA key", + assert_equal "invalid argument: --private-key #{bad}: invalid RSA, DSA, or EC key", e.message - e = assert_raise OptionParser::InvalidArgument do + e = assert_raise Gem::OptionParser::InvalidArgument do @cmd.handle_options %W[--private-key #{PUBLIC_KEY_FILE}] end - assert_equal "invalid argument: " + + assert_equal "invalid argument: " \ "--private-key #{PUBLIC_KEY_FILE}: private key not found", e.message end @@ -791,8 +850,8 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis end def test_handle_options_sign_nonexistent - nonexistent = File.join @tempdir, 'nonexistent' - e = assert_raise OptionParser::InvalidArgument do + nonexistent = File.join @tempdir, "nonexistent" + e = assert_raise Gem::OptionParser::InvalidArgument do @cmd.handle_options %W[ --private-key #{ALTERNATE_KEY_FILE} |