Commit 7bdd68e4 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix random segfaults when running url_blocker_spec

This mocks the timeout exception instead of setting a timeout of 0.

This also makes this spec run on platforms that do not support timeouts
in getaddrinfo
parent 44ef875f
...@@ -167,10 +167,8 @@ RSpec.describe Gitlab::UrlBlocker, :stub_invalid_dns_only do ...@@ -167,10 +167,8 @@ RSpec.describe Gitlab::UrlBlocker, :stub_invalid_dns_only do
subject { described_class.validate!(import_url, dns_rebind_protection: dns_rebind_protection) } subject { described_class.validate!(import_url, dns_rebind_protection: dns_rebind_protection) }
before do before do
skip 'timeout is not available' unless timeout_available?
stub_env('RSPEC_ALLOW_INVALID_URLS', 'false') stub_env('RSPEC_ALLOW_INVALID_URLS', 'false')
stub_const("#{described_class}::GETADDRINFO_TIMEOUT_SECONDS", 0) allow(Addrinfo).to receive(:getaddrinfo).and_raise(SocketError)
end end
context 'with dns rebinding enabled' do context 'with dns rebinding enabled' do
...@@ -189,17 +187,6 @@ RSpec.describe Gitlab::UrlBlocker, :stub_invalid_dns_only do ...@@ -189,17 +187,6 @@ RSpec.describe Gitlab::UrlBlocker, :stub_invalid_dns_only do
let(:expected_hostname) { nil } let(:expected_hostname) { nil }
end end
end end
# Detect whether the timeout option is available.
#
# See https://bugs.ruby-lang.org/issues/15553
def timeout_available?
Addrinfo.getaddrinfo('localhost', nil, timeout: 0)
false
rescue SocketError
true
end
end end
end end
......
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