Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix logic bug with extkeyusage and altnames #195

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifests/certificate/x509.pp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
csr => $csr,
days => $days,
password => $password,
req_ext => !empty($altnames) and !empty($extkeyusage),
req_ext => !empty($altnames) or !empty($extkeyusage),
force => $force,
ca => $ca,
cakey => $cakey,
Expand Down
80 changes: 80 additions & 0 deletions spec/defines/openssl_certificate_x509_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,86 @@
}
end

context 'when passing altnames, extension is enabled' do
let(:params) do
{
country: 'com',
organization: 'bar',
commonname: 'foo.example.com',
altnames: ['bar.example.com'],
}
end

it {
is_expected.to contain_x509_cert('/etc/ssl/certs/foo.crt').with(
ensure: 'present',
template: '/etc/ssl/certs/foo.cnf',
csr: '/etc/ssl/certs/foo.csr',
req_ext: true
)
}
end

context 'when passing extkeyusage, extension is enabled' do
let(:params) do
{
country: 'com',
organization: 'bar',
commonname: 'foo.example.com',
extkeyusage: ['clientauth'],
}
end

it {
is_expected.to contain_x509_cert('/etc/ssl/certs/foo.crt').with(
ensure: 'present',
template: '/etc/ssl/certs/foo.cnf',
csr: '/etc/ssl/certs/foo.csr',
req_ext: true
)
}
end

context 'when passing altnames and extkeyusage, extension is enabled' do
let(:params) do
{
country: 'com',
organization: 'bar',
commonname: 'foo.example.com',
extkeyusage: ['clientauth'],
altnames: ['bar.example.com'],
}
end

it {
is_expected.to contain_x509_cert('/etc/ssl/certs/foo.crt').with(
ensure: 'present',
template: '/etc/ssl/certs/foo.cnf',
csr: '/etc/ssl/certs/foo.csr',
req_ext: true
)
}
end

context 'w/o passing altnames and extkeyusage, extension is disabled' do
let(:params) do
{
country: 'com',
organization: 'bar',
commonname: 'foo.example.com',
}
end

it {
is_expected.to contain_x509_cert('/etc/ssl/certs/foo.crt').with(
ensure: 'present',
template: '/etc/ssl/certs/foo.cnf',
csr: '/etc/ssl/certs/foo.csr',
req_ext: false
)
}
end

context 'when passing all parameters' do
let(:params) do
{
Expand Down
Loading