Skip to content

Commit 339165f

Browse files
junarugaclaude
andcommitted
Fix Artifice.deactivate to properly restore Gem::Net::HTTP
The hardcoded Gem::Net::HTTP in Artifice.deactivate, is actually the replaced Artifice::Net::HTTP. This doesn't restore the original Gem::Net::HTTP. Restore the saved original Gem::Net::HTTP in Artifice.deactivate This issue caused the tests sometimes failed in spec/bundler/fetcher/gem_remote_fetcher_local_ssl_server_spec.rb using Artifice::Net::HTTP unintentionally. Because localhost is not included in spec/support/artifice/helpers/endpoint.rb - permitted_hosts caused HTTP status 403 (response.body: "Host not permitted"). But Gem::Net::HTTP should be used in the tests instead of Artifice::Net::HTTP. Possibly this issue happens when Artifice.deactivate is called in other tests such as spec/commands/ssl_spec.rb. That's why this issue sometimes happened rather than always. ``` 1) Bundler::Fetcher local SSL server #connection PQC connects Failure/Error: expect(response.code).to eq("200") expected: #<Encoding:UTF-8> "200" got: #<Encoding:ASCII-8BIT> "403" (compared using ==) # ./spec/bundler/fetcher/gem_remote_fetcher_local_ssl_server_spec.rb:49:in 'block (4 levels) in <top (required)>' # ./spec/spec_helper.rb:164:in 'block (4 levels) in <top (required)>' # ./spec/spec_helper.rb:164:in 'block (3 levels) in <top (required)>' # ./spec/support/helpers.rb:414:in 'block in Spec::Helpers#with_gem_path_as' # ./spec/support/helpers.rb:428:in 'Spec::Helpers#without_env_side_effects' # ./spec/support/helpers.rb:409:in 'Spec::Helpers#with_gem_path_as' # ./spec/spec_helper.rb:163:in 'block (2 levels) in <top (required)>' # ./lib/rubygems.rb:306:in 'Kernel#load' # ./lib/rubygems.rb:306:in 'Gem.activate_and_load_bin_path' ``` spec/commands/ssl_spec.rb ``` ... after(:each) do ... Artifice.deactivate ... end ... ``` Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 446fddb commit 339165f

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

spec/support/artifice/helpers/artifice.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ module Artifice
1212
def self.activate_with(endpoint)
1313
require_relative "rack_request"
1414

15+
@original_net_http = ::Gem::Net::HTTP
1516
Net::HTTP.endpoint = endpoint
1617
replace_net_http(Artifice::Net::HTTP)
1718
end
1819

1920
# Deactivate the Artifice replacement.
2021
def self.deactivate
21-
replace_net_http(::Gem::Net::HTTP)
22+
replace_net_http(@original_net_http) if @original_net_http
23+
@original_net_http = nil
2224
end
2325

2426
def self.replace_net_http(value)

0 commit comments

Comments
 (0)