2011-01-18 19:08:49 -05:00
|
|
|
######################################################################
|
|
|
|
# This file is imported from the rubygems project.
|
|
|
|
# DO NOT make modifications in this repo. They _will_ be reverted!
|
|
|
|
# File a patch instead and assign it to Ryan Davis or Eric Hodel.
|
|
|
|
######################################################################
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/commands/cert_command'
|
2011-03-07 03:44:45 -05:00
|
|
|
require 'rubygems/fix_openssl_warnings' if RUBY_VERSION < "1.9"
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-02-10 03:00:19 -05:00
|
|
|
unless defined? OpenSSL then
|
|
|
|
warn "`gem cert` tests are being skipped, module OpenSSL not found"
|
|
|
|
end
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemCommandsCertCommand < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@orig_security_trust_dir = Gem::Security::OPT[:trust_dir]
|
|
|
|
Gem::Security::OPT[:trust_dir] = @tempdir
|
|
|
|
|
|
|
|
@cmd = Gem::Commands::CertCommand.new
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
root = File.expand_path(File.dirname(__FILE__), @@project_dir)
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
FileUtils.cp File.join(root, 'data', 'gem-private_key.pem'), @tempdir
|
|
|
|
FileUtils.cp File.join(root, 'data', 'gem-public_cert.pem'), @tempdir
|
|
|
|
|
|
|
|
@cert_file_name = File.join @tempdir, 'gem-public_cert.pem'
|
|
|
|
@pkey_file_name = File.join @tempdir, 'gem-private_key.pem'
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
Gem::Security::OPT[:trust_dir] = @orig_security_trust_dir
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_add
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.send :handle_options, %W[--add #{@cert_file_name}]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "Added '/CN=rubygems/DC=example/DC=com'\n", @ui.output
|
|
|
|
assert_equal '', @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_build
|
|
|
|
FileUtils.rm @cert_file_name
|
|
|
|
FileUtils.rm @pkey_file_name
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
Dir.chdir @tempdir do
|
|
|
|
@cmd.send :handle_options, %W[--build nobody@example.com]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
output = @ui.output.split "\n"
|
|
|
|
|
|
|
|
assert_equal 'Public Cert: gem-public_cert.pem', output.shift
|
|
|
|
assert_equal 'Private Key: gem-private_key.pem', output.shift
|
|
|
|
assert_equal 'Don\'t forget to move the key file to somewhere private...',
|
|
|
|
output.shift
|
|
|
|
assert_equal [], output
|
|
|
|
|
|
|
|
assert_equal '', @ui.error
|
|
|
|
|
|
|
|
assert File.exist?(File.join(@tempdir, 'gem-private_key.pem'))
|
|
|
|
assert File.exist?(File.join(@tempdir, 'gem-public_cert.pem'))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_certificate
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.send :handle_options, %W[--certificate #{@cert_file_name}]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal '', @ui.output
|
|
|
|
assert_equal '', @ui.error
|
|
|
|
|
|
|
|
assert_equal File.read(@cert_file_name),
|
2011-01-18 19:08:49 -05:00
|
|
|
@cmd.options[:issuer_cert].to_s
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_list
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.send :handle_options, %W[--list]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "/CN=rubygems/DC=example/DC=com\n", @ui.output
|
|
|
|
assert_equal '', @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_private_key
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.send :handle_options, %W[--private-key #{@pkey_file_name}]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal '', @ui.output
|
|
|
|
assert_equal '', @ui.error
|
|
|
|
|
|
|
|
assert_equal File.read(@pkey_file_name),
|
2011-01-18 19:08:49 -05:00
|
|
|
@cmd.options[:issuer_key].to_s
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_remove
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.send :handle_options, %W[--remove rubygems]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "Removed '/CN=rubygems/DC=example/DC=com'\n", @ui.output
|
|
|
|
assert_equal '', @ui.error
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
refute File.exist?(@cert_file_name)
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_sign
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.send :handle_options, %W[
|
|
|
|
-K #{@pkey_file_name} -C #{@cert_file_name} --sign #{@cert_file_name}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal '', @ui.output
|
|
|
|
assert_equal '', @ui.error
|
|
|
|
|
|
|
|
# HACK this test sucks
|
|
|
|
end
|
|
|
|
|
2008-02-10 03:00:19 -05:00
|
|
|
end if defined? OpenSSL
|
2007-11-10 02:48:56 -05:00
|
|
|
|