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