-
Notifications
You must be signed in to change notification settings - Fork 39
/
apache_spec.rb
176 lines (149 loc) · 6.24 KB
/
apache_spec.rb
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
require 'spec_helper_acceptance'
describe 'certs::apache' do
before(:all) do
on default, 'rm -rf /root/ssl-build'
end
context 'with default parameters' do
it 'should force regeneration' do
on hosts, "if [ -e /root/ssl-build/#{fact('fqdn')} ] ; then touch /root/ssl-build/#{fact('fqdn')}/#{fact('fqdn')}-apache.update ; fi"
end
it_behaves_like 'an idempotent resource' do
let(:manifest) { 'include certs::apache' }
end
describe x509_certificate('/etc/pki/katello/certs/katello-apache.crt') do
it { should be_certificate }
it { should be_valid }
it { should have_purpose 'server' }
its(:issuer) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
its(:subject) { should match_without_whitespace(/C = US, ST = North Carolina, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
its(:keylength) { should be >= 4096 }
end
describe x509_private_key('/etc/pki/katello/private/katello-apache.key') do
it { should_not be_encrypted }
it { should be_valid }
it { should have_matching_certificate('/etc/pki/katello/certs/katello-apache.crt') }
end
describe x509_certificate("/root/ssl-build/#{fact('fqdn')}/#{fact('fqdn')}-apache.crt") do
it { should be_certificate }
it { should be_valid }
it { should have_purpose 'server' }
its(:issuer) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
its(:subject) { should match_without_whitespace(/C = US, ST = North Carolina, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
its(:keylength) { should be >= 4096 }
end
describe x509_private_key("/root/ssl-build/#{fact('fqdn')}/#{fact('fqdn')}-apache.key") do
it { should_not be_encrypted }
it { should be_valid }
it { should have_matching_certificate("/root/ssl-build/#{fact('fqdn')}/#{fact('fqdn')}-apache.crt") }
end
describe package("#{fact('fqdn')}-apache") do
it { should_not be_installed }
end
end
context 'with server cert' do
before(:context) do
['crt', 'key'].each do |ext|
source_path = "fixtures/example.partial.solutions.#{ext}"
dest_path = "/server.#{ext}"
scp_to(hosts, source_path, dest_path)
end
# Force regen
on hosts, "if [ -e /root/ssl-build/#{fact('fqdn')} ] ; then touch /root/ssl-build/#{fact('fqdn')}/#{fact('fqdn')}-apache.update ; fi"
end
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { '::certs::apache':
server_cert => '/server.crt',
server_key => '/server.key',
}
PUPPET
end
end
describe x509_certificate('/etc/pki/katello/certs/katello-apache.crt') do
it { should be_certificate }
# Doesn't have to be valid - can be expired since it's a static resource
it { should have_purpose 'server' }
its(:issuer) { should match_without_whitespace(/CN = Fake LE Intermediate X1/) }
its(:subject) { should match_without_whitespace(/CN = example.partial.solutions/) }
its(:keylength) { should be >= 2048 }
end
describe x509_private_key('/etc/pki/katello/private/katello-apache.key') do
it { should_not be_encrypted }
it { should be_valid }
it { should have_matching_certificate('/etc/pki/katello/certs/katello-apache.crt') }
end
describe package("#{fact('fqdn')}-apache") do
it { should_not be_installed }
end
end
context 'with deploy false' do
before(:context) do
on default, 'rm -rf /root/ssl-build /etc/pki/katello'
end
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { 'certs::apache':
deploy => false
}
PUPPET
end
end
describe x509_certificate("/root/ssl-build/#{fact('fqdn')}/#{fact('fqdn')}-apache.crt") do
it { should be_certificate }
it { should be_valid }
it { should have_purpose 'server' }
its(:issuer) { should match_without_whitespace(/C = US, ST = North Carolina, L = Raleigh, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
its(:subject) { should match_without_whitespace(/C = US, ST = North Carolina, O = Katello, OU = SomeOrgUnit, CN = #{fact('fqdn')}/) }
its(:keylength) { should be >= 4096 }
end
describe x509_private_key("/root/ssl-build/#{fact('fqdn')}/#{fact('fqdn')}-apache.key") do
it { should_not be_encrypted }
it { should be_valid }
it { should have_matching_certificate("/root/ssl-build/#{fact('fqdn')}/#{fact('fqdn')}-apache.crt") }
end
describe file('/etc/pki/katello/certs/katello-apache.crt') do
it { should_not exist }
end
describe file('/etc/pki/katello/private/katello-apache.key') do
it { should_not exist }
end
end
context 'with custom certificates fresh' do
before(:context) do
['crt', 'key'].each do |ext|
source_path = "fixtures/example.partial.solutions.#{ext}"
dest_path = "/server.#{ext}"
scp_to(hosts, source_path, dest_path)
end
on hosts, 'rm -rf /root/ssl-build'
end
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
class { '::certs::apache':
server_cert => '/server.crt',
server_key => '/server.key',
}
PUPPET
end
end
describe x509_certificate('/etc/pki/katello/certs/katello-apache.crt') do
it { should be_certificate }
# Doesn't have to be valid - can be expired since it's a static resource
it { should have_purpose 'server' }
its(:issuer) { should match_without_whitespace(/CN = Fake LE Intermediate X1/) }
its(:subject) { should match_without_whitespace(/CN = example.partial.solutions/) }
its(:keylength) { should be >= 2048 }
end
describe x509_private_key('/etc/pki/katello/private/katello-apache.key') do
it { should_not be_encrypted }
it { should be_valid }
it { should have_matching_certificate('/etc/pki/katello/certs/katello-apache.crt') }
end
describe package("#{fact('fqdn')}-apache") do
it { should_not be_installed }
end
end
end