security_options_spec.rb 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe SecureMailing::SMIME::SecurityOptions, :aggregate_failures do
  4. before do
  5. Setting.set('smime_integration', true)
  6. end
  7. let(:instance) { described_class.new(ticket:, article:) }
  8. let(:certificate) { create(:smime_certificate, :with_private, fixture: 'smime1@example.com') }
  9. let(:expired_certificate) { create(:smime_certificate, :with_private, fixture: 'expiredsmime1@example.com') }
  10. describe '.process' do
  11. let(:email_address) { create(:email_address, email: 'smime1@example.com') }
  12. let(:group) { create(:group, email_address: email_address) }
  13. let(:ticket) { { 'group_id' => group.id } }
  14. let(:article) { { 'to' => 'smime1@example.com', 'from' => 'smime1@example.com' } }
  15. context 'without certificates present on the system' do
  16. it 'has no possible security options' do
  17. expect(instance.process.signing).to have_attributes(possible?: false, active_by_default?: false, message: 'The certificate for %s was not found.', message_placeholders: ['smime1@example.com'])
  18. expect(instance.process.encryption).to have_attributes(possible?: false, active_by_default?: false, message: "Can't find S/MIME encryption certificates for: smime1@example.com", message_placeholders: [])
  19. end
  20. end
  21. context 'without sender email address' do
  22. let(:group) { create(:group, email_address: nil) }
  23. it 'has no possible security options' do
  24. expect(instance.process.signing).to have_attributes(possible?: false, active_by_default?: false, message: 'There was no certificate found.', message_placeholders: [])
  25. expect(instance.process.encryption).to have_attributes(possible?: false, active_by_default?: false, message: "Can't find S/MIME encryption certificates for: smime1@example.com", message_placeholders: [])
  26. end
  27. end
  28. context 'with valid certificate for sender and receiver' do
  29. before do
  30. certificate
  31. end
  32. it 'allows signing and encryption' do
  33. expect(instance.process.signing).to have_attributes(possible?: true, active_by_default?: true, message: 'The certificate for %s was found.', message_placeholders: ['smime1@example.com'])
  34. expect(instance.process.encryption).to have_attributes(possible?: true, active_by_default?: true, message: 'The certificates for %s were found.', message_placeholders: ['smime1@example.com'])
  35. end
  36. end
  37. context 'with expired certificate for sender and receiver' do
  38. before do
  39. expired_certificate
  40. end
  41. let(:email_address) { create(:email_address, email: 'expiredsmime1@example.com') }
  42. let(:article) { { 'to' => 'expiredsmime1@example.com', 'from' => 'expiredsmime1@example.com' } }
  43. it 'allows signing and encryption' do
  44. expect(instance.process.signing).to have_attributes(possible?: false, active_by_default?: false, message: 'The certificate for %s was found, but it is not valid yet or has expired.', message_placeholders: ['expiredsmime1@example.com'])
  45. expect(instance.process.encryption).to have_attributes(possible?: false, active_by_default?: false, message: 'There were certificates found for %s, but at least one of them is not valid yet or has expired.', message_placeholders: ['expiredsmime1@example.com'])
  46. end
  47. end
  48. end
  49. end