|
46 | 46 | write: true, |
47 | 47 | flush: true, |
48 | 48 | close!: true, |
| 49 | + close: true, |
49 | 50 | path: "#{temp_dir}testing.stuff") |
50 | 51 | allow(Tempfile).to receive(:new).and_return(tempfile) |
51 | 52 | end |
|
97 | 98 |
|
98 | 99 | describe 'when importing a private key and certifcate' do |
99 | 100 | describe '#to_pkcs12' do |
100 | | - it 'converts a certificate to a pkcs12 file' do |
101 | | - sleep 0.1 # due to https://github.com/mitchellh/vagrant/issues/5056 |
102 | | - testing_key = OpenSSL::PKey::RSA.new 1024 |
103 | | - testing_ca = OpenSSL::X509::Certificate.new |
104 | | - testing_ca.serial = 1 |
105 | | - testing_ca.public_key = testing_key.public_key |
106 | | - testing_subj = '/CN=Test CA/ST=Denial/L=Springfield/O=Dis/CN=www.example.com' |
107 | | - testing_ca.subject = OpenSSL::X509::Name.parse testing_subj |
108 | | - testing_ca.issuer = testing_ca.subject |
109 | | - testing_ca.not_before = Time.now |
110 | | - testing_ca.not_after = testing_ca.not_before + 360 |
111 | | - testing_ca.sign(testing_key, OpenSSL::Digest::SHA256.new) |
112 | | - |
113 | | - allow(provider).to receive(:password).and_return(resource[:password]) |
114 | | - allow(File).to receive(:read).with(resource[:private_key]).and_return('private key') |
115 | | - allow(File).to receive(:read).with(resource[:certificate], hash_including(encoding: 'ISO-8859-1')).and_return(testing_ca.to_pem) |
116 | | - expect(OpenSSL::PKey::RSA).to receive(:new).with('private key', 'puppet').and_return('priv_obj') |
117 | | - expect(OpenSSL::X509::Certificate).to receive(:new).with(testing_ca.to_pem.chomp).and_return('cert_obj') |
118 | | - |
119 | | - pkcs_double = BogusPkcs.new |
120 | | - expect(pkcs_double).to receive(:to_der) |
121 | | - expect(OpenSSL::PKCS12).to receive(:create).with(resource[:password], resource[:name], 'priv_obj', 'cert_obj', []).and_return(pkcs_double) |
122 | | - provider.to_pkcs12("#{temp_dir}testing.stuff") |
| 101 | + sleep 0.1 # due to https://github.com/mitchellh/vagrant/issues/5056 |
| 102 | + testing_key = OpenSSL::PKey::RSA.new 1024 |
| 103 | + testing_ca = OpenSSL::X509::Certificate.new |
| 104 | + testing_ca.serial = 1 |
| 105 | + testing_ca.public_key = testing_key.public_key |
| 106 | + testing_subj = '/CN=Test CA/ST=Denial/L=Springfield/O=Dis/CN=www.example.com' |
| 107 | + testing_ca.subject = OpenSSL::X509::Name.parse testing_subj |
| 108 | + testing_ca.issuer = testing_ca.subject |
| 109 | + testing_ca.not_before = Time.now |
| 110 | + testing_ca.not_after = testing_ca.not_before + 360 |
| 111 | + testing_ca.sign(testing_key, OpenSSL::Digest::SHA256.new) |
| 112 | + |
| 113 | + context "Using the file based parameters for certificate and private_key" do |
| 114 | + it 'converts a certificate to a pkcs12 file' do |
| 115 | + allow(provider).to receive(:password).and_return(resource[:password]) |
| 116 | + allow(File).to receive(:read).with(resource[:private_key]).and_return('private key') |
| 117 | + allow(File).to receive(:read).with(resource[:certificate], hash_including(encoding: 'ISO-8859-1')).and_return(testing_ca.to_pem) |
| 118 | + expect(OpenSSL::PKey::RSA).to receive(:new).with('private key', 'puppet').and_return('priv_obj') |
| 119 | + expect(OpenSSL::X509::Certificate).to receive(:new).with(testing_ca.to_pem.chomp).and_return('cert_obj') |
| 120 | + |
| 121 | + pkcs_double = BogusPkcs.new |
| 122 | + expect(pkcs_double).to receive(:to_der) |
| 123 | + expect(OpenSSL::PKCS12).to receive(:create).with(resource[:password], resource[:name], 'priv_obj', 'cert_obj', []).and_return(pkcs_double) |
| 124 | + provider.to_pkcs12("#{temp_dir}testing.stuff") |
| 125 | + end |
| 126 | + end |
| 127 | + |
| 128 | + context "Using content based parameters for certificate and private_key" do |
| 129 | + let(:params) { |
| 130 | + global_params.tap {|h| [:certificate, :private_key].each {|k| h.delete(k)}}.merge( |
| 131 | + :private_key_content => 'private_key', |
| 132 | + :certificate_content => testing_ca.to_pem, |
| 133 | + ) |
| 134 | + } |
| 135 | + |
| 136 | + it 'converts a certificate to a pkcs12 file' do |
| 137 | + allow(provider).to receive(:password).and_return(resource[:password]) |
| 138 | + allow(File).to receive(:read).with('/tmp/testing.stuff').ordered.and_return('private key') |
| 139 | + allow(File).to receive(:read).with('/tmp/testing.stuff', hash_including(encoding: 'ISO-8859-1')).ordered.and_return(testing_ca.to_pem) |
| 140 | + expect(OpenSSL::PKey::RSA).to receive(:new).with('private key', 'puppet').and_return('priv_obj') |
| 141 | + expect(OpenSSL::X509::Certificate).to receive(:new).with(testing_ca.to_pem.chomp).and_return('cert_obj') |
| 142 | + |
| 143 | + pkcs_double = BogusPkcs.new |
| 144 | + expect(pkcs_double).to receive(:to_der) |
| 145 | + expect(OpenSSL::PKCS12).to receive(:create).with(resource[:password], resource[:name], 'priv_obj', 'cert_obj', []).and_return(pkcs_double) |
| 146 | + provider.to_pkcs12("#{temp_dir}testing.stuff") |
| 147 | + end |
123 | 148 | end |
124 | 149 | end |
125 | 150 |
|
|
0 commit comments