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

Test #233

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions examples/export_pkc12_from_key.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include openssl
openssl::export::pkcs12 { 'export.pkcs12':
ensure => 'present',
basedir => '/tmp',
pkey => '/tmp/private.key',
cert => '/tmp/cert.crt',
}
27 changes: 27 additions & 0 deletions examples/generate_cert_from_key.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
include openssl

file { '/tmp/template.cnf':
ensure => file,
content => epp('openssl/cert.cnf', {
'country' => 'de',
'state' => 'BW',
'locality' => 'undef',
'organization' => 'voxpupuli',
'unit' => 'anybody',
'commonname' => 'testpipeline.voxpupuli.org',
'email' => '[email protected]',
'default_bits' => 4096,
'default_md' => 'sha256',
'default_keyfile' => '/tmp/private.key',
'basicconstraints' => ['CA:false'],
'extendedkeyusages' => ['serverAuth'],
'keyusages' => ['critical'],
'subjectaltnames' => ['cert.voxpupuli.org', 'foo.bar.de'],
}),
}

x509_cert { '/tmp/cert.crt':
ensure => present,
private_key => '/tmp/private.key',
template => '/tmp/template.cnf',
}
4 changes: 4 additions & 0 deletions examples/generate_key.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
contain openssl
ssl_pkey { '/tmp/private.key':
ensure => present,
}
6 changes: 6 additions & 0 deletions examples/generate_pem_key.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include openssl
openssl::export::pem_key { 'key-UUID':
ensure => present,
pfx_cert => '/tmp/export.pkcs12.p12',
pem_key => '/tmp/key.pem',
}
19 changes: 19 additions & 0 deletions examples/x509_pkcs12_pemkey.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
openssl::certificate::x509 { 'sample_x509':
ensure => present,
base_dir => '/tmp',
key_size => 1024, #entropy in CI is limited
organization => 'voxpupuli',
}

-> openssl::export::pkcs12 { 'export':
ensure => 'present',
basedir => '/tmp',
pkey => '/tmp/sample_x509.key',
cert => '/tmp/sample_x509.crt',
}

