Skip to content

Commit d739f47

Browse files
committed
add tests
1 parent d4875df commit d739f47

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

manifests/config.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
'listener' => $vault::agent_listeners,
4242
'template' => $vault::agent_template,
4343
'template_config' => $vault::agent_template_config,
44-
'exec' => $vault::exec,
44+
'exec' => $vault::agent_exec,
4545
'env_template' => $vault::agent_env_template,
4646
'telemetry' => $vault::agent_telemetry,
4747
})

spec/acceptance/class_spec.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,51 @@ class { 'vault':
156156
it { is_expected.to be_listening.on('127.0.0.1').with('tcp') }
157157
end
158158
end
159+
160+
context 'vault class with agent configuration' do
161+
let(:manifest) do
162+
<<-PUPPET
163+
class { 'vault':
164+
mode => 'agent',
165+
agent_vault => { 'address' => 'https://vault.example.com:8200' },
166+
agent_auto_auth => {
167+
'method' => [{
168+
'type' => 'approle',
169+
'wrap_ttl' => '1m',
170+
'config' => {
171+
'role_id_file_path' => '/etc/vault/role-id',
172+
'secret_id_file_path' => '/etc/vault/secret-id'
173+
}
174+
}]
175+
},
176+
agent_cache => { 'use_auto_auth_token' => true },
177+
agent_listeners => [{
178+
'tcp' => { 'address' => '127.0.0.1:8100', 'tls_disable' => true }
179+
}]
180+
}
181+
PUPPET
182+
end
183+
184+
it 'applies the manifest without error' do
185+
apply_manifest(manifest, catch_failures: true)
186+
end
187+
188+
it 'creates the config.json with correct settings' do
189+
config_file = file('/etc/vault/config.json')
190+
expect(config_file).to be_file
191+
expect(config_file.content).to include(
192+
'"address": "https://vault.example.com:8200"',
193+
'"wrap_ttl": "1m"',
194+
'"role_id_file_path": "/etc/vault/role-id"',
195+
'"secret_id_file_path": "/etc/vault/secret-id"',
196+
'"use_auto_auth_token": true',
197+
'"address": "127.0.0.1:8100"'
198+
)
199+
end
200+
201+
it 'ensures the vault service is running' do
202+
expect(service('vault')).to be_enabled
203+
expect(service('vault')).to be_running
204+
end
205+
end
159206
end

spec/classes/vault_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,52 @@
417417
}
418418
end
419419

420+
context 'vault class with agent configuration' do
421+
let(:params) do
422+
{
423+
mode: 'agent',
424+
agent_vault: { 'address' => 'https://vault.example.com:8200' },
425+
agent_auto_auth: {
426+
'method' => [{
427+
'type' => 'approle',
428+
'wrap_ttl' => '1m',
429+
'config' => {
430+
'role_id_file_path' => '/etc/vault/role-id',
431+
'secret_id_file_path' => '/etc/vault/secret-id'
432+
}
433+
}]
434+
},
435+
agent_cache: { 'use_auto_auth_token' => true },
436+
agent_listeners: [{
437+
'tcp' => {
438+
'address' => '127.0.0.1:8100',
439+
'tls_disable' => true
440+
}
441+
}]
442+
}
443+
end
444+
445+
it { is_expected.to compile.with_all_deps }
446+
447+
it 'generates the config.json with correct agent settings' do
448+
expect(param_value(catalogue, 'File', '/etc/vault/config.json', 'content')).to include_json(
449+
vault: { 'address' => 'https://vault.example.com:8200' },
450+
auto_auth: {
451+
'method' => [{
452+
'type' => 'approle',
453+
'wrap_ttl' => '1m',
454+
'config' => {
455+
'role_id_file_path' => '/etc/vault/role-id',
456+
'secret_id_file_path' => '/etc/vault/secret-id'
457+
}
458+
}]
459+
},
460+
cache: { 'use_auto_auth_token' => true },
461+
listener: [{ 'tcp' => { 'address' => '127.0.0.1:8100', 'tls_disable' => true } }]
462+
)
463+
end
464+
end
465+
420466
case os_facts[:os]['family']
421467
when 'RedHat'
422468
case os_facts[:os]['release']['major'].to_i

0 commit comments

Comments
 (0)