email_spec.rb 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Manage > Channels > Email', type: :system do
  4. context 'when managing email channels', required_envs: %w[MAIL_ADDRESS MAIL_PASS] do
  5. before do
  6. visit '/#channels/email'
  7. end
  8. context 'when looking at the default screen' do
  9. it 'has correct default settings' do
  10. within :active_content do
  11. # check if postmaster filters are shown
  12. click 'a[href="#c-filter"]'
  13. expect(find('#c-filter .overview')).to have_text 'NO ENTRIES'
  14. # check if signatures are shown
  15. click 'a[href="#c-signature"]'
  16. expect(find('#c-signature .overview')).to have_text 'default'
  17. end
  18. end
  19. end
  20. context 'when creating new channels' do
  21. let(:mailbox_user) { ENV['MAIL_ADDRESS'] }
  22. let(:mailbox_password) { ENV['MAIL_PASS'] }
  23. before do
  24. # Make sure the channel is loaded
  25. 'Channel::Driver::Imap'.constantize
  26. # The normal timeout may be too low in slow CI environments.
  27. stub_const 'Channel::Driver::Imap::CHECK_ONLY_TIMEOUT', 1.minute
  28. # Import mail server CA certificate into the trust store.
  29. SSLCertificate.create!(certificate: Rails.root.join('spec/fixtures/files/imap/ca.crt').read)
  30. end
  31. it 'refuses wrong credentials' do
  32. click 'a[href="#c-account"]'
  33. click '.js-channelNew'
  34. in_modal do
  35. fill_in 'realname', with: 'My System'
  36. fill_in 'email', with: "unknown_user.#{mailbox_user}"
  37. fill_in 'password', with: mailbox_password
  38. set_tree_select_value('group_id', Group.first.name)
  39. click '.js-submit'
  40. expect(page).to have_text('The server settings could not be automatically detected. Please configure them manually.')
  41. end
  42. end
  43. it 'accepts correct credentials' do
  44. click 'a[href="#c-account"]'
  45. click '.js-channelNew'
  46. in_modal timeout: 2.minutes do
  47. fill_in 'realname', with: 'My System'
  48. fill_in 'email', with: mailbox_user
  49. fill_in 'password', with: mailbox_password
  50. set_tree_select_value('group_id', Group.first.name)
  51. click '.js-submit'
  52. end
  53. within :active_content do
  54. expect(page).to have_text(mailbox_user)
  55. all('.js-editInbound').last.click
  56. fill_in 'options::folder', with: 'nonexisting_folder'
  57. click '.js-submit'
  58. expect(page).to have_text("Mailbox doesn't exist")
  59. end
  60. end
  61. end
  62. context 'when managing filters' do
  63. let(:filter_name) { "Test Filter #{SecureRandom.uuid}" }
  64. it 'works as expected' do
  65. click 'a[href="#c-filter"]'
  66. click '.content.active a[data-type="new"]'
  67. in_modal do
  68. fill_in 'name', with: filter_name
  69. fill_in 'match::from::value', with: 'target'
  70. click '.js-submit'
  71. end
  72. expect(page).to have_text(filter_name)
  73. click '.content.active .table .dropdown .btn--table'
  74. click '.content.active .table .dropdown .js-clone'
  75. in_modal do
  76. click '.js-submit'
  77. end
  78. expect(page).to have_text("Clone: #{filter_name}")
  79. end
  80. end
  81. end
  82. context 'non editable' do
  83. it 'hides "Edit" links' do
  84. # ensure that the only existing email channel
  85. # has preferences == { editable: false }
  86. Channel.destroy_all
  87. create(:email_channel, preferences: { editable: false })
  88. visit '/#channels/email'
  89. # verify page has loaded
  90. expect(page).to have_css('#c-account h3', text: 'Inbound')
  91. expect(page).to have_css('#c-account h3', text: 'Outbound')
  92. expect(page).to have_no_css('.js-editInbound, .js-editOutbound', text: 'Edit')
  93. end
  94. end
  95. context 'when adding an email' do
  96. before do
  97. visit '#channels/email'
  98. end
  99. it 'one can switch between default and expert forms' do
  100. click '.js-channelNew'
  101. in_modal do
  102. click '.js-expert'
  103. expect(page).to have_text 'ORGANIZATION & DEPARTMENT NAME'
  104. expect(page).to have_text 'SSL/STARTTLS'
  105. expect(page).to have_text 'PORT'
  106. click '.js-close'
  107. end
  108. end
  109. it 'in the expert form, the port for SSL/NoSSL is set automatically only when it is default' do
  110. click '.js-channelNew'
  111. in_modal do
  112. click '.js-expert'
  113. expect(find('input[name="options::port"]').value).to eq('993')
  114. field = find('select[name="options::ssl"]')
  115. option_yes = field.find(:option, 'SSL')
  116. option_no = field.find(:option, 'No SSL')
  117. option_no.select_option
  118. expect(find('input[name="options::port"]').value).to eq('143')
  119. option_yes.select_option
  120. expect(find('input[name="options::port"]').value).to eq('993')
  121. option_no.select_option
  122. expect(find('input[name="options::port"]').value).to eq('143')
  123. port = '4242'
  124. fill_in 'options::port', with: port
  125. field.click
  126. expect(find('input[name="options::port"]').value).to eq(port)
  127. fill_in 'options::folder', with: 'testabc'
  128. expect(find('input[name="options::port"]').value).to eq(port)
  129. click '.js-close'
  130. end
  131. end
  132. it 'in the expert form, turning on SSL allows to turn on or off SSL verification' do
  133. click '.js-channelNew'
  134. in_modal do
  135. click '.js-expert'
  136. verify_select = find('select[name="options::ssl_verify"]')
  137. ssl_select = find('select[name="options::ssl"]')
  138. expect(page)
  139. .to have_select('options::ssl_verify', selected: 'yes')
  140. .and have_no_text('Turning off SSL verification')
  141. verify_select.find(:option, 'no').select_option
  142. expect(page).to have_text('Turning off SSL verification')
  143. verify_select.find(:option, 'yes').select_option
  144. expect(page).to have_no_text('Turning off SSL verification')
  145. ssl_select.find(:option, 'No SSL').select_option
  146. expect(verify_select).to be_disabled
  147. ssl_select.find(:option, 'STARTTLS').select_option
  148. expect(verify_select).not_to be_disabled
  149. end
  150. end
  151. it 'entered values on the default form are copied to the expert form' do
  152. click '.js-channelNew'
  153. in_modal do
  154. name = 'Area53'
  155. email = 'dont@ask.com'
  156. password = 'f34therRa!nSplash'
  157. fill_in 'realname', with: name
  158. fill_in 'email', with: email
  159. fill_in 'password', with: password
  160. click '.js-expert'
  161. expect(find('input[name="options::realname"]').value).to eq(name)
  162. expect(find('input[name="options::email"]').value).to eq(email)
  163. expect(find('input[name="options::user"]').value).to eq(email)
  164. expect(find('input[name="options::password"]').value).to eq(password)
  165. click '.js-close'
  166. end
  167. end
  168. end
  169. context 'when editing inbound email settings' do
  170. it 'the expert form fields are not shown' do
  171. visit '#channels/email'
  172. click '.js-channelEnable'
  173. click '.js-editInbound'
  174. in_modal do
  175. expect(page).to have_no_text 'ORGANIZATION & DEPARTMENT NAME'
  176. expect(page).to have_no_text 'ORGANIZATION SUPPORT'
  177. expect(page).to have_no_text 'EMAIL'
  178. end
  179. end
  180. context 'with SSL verification off' do
  181. before do
  182. channel = Channel.in_area('Email::Account').first
  183. channel.options[:inbound][:options][:ssl_verify] = false
  184. channel.save!
  185. end
  186. it 'has SSL verification switch in inbound form' do
  187. visit '#channels/email'
  188. click '.js-channelEnable'
  189. click '.js-editInbound'
  190. in_modal do
  191. expect(page)
  192. .to have_select('options::ssl_verify', selected: 'no')
  193. .and have_text('Turning off SSL verification')
  194. verify_select = find('select[name="options::ssl_verify"]')
  195. verify_select.find(:option, 'yes').select_option
  196. expect(page).to have_no_text('Turning off SSL verification')
  197. verify_select.find(:option, 'no').select_option
  198. expect(page).to have_text('Turning off SSL verification')
  199. end
  200. end
  201. end
  202. end
  203. context 'when editing outbound email settings' do
  204. it 'has SSL verification switch in outbound form' do
  205. visit '#channels/email'
  206. click '.js-channelEnable'
  207. click '.js-editOutbound'
  208. in_modal do
  209. adapter_select = find('select[name="adapter"]')
  210. adapter_select.find(:option, 'SMTP - configure your own outgoing SMTP settings').select_option
  211. verify_select = find('select[name="options::ssl_verify"]')
  212. expect(page)
  213. .to have_select('options::ssl_verify', selected: 'yes')
  214. .and have_no_text('Turning off SSL verification')
  215. verify_select.find(:option, 'no').select_option
  216. expect(page).to have_text('Turning off SSL verification')
  217. verify_select.find(:option, 'yes').select_option
  218. expect(page).to have_no_text('Turning off SSL verification')
  219. port_field = find('input[name="options::port"]')
  220. port_field.fill_in with: '25'
  221. port_field.execute_script "$(this).trigger('blur')"
  222. expect(page).to have_css('select[name="options::ssl_verify"][disabled]')
  223. port_field.fill_in with: '465'
  224. port_field.execute_script "$(this).trigger('blur')"
  225. expect(page).to have_css('select[name="options::ssl_verify"]:not([disabled])')
  226. end
  227. end
  228. end
  229. end