|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Copyright (c) 2022 The Regents of the University of Michigan. |
| 4 | +# All Rights Reserved. Licensed according to the terms of the Revised |
| 5 | +# BSD License. See LICENSE.txt for details. |
| 6 | +require "spec_helper" |
| 7 | + |
| 8 | +describe "nebula::profile::certbot_incommon" do |
| 9 | + on_supported_os.each do |os, os_facts| |
| 10 | + context "on #{os}" do |
| 11 | + let(:facts) { os_facts } |
| 12 | + |
| 13 | + it { is_expected.to compile } |
| 14 | + |
| 15 | + it { is_expected.to contain_package("certbot") } |
| 16 | + |
| 17 | + context "with a single cert" do |
| 18 | + let(:params) do |
| 19 | + { |
| 20 | + certs: {"onlyservice" => {"example.invalid" => []}}, |
| 21 | + cert_dir: "/certs", |
| 22 | + haproxy_cert_dir: "/haproxy", |
| 23 | + letsencrypt_email: "[email protected]" |
| 24 | + } |
| 25 | + end |
| 26 | + |
| 27 | + it { is_expected.to compile } |
| 28 | + |
| 29 | + it do |
| 30 | + expect(subject).to contain_file("/tmp/all_cert_commands_incommon") |
| 31 | + .with_content( |
| 32 | + <<~CREDENTIALS |
| 33 | + certbot certonly --standalone --server "https://acme.sectigo.com/v2/InCommonECCOV" -m "[email protected]" -d "example.invalid,*.example.invalid" |
| 34 | + CREDENTIALS |
| 35 | + ) |
| 36 | + end |
| 37 | + |
| 38 | + it { is_expected.to contain_concat("/certs/example.invalid.crt").with_group("puppet") } |
| 39 | + it { is_expected.to contain_concat("/certs/example.invalid.key").with_group("puppet") } |
| 40 | + it { is_expected.to contain_concat("/haproxy/onlyservice/example.invalid.pem").with_group("puppet") } |
| 41 | + |
| 42 | + it do |
| 43 | + expect(subject).to contain_concat_fragment("example.invalid.crt cert") |
| 44 | + .with_target("/certs/example.invalid.crt") |
| 45 | + .with_source("/etc/letsencrypt/live/example.invalid/fullchain.pem") |
| 46 | + end |
| 47 | + |
| 48 | + it do |
| 49 | + expect(subject).to contain_concat_fragment("example.invalid.key key") |
| 50 | + .with_target("/certs/example.invalid.key") |
| 51 | + .with_source("/etc/letsencrypt/live/example.invalid/privkey.pem") |
| 52 | + end |
| 53 | + |
| 54 | + it do |
| 55 | + expect(subject).to contain_concat_fragment("example.invalid.pem cert") |
| 56 | + .with_order("01") |
| 57 | + .with_target("/haproxy/onlyservice/example.invalid.pem") |
| 58 | + .with_source("/etc/letsencrypt/live/example.invalid/fullchain.pem") |
| 59 | + end |
| 60 | + |
| 61 | + it do |
| 62 | + expect(subject).to contain_concat_fragment("example.invalid.pem key") |
| 63 | + .with_order("02") |
| 64 | + .with_target("/haproxy/onlyservice/example.invalid.pem") |
| 65 | + .with_source("/etc/letsencrypt/live/example.invalid/privkey.pem") |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + context "with a multiple certs and services" do |
| 70 | + let(:params) do |
| 71 | + { |
| 72 | + certs: { |
| 73 | + "a" => {"abc.invalid" => %w[abc.example], "abc.com" => []}, |
| 74 | + "z" => {"zyx.invalid" => []} |
| 75 | + } |
| 76 | + } |
| 77 | + end |
| 78 | + |
| 79 | + it do |
| 80 | + expect(subject).to contain_file("/tmp/all_cert_commands_incommon") |
| 81 | + .with_content( |
| 82 | + <<~CREDENTIALS |
| 83 | + certbot certonly --standalone --server "https://acme.sectigo.com/v2/InCommonECCOV" -m "[email protected]" -d "abc.invalid,*.abc.invalid,abc.example,*.abc.example" |
| 84 | + certbot certonly --standalone --server "https://acme.sectigo.com/v2/InCommonECCOV" -m "[email protected]" -d "abc.com,*.abc.com" |
| 85 | + certbot certonly --standalone --server "https://acme.sectigo.com/v2/InCommonECCOV" -m "[email protected]" -d "zyx.invalid,*.zyx.invalid" |
| 86 | + CREDENTIALS |
| 87 | + ) |
| 88 | + end |
| 89 | + |
| 90 | + it { is_expected.to compile } |
| 91 | + |
| 92 | + it { is_expected.to contain_concat("/var/local/cert_dir/abc.invalid.crt") } |
| 93 | + it { is_expected.to contain_concat("/var/local/cert_dir/abc.invalid.key") } |
| 94 | + it { is_expected.to contain_concat("/var/local/haproxy_cert_dir/a/abc.invalid.pem") } |
| 95 | + it { is_expected.to contain_concat_fragment("abc.invalid.crt cert") } |
| 96 | + it { is_expected.to contain_concat_fragment("abc.invalid.key key") } |
| 97 | + it { is_expected.to contain_concat_fragment("abc.invalid.pem cert") } |
| 98 | + it { is_expected.to contain_concat_fragment("abc.invalid.pem key") } |
| 99 | + |
| 100 | + it { is_expected.to contain_concat("/var/local/cert_dir/abc.com.crt") } |
| 101 | + it { is_expected.to contain_concat("/var/local/cert_dir/abc.com.key") } |
| 102 | + it { is_expected.to contain_concat("/var/local/haproxy_cert_dir/a/abc.com.pem") } |
| 103 | + it { is_expected.to contain_concat_fragment("abc.com.crt cert") } |
| 104 | + it { is_expected.to contain_concat_fragment("abc.com.key key") } |
| 105 | + it { is_expected.to contain_concat_fragment("abc.com.pem cert") } |
| 106 | + it { is_expected.to contain_concat_fragment("abc.com.pem key") } |
| 107 | + |
| 108 | + it { is_expected.to contain_concat("/var/local/cert_dir/zyx.invalid.crt") } |
| 109 | + it { is_expected.to contain_concat("/var/local/cert_dir/zyx.invalid.key") } |
| 110 | + it { is_expected.to contain_concat("/var/local/haproxy_cert_dir/z/zyx.invalid.pem") } |
| 111 | + it { is_expected.to contain_concat_fragment("zyx.invalid.crt cert") } |
| 112 | + it { is_expected.to contain_concat_fragment("zyx.invalid.key key") } |
| 113 | + it { is_expected.to contain_concat_fragment("zyx.invalid.pem cert") } |
| 114 | + it { is_expected.to contain_concat_fragment("zyx.invalid.pem key") } |
| 115 | + |
| 116 | + it { is_expected.not_to contain_concat("/var/local/cert_dir/abc.example.crt") } |
| 117 | + it { is_expected.not_to contain_concat("/var/local/cert_dir/abc.example.key") } |
| 118 | + it { is_expected.not_to contain_concat("/var/local/haproxy_cert_dir/a/abc.example.pem") } |
| 119 | + it { is_expected.not_to contain_concat_fragment("abc.example.crt cert") } |
| 120 | + it { is_expected.not_to contain_concat_fragment("abc.example.key key") } |
| 121 | + it { is_expected.not_to contain_concat_fragment("abc.example.pem cert") } |
| 122 | + it { is_expected.not_to contain_concat_fragment("abc.example.pem key") } |
| 123 | + end |
| 124 | + |
| 125 | + context "with one simple cert, no SANs" do |
| 126 | + let(:params) do |
| 127 | + { |
| 128 | + simple_certs: { |
| 129 | + "abc.example": [] |
| 130 | + } |
| 131 | + } |
| 132 | + end |
| 133 | + |
| 134 | + it { is_expected.to compile } |
| 135 | + |
| 136 | + it do |
| 137 | + expect(subject).to contain_file("/tmp/all_cert_commands_incommon") |
| 138 | + .with_content(%r{certbot certonly --standalone --server "https://acme.sectigo.com/v2/InCommonECCOV" -m "[email protected]" -d "abc.example"}) |
| 139 | + end |
| 140 | + |
| 141 | + it do |
| 142 | + expect(subject).to contain_concat_fragment("/var/local/cert_dir/abc.example.crt cert") |
| 143 | + .with_target("/var/local/cert_dir/abc.example.crt") |
| 144 | + .with_source("/etc/letsencrypt/live/abc.example/fullchain.pem") |
| 145 | + end |
| 146 | + |
| 147 | + it do |
| 148 | + expect(subject).to contain_concat_fragment("/var/local/cert_dir/abc.example.key key") |
| 149 | + .with_target("/var/local/cert_dir/abc.example.key") |
| 150 | + .with_source("/etc/letsencrypt/live/abc.example/privkey.pem") |
| 151 | + end |
| 152 | + end |
| 153 | + |
| 154 | + context "with one simple cert, two SANs" do |
| 155 | + let(:params) do |
| 156 | + { |
| 157 | + simple_certs: { |
| 158 | + "abc.example": ["san.local", "xyz.local"] |
| 159 | + } |
| 160 | + } |
| 161 | + end |
| 162 | + |
| 163 | + it do |
| 164 | + expect(subject).to contain_file("/tmp/all_cert_commands_incommon") |
| 165 | + .with_content( |
| 166 | + <<~CREDENTIALS |
| 167 | + certbot certonly --standalone --server "https://acme.sectigo.com/v2/InCommonECCOV" -m "[email protected]" -d "abc.example,san.local,xyz.local" |
| 168 | + CREDENTIALS |
| 169 | + ) |
| 170 | + end |
| 171 | + end |
| 172 | + |
| 173 | + context "with two simple certs" do |
| 174 | + let(:params) do |
| 175 | + { |
| 176 | + simple_certs: { |
| 177 | + "abc.example": [], |
| 178 | + "xyz.example": ["alt.example", "*.alt.example"] |
| 179 | + } |
| 180 | + } |
| 181 | + end |
| 182 | + |
| 183 | + it do |
| 184 | + expect(subject).to contain_file("/tmp/all_cert_commands_incommon") |
| 185 | + .with_content(%r{certbot certonly --standalone --server "https://acme.sectigo.com/v2/InCommonECCOV" -m "[email protected]" -d "abc.example"}) |
| 186 | + end |
| 187 | + |
| 188 | + it do |
| 189 | + expect(subject).to contain_file("/tmp/all_cert_commands_incommon") |
| 190 | + .with_content(%r{certbot certonly --standalone --server "https://acme.sectigo.com/v2/InCommonECCOV" -m "[email protected]" -d "xyz.example,alt.example,\*.alt.example"}) |
| 191 | + end |
| 192 | + |
| 193 | + it do |
| 194 | + expect(subject).to contain_concat_fragment("/var/local/cert_dir/abc.example.crt cert") |
| 195 | + .with_target("/var/local/cert_dir/abc.example.crt") |
| 196 | + .with_source("/etc/letsencrypt/live/abc.example/fullchain.pem") |
| 197 | + end |
| 198 | + |
| 199 | + it do |
| 200 | + expect(subject).to contain_concat_fragment("/var/local/cert_dir/xyz.example.crt cert") |
| 201 | + .with_target("/var/local/cert_dir/xyz.example.crt") |
| 202 | + .with_source("/etc/letsencrypt/live/xyz.example/fullchain.pem") |
| 203 | + end |
| 204 | + end |
| 205 | + end |
| 206 | + end |
| 207 | +end |
0 commit comments