ticket_create_security_spec.rb 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'system/apps/mobile_old/examples/article_security_examples'
  4. RSpec.describe 'Mobile > Ticket > Create with security options', app: :mobile, authenticated_as: :authenticate, type: :system do
  5. def prepare_phone_article
  6. within_form(form_updater_gql_number: 1) do
  7. # Step 1.
  8. find_input('Title').type(Faker::Name.unique.name_with_middle)
  9. next_step
  10. # Step 2.
  11. next_step
  12. # Step 3.
  13. find_autocomplete('Customer').search_for_option(customer.email, label: customer.fullname)
  14. next_step
  15. end
  16. end
  17. def prepare_email_article(with_body: false)
  18. within_form(form_updater_gql_number: 1) do
  19. # Step 1.
  20. find_input('Title').type(Faker::Name.unique.name_with_middle)
  21. next_step
  22. # Step 2.
  23. find_radio('articleSenderType').select_choice('Send Email')
  24. next_step
  25. # Step 3.
  26. find_autocomplete('Customer').search_for_option(customer.email, label: customer.fullname)
  27. next_step
  28. # Step 4.
  29. if with_body
  30. find_editor('Text').type(Faker::Hacker.say_something_smart)
  31. end
  32. end
  33. end
  34. def next_step
  35. find_button('Continue').click
  36. end
  37. def go_to_step(step)
  38. find("button[order=\"#{step}\"]").click
  39. end
  40. def submit_form
  41. find_button('Create ticket', match: :first).click
  42. wait_for_gql('shared/entities/ticket/graphql/mutations/create.graphql')
  43. end
  44. before do
  45. visit '/tickets/create'
  46. wait_for_form_to_settle('ticket-create')
  47. end
  48. context 'when setting security options' do
  49. let(:group) { Group.find_by(name: 'Users') }
  50. let(:agent) { create(:agent, groups: [group]) }
  51. let!(:customer) { create(:customer) } # rubocop:disable RSpec/LetSetup
  52. it_behaves_like 'mobile app: article security', ticket_create: true, integration: :smime
  53. it_behaves_like 'mobile app: article security', ticket_create: true, integration: :pgp
  54. context 'when two integrations are enabled', authenticated_as: :agent do
  55. let(:system_email_address) { 'pgp+smime-sender@example.com' }
  56. let(:recipient_email_address) { 'pgp+smime-recipient@example.com' }
  57. let(:email_address) { create(:email_address, email: system_email_address) }
  58. let(:group) { create(:group, email_address: email_address) }
  59. let!(:customer) { create(:customer, email: recipient_email_address) } # rubocop:disable RSpec/LetSetup
  60. before do
  61. Setting.set('pgp_integration', true)
  62. Setting.set('smime_integration', true)
  63. create(:pgp_key, :with_private, fixture: system_email_address)
  64. create(:pgp_key, fixture: recipient_email_address)
  65. create(:smime_certificate, :with_private, fixture: system_email_address)
  66. create(:smime_certificate, fixture: recipient_email_address)
  67. end
  68. it 'can switch between two integrations' do
  69. prepare_email_article
  70. expect(page).to have_button('PGP')
  71. expect(page).to have_button('S/MIME')
  72. # S/MIME is preferred type when both PGP + S/MIME are configured.
  73. expect(find_button('S/MIME')['aria-selected']).to eq('true')
  74. expect(find_button('Encrypt')['aria-selected']).to eq('true')
  75. expect(find_button('Sign')['aria-selected']).to eq('true')
  76. click_on('PGP')
  77. expect(find_button('Encrypt')['aria-selected']).to eq('true')
  78. expect(find_button('Sign')['aria-selected']).to eq('true')
  79. click_on('S/MIME')
  80. expect(find_button('Encrypt')['aria-selected']).to eq('true')
  81. expect(find_button('Sign')['aria-selected']).to eq('true')
  82. end
  83. end
  84. end
  85. end