-
# frozen_string_literal: true
-
-
1
require 'ostruct'
-
1
require 'spec_helper'
-
-
1
describe 'letsencryptaws::default' do
-
1
platform 'ubuntu', '20.04'
-
-
1
override_attributes['letsencryptaws']['certs']['test.example.com'] = []
-
1
override_attributes['letsencryptaws']['data_bag'] = 'testbag'
-
1
override_attributes['letsencryptaws']['data_bag_item'] = 'testitem'
-
1
override_attributes['letsencryptaws']['sync_bucket'] = 'foobucket'
-
-
1
before do
-
8
allow(Etc).to receive(:getpwnam).and_return(OpenStruct.new(uid: 0))
-
8
allow(Etc).to receive(:getgrnam).and_return(OpenStruct.new(gid: 0))
-
8
allow(Dir).to receive(:exist?).and_call_original
-
8
allow(Dir).to receive(:exist?).with('/etc/ssl/certs').and_return(true)
-
8
allow(Dir).to receive(:exist?).with('/etc/ssl/private').and_return(true)
-
8
stub_data_bag_item('testbag', 'testitem').and_return('p12_password' => 'foo')
-
end
-
-
1
it 'creates directories' do
-
1
expect(chef_run).to create_directory('/etc/ssl/certs')
-
1
expect(chef_run).to create_directory('/etc/ssl/private')
-
end
-
-
1
it 'ensures ssl group' do
-
1
expect(chef_run).to create_group('ssl-cert')
-
end
-
-
1
it 'downloads default certificates' do
-
1
expect(chef_run).to create_aws_s3_file('/etc/ssl/certs/default.crt')
-
1
expect(chef_run).to create_aws_s3_file('/etc/ssl/private/default.key')
-
1
expect(chef_run).to create_aws_s3_file('/etc/ssl/certs/default.ca')
-
end
-
-
1
it 'does not update ca certificates' do
-
1
expect(chef_run).to nothing_execute('update-ca-certificates')
-
end
-
-
1
it 'downloads requested certificates' do
-
1
expect(chef_run).to create_aws_s3_file('/etc/ssl/certs/test.example.com.crt')
-
1
expect(chef_run).to create_aws_s3_file('/etc/ssl/private/test.example.com.key')
-
1
expect(chef_run).to create_aws_s3_file('/etc/ssl/certs/test.example.com.ca')
-
end
-
-
1
it 'composes requested certificates' do
-
1
expect(chef_run).to create_if_missing_file('/etc/ssl/certs/test.example.com.crt')
-
1
expect(chef_run).to create_if_missing_file('/etc/ssl/private/test.example.com.key')
-
1
expect(chef_run).to create_if_missing_file('/etc/ssl/certs/test.example.com.ca')
-
1
expect(chef_run).to create_file('/etc/ssl/certs/test.example.com.crt-chain')
-
end
-
-
1
it 'generates pkcs12 keyring' do
-
1
expect(chef_run).to nothing_execute('generate pkcs12 store for test.example.com')
-
1
expect(chef_run.execute('generate pkcs12 store for test.example.com')).to \
-
subscribe_to('aws_s3_file[/etc/ssl/certs/test.example.com.crt]').on(:run).delayed
-
1
expect(chef_run).to nothing_notify_group('pkcs12 store needs generated for test.example.com')
-
1
expect(chef_run.notify_group('pkcs12 store needs generated for test.example.com')).to \
-
notify('execute[generate pkcs12 store for test.example.com]').to(:run).immediately
-
1
expect(chef_run).to create_file('/etc/ssl/private/test.example.com.p12')
-
end
-
-
1
context 'when testing' do
-
1
override_attributes['letsencryptaws']['test_certs'] = true
-
-
1
it 'updates ca certificates' do
-
1
expect(chef_run).to create_remote_file('/usr/local/share/ca-certificates/fakeroot.crt')
-
1
expect(chef_run.remote_file('/usr/local/share/ca-certificates/fakeroot.crt')).to \
-
notify('execute[update-ca-certificates]').to(:run).immediately
-
end
-
end
-
end