Skip to content

Commit 8047213

Browse files
hsbtclaude
authored andcommitted
[ruby/rubygems] Honor explicit --attestation option regardless of platform and host
The send_push_request method previously skipped all attestation handling on JRuby, non-rubygems.org hosts, or outside GitHub Actions. This meant that even when a user explicitly passed --attestation with a local sigstore bundle, the attestation was silently ignored. Now we check options[:attestations] first and always use them when provided, only gating the auto-attestation path behind the platform/host/CI checks. ruby/rubygems@0178a0dc56 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 54ce911 commit 8047213

2 files changed

Lines changed: 13 additions & 19 deletions

File tree

lib/rubygems/commands/push_command.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ def send_gem(name)
9292
private
9393

9494
def send_push_request(name, args)
95-
# Attestation is only supported on rubygems.org with GitHub Actions (not JRuby)
96-
if RUBY_ENGINE != "jruby" && attestation_supported_host? && ENV["GITHUB_ACTIONS"]
95+
# Always honor explicit --attestation option
96+
# Auto-attestation is only supported on rubygems.org with GitHub Actions (not JRuby)
97+
if options[:attestations].any? || (RUBY_ENGINE != "jruby" && attestation_supported_host? && ENV["GITHUB_ACTIONS"])
9798
send_push_request_with_attestation(name, args)
9899
else
99100
send_push_request_without_attestation(name, args)

test/rubygems/test_gem_commands_push_command.rb

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,19 @@ def test_execute_host
103103
end
104104

105105
def test_execute_attestation
106-
omit if RUBY_ENGINE == "jruby"
107-
108-
ENV["GITHUB_ACTIONS"] = "true"
109-
begin
110-
@response = "Successfully registered gem: freewill (1.0.0)"
111-
@fetcher.data["#{Gem.host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
106+
@response = "Successfully registered gem: freewill (1.0.0)"
107+
@fetcher.data["#{Gem.host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK")
112108

113-
File.write("#{@path}.sigstore.json", "attestation")
114-
@cmd.options[:args] = [@path]
115-
@cmd.options[:attestations] = ["#{@path}.sigstore.json"]
109+
File.write("#{@path}.sigstore.json", "attestation")
110+
@cmd.options[:args] = [@path]
111+
@cmd.options[:attestations] = ["#{@path}.sigstore.json"]
116112

117-
@cmd.execute
113+
@cmd.execute
118114

119-
assert_equal Gem::Net::HTTP::Post, @fetcher.last_request.class
120-
content_length = @fetcher.last_request["Content-Length"].to_i
121-
assert_equal content_length, @fetcher.last_request.body.length
122-
assert_attestation_multipart Gem.read_binary("#{@path}.sigstore.json")
123-
ensure
124-
ENV.delete("GITHUB_ACTIONS")
125-
end
115+
assert_equal Gem::Net::HTTP::Post, @fetcher.last_request.class
116+
content_length = @fetcher.last_request["Content-Length"].to_i
117+
assert_equal content_length, @fetcher.last_request.body.length
118+
assert_attestation_multipart Gem.read_binary("#{@path}.sigstore.json")
126119
end
127120

128121
def test_execute_attestation_auto

0 commit comments

Comments
 (0)