From 53b5cb211bf0862ad7d48a9ab5b2476786268f07 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 10:15:24 +0000 Subject: [PATCH 1/3] Initial plan From a23584920872e46f1936a67137da2dfa68534385 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 10:18:20 +0000 Subject: [PATCH 2/3] Add test coverage for skipping auto-attestation Co-authored-by: hsbt <12301+hsbt@users.noreply.github.com> --- .../test_gem_commands_push_command.rb | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb index 1f357159d3d1..cbf0bf3f0c9b 100644 --- a/test/rubygems/test_gem_commands_push_command.rb +++ b/test/rubygems/test_gem_commands_push_command.rb @@ -155,6 +155,55 @@ def test_execute_attestation_fallback @fetcher.last_request["Content-Type"] end + def test_execute_attestation_skipped_on_non_rubygems_host + @spec, @path = util_gem "freebird", "1.0.1" do |spec| + spec.metadata["allowed_push_host"] = "https://privategemserver.example" + end + + @response = "Successfully registered gem: freebird (1.0.1)" + @fetcher.data["#{@spec.metadata["allowed_push_host"]}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK") + + @cmd.options[:args] = [@path] + + attest_called = false + @cmd.stub(:attest!, proc { attest_called = true; raise "attest! should not be called" }) do + @cmd.execute + end + + refute attest_called, "attest! should not be called for non-rubygems.org hosts" + assert_equal Gem::Net::HTTP::Post, @fetcher.last_request.class + assert_equal Gem.read_binary(@path), @fetcher.last_request.body + assert_equal "application/octet-stream", + @fetcher.last_request["Content-Type"] + end + + def test_execute_attestation_skipped_on_jruby + @response = "Successfully registered gem: freewill (1.0.0)" + @fetcher.data["#{Gem.host}/api/v1/gems"] = HTTPResponseFactory.create(body: @response, code: 200, msg: "OK") + + @cmd.options[:args] = [@path] + + attest_called = false + engine = RUBY_ENGINE + Object.send :remove_const, :RUBY_ENGINE + Object.const_set :RUBY_ENGINE, "jruby" + + begin + @cmd.stub(:attest!, proc { attest_called = true; raise "attest! should not be called" }) do + @cmd.execute + end + + refute attest_called, "attest! should not be called on JRuby" + assert_equal Gem::Net::HTTP::Post, @fetcher.last_request.class + assert_equal Gem.read_binary(@path), @fetcher.last_request.body + assert_equal "application/octet-stream", + @fetcher.last_request["Content-Type"] + ensure + Object.send :remove_const, :RUBY_ENGINE + Object.const_set :RUBY_ENGINE, engine + end + end + def test_execute_allowed_push_host @spec, @path = util_gem "freebird", "1.0.1" do |spec| spec.metadata["allowed_push_host"] = "https://privategemserver.example" From 4cd2f189c54b9d009c4d87074b9ad999d4dcae0a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Feb 2026 10:19:16 +0000 Subject: [PATCH 3/3] Remove raise from stub to rely on flag for test assertions Co-authored-by: hsbt <12301+hsbt@users.noreply.github.com> --- test/rubygems/test_gem_commands_push_command.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb index cbf0bf3f0c9b..704c1115c721 100644 --- a/test/rubygems/test_gem_commands_push_command.rb +++ b/test/rubygems/test_gem_commands_push_command.rb @@ -166,7 +166,7 @@ def test_execute_attestation_skipped_on_non_rubygems_host @cmd.options[:args] = [@path] attest_called = false - @cmd.stub(:attest!, proc { attest_called = true; raise "attest! should not be called" }) do + @cmd.stub(:attest!, proc { attest_called = true }) do @cmd.execute end @@ -189,7 +189,7 @@ def test_execute_attestation_skipped_on_jruby Object.const_set :RUBY_ENGINE, "jruby" begin - @cmd.stub(:attest!, proc { attest_called = true; raise "attest! should not be called" }) do + @cmd.stub(:attest!, proc { attest_called = true }) do @cmd.execute end