Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

Commit ee1b60e

Browse files
author
Joshua Hoblitt
committed
change nssdb::add_cert_and_key type to treat it's title as the default nickname
Previously, the title was being used as the default certdir param value.
1 parent 7ea6c6a commit ee1b60e

File tree

4 files changed

+90
-51
lines changed

4 files changed

+90
-51
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,19 @@ nssdb::create { '/etc/dirsrv/slapd-ldap1':
1414
manage_certdir => false,
1515
}
1616
17-
nssdb::add_cert_and_key{ '/etc/dirsrv/slapd-ldap1':
17+
nssdb::add_cert_and_key{ 'Server-Cert':
1818
certdir => '/etc/dirsrv/slapd-ldap1',
19-
nickname => 'Server-Cert',
2019
cert => '/tmp/foo.pem',
2120
key => '/tmp/foo.key',
2221
}
2322
2423
nssdb::add_cert { 'AlphaSSL CA':
2524
certdir => '/etc/dirsrv/slapd-ldap1',
26-
nickname => 'AlphaSSL CA',
2725
cert => '/tmp/alphassl_intermediate.pem',
2826
}
2927
3028
nssdb::add_cert { 'GlobalSign Root CA':
3129
certdir => '/etc/dirsrv/slapd-ldap1',
32-
nickname => 'GlobalSign Root CA',
3330
cert => '/tmp/globalsign_root.pem',
3431
}
3532
```

manifests/add_cert_and_key.pp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
# Loads a certificate and key into an NSS database.
22
#
33
# Parameters:
4-
# $nickname - required - the nickname for the NSS certificate
5-
# $cert - required - path to certificate in PEM format
6-
# $key - required - path to unencrypted key in PEM format
7-
# $certdir - optional - defaults to $title
4+
# $certdir - required - defaults to $title
5+
# $cert - required - path to certificate in PEM format
6+
# $key - required - path to unencrypted key in PEM format
7+
# $nickname - optional - the nickname for the NSS certificate
88
#
99
# Actions:
1010
# loads certificate and key into the NSS database.
1111
#
1212
# Requires:
13-
# $nickname
13+
# $certdir
1414
# $cert
1515
# $key
1616
#
1717
# Sample Usage:
1818
#
19-
# nssdb::add_cert_and_key{"qpidd":
20-
# nickname=> 'Server-Cert',
21-
# cert => '/tmp/server.crt',
22-
# key => '/tmp/server.key',
23-
# }
19+
# nssdb::add_cert_and_key{ 'Server-Cert':
20+
# certdir => '/dne',
21+
# cert => '/tmp/server.crt',
22+
# key => '/tmp/server.key',
23+
# }
2424
#
2525
define nssdb::add_cert_and_key (
26-
$nickname,
26+
$certdir,
2727
$cert,
2828
$key,
29-
$certdir = $title
29+
$nickname = $title
3030
) {
3131
include nssdb
3232

Lines changed: 77 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,86 @@
11
require 'spec_helper'
22

33
describe 'nssdb::add_cert_and_key', :type => :define do
4-
let(:title) { '/dne' }
5-
let(:params) do
6-
{
7-
:nickname => 'Server-Cert',
8-
:cert => '/tmp/server.cert',
9-
:key => '/tmp/server.key',
10-
}
11-
end
4+
context 'default params' do
5+
let(:title) { 'Server-Cert' }
6+
let(:params) do
7+
{
8+
:certdir => '/dne',
9+
:cert => '/tmp/server.cert',
10+
:key => '/tmp/server.key',
11+
}
12+
end
13+
14+
context 'generate_pkcs12' do
15+
it do
16+
should contain_exec('generate_pkcs12_Server-Cert').with(
17+
:command => "/usr/bin/openssl pkcs12 -export -in /tmp/server.cert -inkey /tmp/server.key -password 'file:/dne/password.conf' -out '/dne/server-cert.p12' -name 'Server-Cert'",
18+
:require => [
19+
'Nssdb::Create[/dne]',
20+
'Class[Nssdb]'
21+
],
22+
:creates => '/dne/server-cert.p12',
23+
:subscribe => 'File[/dne/password.conf]'
24+
)
25+
end
26+
end
1227

13-
context 'generate_pkcs12' do
14-
it do
15-
should contain_exec('generate_pkcs12_/dne').with(
16-
:command => "/usr/bin/openssl pkcs12 -export -in /tmp/server.cert -inkey /tmp/server.key -password 'file:/dne/password.conf' -out '/dne/server-cert.p12' -name 'Server-Cert'",
17-
:require => [
18-
'Nssdb::Create[/dne]',
19-
'Class[Nssdb]'
20-
],
21-
:creates => '/dne/server-cert.p12',
22-
:subscribe => 'File[/dne/password.conf]'
23-
)
28+
context 'add_pkcs12' do
29+
it do
30+
should contain_exec('add_pkcs12_Server-Cert').with(
31+
:path => ['/usr/bin'],
32+
:command => "pk12util -d /dne -i /dne/server-cert.p12 -w /dne/password.conf -k /dne/password.conf",
33+
:unless => "certutil -d /dne -L -n 'Server-Cert'",
34+
:logoutput => true,
35+
:require => [
36+
'Exec[generate_pkcs12_Server-Cert]',
37+
'Nssdb::Create[/dne]',
38+
'Class[Nssdb]'
39+
]
40+
)
41+
end
2442
end
25-
end
43+
end # default params
2644

27-
context 'add_pkcs12' do
28-
it do
29-
should contain_exec('add_pkcs12_/dne').with(
30-
:path => ['/usr/bin'],
31-
:command => "pk12util -d /dne -i /dne/server-cert.p12 -w /dne/password.conf -k /dne/password.conf",
32-
:unless => "certutil -d /dne -L -n 'Server-Cert'",
33-
:logoutput => true,
34-
:require => [
35-
'Exec[generate_pkcs12_/dne]',
36-
'Nssdb::Create[/dne]',
37-
'Class[Nssdb]'
38-
]
39-
)
45+
context 'all params' do
46+
let(:title) { 'foo' }
47+
let(:params) do
48+
{
49+
:nickname => 'Server-Cert',
50+
:certdir => '/dne',
51+
:cert => '/tmp/server.cert',
52+
:key => '/tmp/server.key',
53+
}
4054
end
41-
end
4255

56+
context 'generate_pkcs12' do
57+
it do
58+
should contain_exec('generate_pkcs12_foo').with(
59+
:command => "/usr/bin/openssl pkcs12 -export -in /tmp/server.cert -inkey /tmp/server.key -password 'file:/dne/password.conf' -out '/dne/server-cert.p12' -name 'Server-Cert'",
60+
:require => [
61+
'Nssdb::Create[/dne]',
62+
'Class[Nssdb]'
63+
],
64+
:creates => '/dne/server-cert.p12',
65+
:subscribe => 'File[/dne/password.conf]'
66+
)
67+
end
68+
end
69+
70+
context 'add_pkcs12' do
71+
it do
72+
should contain_exec('add_pkcs12_foo').with(
73+
:path => ['/usr/bin'],
74+
:command => "pk12util -d /dne -i /dne/server-cert.p12 -w /dne/password.conf -k /dne/password.conf",
75+
:unless => "certutil -d /dne -L -n 'Server-Cert'",
76+
:logoutput => true,
77+
:require => [
78+
'Exec[generate_pkcs12_foo]',
79+
'Nssdb::Create[/dne]',
80+
'Class[Nssdb]'
81+
]
82+
)
83+
end
84+
end
85+
end # all params
4386
end

tests/create.pp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
certdir => '/tmp/nssdb',
1313
cert => '/tmp/cert.pem',
1414
key => '/tmp/key.pem',
15-
nickname => 'test',
1615
}
1716

1817
# You can confirm that things are loaded properly with:

0 commit comments

Comments
 (0)