Skip to content

Commit c24f7e3

Browse files
committed
Update and consolidate tarfile test cases
Signed-off-by: Eric D. Helms <[email protected]>
1 parent aba8e66 commit c24f7e3

File tree

2 files changed

+145
-189
lines changed

2 files changed

+145
-189
lines changed

spec/acceptance/certs_spec.rb

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -151,115 +151,4 @@ class { 'certs':
151151
its(:keylength) { should be >= 2048 }
152152
end
153153
end
154-
155-
context 'with tar file' do
156-
before(:context) do
157-
['crt', 'key'].each do |ext|
158-
source_path = "fixtures/example.partial.solutions.#{ext}"
159-
dest_path = "/server.#{ext}"
160-
scp_to(hosts, source_path, dest_path)
161-
end
162-
end
163-
164-
context 'with default ca' do
165-
before(:context) do
166-
manifest = <<~PUPPET
167-
class { 'certs':
168-
generate => true,
169-
deploy => false,
170-
}
171-
172-
class { 'certs::foreman_proxy_content':
173-
foreman_proxy_fqdn => 'foreman-proxy.example.com',
174-
certs_tar => '/root/foreman-proxy.example.com.tar.gz',
175-
}
176-
PUPPET
177-
178-
apply_manifest(manifest, catch_failures: true)
179-
180-
on default, 'rm -rf /root/ssl-build'
181-
end
182-
183-
describe 'deploy certificates' do
184-
manifest = <<-PUPPET
185-
class { 'certs':
186-
tar_file => '/root/foreman-proxy.example.com.tar.gz',
187-
}
188-
PUPPET
189-
# tar extraction is not idempotent
190-
it { apply_manifest(manifest, catch_failures: true) }
191-
end
192-
193-
describe 'default and server ca certs match' do
194-
it { expect(file('/etc/pki/katello/certs/katello-default-ca.crt').content).to eq(file('/etc/pki/katello/certs/katello-server-ca.crt').content) }
195-
end
196-
197-
describe x509_certificate('/etc/pki/katello/certs/katello-default-ca.crt') do
198-
it { should be_certificate }
199-
it { should be_valid }
200-
it { should have_purpose 'SSL server CA' }
201-
its(:issuer) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
202-
its(:subject) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
203-
its(:keylength) { should be >= 4096 }
204-
end
205-
end
206-
207-
context 'with custom certificates' do
208-
before(:context) do
209-
manifest = <<~PUPPET
210-
class { 'certs':
211-
server_cert => '/server.crt',
212-
server_key => '/server.key',
213-
server_ca_cert => '/server-ca.crt',
214-
generate => true,
215-
deploy => false,
216-
}
217-
218-
class { 'certs::foreman_proxy_content':
219-
foreman_proxy_fqdn => 'foreman-proxy.example.com',
220-
certs_tar => '/root/foreman-proxy.example.com.tar.gz',
221-
}
222-
PUPPET
223-
224-
apply_manifest(manifest, catch_failures: true)
225-
226-
on default, 'rm -rf /root/ssl-build'
227-
end
228-
229-
describe 'deploy certificates' do
230-
manifest = <<-PUPPET
231-
class { 'certs':
232-
generate => false,
233-
tar_file => '/root/foreman-proxy.example.com.tar.gz',
234-
}
235-
PUPPET
236-
# tar extraction is not idempotent
237-
it { apply_manifest(manifest, catch_failures: true) }
238-
end
239-
240-
describe 'default and server ca certs match' do
241-
it { expect(file('/etc/pki/katello/certs/katello-default-ca.crt').content).not_to eq(file('/etc/pki/katello/certs/katello-server-ca.crt').content) }
242-
end
243-
244-
describe x509_certificate('/etc/pki/katello/certs/katello-default-ca.crt') do
245-
it { should be_certificate }
246-
it { should be_valid }
247-
it { should have_purpose 'SSL server CA' }
248-
its(:issuer) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
249-
its(:subject) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
250-
its(:keylength) { should be >= 4096 }
251-
end
252-
253-
describe x509_certificate('/etc/pki/katello/certs/katello-server-ca.crt') do
254-
it { should be_certificate }
255-
it { should be_valid }
256-
it { should have_purpose 'SSL server CA' }
257-
# These don't match since we only configure it with the intermediate
258-
# and not the actual root
259-
its(:issuer) { should match_without_whitespace(/CN = Fake LE Root X1/) }
260-
its(:subject) { should match_without_whitespace(/CN = Fake LE Intermediate X1/) }
261-
its(:keylength) { should be >= 2048 }
262-
end
263-
end
264-
end
265154
end

spec/acceptance/certs_tar_extract_spec.rb

Lines changed: 145 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,87 +3,154 @@
33
describe 'certs with tar archive' do
44
before(:all) do
55
on default, 'rm -rf /root/ssl-build'
6+
on default, 'rm -rf /etc/pki/katello'
67
end
78

8-
before(:context) do
9-
apply_manifest('include certs', catch_failures: true)
10-
11-
pp = <<-PUPPET
12-
class { 'certs':
13-
generate => true,
14-
deploy => false,
15-
}
16-
17-
class { 'certs::foreman_proxy_content':
18-
foreman_proxy_fqdn => 'foreman-proxy.example.com',
19-
certs_tar => '/root/foreman-proxy.example.com.tar.gz',
20-
}
21-
PUPPET
22-
23-
apply_manifest(pp, catch_failures: true)
24-
on default, "rm -rf /root/ssl-build"
25-
26-
install_certs = <<-PUPPET
27-
class { 'certs':
28-
tar_file => '/root/foreman-proxy.example.com.tar.gz',
29-
generate => false,
30-
node_fqdn => 'foreman-proxy.example.com',
31-
}
32-
33-
include certs::apache
34-
PUPPET
35-
36-
# generation of a certs tar archive and extraction of it are not idempotent by design
37-
apply_manifest(install_certs, catch_failures: true)
38-
end
39-
40-
after(:context) do
41-
on default, 'yum -y remove foreman-proxy.example.com*noarch*'
42-
end
43-
44-
describe x509_certificate('/etc/pki/katello/certs/katello-apache.crt') do
45-
it { should be_certificate }
46-
it { should be_valid }
47-
it { should have_purpose 'server' }
48-
its(:issuer) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
49-
its(:subject) { should match_without_whitespace(/C = US, ST = North Carolina, O = Katello, OU = SomeOrgUnit, CN = foreman-proxy.example.com/) }
50-
its(:keylength) { should be >= 4096 }
51-
end
52-
53-
describe x509_private_key('/etc/pki/katello/private/katello-apache.key') do
54-
it { should_not be_encrypted }
55-
it { should be_valid }
56-
it { should have_matching_certificate('/etc/pki/katello/certs/katello-apache.crt') }
57-
end
58-
59-
describe x509_certificate('/root/ssl-build/foreman-proxy.example.com/foreman-proxy.example.com-apache.crt') do
60-
it { should be_certificate }
61-
it { should be_valid }
62-
it { should have_purpose 'server' }
63-
its(:issuer) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
64-
its(:subject) { should match_without_whitespace(/C = US, ST = North Carolina, O = Katello, OU = SomeOrgUnit, CN = foreman-proxy.example.com/) }
65-
its(:keylength) { should be >= 4096 }
66-
end
67-
68-
describe x509_private_key('/root/ssl-build/foreman-proxy.example.com/foreman-proxy.example.com-apache.key') do
69-
it { should_not be_encrypted }
70-
it { should be_valid }
71-
it { should have_matching_certificate('/root/ssl-build/foreman-proxy.example.com/foreman-proxy.example.com-apache.crt') }
72-
end
73-
74-
describe package("foreman-proxy.example.com-apache") do
75-
it { should_not be_installed }
76-
end
77-
78-
describe file('/root/ssl-build/foreman-proxy.example.com') do
79-
it { should be_directory }
80-
end
81-
82-
describe file('/root/ssl-build/katello-default-ca.crt') do
83-
it { should exist }
9+
context 'default certificates' do
10+
before(:context) do
11+
pp = <<-PUPPET
12+
class { 'certs':
13+
generate => true,
14+
deploy => false,
15+
}
16+
17+
class { 'certs::foreman_proxy_content':
18+
foreman_proxy_fqdn => 'foreman-proxy.example.com',
19+
certs_tar => '/root/foreman-proxy.example.com.tar.gz',
20+
}
21+
PUPPET
22+
23+
apply_manifest(pp, catch_failures: true)
24+
on default, "rm -rf /root/ssl-build"
25+
26+
install_certs = <<-PUPPET
27+
class { 'certs':
28+
tar_file => '/root/foreman-proxy.example.com.tar.gz',
29+
generate => false,
30+
node_fqdn => 'foreman-proxy.example.com',
31+
}
32+
33+
include certs::apache
34+
PUPPET
35+
36+
# generation of a certs tar archive and extraction of it are not idempotent by design
37+
apply_manifest(install_certs, catch_failures: true)
38+
end
39+
40+
describe x509_certificate('/etc/pki/katello/certs/katello-apache.crt') do
41+
it { should be_certificate }
42+
it { should be_valid }
43+
it { should have_purpose 'server' }
44+
its(:issuer) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
45+
its(:subject) { should match_without_whitespace(/C = US, ST = North Carolina, O = Katello, OU = SomeOrgUnit, CN = foreman-proxy.example.com/) }
46+
its(:keylength) { should be >= 4096 }
47+
end
48+
49+
describe x509_private_key('/etc/pki/katello/private/katello-apache.key') do
50+
it { should_not be_encrypted }
51+
it { should be_valid }
52+
it { should have_matching_certificate('/etc/pki/katello/certs/katello-apache.crt') }
53+
end
54+
55+
describe x509_certificate('/root/ssl-build/foreman-proxy.example.com/foreman-proxy.example.com-apache.crt') do
56+
it { should be_certificate }
57+
it { should be_valid }
58+
it { should have_purpose 'server' }
59+
its(:issuer) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
60+
its(:subject) { should match_without_whitespace(/C = US, ST = North Carolina, O = Katello, OU = SomeOrgUnit, CN = foreman-proxy.example.com/) }
61+
its(:keylength) { should be >= 4096 }
62+
end
63+
64+
describe x509_private_key('/root/ssl-build/foreman-proxy.example.com/foreman-proxy.example.com-apache.key') do
65+
it { should_not be_encrypted }
66+
it { should be_valid }
67+
it { should have_matching_certificate('/root/ssl-build/foreman-proxy.example.com/foreman-proxy.example.com-apache.crt') }
68+
end
69+
70+
describe package("foreman-proxy.example.com-apache") do
71+
it { should_not be_installed }
72+
end
73+
74+
describe file('/root/ssl-build/foreman-proxy.example.com') do
75+
it { should be_directory }
76+
end
77+
78+
describe file('/root/ssl-build/katello-default-ca.crt') do
79+
it { should exist }
80+
end
81+
82+
describe file('/root/ssl-build/katello-server-ca.crt') do
83+
it { should exist }
84+
end
8485
end
8586

86-
describe file('/root/ssl-build/katello-server-ca.crt') do
87-
it { should exist }
87+
context 'with custom certificates' do
88+
before(:context) do
89+
['crt', 'key'].each do |ext|
90+
source_path = "fixtures/example.partial.solutions.#{ext}"
91+
dest_path = "/server.#{ext}"
92+
scp_to(hosts, source_path, dest_path)
93+
end
94+
95+
source_path = "fixtures/example.partial.solutions-chain.pem"
96+
dest_path = "/server-ca.crt"
97+
scp_to(hosts, source_path, dest_path)
98+
99+
manifest = <<~PUPPET
100+
class { 'certs':
101+
server_cert => '/server.crt',
102+
server_key => '/server.key',
103+
server_ca_cert => '/server-ca.crt',
104+
generate => true,
105+
deploy => false,
106+
}
107+
108+
class { 'certs::foreman_proxy_content':
109+
foreman_proxy_fqdn => 'foreman-proxy.example.com',
110+
certs_tar => '/root/foreman-proxy.example.com.tar.gz',
111+
}
112+
PUPPET
113+
114+
apply_manifest(manifest, catch_failures: true)
115+
116+
on default, 'rm -rf /root/ssl-build'
117+
118+
install_certs = <<-PUPPET
119+
class { 'certs':
120+
tar_file => '/root/foreman-proxy.example.com.tar.gz',
121+
generate => false,
122+
node_fqdn => 'foreman-proxy.example.com',
123+
}
124+
125+
include certs::apache
126+
PUPPET
127+
128+
# generation of a certs tar archive and extraction of it are not idempotent by design
129+
apply_manifest(install_certs, catch_failures: true)
130+
end
131+
132+
describe 'default and server ca certs do not match' do
133+
it { expect(file('/etc/pki/katello/certs/katello-default-ca.crt').content).not_to eq(file('/etc/pki/katello/certs/katello-server-ca.crt').content) }
134+
end
135+
136+
describe x509_certificate('/etc/pki/katello/certs/katello-default-ca.crt') do
137+
it { should be_certificate }
138+
it { should be_valid }
139+
it { should have_purpose 'SSL server CA' }
140+
its(:issuer) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
141+
its(:subject) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
142+
its(:keylength) { should be >= 4096 }
143+
end
144+
145+
describe x509_certificate('/etc/pki/katello/certs/katello-server-ca.crt') do
146+
it { should be_certificate }
147+
it { should be_valid }
148+
it { should have_purpose 'SSL server CA' }
149+
# The issuer and subject are not identical as we only configure it with the intermediate
150+
# and not the actual root
151+
its(:issuer) { should match_without_whitespace(/CN = Fake LE Root X1/) }
152+
its(:subject) { should match_without_whitespace(/CN = Fake LE Intermediate X1/) }
153+
its(:keylength) { should be >= 2048 }
154+
end
88155
end
89156
end

0 commit comments

Comments
 (0)