Bug #11248 » rubygems-ruby_2_2.patch
| lib/rubygems/remote_fetcher.rb | ||
|---|---|---|
|
rescue Resolv::ResolvError
|
||
|
uri
|
||
|
else
|
||
|
URI.parse "#{uri.scheme}://#{res.target}#{uri.path}"
|
||
|
target = res.target.to_s.strip
|
||
|
if /\.#{Regexp.quote(host)}\z/ =~ target
|
||
|
return URI.parse "#{uri.scheme}://#{target}#{uri.path}"
|
||
|
end
|
||
|
uri
|
||
|
end
|
||
|
end
|
||
| test/rubygems/test_gem_remote_fetcher.rb | ||
|---|---|---|
|
end
|
||
|
def test_api_endpoint
|
||
|
uri = URI.parse "http://example.com/foo"
|
||
|
target = MiniTest::Mock.new
|
||
|
target.expect :target, "gems.example.com"
|
||
|
dns = MiniTest::Mock.new
|
||
|
dns.expect :getresource, target, [String, Object]
|
||
|
fetch = Gem::RemoteFetcher.new nil, dns
|
||
|
assert_equal URI.parse("http://gems.example.com/foo"), fetch.api_endpoint(uri)
|
||
|
target.verify
|
||
|
dns.verify
|
||
|
end
|
||
|
def test_api_endpoint_ignores_trans_domain_values
|
||
|
uri = URI.parse "http://gems.example.com/foo"
|
||
|
target = MiniTest::Mock.new
|
||
|
target.expect :target, "blah.com"
|
||
| ... | ... | |
|
dns.expect :getresource, target, [String, Object]
|
||
|
fetch = Gem::RemoteFetcher.new nil, dns
|
||
|
@fetcher = fetcher
|
||
|
assert_equal URI.parse("http://blah.com/foo"), fetch.api_endpoint(uri)
|
||
|
assert_equal URI.parse("http://gems.example.com/foo"), fetch.api_endpoint(uri)
|
||
|
target.verify
|
||
|
dns.verify
|
||
|
end
|
||
|
def test_api_endpoint_ignores_trans_domain_values_that_starts_with_original
|
||
|
uri = URI.parse "http://example.com/foo"
|
||
|
target = MiniTest::Mock.new
|
||
|
target.expect :target, "example.combadguy.com"
|
||
|
dns = MiniTest::Mock.new
|
||
|
dns.expect :getresource, target, [String, Object]
|
||
|
fetch = Gem::RemoteFetcher.new nil, dns
|
||
|
assert_equal URI.parse("http://example.com/foo"), fetch.api_endpoint(uri)
|
||
|
target.verify
|
||
|
dns.verify
|
||
|
end
|
||
|
def test_api_endpoint_ignores_trans_domain_values_that_end_with_original
|
||
|
uri = URI.parse "http://example.com/foo"
|
||
|
target = MiniTest::Mock.new
|
||
|
target.expect :target, "badexample.com"
|
||
|
dns = MiniTest::Mock.new
|
||
|
dns.expect :getresource, target, [String, Object]
|
||
|
fetch = Gem::RemoteFetcher.new nil, dns
|
||
|
assert_equal URI.parse("http://example.com/foo"), fetch.api_endpoint(uri)
|
||
|
target.verify
|
||
|
dns.verify
|
||