2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2021-06-01 23:32:47 -04:00
|
|
|
require_relative 'helper'
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
unless Gem.java_platform? # jruby can't require the simple_gem file
|
|
|
|
require 'rubygems/simple_gem'
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
class TestGemPackageOld < Gem::TestCase
|
|
|
|
def setup
|
|
|
|
super
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
File.open 'old_format.gem', 'wb' do |io|
|
|
|
|
io.write SIMPLE_GEM
|
|
|
|
end
|
2013-03-11 17:29:32 -04:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
@package = Gem::Package::Old.new 'old_format.gem'
|
|
|
|
@destination = File.join @tempdir, 'extract'
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
FileUtils.mkdir_p @destination
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
def test_contents
|
|
|
|
assert_equal %w[lib/foo.rb lib/test.rb lib/test/wow.rb], @package.contents
|
|
|
|
end
|
2013-09-14 04:59:02 -04:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
def test_contents_security_policy
|
2021-05-10 23:27:07 -04:00
|
|
|
pend 'openssl is missing' unless Gem::HAVE_OPENSSL
|
2013-02-07 17:48:35 -05:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
@package.security_policy = Gem::Security::AlmostNoSecurity
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::Security::Exception do
|
2019-06-01 05:45:11 -04:00
|
|
|
@package.contents
|
|
|
|
end
|
2013-02-07 17:48:35 -05:00
|
|
|
end
|
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
def test_extract_files
|
|
|
|
@package.extract_files @destination
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
extracted = File.join @destination, 'lib/foo.rb'
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_exist extracted
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
mask = 0100644 & (~File.umask)
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
assert_equal mask, File.stat(extracted).mode unless win_platform?
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
def test_extract_files_security_policy
|
2021-05-10 23:27:07 -04:00
|
|
|
pend 'openssl is missing' unless Gem::HAVE_OPENSSL
|
2013-09-14 04:59:02 -04:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
@package.security_policy = Gem::Security::AlmostNoSecurity
|
2013-02-07 17:48:35 -05:00
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::Security::Exception do
|
2019-06-01 05:45:11 -04:00
|
|
|
@package.extract_files @destination
|
|
|
|
end
|
2013-02-07 17:48:35 -05:00
|
|
|
end
|
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
def test_spec
|
|
|
|
assert_equal 'testing', @package.spec.name
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
def test_spec_security_policy
|
2021-05-10 23:27:07 -04:00
|
|
|
pend 'openssl is missing' unless Gem::HAVE_OPENSSL
|
2013-09-14 04:59:02 -04:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
@package.security_policy = Gem::Security::AlmostNoSecurity
|
2013-02-07 17:48:35 -05:00
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::Security::Exception do
|
2019-06-01 05:45:11 -04:00
|
|
|
@package.spec
|
|
|
|
end
|
2013-02-07 17:48:35 -05:00
|
|
|
end
|
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
def test_verify
|
2021-05-10 23:27:07 -04:00
|
|
|
pend 'openssl is missing' unless Gem::HAVE_OPENSSL
|
2013-09-14 04:59:02 -04:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
assert @package.verify
|
2013-02-07 17:48:35 -05:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
@package.security_policy = Gem::Security::NoSecurity
|
2013-02-07 17:48:35 -05:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
assert @package.verify
|
2013-02-07 17:48:35 -05:00
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
@package.security_policy = Gem::Security::AlmostNoSecurity
|
2013-02-07 17:48:35 -05:00
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
e = assert_raise Gem::Security::Exception do
|
2019-06-01 05:45:11 -04:00
|
|
|
@package.verify
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'old format gems do not contain signatures ' +
|
|
|
|
'and cannot be verified',
|
|
|
|
e.message
|
2013-02-07 17:48:35 -05:00
|
|
|
end
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|