smime_meta_information_data_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe SMIMEMetaInformationData, db_strategy: :reset, type: :db_migration do
  4. let(:smime_certificate) { create(:smime_certificate, fixture: 'smime1@example.com') }
  5. let(:smime_object) { Certificate::X509::SMIME.new(smime_certificate.pem) }
  6. describe 'migrate smime_certificates' do
  7. before do
  8. smime_certificate.update!(email_addresses: nil)
  9. end
  10. it 'stores correct meta information' do
  11. migrate
  12. expect(smime_certificate.reload).to have_attributes(
  13. email_addresses: smime_object.email_addresses,
  14. issuer_hash: smime_object.issuer_hash,
  15. subject_hash: smime_object.subject_hash,
  16. )
  17. end
  18. end
  19. describe 'migrate smime_certificates with invalid PEM' do
  20. before do
  21. smime_certificate.update!(pem: 'invalid')
  22. end
  23. it 'stores blank meta information and logs warning', :aggregate_failures do
  24. allow(Rails.logger).to receive(:warn)
  25. migrate
  26. expect(smime_certificate.reload).to have_attributes(
  27. email_addresses: [],
  28. issuer_hash: '',
  29. subject_hash: '',
  30. )
  31. message = <<~TEXT.squish
  32. SMIME: The migration of the certificate with fingerprint #{smime_certificate.fingerprint} failed.
  33. The certificate might not be usable anymore.
  34. TEXT
  35. expect(Rails.logger).to have_received(:warn).with(message)
  36. end
  37. end
  38. end