Skip to content

Commit 5e024ad

Browse files
hsbtclaude
authored andcommitted
[ruby/rubygems] Forward security policy to old-format gems
The Gem::Package.new factory forwarded security_policy via super on the normal path but dropped it on the old-format branch, so -P/--trust-policy was silently ignored for MD5SUM gems and verify became a no-op. ruby/rubygems@7cd3cdb6dd Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent aa4d4c4 commit 5e024ad

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

lib/rubygems/package.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def self.new(gem, security_policy = nil)
161161
return super unless gem.start
162162
return super unless gem.start.include? "MD5SUM ="
163163

164-
Gem::Package::Old.new gem
164+
Gem::Package::Old.new gem, security_policy
165165
end
166166

167167
##

test/rubygems/test_gem_package.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ def test_class_new_old_format
3333
assert package.spec
3434
end
3535

36+
def test_class_new_old_format_forwards_security_policy
37+
pend "jruby can't require the simple_gem file" if Gem.java_platform?
38+
pend "openssl is missing" unless Gem::HAVE_OPENSSL
39+
require_relative "simple_gem"
40+
File.open "old_format.gem", "wb" do |io|
41+
io.write SIMPLE_GEM
42+
end
43+
44+
package = Gem::Package.new "old_format.gem", Gem::Security::HighSecurity
45+
46+
e = assert_raise Gem::Security::Exception do
47+
package.verify
48+
end
49+
50+
assert_equal "old format gems do not contain signatures " \
51+
"and cannot be verified",
52+
e.message
53+
end
54+
3655
def test_add_checksums
3756
gem_io = StringIO.new
3857

0 commit comments

Comments
 (0)