blob: cf9e306f06edc635a2d2124baeb66dbb4a709899 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
module ProxyHelper
def x509_certificate(host)
License::Management.root.join("tmp/#{host}.crt")
end
def generate_self_signed_certificate_for(host)
Dir.chdir License::Management.root.join('tmp') do
system([
"rm -f #{host}.*",
"openssl req -x509 -newkey rsa:4096 -keyout #{host}.key -out #{host}.crt -days 999 -nodes -subj \"/C=/ST=/L=/O=/OU=/CN=*.test\"",
"cat #{host}.* > #{host}.pem"
].join("&&"))
end
end
def start_proxy_server
@proxy_server_pid ||=
begin
generate_self_signed_certificate_for('wildcard.test')
spawn("/usr/sbin/haproxy -f #{fixture_file('haproxy.cfg')}")
end
end
def stop_proxy_server
return if !defined?(@proxy_server_pid) || @proxy_server_pid.nil?
Process.kill("TERM", @proxy_server_pid)
Process.wait(@proxy_server_pid)
@proxy_server_pid = nil
end
end
RSpec.configure do |config|
config.include(ProxyHelper, type: :integration)
config.after(:example, type: :integration) do
stop_proxy_server
system("rm -f /usr/local/share/ca-certificates/custom.*")
end
end
|