debian-mirror-gitlab/spec/support/webmock.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.3 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2015-09-11 14:41:01 +05:30
require 'webmock'
require 'webmock/rspec'
2019-07-07 11:18:12 +05:30
def webmock_allowed_hosts
%w[elasticsearch registry.gitlab.com-gitlab-org-test-elastic-image].tap do |hosts|
if ENV.key?('ELASTIC_URL')
hosts << URI.parse(ENV['ELASTIC_URL']).host
end
2020-01-01 13:55:28 +05:30
2023-04-23 21:23:45 +05:30
if ENV.key?('ZOEKT_INDEX_BASE_URL')
hosts.concat(allowed_host_and_ip(ENV['ZOEKT_INDEX_BASE_URL']))
end
if ENV.key?('ZOEKT_SEARCH_BASE_URL')
hosts.concat(allowed_host_and_ip(ENV['ZOEKT_SEARCH_BASE_URL']))
end
2020-01-01 13:55:28 +05:30
if Gitlab.config.webpack&.dev_server&.enabled
hosts << Gitlab.config.webpack.dev_server.host
end
end.compact.uniq
2019-07-07 11:18:12 +05:30
end
2023-04-23 21:23:45 +05:30
def allowed_host_and_ip(url)
host = URI.parse(url).host
ip_address = Addrinfo.ip(host).ip_address
[host, ip_address]
end
2023-01-13 00:05:48 +05:30
def with_net_connect_allowed
WebMock.allow_net_connect!
yield
ensure
webmock_enable!
end
2020-05-24 23:13:21 +05:30
# This prevents Selenium/WebMock from spawning thousands of connections
# while waiting for an element to appear via Capybara's find:
# https://github.com/teamcapybara/capybara/issues/2322#issuecomment-619321520
def webmock_enable_with_http_connect_on_start!
webmock_enable!(net_http_connect_on_start: true)
end
def webmock_enable!(options = {})
WebMock.disable_net_connect!(
{
allow_localhost: true,
allow: webmock_allowed_hosts
}.merge(options)
)
end
webmock_enable!