Skip to content

Commit cad2fc9

Browse files
committed
(PUP-11522) Add tests for system and external CA stores
Add unit tests relating to changes in commit 7e169c6. The tests show how `create_system_context` trusts the system CA store by default, whereas `create_context` and `load_context` do not.
1 parent 71b887b commit cad2fc9

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

spec/unit/ssl/ssl_provider_spec.rb

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,21 @@
113113
}.to raise_error(/can't modify frozen/)
114114
end
115115

116-
it 'trusts system ca store' do
116+
it 'trusts system ca store by default' do
117117
expect_any_instance_of(OpenSSL::X509::Store).to receive(:set_default_paths)
118118

119119
subject.create_system_context(cacerts: [])
120120
end
121121

122+
it 'trusts an external ca store' do
123+
path = tmpfile('system_cacerts')
124+
File.write(path, cert_fixture('ca.pem').to_pem)
125+
126+
expect_any_instance_of(OpenSSL::X509::Store).to receive(:add_file).with(path)
127+
128+
subject.create_system_context(cacerts: [], path: path)
129+
end
130+
122131
it 'verifies peer' do
123132
sslctx = subject.create_system_context(cacerts: [])
124133
expect(sslctx.verify_peer).to eq(true)
@@ -448,6 +457,18 @@
448457
sslctx = subject.create_context(**config)
449458
expect(sslctx.verify_peer).to eq(true)
450459
end
460+
461+
it 'does not trust the system ca store by default' do
462+
expect_any_instance_of(OpenSSL::X509::Store).to receive(:set_default_paths).never
463+
464+
subject.create_context(**config)
465+
end
466+
467+
it 'trusts the system ca store' do
468+
expect_any_instance_of(OpenSSL::X509::Store).to receive(:set_default_paths)
469+
470+
subject.create_context(**config.merge(include_system_store: true))
471+
end
451472
end
452473

453474
context 'when loading an ssl context' do
@@ -528,6 +549,18 @@
528549
subject.load_context(password: 'wrongpassword')
529550
}.to raise_error(Puppet::SSL::SSLError, /Failed to load private key for host 'signed': Could not parse PKey/)
530551
end
552+
553+
it 'does not trust the system ca store by default' do
554+
expect_any_instance_of(OpenSSL::X509::Store).to receive(:set_default_paths).never
555+
556+
subject.load_context
557+
end
558+
559+
it 'trusts the system ca store' do
560+
expect_any_instance_of(OpenSSL::X509::Store).to receive(:set_default_paths)
561+
562+
subject.load_context(include_system_store: true)
563+
end
531564
end
532565

533566
context 'when verifying requests' do

0 commit comments

Comments
 (0)