summaryrefslogtreecommitdiff
path: root/spec/support/helpers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-24 21:09:09 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-24 21:09:09 +0000
commit167894d0e7c98aae1c6d4f5a060ad6d58ea3f382 (patch)
treedd0ce964cf0db395b0b143a079c58bb4aabae591 /spec/support/helpers
parent411cc77938f99b495e0fe802705d275a28e939ef (diff)
downloadgitlab-ce-167894d0e7c98aae1c6d4f5a060ad6d58ea3f382.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/helpers')
-rw-r--r--spec/support/helpers/dns_helpers.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/support/helpers/dns_helpers.rb b/spec/support/helpers/dns_helpers.rb
new file mode 100644
index 00000000000..941b57c2c97
--- /dev/null
+++ b/spec/support/helpers/dns_helpers.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+module DnsHelpers
+ def block_dns!
+ stub_all_dns!
+ stub_invalid_dns!
+ permit_local_dns!
+ end
+
+ def permit_dns!
+ allow(Addrinfo).to receive(:getaddrinfo).and_call_original
+ end
+
+ def stub_all_dns!
+ allow(Addrinfo).to receive(:getaddrinfo).with(anything, anything, nil, :STREAM).and_return([])
+ allow(Addrinfo).to receive(:getaddrinfo).with(anything, anything, nil, :STREAM, anything, anything).and_return([])
+ end
+
+ def stub_invalid_dns!
+ allow(Addrinfo).to receive(:getaddrinfo).with(/foobar\.\w|(\d{1,3}\.){4,}\d{1,3}/i, anything, nil, :STREAM) do
+ raise SocketError.new("getaddrinfo: Name or service not known")
+ end
+ end
+
+ def permit_local_dns!
+ local_addresses = /(127|10)\.0\.0\.\d{1,3}|(192\.168|172\.16)\.\d{1,3}\.\d{1,3}|0\.0\.0\.0|localhost/i
+ allow(Addrinfo).to receive(:getaddrinfo).with(local_addresses, anything, nil, :STREAM).and_call_original
+ allow(Addrinfo).to receive(:getaddrinfo).with(local_addresses, anything, nil, :STREAM, anything, anything).and_call_original
+ end
+end