loading
Generated 2020-07-01T12:14:45-07:00

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

2 files in total.
56 relevant lines, 56 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 % 71 43 43 0 1.49
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

43 relevant lines. 43 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 stub_data_bag_item('testbag', 'testitem').and_return('p12_password' => 'foo')
  14. end
  15. 1 it 'creates directories' do
  16. 1 expect(chef_run).to create_directory('/etc/ssl/certs')
  17. 1 expect(chef_run).to create_directory('/etc/ssl/private')
  18. end
  19. 1 it 'ensures ssl group' do
  20. 1 expect(chef_run).to create_group('ssl-cert')
  21. end
  22. 1 it 'downloads default certificates' do
  23. 1 expect(chef_run).to create_remote_file_s3('/etc/ssl/certs/default.crt')
  24. 1 expect(chef_run).to create_remote_file_s3('/etc/ssl/private/default.key')
  25. 1 expect(chef_run).to create_remote_file_s3('/etc/ssl/certs/default.ca')
  26. end
  27. 1 it 'does not update ca certificates' do
  28. 1 expect(chef_run).to nothing_execute('update-ca-certificates')
  29. end
  30. 1 it 'downloads requested certificates' do
  31. 1 expect(chef_run).to create_remote_file_s3('/etc/ssl/certs/test.example.com.crt')
  32. 1 expect(chef_run).to create_remote_file_s3('/etc/ssl/private/test.example.com.key')
  33. 1 expect(chef_run).to create_remote_file_s3('/etc/ssl/certs/test.example.com.ca')
  34. end
  35. 1 it 'composes requested certificates' do
  36. 1 expect(chef_run).to create_if_missing_file('/etc/ssl/certs/test.example.com.crt')
  37. 1 expect(chef_run).to create_if_missing_file('/etc/ssl/private/test.example.com.key')
  38. 1 expect(chef_run).to create_if_missing_file('/etc/ssl/certs/test.example.com.ca')
  39. 1 expect(chef_run).to create_file('/etc/ssl/certs/test.example.com.crt-chain')
  40. end
  41. 1 it 'generates pkcs12 keyring' do
  42. 1 expect(chef_run).to nothing_execute('generate pkcs12 store for test.example.com')
  43. 1 expect(chef_run.execute('generate pkcs12 store for test.example.com')).to \
  44. subscribe_to('remote_file_s3[/etc/ssl/certs/test.example.com.crt]').on(:run).delayed
  45. 1 expect(chef_run).to nothing_notify_group('pkcs12 store needs generated for test.example.com')
  46. 1 expect(chef_run.notify_group('pkcs12 store needs generated for test.example.com')).to \
  47. notify('execute[generate pkcs12 store for test.example.com]').to(:run).immediately
  48. 1 expect(chef_run).to create_file('/etc/ssl/private/test.example.com.p12')
  49. end
  50. 1 context 'when testing' do
  51. 1 override_attributes['letsencryptaws']['test_certs'] = true
  52. 1 it 'updates ca certificates' do
  53. 1 expect(chef_run).to create_remote_file('/usr/local/share/ca-certificates/fakeroot.crt')
  54. 1 expect(chef_run.remote_file('/usr/local/share/ca-certificates/fakeroot.crt')).to \
  55. notify('execute[update-ca-certificates]').to(:run).immediately
  56. end
  57. end
  58. 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