-> openssl::export::pem_key { 'key-UUID':
ensure => present,
pfx_cert => '/tmp/export.p12',
pem_key => '/tmp/key.pem',
}
8 changes: 4 additions & 4 deletions manifests/export/pem_key.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
) {
if $ensure == 'present' {
if $in_pass {
$passin_opt = ['-nokeys', '-passin', 'env:CERTIFICATE_PASSIN']
$passin_opt = ['-passin', 'env:CERTIFICATE_PASSIN']
$passin_env = ["CERTIFICATE_PASSIN=${in_pass}"]
} else {
$passin_opt = []
$passin_opt = ['-passin', 'pass:']
$passin_env = []
}

if $out_pass {
$passout_opt = ['-nokeys', '-passout', 'env:CERTIFICATE_PASSOUT']
$passout_opt = ['-passout', 'env:CERTIFICATE_PASSOUT']
$passout_env = ["CERTIFICATE_PASSOUT=${out_pass}"]
} else {
$passout_opt = []
$passout_opt = ['-nodes']
$passout_env = []
}

Expand Down
8 changes: 4 additions & 4 deletions manifests/export/pkcs12.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@

if $ensure == 'present' {
if $in_pass {
$passin_opt = ['-nokeys', '-passin', 'env:CERTIFICATE_PASSIN']
$passin_opt = ['-passin', 'env:CERTIFICATE_PASSIN']
$passin_env = ["CERTIFICATE_PASSIN=${in_pass}"]
} else {
$passin_opt = []
$passin_opt = ['-passin', 'pass:']
$passin_env = []
}

if $out_pass {
$passout_opt = ['-nokeys', '-passout', 'env:CERTIFICATE_PASSOUT']
$passout_opt = ['-passout', 'env:CERTIFICATE_PASSOUT']
$passout_env = ["CERTIFICATE_PASSOUT=${out_pass}"]
} else {
$passout_opt = []
$passout_opt = ['-passout', 'pass:']
$passout_env = []
}

Expand Down
38 changes: 38 additions & 0 deletions spec/acceptance/x509_pkcs12_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

# the openssl output changed and differs between EL9 vs older versions
# https://github.com/mizzy/serverspec/commit/ac366dd40015f0b53e70a3ed881b931dfc83c603 might not be a correct fix
# Ewoud is working on a fix in https://github.com/ekohl/serverspec/commit/64874e9c8cc70b097300c3a60281572a3528768e
# in the meantime we won't use x509_certificate matcher
describe 'x509 to pkcs12 to pem key' do
it_behaves_like 'the example', 'x509_pkcs12_pemkey.pp' do
describe x509_certificate('/tmp/sample_x509.crt') do
it { is_expected.to be_certificate }
it { is_expected.to be_valid }
its(:keylength) { is_expected.to eq 1024 }
end

describe command('openssl pkcs12 -info -in /tmp/export.p12 -passin pass: -passout pass:') do
its(:exit_status) { is_expected.to eq 0 }

Check failure on line 18 in spec/acceptance/x509_pkcs12_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Debian 11

x509 to pkcs12 to pem key behaves like the example Command "openssl pkcs12 -info -in /tmp/export.p12 -passin pass: -passout pass:" exit_status is expected to eq 0 Failure/Error: its(:exit_status) { is_expected.to eq 0 } expected: 0 got: 1 (compared using ==) Shared Example Group: "the example" called from ./spec/acceptance/x509_pkcs12_spec.rb:10

Check failure on line 18 in spec/acceptance/x509_pkcs12_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Debian 11

x509 to pkcs12 to pem key behaves like the example Command "openssl pkcs12 -info -in /tmp/export.p12 -passin pass: -passout pass:" exit_status is expected to eq 0 Failure/Error: its(:exit_status) { is_expected.to eq 0 } expected: 0 got: 1 (compared using ==) Shared Example Group: "the example" called from ./spec/acceptance/x509_pkcs12_spec.rb:10

Check failure on line 18 in spec/acceptance/x509_pkcs12_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Ubuntu 20.04

x509 to pkcs12 to pem key behaves like the example Command "openssl pkcs12 -info -in /tmp/export.p12 -passin pass: -passout pass:" exit_status is expected to eq 0 Failure/Error: its(:exit_status) { is_expected.to eq 0 } expected: 0 got: 1 (compared using ==) Shared Example Group: "the example" called from ./spec/acceptance/x509_pkcs12_spec.rb:10

Check failure on line 18 in spec/acceptance/x509_pkcs12_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Ubuntu 20.04

x509 to pkcs12 to pem key behaves like the example Command "openssl pkcs12 -info -in /tmp/export.p12 -passin pass: -passout pass:" exit_status is expected to eq 0 Failure/Error: its(:exit_status) { is_expected.to eq 0 } expected: 0 got: 1 (compared using ==) Shared Example Group: "the example" called from ./spec/acceptance/x509_pkcs12_spec.rb:10

Check failure on line 18 in spec/acceptance/x509_pkcs12_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - OracleLinux 8

x509 to pkcs12 to pem key behaves like the example Command "openssl pkcs12 -info -in /tmp/export.p12 -passin pass: -passout pass:" exit_status is expected to eq 0 Failure/Error: its(:exit_status) { is_expected.to eq 0 } expected: 0 got: 1 (compared using ==) Shared Example Group: "the example" called from ./spec/acceptance/x509_pkcs12_spec.rb:10

Check failure on line 18 in spec/acceptance/x509_pkcs12_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - OracleLinux 8

x509 to pkcs12 to pem key behaves like the example Command "openssl pkcs12 -info -in /tmp/export.p12 -passin pass: -passout pass:" exit_status is expected to eq 0 Failure/Error: its(:exit_status) { is_expected.to eq 0 } expected: 0 got: 1 (compared using ==) Shared Example Group: "the example" called from ./spec/acceptance/x509_pkcs12_spec.rb:10

Check failure on line 18 in spec/acceptance/x509_pkcs12_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Rocky 8

x509 to pkcs12 to pem key behaves like the example Command "openssl pkcs12 -info -in /tmp/export.p12 -passin pass: -passout pass:" exit_status is expected to eq 0 Failure/Error: its(:exit_status) { is_expected.to eq 0 } expected: 0 got: 1 (compared using ==) Shared Example Group: "the example" called from ./spec/acceptance/x509_pkcs12_spec.rb:10

Check failure on line 18 in spec/acceptance/x509_pkcs12_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Rocky 8

x509 to pkcs12 to pem key behaves like the example Command "openssl pkcs12 -info -in /tmp/export.p12 -passin pass: -passout pass:" exit_status is expected to eq 0 Failure/Error: its(:exit_status) { is_expected.to eq 0 } expected: 0 got: 1 (compared using ==) Shared Example Group: "the example" called from ./spec/acceptance/x509_pkcs12_spec.rb:10

Check failure on line 18 in spec/acceptance/x509_pkcs12_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - AlmaLinux 8

x509 to pkcs12 to pem key behaves like the example Command "openssl pkcs12 -info -in /tmp/export.p12 -passin pass: -passout pass:" exit_status is expected to eq 0 Failure/Error: its(:exit_status) { is_expected.to eq 0 } expected: 0 got: 1 (compared using ==) Shared Example Group: "the example" called from ./spec/acceptance/x509_pkcs12_spec.rb:10

Check failure on line 18 in spec/acceptance/x509_pkcs12_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - AlmaLinux 8

x509 to pkcs12 to pem key behaves like the example Command "openssl pkcs12 -info -in /tmp/export.p12 -passin pass: -passout pass:" exit_status is expected to eq 0 Failure/Error: its(:exit_status) { is_expected.to eq 0 } expected: 0 got: 1 (compared using ==) Shared Example Group: "the example" called from ./spec/acceptance/x509_pkcs12_spec.rb:10
end
end

# rubocop:disable RSpec/RepeatedExampleGroupBody
describe file('/tmp/sample_x509.crt') do
it { is_expected.to be_file }
its(:size) { is_expected.to be > 0 }
end

describe file('/tmp/sample_x509.key') do
it { is_expected.to be_file }
its(:size) { is_expected.to be > 0 }
end

describe file('/tmp/export.p12') do
it { is_expected.to be_file }
its(:size) { is_expected.to be > 0 }
end
# rubocop:enable RSpec/RepeatedExampleGroupBody
end
Loading