-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathpkcs12_spec.rb
151 lines (137 loc) · 5.37 KB
/
pkcs12_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
# frozen_string_literal: true
require 'spec_helper_acceptance'
# SLES by default does not support this form of encyrption.
describe 'managing java pkcs12', unless: (os[:family] == 'sles' || (os[:family] == 'debian' && os[:release].start_with?('10')) || (os[:family] == 'ubuntu' && os[:release].start_with?('18'))) do
# rubocop:disable RSpec/InstanceVariable : Instance variables are inherited and thus cannot be contained within lets
include_context 'with common variables'
context 'with defaults' do
it 'creates a private key with chain' do
pp = <<-MANIFEST
java_ks { 'Leaf Cert:#{@temp_dir}pkcs12.ks':
ensure => #{@ensure_ks},
certificate => "#{@temp_dir}leaf.p12",
storetype => 'pkcs12',
password => 'puppet',
path => #{@resource_path},
source_password => 'pkcs12pass'
}
MANIFEST
idempotent_apply(pp)
end
expectations = [
%r{Alias name: leaf cert},
%r{Entry type: (keyEntry|PrivateKeyEntry)},
%r{Certificate chain length: 3},
%r{^Serial number: 5.*^Serial number: 4.*^Serial number: 3}m,
]
it 'verifies the private key and chain' do
run_shell(keytool_command("-list -v -keystore #{@temp_dir}pkcs12.ks -storepass puppet"), expect_failures: true) do |r|
expectations.each do |expect|
expect(r.stdout).to match(expect)
end
end
end
it 'updates the chain' do
pp = <<-MANIFEST
java_ks { 'Leaf Cert:#{@temp_dir}pkcs12.ks':
ensure => #{@ensure_ks},
certificate => "#{@temp_dir}leaf2.p12",
storetype => 'pkcs12',
password => 'puppet',
path => #{@resource_path},
source_password => 'pkcs12pass'
}
MANIFEST
idempotent_apply(pp)
expectations = if os[:family] == 'windows' || (os[:family] == 'ubuntu' && ['20.04', '22.04'].include?(os[:release])) ||
(os[:family] == 'debian' && os[:release] =~ %r{^11|12})
[
%r{Alias name: leaf cert},
%r{Entry type: (keyEntry|PrivateKeyEntry)},
%r{Certificate chain length: 3},
%r{^Serial number: 3}m,
%r{^Serial number: 4}m,
%r{^Serial number: 5}m,
]
else
[
%r{Alias name: leaf cert},
%r{Entry type: (keyEntry|PrivateKeyEntry)},
%r{Certificate chain length: 2},
%r{^Serial number: 5$.*^Serial number: 6$}m,
]
end
run_shell(keytool_command("-list -v -keystore #{@temp_dir}pkcs12.ks -storepass puppet"), expect_failures: true) do |r|
expectations.each do |expect|
expect(r.stdout).to match(expect)
end
end
end
end
context 'with a different alias' do
it 'creates a private key with chain' do
pp = <<-MANIFEST
java_ks { 'Leaf_Cert:#{@temp_dir}pkcs12.ks':
ensure => #{@ensure_ks},
certificate => "#{@temp_dir}leaf.p12",
storetype => 'pkcs12',
password => 'puppet',
path => #{@resource_path},
source_password => 'pkcs12pass',
source_alias => 'Leaf Cert'
}
MANIFEST
idempotent_apply(pp)
end
expectations = [
%r{Alias name: leaf_cert},
%r{Entry type: (keyEntry|PrivateKeyEntry)},
%r{Certificate chain length: 3},
%r{^Serial number: 5.*^Serial number: 4.*^Serial number: 3}m,
]
it 'verifies the private key and chain' do
run_shell(keytool_command("-list -v -keystore #{@temp_dir}pkcs12.ks -storepass puppet"), expect_failures: true) do |r|
expectations.each do |expect|
expect(r.stdout).to match(expect)
end
end
end
end
context 'with a destkeypass' do
command = if os[:family] == 'windows'
interpolate_powershell("rm -force #{@temp_dir}pkcs12.ks")
else
"rm -f #{@temp_dir}pkcs12.ks"
end
before(:all) { run_shell(command, expect_failures: true) }
it 'creates a private key with chain' do
pp = <<-MANIFEST
java_ks { 'Leaf_Cert:#{@temp_dir}/pkcs12.ks':
ensure => #{@ensure_ks},
certificate => "#{@temp_dir}leaf.p12",
destkeypass => "abcdef123456",
storetype => 'pkcs12',
password => 'puppet',
path => #{@resource_path},
source_password => 'pkcs12pass',
source_alias => 'Leaf Cert'
}
MANIFEST
idempotent_apply(pp)
end
expectations = [
%r{Alias name: leaf_cert},
%r{Entry type: (keyEntry|PrivateKeyEntry)},
%r{Certificate chain length: 3},
%r{^Serial number: 5.*^Serial number: 4.*^Serial number: 3}m,
]
it 'verifies the private key and chain' do
run_shell(keytool_command("-list -v -keystore #{@temp_dir}pkcs12.ks -storepass puppet"), expect_failures: true) do |r|
expectations.each do |expect|
expect(r.stdout).to match(expect)
end
end
end
end
# rubocop:enable RSpec/InstanceVariable
end