set_mail_ssl_default_spec.rb 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe SetMailSSLDefault, :aggregate_failures, type: :db_migration do
  4. let(:email_notification_smtp) { create(:email_notification_channel, :smtp) }
  5. let(:email_notification_smtp_nonssl) { create(:email_notification_channel, :smtp, outbound_port: 25) }
  6. let(:email_notification_sendmail) { create(:email_notification_channel, :sendmail) }
  7. let(:email_channel_smtp_imap) { create(:email_channel, :smtp, :imap) }
  8. let(:email_channel_smtp_nonssl) { create(:email_channel, :smtp, outbound_port: 25) }
  9. let(:email_channel_sendmail_pop3) { create(:email_channel, :sendmail, :pop3) }
  10. let(:email_gmail) { create(:google_channel) }
  11. let(:email_microsoft) { create(:microsoft365_channel) }
  12. before do
  13. [
  14. email_notification_smtp, email_notification_sendmail,
  15. email_channel_smtp_imap, email_channel_sendmail_pop3,
  16. email_channel_smtp_nonssl, email_notification_smtp_nonssl,
  17. email_gmail, email_microsoft
  18. ].each do |elem|
  19. if elem.options[:outbound][:options]
  20. elem.options[:outbound][:options].delete :ssl_verify
  21. if elem.options[:outbound][:adapter] == 'smtp'
  22. elem.options[:outbound][:options].delete :ssl
  23. end
  24. end
  25. if elem.options[:inbound]
  26. elem.options[:inbound][:options].delete :ssl_verify
  27. end
  28. elem.save!
  29. end
  30. migrate
  31. end
  32. it 'sets Oauth channels to verify SSL' do
  33. [email_gmail, email_microsoft].each do |elem|
  34. expect(elem.reload.options).to include(
  35. inbound: include(
  36. options: include(ssl_verify: true)
  37. ),
  38. outbound: include(
  39. options: include(ssl_verify: true)
  40. )
  41. )
  42. end
  43. end
  44. it 'sets custom channels to not verify SSL' do
  45. expect(email_channel_smtp_imap.reload.options).to include(
  46. inbound: include(
  47. adapter: 'imap',
  48. options: include(ssl_verify: false)
  49. ),
  50. outbound: include(
  51. adapter: 'smtp',
  52. options: include(ssl_verify: false)
  53. )
  54. )
  55. expect(email_channel_sendmail_pop3.reload.options).to include(
  56. outbound: include(
  57. adapter: 'sendmail',
  58. ),
  59. inbound: include(
  60. adapter: 'pop3',
  61. options: include(ssl_verify: false)
  62. )
  63. )
  64. expect(email_channel_sendmail_pop3.options[:outbound]).not_to have_key('options')
  65. expect(email_notification_smtp.reload.options).to include(
  66. outbound: include(
  67. adapter: 'smtp',
  68. options: include(ssl_verify: false)
  69. )
  70. )
  71. expect(email_notification_sendmail.options[:outbound]).not_to have_key('options')
  72. end
  73. end