Commit fa107daf authored by rpereira2's avatar rpereira2

Improve the stub_domain_resolv spec helper

* Use instance_double instead of double.
* Add port parameter.
* Addrinfo does not have an attribute called ipv6_link_local?. It is
  actually called ipv6_linklocal?.
  These kinds of errors are prevented by using instance_double.
parent 27a6901a
...@@ -504,9 +504,17 @@ describe Gitlab::UrlBlocker, :stub_invalid_dns_only do ...@@ -504,9 +504,17 @@ describe Gitlab::UrlBlocker, :stub_invalid_dns_only do
end end
end end
def stub_domain_resolv(domain, ip, &block) def stub_domain_resolv(domain, ip, port = 80, &block)
address = double(ip_address: ip, ipv4_private?: true, ipv6_link_local?: false, ipv4_loopback?: false, ipv6_loopback?: false, ipv4?: false) address = instance_double(Addrinfo,
allow(Addrinfo).to receive(:getaddrinfo).with(domain, any_args).and_return([address]) ip_address: ip,
ipv4_private?: true,
ipv6_linklocal?: false,
ipv4_loopback?: false,
ipv6_loopback?: false,
ipv4?: false,
ip_port: port
)
allow(Addrinfo).to receive(:getaddrinfo).with(domain, port, any_args).and_return([address])
allow(address).to receive(:ipv6_v4mapped?).and_return(false) allow(address).to receive(:ipv6_v4mapped?).and_return(false)
yield yield
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment