-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add test coverage for auto-attestation skipping on non-rubygems.org hosts and JRuby #9326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 }) 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 | ||||||||||||||||||||||
|
Comment on lines
+187
to
+191
|
||||||||||||||||||||||
| engine = RUBY_ENGINE | |
| Object.send :remove_const, :RUBY_ENGINE | |
| Object.const_set :RUBY_ENGINE, "jruby" | |
| begin | |
| begin | |
| engine = RUBY_ENGINE | |
| Object.send :remove_const, :RUBY_ENGINE | |
| Object.const_set :RUBY_ENGINE, "jruby" |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as above: the attest! stub returns true, so if attest! is unexpectedly called this test will likely error out during request construction rather than failing with a clear assertion message. Prefer a stub that explicitly fails if invoked so the failure points directly at the regression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
attest!stub returnstrue, so if the code path regresses andattest!is invoked, the test will likely fail with an unrelatedGem.read_binary(true)type error before reaching therefute attest_calledassertion. Consider making the stub explicitly fail (e.g., raising/flunking) to produce a clearer failure reason tied to the behavior being tested.