loading
Generated 2022-02-24T08:52:22-07:00

All Files ( 100.0% covered at 1.73 hits/line )

2 files in total.
59 relevant lines, 59 lines covered and 0 lines missed. ( 100.0% )
File % covered Lines Relevant Lines Lines covered Lines missed Avg. Hits / Line
spec/unit/recipes/default_spec.rb 100.00 % 74 46 46 0 1.91
spec/unit/recipes/import_keystore_spec.rb 100.00 % 28 13 13 0 1.08

spec/unit/recipes/default_spec.rb

100.0% lines covered

46 relevant lines. 46 lines covered and 0 lines missed.
    
  1. # frozen_string_literal: true
  2. 1 require 'ostruct'
  3. 1 require 'spec_helper'
  4. 1 describe 'letsencryptaws::default' do
  5. 1 platform 'ubuntu', '20.04'
  6. 1 override_attributes['letsencryptaws']['certs']['test.example.com'] = []
  7. 1 override_attributes['letsencryptaws']['data_bag'] = 'testbag'
  8. 1 override_attributes['letsencryptaws']['data_bag_item'] = 'testitem'
  9. 1 override_attributes['letsencryptaws']['sync_bucket'] = 'foobucket'
  10. 1 before do
  11. 8 allow(Etc).to receive(:getpwnam).and_return(OpenStruct.new(uid: 0))
  12. 8 allow(Etc).to receive(:getgrnam).and_return(OpenStruct.new(gid: 0))
  13. 8 allow(Dir).to receive(:exist?).and_call_original
  14. 8 allow(Dir).to receive(:exist?).with('/etc/ssl/certs').and_return(true)
  15. 8 allow(Dir).to receive(:exist?).with('/etc/ssl/private').and_return(true)
  16. 8 stub_data_bag_item('testbag', 'testitem').and_return('p12_password' => 'foo')
  17. end
  18. 1 it 'creates directories' do
  19. 1 expect(chef_run).to create_directory('/etc/ssl/certs')
  20. 1 expect(chef_run).to create_directory('/etc/ssl/private')
  21. end
  22. 1 it 'ensures ssl group' do
  23. 1 expect(chef_run).to create_group('ssl-cert')
  24. end
  25. 1 it 'downloads default certificates' do
  26. 1 expect(chef_run).to create_aws_s3_file('/etc/ssl/certs/default.crt')
  27. 1 expect(chef_run).to create_aws_s3_file('/etc/ssl/private/default.key')
  28. 1 expect(chef_run).to create_aws_s3_file('/etc/ssl/certs/default.ca')
  29. end
  30. 1 it 'does not update ca certificates' do
  31. 1 expect(chef_run).to nothing_execute('update-ca-certificates')
  32. end
  33. 1 it 'downloads requested certificates' do
  34. 1 expect(chef_run).to create_aws_s3_file('/etc/ssl/certs/test.example.com.crt')
  35. 1 expect(chef_run).to create_aws_s3_file('/etc/ssl/private/test.example.com.key')
  36. 1 expect(chef_run).to create_aws_s3_file('/etc/ssl/certs/test.example.com.ca')
  37. end
  38. 1 it 'composes requested certificates' do
  39. 1 expect(chef_run).to create_if_missing_file('/etc/ssl/certs/test.example.com.crt')
  40. 1 expect(chef_run).to create_if_missing_file('/etc/ssl/private/test.example.com.key')
  41. 1 expect(chef_run).to create_if_missing_file('/etc/ssl/certs/test.example.com.ca')
  42. 1 expect(chef_run).to create_file('/etc/ssl/certs/test.example.com.crt-chain')
  43. end
  44. 1 it 'generates pkcs12 keyring' do
  45. 1 expect(chef_run).to nothing_execute('generate pkcs12 store for test.example.com')
  46. 1 expect(chef_run.execute('generate pkcs12 store for test.example.com')).to \
  47. subscribe_to('aws_s3_file[/etc/ssl/certs/test.example.com.crt]').on(:run).delayed
  48. 1 expect(chef_run).to nothing_notify_group('pkcs12 store needs generated for test.example.com')
  49. 1 expect(chef_run.notify_group('pkcs12 store needs generated for test.example.com')).to \
  50. notify('execute[generate pkcs12 store for test.example.com]').to(:run).immediately
  51. 1 expect(chef_run).to create_file('/etc/ssl/private/test.example.com.p12')
  52. end
  53. 1 context 'when testing' do
  54. 1 override_attributes['letsencryptaws']['test_certs'] = true
  55. 1 it 'updates ca certificates' do
  56. 1 expect(chef_run).to create_remote_file('/usr/local/share/ca-certificates/fakeroot.crt')
  57. 1 expect(chef_run.remote_file('/usr/local/share/ca-certificates/fakeroot.crt')).to \
  58. notify('execute[update-ca-certificates]').to(:run).immediately
  59. end
  60. end
  61. end

spec/unit/recipes/import_keystore_spec.rb

100.0% lines covered

13 relevant lines. 13 lines covered and 0 lines missed.
    
  1. # frozen_string_literal: true
  2. 1 require 'spec_helper'
  3. 1 describe 'letsencryptaws::import_keystore' do
  4. 1 platform 'ubuntu', '20.04'
  5. 1 override_attributes['letsencryptaws']['certs']['test.example.com'] = []
  6. 1 override_attributes['letsencryptaws']['data_bag'] = 'testbag'
  7. 1 override_attributes['letsencryptaws']['data_bag_item'] = 'testitem'
  8. 1 override_attributes['letsencryptaws']['import_keystore']['/tmp/foo'] = ['test.example.com']
  9. 1 before do
  10. 2 stub_data_bag_item('testbag', 'testitem').and_return(
  11. 'p12_password' => 'foo',
  12. 'keystore_passwords' => { 'default' => 'bar' }
  13. )
  14. end
  15. 1 it 'installs java' do
  16. 1 expect(chef_run).to install_package('openjdk-8-jre')
  17. end
  18. # Subscribes can't be tested because the target resource is outside this recipe
  19. 1 it 'imports pkcs12 keyring into keystore' do
  20. 1 expect(chef_run).to nothing_execute('import test.example.com into /tmp/foo')
  21. end
  22. end