summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_commands_build_command.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-22 00:27:02 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-22 00:27:02 +0000
commit615ac3593499f54fde4b1eb0fba66b6bd944821b (patch)
tree1f0b0e97ee3dd51798658d53cee7eec976a83a97 /test/rubygems/test_gem_commands_build_command.rb
parentff31b35f6a66f3c1548e3356d506ff65a574be7f (diff)
Merge rubygems master branch from github.com/rubygems/rubygems.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems/test_gem_commands_build_command.rb')
-rw-r--r--test/rubygems/test_gem_commands_build_command.rb79
1 files changed, 76 insertions, 3 deletions
diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb
index 8048f3e8f5..f7c92ebd7e 100644
--- a/test/rubygems/test_gem_commands_build_command.rb
+++ b/test/rubygems/test_gem_commands_build_command.rb
@@ -6,6 +6,12 @@ require 'rubygems/package'
class TestGemCommandsBuildCommand < Gem::TestCase
+ CERT_FILE = cert_path 'public3072'
+ SIGNING_KEY = key_path 'private3072'
+
+ EXPIRED_CERT_FILE = cert_path 'expired'
+ PRIVATE_KEY_FILE = key_path 'private'
+
def setup
super
@@ -50,6 +56,32 @@ class TestGemCommandsBuildCommand < Gem::TestCase
util_test_build_gem @gem
end
+ def test_execute_bad_name
+ [".", "-", "_"].each do |special_char|
+ gem = util_spec 'some_gem_with_bad_name' do |s|
+ s.name = "#{special_char}bad_gem_name"
+ s.license = 'AGPL-3.0'
+ s.files = ['README.md']
+ end
+
+ gemspec_file = File.join(@tempdir, gem.spec_name)
+
+ File.open gemspec_file, 'w' do |gs|
+ gs.write gem.to_ruby
+ end
+
+ @cmd.options[:args] = [gemspec_file]
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ assert_raises Gem::InvalidSpecificationException do
+ @cmd.execute
+ end
+ end
+ end
+ end
+ end
+
def test_execute_strict_without_warnings
gemspec_file = File.join(@tempdir, @gem.spec_name)
@@ -221,9 +253,6 @@ class TestGemCommandsBuildCommand < Gem::TestCase
util_test_build_gem @gem
end
- CERT_FILE = cert_path 'public3072'
- SIGNING_KEY = key_path 'private3072'
-
def test_build_signed_gem
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
@@ -251,4 +280,48 @@ class TestGemCommandsBuildCommand < Gem::TestCase
assert gem.verify
end
+ def test_build_signed_gem_with_cert_expiration_length_days
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+
+ gem_path = File.join Gem.user_home, ".gem"
+ Dir.mkdir gem_path
+
+ trust_dir = Gem::Security.trust_dir
+
+ tmp_expired_cert_file = File.join gem_path, "gem-public_cert.pem"
+ File.write(tmp_expired_cert_file, File.read(EXPIRED_CERT_FILE))
+
+ tmp_private_key_file = File.join gem_path, "gem-private_key.pem"
+ File.write(tmp_private_key_file, File.read(PRIVATE_KEY_FILE))
+
+ spec = util_spec 'some_gem' do |s|
+ s.signing_key = tmp_private_key_file
+ s.cert_chain = [tmp_expired_cert_file]
+ end
+
+ gemspec_file = File.join(@tempdir, spec.spec_name)
+
+ File.open gemspec_file, 'w' do |gs|
+ gs.write spec.to_ruby
+ end
+
+ @cmd.options[:args] = [gemspec_file]
+
+ Gem.configuration.cert_expiration_length_days = 28
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ 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)
+
+ gem_file = File.join @tempdir, File.basename(spec.cache_file)
+
+ assert File.exist?(gem_file)
+ assert_equal(28, cert_days_to_expire)
+ end
+
end