1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/rubygems/test_gem_commands_cert_command.rb
drbrain fbf59bdbea Import RubyGems trunk revision 1493.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-10 07:48:56 +00:00

122 lines
3 KiB
Ruby

require 'test/unit'
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
require 'rubygems/commands/cert_command'
class TestGemCommandsCertCommand < RubyGemTestCase
def setup
super
@orig_security_trust_dir = Gem::Security::OPT[:trust_dir]
Gem::Security::OPT[:trust_dir] = @tempdir
@cmd = Gem::Commands::CertCommand.new
root = File.expand_path(File.dirname(__FILE__))
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),
Gem::Security::OPT[:issuer_cert].to_s
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),
Gem::Security::OPT[:issuer_key].to_s
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
assert !File.exist?(@cert_file_name)
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
end