forked from jsok/puppet-vault
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathclass_spec.rb
201 lines (181 loc) · 5.68 KB
/
class_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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# frozen_string_literal: true
require 'spec_helper_acceptance'
describe 'vault class' do
context 'default parameters' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
if $facts['os']['name'] == 'Archlinux' {
class { 'file_capability':
package_name => 'libcap',
}
} else {
include file_capability
}
package { 'unzip': ensure => present }
-> class { 'vault':
storage => {
file => {
path => '/tmp',
}
},
bin_dir => '/usr/local/bin',
install_method => 'archive',
require => Class['file_capability'],
}
PUPPET
end
end
# rubocop:disable RSpec/RepeatedExampleGroupBody
describe user('vault') do
it { is_expected.to exist }
end
describe group('vault') do
it { is_expected.to exist }
end
# rubocop:enable RSpec/RepeatedExampleGroupBody
describe command('getcap /usr/local/bin/vault') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match %r{/usr/local/bin/vault.*cap_ipc_lock.*ep} }
end
describe file('/usr/local/bin/vault') do
it { is_expected.to exist }
it { is_expected.to be_mode 755 }
it { is_expected.to be_owned_by 'root' }
it { is_expected.to be_grouped_into 'root' }
end
describe file('/etc/systemd/system/vault.service') do
it { is_expected.to be_file }
it { is_expected.to be_mode 444 }
it { is_expected.to be_owned_by 'root' }
it { is_expected.to be_grouped_into 'root' }
its(:content) { is_expected.to include 'User=vault' }
its(:content) { is_expected.to include 'Group=vault' }
its(:content) { is_expected.to include 'ExecStart=/usr/local/bin/vault server -config=/etc/vault/config.json ' }
its(:content) { is_expected.to match %r{Environment=GOMAXPROCS=\d+} }
end
describe command('systemctl list-units') do
its(:stdout) { is_expected.to include 'vault.service' }
end
describe file('/etc/vault') do
it { is_expected.to be_directory }
end
describe file('/etc/vault/config.json') do
it { is_expected.to be_file }
its(:content) { is_expected.to include('"address": "127.0.0.1:8200"') }
end
describe service('vault') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end
describe port(8200) do
it { is_expected.to be_listening.on('127.0.0.1').with('tcp') }
end
describe command('/usr/local/bin/vault version') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match %r{Vault v1.12.0} }
end
end
context 'default parameters with vesion higher than fact' do
let(:manifest) do
<<-PUPPET
if $facts['os']['name'] == 'Archlinux' {
class { 'file_capability':
package_name => 'libcap',
}
} else {
include file_capability
}
package { 'unzip': ensure => present }
-> class { 'vault':
storage => {
file => {
path => '/tmp',
}
},
bin_dir => '/usr/local/bin',
install_method => 'archive',
version => '1.12.1',
require => Class['file_capability'],
}
PUPPET
end
it 'will not be idempotent and cause changes' do
apply_manifest(manifest, expect_changes: true)
end
describe command('/usr/local/bin/vault version') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match %r{Vault v1.12.1} }
end
end
context 'with package based setup' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
if $facts['os']['name'] == 'Archlinux' {
class { 'file_capability':
package_name => 'libcap',
}
} else {
include file_capability
}
class { 'vault':
storage => {
file => {
path => '/tmp',
}
},
install_method => 'repo',
require => Class['file_capability'],
}
PUPPET
end
end
describe service('vault') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end
describe port(8200) do
it { is_expected.to be_listening.on('127.0.0.1').with('tcp') }
end
end
context 'vault class with agent configuration' do
let(:manifest) do
<<-PUPPET
class { 'vault':
mode => 'agent',
agent_vault => { 'address' => 'https://vault.example.com:8200' },
agent_auto_auth => {
'method' => [{
'type' => 'approle',
'wrap_ttl' => '1m',
'config' => {
'role_id_file_path' => '/etc/vault/role-id',
'secret_id_file_path' => '/etc/vault/secret-id'
}
}]
},
agent_cache => { 'use_auto_auth_token' => true },
agent_listeners => [{
'tcp' => { 'address' => '127.0.0.1:8100', 'tls_disable' => true }
}]
}
PUPPET
end
it 'applies the manifest without error' do
apply_manifest(manifest, catch_failures: true)
end
it 'creates the config.json with correct settings' do
config_file = file('/etc/vault/config.json')
expect(config_file).to be_file
expect(config_file.content).to include(
'"address": "https://vault.example.com:8200"',
'"wrap_ttl": "1m"',
'"role_id_file_path": "/etc/vault/role-id"',
'"secret_id_file_path": "/etc/vault/secret-id"',
'"use_auto_auth_token": true',
'"address": "127.0.0.1:8100"'
)
end
end
end