zoom_spec.rb 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. require 'rails_helper'
  2. RSpec.describe 'Ticket zoom', type: :system do
  3. describe 'owner auto-assignment' do
  4. let!(:ticket) { create(:ticket, group: Group.find_by(name: 'Users'), state: Ticket::State.find_by(name: 'new')) }
  5. let!(:session_user) { User.find_by(login: 'master@example.com') }
  6. context 'for agent disabled' do
  7. before do
  8. Setting.set('ticket_auto_assignment', false)
  9. Setting.set('ticket_auto_assignment_selector', { condition: { 'ticket.state_id' => { operator: 'is', value: Ticket::State.by_category(:work_on).pluck(:id) } } })
  10. Setting.set('ticket_auto_assignment_user_ids_ignore', [])
  11. end
  12. it 'do not assign ticket to current session user' do
  13. refresh
  14. visit "#ticket/zoom/#{ticket.id}"
  15. within(:active_content) do
  16. expect(page).to have_css('select[name=owner_id]')
  17. expect(page).to have_select('owner_id',
  18. selected: '-',
  19. options: ['-', 'Agent 1 Test', 'Test Master Agent'])
  20. end
  21. end
  22. end
  23. context 'for agent enabled' do
  24. before do
  25. Setting.set('ticket_auto_assignment', true)
  26. Setting.set('ticket_auto_assignment_selector', { condition: { 'ticket.state_id' => { operator: 'is', value: Ticket::State.by_category(:work_on).pluck(:id) } } })
  27. end
  28. context 'with empty "ticket_auto_assignment_user_ids_ignore"' do
  29. it 'assigns ticket to current session user' do
  30. refresh
  31. visit "#ticket/zoom/#{ticket.id}"
  32. within(:active_content) do
  33. expect(page).to have_css('.content.active select[name=owner_id]')
  34. expect(page).to have_select('owner_id',
  35. selected: session_user.fullname,
  36. options: ['-', 'Agent 1 Test', 'Test Master Agent'])
  37. end
  38. end
  39. end
  40. context 'with "ticket_auto_assignment_user_ids_ignore" (as integer)' do
  41. it 'assigns ticket not to current session user' do
  42. Setting.set('ticket_auto_assignment_user_ids_ignore', session_user.id)
  43. refresh
  44. visit "#ticket/zoom/#{ticket.id}"
  45. within(:active_content) do
  46. expect(page).to have_css('select[name=owner_id]')
  47. expect(page).to have_select('owner_id',
  48. selected: '-',
  49. options: ['-', 'Agent 1 Test', 'Test Master Agent'])
  50. end
  51. end
  52. end
  53. context 'with "ticket_auto_assignment_user_ids_ignore" (as string)' do
  54. it 'assigns ticket not to current session user' do
  55. Setting.set('ticket_auto_assignment_user_ids_ignore', session_user.id.to_s)
  56. refresh
  57. visit "#ticket/zoom/#{ticket.id}"
  58. within(:active_content) do
  59. expect(page).to have_css('select[name=owner_id]')
  60. expect(page).to have_select('owner_id',
  61. selected: '-',
  62. options: ['-', 'Agent 1 Test', 'Test Master Agent'])
  63. end
  64. end
  65. end
  66. context 'with "ticket_auto_assignment_user_ids_ignore" (as [integer])' do
  67. it 'assigns ticket not to current session user' do
  68. Setting.set('ticket_auto_assignment_user_ids_ignore', [session_user.id])
  69. refresh
  70. visit "#ticket/zoom/#{ticket.id}"
  71. within(:active_content) do
  72. expect(page).to have_css('select[name=owner_id]')
  73. expect(page).to have_select('owner_id',
  74. selected: '-',
  75. options: ['-', 'Agent 1 Test', 'Test Master Agent'])
  76. end
  77. end
  78. end
  79. context 'with "ticket_auto_assignment_user_ids_ignore" (as [string])' do
  80. it 'assigns ticket not to current session user' do
  81. Setting.set('ticket_auto_assignment_user_ids_ignore', [session_user.id.to_s])
  82. refresh
  83. visit "#ticket/zoom/#{ticket.id}"
  84. within(:active_content) do
  85. expect(page).to have_css('select[name=owner_id]')
  86. expect(page).to have_select('owner_id',
  87. selected: '-',
  88. options: ['-', 'Agent 1 Test', 'Test Master Agent'])
  89. end
  90. end
  91. end
  92. context 'with "ticket_auto_assignment_user_ids_ignore" and other user ids' do
  93. it 'assigns ticket to current session user' do
  94. Setting.set('ticket_auto_assignment_user_ids_ignore', [99_999, 999_999])
  95. refresh
  96. visit "#ticket/zoom/#{ticket.id}"
  97. within(:active_content) do
  98. expect(page).to have_css('select[name=owner_id]')
  99. expect(page).to have_select('owner_id',
  100. selected: session_user.fullname,
  101. options: ['-', 'Agent 1 Test', 'Test Master Agent'])
  102. end
  103. end
  104. end
  105. end
  106. end
  107. context 'when ticket has an attachment' do
  108. let(:group) { Group.find_by(name: 'Users') }
  109. let(:ticket) { create(:ticket, group: group) }
  110. let(:article) { create(:ticket_article, ticket: ticket) }
  111. let(:attachment_name) { 'some_file.txt' }
  112. before do
  113. Store.add(
  114. object: 'Ticket::Article',
  115. o_id: article.id,
  116. data: 'some content',
  117. filename: attachment_name,
  118. preferences: {
  119. 'Content-Type' => 'text/plain',
  120. },
  121. created_by_id: 1,
  122. )
  123. end
  124. context 'article was already forwarded once' do
  125. before do
  126. visit "#ticket/zoom/#{ticket.id}"
  127. within(:active_content) do
  128. find('a[data-type=emailForward]').click
  129. click('.js-reset')
  130. have_no_css('.js-reset')
  131. end
  132. end
  133. it 'adds attachments when forwarding multiple times' do
  134. within(:active_content) do
  135. find('a[data-type=emailForward]').click
  136. end
  137. within('.js-writeArea') do
  138. expect(page).to have_text attachment_name
  139. end
  140. end
  141. end
  142. end
  143. context 'replying' do
  144. context 'Group without signature' do
  145. let(:ticket) { create(:ticket) }
  146. let(:current_user) { create(:agent_user, password: 'test', groups: [ticket.group]) }
  147. before do
  148. # initial article to reply to
  149. create(:ticket_article, ticket: ticket)
  150. end
  151. it 'ensures that text input opens on multiple replies', authenticated: -> { current_user } do
  152. visit "ticket/zoom/#{ticket.id}"
  153. 2.times do |article_offset|
  154. articles_existing = 1
  155. articles_expected = articles_existing + (article_offset + 1)
  156. all('a[data-type=emailReply]').last.click
  157. # wait till input box expands completely
  158. find('.attachmentPlaceholder-label').in_fixed_postion
  159. expect(page).not_to have_css('.attachmentPlaceholder-hint', wait: 0)
  160. find('.articleNewEdit-body').send_keys('Some reply')
  161. click '.js-submit'
  162. expect(page).to have_css('.ticket-article-item', count: articles_expected)
  163. end
  164. end
  165. end
  166. end
  167. describe 'delete article', authenticated: -> { user } do
  168. let(:admin) { create :admin, groups: [Group.first] }
  169. let(:agent) { create :agent, groups: [Group.first] }
  170. let(:other_agent) { create :agent, groups: [Group.first] }
  171. let(:customer) { create :customer }
  172. let(:ticket) { create :ticket, group: agent.groups.first, customer: customer }
  173. let(:article) { send(item) }
  174. def article_communication
  175. create_ticket_article(sender_name: 'Agent', internal: false, type_name: 'email', updated_by: customer)
  176. end
  177. def article_note_self
  178. create_ticket_article(sender_name: 'Agent', internal: true, type_name: 'note', updated_by: user)
  179. end
  180. def article_note_other
  181. create_ticket_article(sender_name: 'Agent', internal: true, type_name: 'note', updated_by: other_agent)
  182. end
  183. def article_note_customer
  184. create_ticket_article(sender_name: 'Customer', internal: false, type_name: 'note', updated_by: customer)
  185. end
  186. def article_note_communication_self
  187. create(:ticket_article_type, name: 'note_communication', communication: true)
  188. create_ticket_article(sender_name: 'Agent', internal: true, type_name: 'note_communication', updated_by: user)
  189. end
  190. def article_note_communication_other
  191. create(:ticket_article_type, name: 'note_communication', communication: true)
  192. create_ticket_article(sender_name: 'Agent', internal: true, type_name: 'note_communication', updated_by: other_agent)
  193. end
  194. def create_ticket_article(sender_name:, internal:, type_name:, updated_by:)
  195. create(:ticket_article,
  196. sender_name: sender_name, internal: internal, type_name: type_name, ticket: ticket,
  197. body: "to be deleted #{offset} #{item}",
  198. updated_by_id: updated_by.id, created_by_id: updated_by.id,
  199. created_at: offset.ago, updated_at: offset.ago)
  200. end
  201. context 'going through full stack' do
  202. context 'as admin' do
  203. let(:user) { admin }
  204. let(:item) { 'article_note_self' }
  205. let(:offset) { 0.minutes }
  206. it 'succeeds' do
  207. refresh # make sure user roles are loaded
  208. ensure_websocket do
  209. visit "ticket/zoom/#{ticket.id}"
  210. end
  211. within :active_ticket_article, article, wait: 15 do
  212. click '.js-ArticleAction[data-type=delete]'
  213. end
  214. in_modal do
  215. click '.js-submit'
  216. end
  217. wait.until_disappears { find :active_ticket_article, article, wait: false }
  218. end
  219. end
  220. end
  221. context 'verifying permissions matrix' do
  222. shared_examples 'according to permission matrix' do |item:, expects_visible:, offset:, description:|
  223. context "looking at #{description} #{item}" do
  224. let(:item) { item }
  225. let!(:article) { send(item) }
  226. let(:offset) { offset }
  227. let(:matcher) { expects_visible ? :have_css : :have_no_css }
  228. it expects_visible ? 'delete button is visible' : 'delete button is not visible' do
  229. refresh # make sure user roles are loaded
  230. visit "ticket/zoom/#{ticket.id}"
  231. within :active_ticket_article, article, wait: 15 do
  232. expect(page).to send(matcher, '.js-ArticleAction[data-type=delete]', wait: 0)
  233. end
  234. end
  235. end
  236. end
  237. shared_examples 'deleting ticket article' do |item:, now:, later:, much_later:|
  238. include_examples 'according to permission matrix', item: item, expects_visible: now, offset: 0.minutes, description: 'just created'
  239. include_examples 'according to permission matrix', item: item, expects_visible: later, offset: 6.minutes, description: 'few minutes old'
  240. include_examples 'according to permission matrix', item: item, expects_visible: much_later, offset: 11.minutes, description: 'very old'
  241. end
  242. context 'as admin' do
  243. let(:user) { admin }
  244. include_examples 'deleting ticket article',
  245. item: 'article_communication',
  246. now: false, later: false, much_later: false
  247. include_examples 'deleting ticket article',
  248. item: 'article_note_self',
  249. now: true, later: true, much_later: false
  250. include_examples 'deleting ticket article',
  251. item: 'article_note_other',
  252. now: false, later: false, much_later: false
  253. include_examples 'deleting ticket article',
  254. item: 'article_note_customer',
  255. now: false, later: false, much_later: false
  256. include_examples 'deleting ticket article',
  257. item: 'article_note_communication_self',
  258. now: false, later: false, much_later: false
  259. include_examples 'deleting ticket article',
  260. item: 'article_note_communication_other',
  261. now: false, later: false, much_later: false
  262. end
  263. context 'as agent' do
  264. let(:user) { agent }
  265. include_examples 'deleting ticket article',
  266. item: 'article_communication',
  267. now: false, later: false, much_later: false
  268. include_examples 'deleting ticket article',
  269. item: 'article_note_self',
  270. now: true, later: true, much_later: false
  271. include_examples 'deleting ticket article',
  272. item: 'article_note_other',
  273. now: false, later: false, much_later: false
  274. include_examples 'deleting ticket article',
  275. item: 'article_note_customer',
  276. now: false, later: false, much_later: false
  277. include_examples 'deleting ticket article',
  278. item: 'article_note_communication_self',
  279. now: false, later: false, much_later: false
  280. include_examples 'deleting ticket article',
  281. item: 'article_note_communication_other',
  282. now: false, later: false, much_later: false
  283. end
  284. context 'as customer' do
  285. let(:user) { customer }
  286. include_examples 'deleting ticket article',
  287. item: 'article_communication',
  288. now: false, later: false, much_later: false
  289. include_examples 'deleting ticket article',
  290. item: 'article_note_customer',
  291. now: false, later: false, much_later: false
  292. end
  293. context 'with custom offset' do
  294. before { Setting.set 'ui_ticket_zoom_article_delete_timeframe', 6000 }
  295. context 'as admin' do
  296. let(:user) { admin }
  297. include_examples 'according to permission matrix', item: 'article_note_self', expects_visible: true, offset: 5000.seconds, description: 'outside of delete timeframe'
  298. include_examples 'according to permission matrix', item: 'article_note_self', expects_visible: false, offset: 8000.seconds, description: 'outside of delete timeframe'
  299. end
  300. context 'as agent' do
  301. let(:user) { agent }
  302. include_examples 'according to permission matrix', item: 'article_note_self', expects_visible: true, offset: 5000.seconds, description: 'outside of delete timeframe'
  303. include_examples 'according to permission matrix', item: 'article_note_self', expects_visible: false, offset: 8000.seconds, description: 'outside of delete timeframe'
  304. end
  305. end
  306. context 'with timeframe as 0' do
  307. before { Setting.set 'ui_ticket_zoom_article_delete_timeframe', 0 }
  308. context 'as agent' do
  309. let(:user) { agent }
  310. include_examples 'according to permission matrix', item: 'article_note_self', expects_visible: true, offset: 99.days, description: 'long after'
  311. end
  312. end
  313. end
  314. context 'button is hidden on the go' do
  315. before { Setting.set 'ui_ticket_zoom_article_delete_timeframe', 5 }
  316. let(:user) { agent }
  317. let(:item) { 'article_note_self' }
  318. let!(:article) { send(item) }
  319. let(:offset) { 0.seconds }
  320. it 'successfully' do
  321. refresh # make sure user roles are loaded
  322. visit "ticket/zoom/#{ticket.id}"
  323. within :active_ticket_article, article do
  324. find '.js-ArticleAction[data-type=delete]' # make sure delete button did show up
  325. expect(page).to have_no_css('.js-ArticleAction[data-type=delete]', wait: 15)
  326. end
  327. end
  328. end
  329. end
  330. context 'S/MIME active', authenticated: -> { agent } do
  331. let(:system_email_address) { 'smime1@example.com' }
  332. let(:email_address) { create(:email_address, email: system_email_address) }
  333. let(:group) { create(:group, email_address: email_address) }
  334. let(:agent_groups) { [group] }
  335. let(:agent) { create(:agent_user, groups: agent_groups) }
  336. let(:sender_email_address) { 'smime2@example.com' }
  337. let(:customer) { create(:customer_user, email: sender_email_address) }
  338. let!(:ticket) { create(:ticket, group: group, owner: agent, customer: customer) }
  339. before do
  340. Setting.set('smime_integration', true)
  341. end
  342. context 'received mail' do
  343. context 'article meta information' do
  344. context 'success' do
  345. it 'shows encryption/sign information' do
  346. create(:ticket_article, preferences: {
  347. security: {
  348. type: 'S/MIME',
  349. encryption: {
  350. success: true,
  351. comment: 'COMMENT_ENCRYPT_SUCCESS',
  352. },
  353. sign: {
  354. success: true,
  355. comment: 'COMMENT_SIGN_SUCCESS',
  356. },
  357. }
  358. }, ticket: ticket)
  359. visit "#ticket/zoom/#{ticket.id}"
  360. expect(page).to have_css('svg.icon-lock')
  361. expect(page).to have_css('svg.icon-signed')
  362. open_article_meta
  363. expect(page).to have_css('span', text: 'Encrypted')
  364. expect(page).to have_css('span', text: 'Signed')
  365. expect(page).to have_css('span[title=COMMENT_ENCRYPT_SUCCESS]')
  366. expect(page).to have_css('span[title=COMMENT_SIGN_SUCCESS]')
  367. end
  368. end
  369. context 'error' do
  370. it 'shows create information about encryption/sign failed' do
  371. create(:ticket_article, preferences: {
  372. security: {
  373. type: 'S/MIME',
  374. encryption: {
  375. success: false,
  376. comment: 'Encryption failed because XXX',
  377. },
  378. sign: {
  379. success: false,
  380. comment: 'Sign failed because XXX',
  381. },
  382. }
  383. }, ticket: ticket)
  384. visit "#ticket/zoom/#{ticket.id}"
  385. expect(page).to have_css('svg.icon-not-signed')
  386. open_article_meta
  387. expect(page).to have_css('div.alert.alert--warning', text: 'Encryption failed because XXX')
  388. expect(page).to have_css('div.alert.alert--warning', text: 'Sign failed because XXX')
  389. end
  390. end
  391. end
  392. context 'certificate not present at time of arrival' do
  393. it 'retry' do
  394. smime1 = create(:smime_certificate, :with_private, fixture: system_email_address)
  395. smime2 = create(:smime_certificate, :with_private, fixture: sender_email_address)
  396. mail = Channel::EmailBuild.build(
  397. from: sender_email_address,
  398. to: system_email_address,
  399. body: 'somebody with some text',
  400. content_type: 'text/plain',
  401. security: {
  402. type: 'S/MIME',
  403. sign: {
  404. success: true,
  405. },
  406. encryption: {
  407. success: true,
  408. },
  409. },
  410. )
  411. smime1.destroy
  412. smime2.destroy
  413. parsed_mail = Channel::EmailParser.new.parse(mail.to_s)
  414. ticket, article, _user, _mail = Channel::EmailParser.new.process({ group_id: group.id }, parsed_mail['raw'])
  415. expect(Ticket::Article.find(article.id).body).to eq('no visible content')
  416. create(:smime_certificate, fixture: sender_email_address)
  417. create(:smime_certificate, :with_private, fixture: system_email_address)
  418. visit "#ticket/zoom/#{ticket.id}"
  419. expect(page).not_to have_css('.article-content', text: 'somebody with some text')
  420. click '.js-securityRetryProcess'
  421. expect(page).to have_css('.article-content', text: 'somebody with some text')
  422. end
  423. end
  424. end
  425. context 'replying' do
  426. before do
  427. create(:ticket_article, ticket: ticket, from: customer.email)
  428. create(:smime_certificate, :with_private, fixture: system_email_address)
  429. create(:smime_certificate, fixture: sender_email_address)
  430. end
  431. it 'plain' do
  432. visit "#ticket/zoom/#{ticket.id}"
  433. all('a[data-type=emailReply]').last.click
  434. find('.articleNewEdit-body').send_keys('Test')
  435. expect(page).to have_css('.js-securityEncrypt.btn--active', wait: 5)
  436. expect(page).to have_css('.js-securitySign.btn--active', wait: 5)
  437. click '.js-securityEncrypt'
  438. click '.js-securitySign'
  439. click '.js-submit'
  440. expect(page).to have_css('.ticket-article-item', count: 2)
  441. expect(Ticket::Article.last.preferences['security']['encryption']['success']).to be nil
  442. expect(Ticket::Article.last.preferences['security']['sign']['success']).to be nil
  443. end
  444. it 'signed' do
  445. visit "#ticket/zoom/#{ticket.id}"
  446. all('a[data-type=emailReply]').last.click
  447. find('.articleNewEdit-body').send_keys('Test')
  448. expect(page).to have_css('.js-securityEncrypt.btn--active', wait: 5)
  449. expect(page).to have_css('.js-securitySign.btn--active', wait: 5)
  450. click '.js-securityEncrypt'
  451. click '.js-submit'
  452. expect(page).to have_css('.ticket-article-item', count: 2)
  453. expect(Ticket::Article.last.preferences['security']['encryption']['success']).to be nil
  454. expect(Ticket::Article.last.preferences['security']['sign']['success']).to be true
  455. end
  456. it 'encrypted' do
  457. visit "#ticket/zoom/#{ticket.id}"
  458. all('a[data-type=emailReply]').last.click
  459. find('.articleNewEdit-body').send_keys('Test')
  460. expect(page).to have_css('.js-securityEncrypt.btn--active', wait: 5)
  461. expect(page).to have_css('.js-securitySign.btn--active', wait: 5)
  462. click '.js-securitySign'
  463. click '.js-submit'
  464. expect(page).to have_css('.ticket-article-item', count: 2)
  465. expect(Ticket::Article.last.preferences['security']['encryption']['success']).to be true
  466. expect(Ticket::Article.last.preferences['security']['sign']['success']).to be nil
  467. end
  468. it 'signed and encrypted' do
  469. visit "#ticket/zoom/#{ticket.id}"
  470. all('a[data-type=emailReply]').last.click
  471. find('.articleNewEdit-body').send_keys('Test')
  472. expect(page).to have_css('.js-securityEncrypt.btn--active', wait: 5)
  473. expect(page).to have_css('.js-securitySign.btn--active', wait: 5)
  474. click '.js-submit'
  475. expect(page).to have_css('.ticket-article-item', count: 2)
  476. expect(Ticket::Article.last.preferences['security']['encryption']['success']).to be true
  477. expect(Ticket::Article.last.preferences['security']['sign']['success']).to be true
  478. end
  479. end
  480. context 'Group default behavior' do
  481. let(:smime_config) { {} }
  482. before do
  483. Setting.set('smime_config', smime_config)
  484. create(:ticket_article, ticket: ticket, from: customer.email)
  485. create(:smime_certificate, :with_private, fixture: system_email_address)
  486. create(:smime_certificate, fixture: sender_email_address)
  487. end
  488. shared_examples 'security defaults example' do |sign:, encrypt:|
  489. it "security defaults sign: #{sign}, encrypt: #{encrypt}" do
  490. within(:active_content) do
  491. encrypt_button = find('.js-securityEncrypt', wait: 5)
  492. sign_button = find('.js-securitySign', wait: 5)
  493. await_empty_ajax_queue
  494. active_button_class = '.btn--active'
  495. expect(encrypt_button.matches_css?(active_button_class, wait: 2)).to be(encrypt)
  496. expect(sign_button.matches_css?(active_button_class, wait: 2)).to be(sign)
  497. end
  498. end
  499. end
  500. shared_examples 'security defaults' do |sign:, encrypt:|
  501. before do
  502. visit "#ticket/zoom/#{ticket.id}"
  503. within(:active_content) do
  504. all('a[data-type=emailReply]').last.click
  505. find('.articleNewEdit-body').send_keys('Test')
  506. await_empty_ajax_queue
  507. end
  508. end
  509. include_examples 'security defaults example', sign: sign, encrypt: encrypt
  510. end
  511. shared_examples 'security defaults group change' do |sign:, encrypt:|
  512. before do
  513. visit "#ticket/zoom/#{ticket.id}"
  514. within(:active_content) do
  515. all('a[data-type=emailReply]').last.click
  516. find('.articleNewEdit-body').send_keys('Test')
  517. await_empty_ajax_queue
  518. select new_group.name, from: 'group_id'
  519. end
  520. end
  521. include_examples 'security defaults example', sign: sign, encrypt: encrypt
  522. end
  523. context 'not configured' do
  524. it_behaves_like 'security defaults', sign: true, encrypt: true
  525. end
  526. context 'configuration present' do
  527. let(:smime_config) do
  528. {
  529. 'group_id' => group_defaults
  530. }
  531. end
  532. let(:group_defaults) do
  533. {
  534. 'default_encryption' => {
  535. group.id.to_s => default_encryption,
  536. },
  537. 'default_sign' => {
  538. group.id.to_s => default_sign,
  539. }
  540. }
  541. end
  542. let(:default_sign) { true }
  543. let(:default_encryption) { true }
  544. shared_examples 'sign and encrypt variations' do |check_examples_name|
  545. it_behaves_like check_examples_name, sign: true, encrypt: true
  546. context 'no value' do
  547. let(:group_defaults) { {} }
  548. it_behaves_like check_examples_name, sign: true, encrypt: true
  549. end
  550. context 'signing disabled' do
  551. let(:default_sign) { false }
  552. it_behaves_like check_examples_name, sign: false, encrypt: true
  553. end
  554. context 'encryption disabled' do
  555. let(:default_encryption) { false }
  556. it_behaves_like check_examples_name, sign: true, encrypt: false
  557. end
  558. end
  559. context 'same Group' do
  560. it_behaves_like 'sign and encrypt variations', 'security defaults'
  561. end
  562. context 'Group change' do
  563. let(:new_group) { create(:group, email_address: email_address) }
  564. let(:agent_groups) { [group, new_group] }
  565. let(:group_defaults) do
  566. {
  567. 'default_encryption' => {
  568. new_group.id.to_s => default_encryption,
  569. },
  570. 'default_sign' => {
  571. new_group.id.to_s => default_sign,
  572. }
  573. }
  574. end
  575. it_behaves_like 'sign and encrypt variations', 'security defaults group change'
  576. end
  577. end
  578. end
  579. end
  580. end