diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-09 23:21:36 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-09 23:21:36 +0000 |
commit | 47f0248b0858898dd24d1e654cedf174059ca677 (patch) | |
tree | 493e84160f8609db408d88349f0624a3ff92c3c2 /test/rubygems/test_gem_package.rb | |
parent | cd9f9e471977447a991ced4ea38efb2309459ef5 (diff) | |
download | bundler-47f0248b0858898dd24d1e654cedf174059ca677.tar.gz |
* lib/rubygems: Import RubyGems 2.1
* test/rubygems: Ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems/test_gem_package.rb')
-rw-r--r-- | test/rubygems/test_gem_package.rb | 121 |
1 files changed, 115 insertions, 6 deletions
diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb index bb78829bf9..55bb32af04 100644 --- a/test/rubygems/test_gem_package.rb +++ b/test/rubygems/test_gem_package.rb @@ -89,16 +89,19 @@ class TestGemPackage < Gem::Package::TarTestCase end expected = { - 'SHA1' => { - 'metadata.gz' => metadata_sha1, - 'data.tar.gz' => data_digests['SHA1'].hexdigest, - }, 'SHA512' => { 'metadata.gz' => metadata_sha512, 'data.tar.gz' => data_digests['SHA512'].hexdigest, } } + if defined?(OpenSSL::Digest) then + expected['SHA1'] = { + 'metadata.gz' => metadata_sha1, + 'data.tar.gz' => data_digests['SHA1'].hexdigest, + } + end + assert_equal expected, YAML.load(checksums) end @@ -162,12 +165,57 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_build_auto_signed + skip 'openssl is missing' unless defined?(OpenSSL::SSL) + 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 PRIVATE_KEY, private_key_path public_cert_path = File.join Gem.user_home, '.gem', 'gem-public_cert.pem' + FileUtils.cp PUBLIC_CERT_PATH, public_cert_path + + spec = Gem::Specification.new 'build', '1' + spec.summary = 'build' + spec.authors = 'build' + spec.files = ['lib/code.rb'] + + FileUtils.mkdir 'lib' + + open 'lib/code.rb', 'w' do |io| + io.write '# lib/code.rb' + end + + package = Gem::Package.new spec.file_name + package.spec = spec + + package.build + + assert_equal Gem::VERSION, spec.rubygems_version + assert_path_exists spec.file_name + + reader = Gem::Package.new spec.file_name + assert reader.verify + + assert_equal [PUBLIC_CERT.to_pem], reader.spec.cert_chain + + assert_equal %w[metadata.gz metadata.gz.sig + data.tar.gz data.tar.gz.sig + checksums.yaml.gz checksums.yaml.gz.sig], + reader.files + + assert_equal %w[lib/code.rb], reader.contents + end + + def test_build_auto_signed_encrypted_key + skip 'openssl is missing' unless defined?(OpenSSL::SSL) + + FileUtils.mkdir_p File.join(Gem.user_home, '.gem') + + private_key_path = File.join Gem.user_home, '.gem', 'gem-private_key.pem' + FileUtils.cp ENCRYPTED_PRIVATE_KEY_PATH, private_key_path + + public_cert_path = File.join Gem.user_home, '.gem', 'gem-public_cert.pem' Gem::Security.write PUBLIC_CERT, public_cert_path spec = Gem::Specification.new 'build', '1' @@ -216,6 +264,8 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_build_signed + skip 'openssl is missing' unless defined?(OpenSSL::SSL) + spec = Gem::Specification.new 'build', '1' spec.summary = 'build' spec.authors = 'build' @@ -250,6 +300,43 @@ class TestGemPackage < Gem::Package::TarTestCase assert_equal %w[lib/code.rb], reader.contents end + def test_build_signed_encryped_key + skip 'openssl is missing' unless defined?(OpenSSL::SSL) + + spec = Gem::Specification.new 'build', '1' + spec.summary = 'build' + spec.authors = 'build' + spec.files = ['lib/code.rb'] + spec.cert_chain = [PUBLIC_CERT.to_pem] + spec.signing_key = ENCRYPTED_PRIVATE_KEY + + FileUtils.mkdir 'lib' + + open 'lib/code.rb', 'w' do |io| + io.write '# lib/code.rb' + end + + package = Gem::Package.new spec.file_name + package.spec = spec + + package.build + + assert_equal Gem::VERSION, spec.rubygems_version + assert_path_exists spec.file_name + + reader = Gem::Package.new spec.file_name + assert reader.verify + + assert_equal spec, reader.spec + + assert_equal %w[metadata.gz metadata.gz.sig + data.tar.gz data.tar.gz.sig + checksums.yaml.gz checksums.yaml.gz.sig], + reader.files + + assert_equal %w[lib/code.rb], reader.contents + end + def test_contents package = Gem::Package.new @gem @@ -446,7 +533,7 @@ class TestGemPackage < Gem::Package::TarTestCase io.write metadata_gz end - digest = OpenSSL::Digest::SHA1.new + digest = Digest::SHA1.new digest << metadata_gz checksums = { @@ -478,7 +565,8 @@ class TestGemPackage < Gem::Package::TarTestCase def test_verify_corrupt Tempfile.open 'corrupt' do |io| data = Gem.gzip 'a' * 10 - io.write tar_file_header('metadata.gz', "\000x", 0644, data.length) + io.write \ + tar_file_header('metadata.gz', "\000x", 0644, data.length, Time.now) io.write data io.rewind @@ -517,6 +605,8 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_verify_security_policy + skip 'openssl is missing' unless defined?(OpenSSL::SSL) + package = Gem::Package.new @gem package.security_policy = Gem::Security::HighSecurity @@ -532,6 +622,8 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_verify_security_policy_low_security + skip 'openssl is missing' unless defined?(OpenSSL::SSL) + @spec.cert_chain = [PUBLIC_CERT.to_pem] @spec.signing_key = PRIVATE_KEY @@ -550,6 +642,8 @@ class TestGemPackage < Gem::Package::TarTestCase end def test_verify_security_policy_checksum_missing + skip 'openssl is missing' unless defined?(OpenSSL::SSL) + @spec.cert_chain = [PUBLIC_CERT.to_pem] @spec.signing_key = PRIVATE_KEY @@ -605,6 +699,21 @@ class TestGemPackage < Gem::Package::TarTestCase e.message end + # end #verify tests + + def test_verify_entry + entry = Object.new + def entry.full_name() raise ArgumentError, 'whatever' end + + package = Gem::Package.new @gem + + e = assert_raises Gem::Package::FormatError do + package.verify_entry entry + end + + assert_equal "package is corrupt, exception while verifying: whatever (ArgumentError) in #{@gem}", e.message + end + def test_spec package = Gem::Package.new @gem |