mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-08-07 15:28:45 +09:00
Address Copilot review: require ipaddr and re-assert the socket port
The guard uses IPAddr but relied on something else loading it first; require it explicitly. And the rebinding tests lost their port assertion when the matchers were loosened for newer Net::HTTP keyword args, so check the port alongside the IP again.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
require "ipaddr"
|
||||
require "resolv"
|
||||
|
||||
module RestrictedHTTP
|
||||
|
||||
@@ -50,7 +50,7 @@ class Opengraph::FetchTest < ActiveSupport::TestCase
|
||||
WebMock.disable_net_connect! allow: [ @url.host ]
|
||||
Resolv.stubs(:getaddress).with(@url.host).returns("1.2.3.4", "127.0.0.1")
|
||||
TCPSocket.expects(:open).with { |*args, **| args.first == @url.host }.never
|
||||
TCPSocket.expects(:open).with { |*args, **| args.first == "1.2.3.4" }.throws(:dns_not_rebound)
|
||||
TCPSocket.expects(:open).with { |*args, **| args.first == "1.2.3.4" && args[1] == 443 }.throws(:dns_not_rebound)
|
||||
|
||||
assert_throws :dns_not_rebound do
|
||||
@fetch.fetch_document(@url)
|
||||
@@ -67,7 +67,7 @@ class Opengraph::FetchTest < ActiveSupport::TestCase
|
||||
WebMock.disable_net_connect! allow: [ @url.host ]
|
||||
Resolv.stubs(:getaddress).with(@url.host).returns("1.2.3.4", "127.0.0.1")
|
||||
TCPSocket.expects(:open).with { |*args, **| args.first == @url.host }.never
|
||||
TCPSocket.expects(:open).with { |*args, **| args.first == "1.2.3.4" }.throws(:dns_not_rebound)
|
||||
TCPSocket.expects(:open).with { |*args, **| args.first == "1.2.3.4" && args[1] == 443 }.throws(:dns_not_rebound)
|
||||
|
||||
assert_throws :dns_not_rebound do
|
||||
@fetch.fetch_document(URI.parse("https://www.other.com/"), ip: "1.2.3.4")
|
||||
|
||||
Reference in New Issue
Block a user