retry_security_process_spec.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::Ticket::Article::RetrySecurityProcess, :aggregate_failures, type: :graphql do
  4. before do
  5. # Import S/MIME mail without certificates present, generating signature verification error.
  6. Setting.set('smime_integration', true)
  7. smime_mail = Rails.root.join('spec/fixtures/files/smime/sender_is_signer.eml').read
  8. allow(ARGF).to receive(:read).and_return(smime_mail)
  9. Channel::Driver::MailStdin.new
  10. end
  11. let(:query) do
  12. <<~QUERY
  13. mutation ticketArticleRetrySecurityProcess($articleId: ID!) {
  14. ticketArticleRetrySecurityProcess(articleId: $articleId) {
  15. retryResult {
  16. type
  17. signingSuccess
  18. signingMessage
  19. encryptionSuccess
  20. encryptionMessage
  21. }
  22. article {
  23. securityState {
  24. type
  25. signingSuccess
  26. signingMessage
  27. encryptionSuccess
  28. encryptionMessage
  29. }
  30. }
  31. errors {
  32. message
  33. field
  34. }
  35. }
  36. }
  37. QUERY
  38. end
  39. let(:agent) { create(:agent, groups: [ Group.find_by(name: 'Users')]) }
  40. let(:customer) { create(:customer) }
  41. let(:article) { Ticket.last.articles.last }
  42. let(:variables) { { articleId: gql.id(article) } }
  43. context "when retrying an article's security process" do
  44. context 'with an agent', authenticated_as: :agent do
  45. let(:expected_security_state) do
  46. {
  47. 'type' => 'SMIME',
  48. 'signingSuccess' => true,
  49. 'signingMessage' => '/C=DE/ST=Berlin/L=Berlin/O=Example Security/OU=IT Department/CN=example.com/emailAddress=smime1@example.com',
  50. 'encryptionSuccess' => false,
  51. 'encryptionMessage' => nil,
  52. }
  53. end
  54. it 'updates security status' do
  55. expect(article.preferences['security']['sign']).to eq('success' => false, 'comment' => 'The certificate for verification could not be found.')
  56. # Import missing certificate.
  57. create(:smime_certificate, :with_private, fixture: 'smime1@example.com')
  58. gql.execute(query, variables: variables)
  59. expect(gql.result.data['retryResult']).to eq(expected_security_state)
  60. expect(gql.result.data['article']['securityState']).to eq(expected_security_state)
  61. end
  62. end
  63. context 'with a customer', authenticated_as: :customer do
  64. it 'raises an error' do
  65. gql.execute(query, variables: variables)
  66. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  67. end
  68. end
  69. end
  70. end