Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/helpers/dns_helpers.rb')
-rw-r--r--spec/support/helpers/dns_helpers.rb25
1 files changed, 21 insertions, 4 deletions
diff --git a/spec/support/helpers/dns_helpers.rb b/spec/support/helpers/dns_helpers.rb
index b941e7c4808..c60c14f10a3 100644
--- a/spec/support/helpers/dns_helpers.rb
+++ b/spec/support/helpers/dns_helpers.rb
@@ -5,6 +5,7 @@ module DnsHelpers
stub_all_dns!
stub_invalid_dns!
permit_local_dns!
+ permit_postgresql!
end
def permit_dns!
@@ -25,14 +26,30 @@ module DnsHelpers
def permit_local_dns!
local_addresses = %r{
\A
- ::1? | # IPV6
- (127|10)\.0\.0\.\d{1,3} | # 127.0.0.x or 10.0.0.x local network
- (192\.168|172\.16)\.\d{1,3}\.\d{1,3} | # 192.168.x.x or 172.16.x.x local network
- 0\.0\.0\.0 | # loopback
+ ::1? | # IPV6
+ (127|10)\.0\.0\.\d{1,3} | # 127.0.0.x or 10.0.0.x local network
+ 192\.168\.\d{1,3}\.\d{1,3} | # 192.168.x.x local network
+ 172\.(1[6-9]|2[0-9]|3[0-1])\.\d{1,3}\.\d{1,3} | # 172.16.x.x - 172.31.x.x local network
+ 0\.0\.0\.0 | # loopback
localhost
\z
}xi
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, any_args).and_call_original
end
+
+ # pg v1.4.0, unlike v1.3.5, uses AddrInfo.getaddrinfo to resolve IPv4 and IPv6 addresses:
+ # https://github.com/ged/ruby-pg/pull/459
+ def permit_postgresql!
+ db_hosts.each do |host|
+ next if host.start_with?('/') # Exclude UNIX sockets
+
+ # https://github.com/ged/ruby-pg/blob/252512608a814de16bbad55911f9bbcef0e73cb9/lib/pg/connection.rb#L720
+ allow(Addrinfo).to receive(:getaddrinfo).with(host, anything, nil, :STREAM).and_call_original
+ end
+ end
+
+ def db_hosts
+ ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).map(&:host).compact.uniq
+ end
end