summaryrefslogtreecommitdiff
path: root/kitchen-tests/cookbooks/end_to_end/recipes/_chef_client_trusted_certificate.rb
blob: 28d6f4a88203e79801e76a1f1277a31e38045ad3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# First grab the cert. While this wouldn't ordinarily be secure, this isn't
# trying to secure something, we simply want to make sure that if we
# have said a certificate is trusted, it will be trusted. So lets grab it, trust
# it, and then try to use it.

# First, grab it
out = Mixlib::ShellOut.new(
  %w{openssl s_client -showcerts -connect self-signed.badssl.com:443}
).run_command.stdout

cert = Mixlib::ShellOut.new(%w{openssl x509}, input: out).run_command.stdout

# Second trust it
chef_client_trusted_certificate "self-signed.badssl.com" do
  certificate cert
end

# see if we can fetch from our new trusted domain
remote_file ::File.join(Chef::Config[:file_cache_path], "index.html") do
  source "https://self-signed.badssl.com/index.html"
end