123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840 |
- # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- require 'rails_helper'
- RSpec.describe SecureMailing::PGP, :aggregate_failures do
- before do
- Setting.set('pgp_integration', true)
- end
- let(:raw_body) { 'Testing some Content' }
- let(:attachments) { [] }
- let(:system_email_address) { 'pgp1@example.com' }
- let(:customer_email_address) { 'pgp2@example.com' }
- let(:cc_customer_email_address) { 'pgp3@example.com' }
- let(:expired_email_address) { 'expiredpgp1@example.com' }
- let(:content_type) { 'text/plain' }
- def build_mail
- Channel::EmailBuild.build(
- from: sender_email_address,
- to: recipient_email_address,
- cc: cc_recipient_email_address,
- body: raw_body,
- content_type: content_type,
- security: security_preferences,
- attachments: attachments
- )
- end
- describe 'outgoing' do
- shared_examples 'HttpLog writer' do |status|
- it "logs #{status}" do
- expect do
- build_mail
- rescue
- # allow failures
- end.to change(HttpLog, :count).by(1)
- expect(HttpLog.last.attributes).to include('direction' => 'out', 'status' => status)
- end
- end
- let(:sender_email_address) { system_email_address }
- let(:recipient_email_address) { customer_email_address }
- let(:cc_recipient_email_address) { cc_customer_email_address }
- context 'without security' do
- let(:security_preferences) do
- nil
- end
- it 'builds mail' do
- expect(build_mail.body).not_to match(SecureMailing::PGP::Incoming::SIGNATURE_CONTENT_TYPE)
- expect(build_mail.body).to eq(raw_body)
- end
- end
- context 'with signing' do
- let(:security_preferences) do
- {
- type: 'PGP',
- sign: {
- success: true,
- },
- encryption: {
- success: false,
- },
- }
- end
- context 'when private key present' do
- before do
- create(:pgp_key, :with_private, fixture: system_email_address)
- end
- it 'builds mail' do
- expect(build_mail.body).to match(SecureMailing::PGP::Incoming::SIGNATURE_CONTENT_TYPE)
- end
- it_behaves_like 'HttpLog writer', 'success'
- context 'with expired key' do
- let(:system_email_address) { expired_email_address }
- it 'raises exception' do
- expect { build_mail }.to raise_error ActiveRecord::RecordNotFound
- end
- it_behaves_like 'HttpLog writer', 'failed'
- end
- end
- context 'when no private key is present' do
- it 'raises exception' do
- expect { build_mail }.to raise_error ActiveRecord::RecordNotFound
- end
- it_behaves_like 'HttpLog writer', 'failed'
- end
- end
- context 'with encryption' do
- let(:security_preferences) do
- {
- type: 'PGP',
- sign: {
- success: false,
- },
- encryption: {
- success: true,
- },
- }
- end
- context 'when all needed keys are present' do
- before do
- create(:pgp_key, :with_private, fixture: system_email_address)
- create(:pgp_key, fixture: recipient_email_address)
- create(:pgp_key, fixture: cc_recipient_email_address)
- end
- it 'builds mail' do
- mail = build_mail
- expect(mail['Content-Type'].value).to include('multipart/encrypted')
- expect(mail.body).not_to include(raw_body)
- end
- it_behaves_like 'HttpLog writer', 'success'
- end
- context 'when needed keys are not present' do
- it 'raises exception' do
- expect { build_mail }.to raise_error ActiveRecord::RecordNotFound
- end
- end
- context 'when one key is expired' do
- before do
- create(:pgp_key, :with_private, fixture: system_email_address)
- create(:pgp_key, fixture: recipient_email_address)
- create(:pgp_key, fixture: cc_recipient_email_address)
- end
- let(:customer_email_address) { expired_email_address }
- it 'raises exception' do
- expect { build_mail }.to raise_error ActiveRecord::RecordNotFound
- end
- end
- context 'when a key with multiple UIDs is present' do
- let(:customer_email_address) { 'multipgp2@example.com' }
- before do
- create(:pgp_key, :with_private, fixture: system_email_address)
- create(:pgp_key, fixture: recipient_email_address)
- create(:pgp_key, fixture: cc_customer_email_address)
- end
- it 'builds mail' do
- mail = build_mail
- expect(mail['Content-Type'].value).to include('multipart/encrypted')
- expect(mail.body).not_to include(raw_body)
- end
- it_behaves_like 'HttpLog writer', 'success'
- end
- end
- context 'with encryption and signing' do
- let(:security_preferences) do
- {
- type: 'PGP',
- sign: {
- success: true,
- },
- encryption: {
- success: true,
- },
- }
- end
- before do
- create(:pgp_key, :with_private, fixture: system_email_address)
- create(:pgp_key, :with_private, fixture: recipient_email_address)
- create(:pgp_key, fixture: cc_customer_email_address)
- end
- it 'builds mail' do
- mail = build_mail
- expect(mail['Content-Type'].value).to include('multipart/encrypted')
- expect(mail.body).not_to include(raw_body)
- end
- context 'with inline image' do
- let(:article) do
- create(:ticket_article,
- ticket: create(:ticket),
- body: '<div>some message article helper test1</div><div><img src="cid:15.274327094.140939@zammad.example.com"><br></div>')
- end
- let(:attachments) do
- create_list(
- :store,
- 1,
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'fake',
- filename: 'inline_image.jpg',
- preferences: {
- 'Content-Type' => 'image/jpeg',
- 'Mime-Type' => 'image/jpeg',
- 'Content-ID' => '<15.274327094.140939>',
- 'Content-Disposition' => 'inline',
- }
- )
- end
- let(:raw_body) do
- <<~MSG_HTML.chomp
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- </head>
- <body style="font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;">
- <div>some message article helper test1</div>
- <div><img src="cid:15.274327094.140939@zammad.example.com"><br></div>
- </body>
- </html>
- MSG_HTML
- end
- let(:content_type) { 'text/html' }
- it 'builds mail' do
- mail = build_mail
- expect(mail['Content-Type'].value).to include('multipart/encrypted')
- end
- end
- end
- end
- describe '.incoming' do
- shared_examples 'HttpLog writer' do |status|
- it "logs #{status}" do
- expect do
- mail
- rescue
- # allow failures
- end.to change(HttpLog, :count).by(2)
- expect(HttpLog.last.attributes).to include('direction' => 'in', 'status' => status)
- end
- end
- shared_examples 'decrypting message content' do
- it 'decrypts message content' do
- expect(mail[:body]).to include(raw_body)
- expect(mail['x-zammad-article-preferences'][:security][:sign][:success]).to be false
- expect(mail['x-zammad-article-preferences'][:security][:sign][:comment]).to be_nil
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:success]).to be true
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:comment]).to eq ''
- end
- end
- shared_examples 'decrypting and verifying signature' do
- it 'decrypts and verifies signature' do
- expect(mail[:body]).to include(raw_body)
- expect(mail['x-zammad-article-preferences'][:security][:sign][:success]).to be true
- expect(mail['x-zammad-article-preferences'][:security][:sign][:comment]).to eq('Good signature')
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:success]).to be true
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:comment]).to eq ''
- end
- end
- let(:sender_email_address) { system_email_address }
- let(:recipient_email_address) { customer_email_address }
- let(:cc_recipient_email_address) { cc_customer_email_address }
- context 'when signature verification' do
- context 'when sender public key present' do
- before do
- create(:pgp_key, :with_private, fixture: sender_email_address)
- end
- let(:security_preferences) do
- {
- type: 'PGP',
- sign: {
- success: true,
- },
- encryption: {
- success: false,
- },
- }
- end
- let(:mail) do
- pgp_mail = build_mail
- mail = Channel::EmailParser.new.parse(pgp_mail.to_s)
- SecureMailing.incoming(mail)
- mail
- end
- it 'verifies' do
- expect(mail[:body]).to include(raw_body)
- expect(mail['x-zammad-article-preferences'][:security][:sign][:success]).to be true
- expect(mail['x-zammad-article-preferences'][:security][:sign][:comment]).to eq 'Good signature'
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:success]).to be false
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:comment]).to be_nil
- end
- it_behaves_like 'HttpLog writer', 'success'
- context 'with html mail' do
- let(:raw_content) { '<div>> Welcome!</div><div>></div><div>> Thank you for installing Zammad. äöüß</div><div>></div>' }
- let(:raw_body) do
- <<~MSG_HTML.chomp
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- </head>
- <body style="font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;">
- #{raw_content}
- </body>
- </html>
- MSG_HTML
- end
- let(:content_type) { 'text/html' }
- it 'verifies' do
- expect(mail[:body]).to eq(raw_content)
- expect(mail['x-zammad-article-preferences'][:security][:sign][:success]).to be true
- expect(mail['x-zammad-article-preferences'][:security][:sign][:comment]).to eq 'Good signature'
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:success]).to be false
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:comment]).to be_nil
- end
- end
- context 'when key is expired' do
- let(:mail) do
- # Import a mail which was created with a now expired key.
- pgp_mail = Rails.root.join('spec/fixtures/files/pgp/mail/mail-expired.box').read
- mail = Channel::EmailParser.new.parse(pgp_mail)
- SecureMailing.incoming(mail)
- mail
- end
- let(:sender_email_address) { expired_email_address }
- it 'not verified' do
- expect(mail[:body]).to include(raw_body)
- expect(mail['x-zammad-article-preferences'][:security][:sign][:success]).to be true
- expect(mail['x-zammad-article-preferences'][:security][:sign][:comment]).to eq 'Good signature'
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:success]).to be false
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:comment]).to be_nil
- end
- end
- end
- end
- context 'with decryption' do
- let(:security_preferences) do
- {
- type: 'PGP',
- sign: {
- success: false,
- },
- encryption: {
- success: true,
- },
- }
- end
- let!(:sender_key) { create(:pgp_key, :with_private, fixture: sender_email_address) }
- let!(:recipient_key) { create(:pgp_key, :with_private, fixture: recipient_email_address) }
- let!(:cc_recipient_key) { create(:pgp_key, :with_private, fixture: cc_recipient_email_address) }
- context 'when private key present' do
- let(:mail) do
- pgp_mail = build_mail
- parsed_mail = Channel::EmailParser.new.parse(pgp_mail.to_s)
- SecureMailing.incoming(parsed_mail)
- parsed_mail
- end
- it_behaves_like 'decrypting message content'
- it_behaves_like 'HttpLog writer', 'success'
- context 'with existing second key for same uid' do
- let(:mail) do
- # Import a mail which was created with a now expired key.
- pgp_mail = Rails.root.join('spec/fixtures/files/pgp/mail/mail-other-key.box').read
- mail = Channel::EmailParser.new.parse(pgp_mail)
- SecureMailing.incoming(mail)
- mail
- end
- before do
- create(:pgp_key, :with_private, fixture: "#{recipient_email_address}-other")
- end
- it_behaves_like 'decrypting message content'
- end
- context 'with OCB key' do
- let(:recipient_email_address) { 'ocbpgp1@example.com' }
- let(:mail) do
- # Import a mail which was created with an OCB key.
- pgp_mail = Rails.root.join('spec/fixtures/files/pgp/mail/mail-ocb.box').read
- mail = Channel::EmailParser.new.parse(pgp_mail)
- SecureMailing.incoming(mail)
- mail
- end
- context 'with GPG version >= 2.2.27', if: SecureMailing::PGP::Tool.version >= '2.2.27' do
- it_behaves_like 'decrypting message content'
- end
- context 'with GPG version < 2.2.27', if: ENV['CI'] && SecureMailing::PGP::Tool.version < '2.2.27' do
- it 'provides an error message as an article comment' do
- expect(mail['x-zammad-article-preferences'][:security][:sign][:success]).to be false
- expect(mail['x-zammad-article-preferences'][:security][:sign][:comment]).to be_nil
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:success]).to be false
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:comment]).to eq 'There was an unknown PGP error. This PGP email was encrypted with a potentially unknown encryption algorithm.'
- end
- end
- end
- context 'when recipient is bcc only' do
- let(:mail) do
- create(:pgp_key, :with_private, fixture: 'zammad@localhost')
- # Import a mail which was created with bcc recipient only.
- pgp_mail = Rails.root.join('spec/fixtures/files/pgp/mail/mail-decrypt-bcc.box').read
- mail = Channel::EmailParser.new.parse(pgp_mail)
- SecureMailing.incoming(mail)
- mail
- end
- it_behaves_like 'decrypting message content'
- end
- end
- context 'with no private key present' do
- let(:mail) do
- pgp_mail = build_mail
- mail = Channel::EmailParser.new.parse(pgp_mail.to_s)
- sender_key.destroy!
- recipient_key.destroy!
- cc_recipient_key.destroy!
- SecureMailing.incoming(mail)
- mail
- end
- it 'fails' do
- expect(mail[:body]).to include('no visible content')
- expect(mail['x-zammad-article-preferences'][:security][:sign][:success]).to be false
- expect(mail['x-zammad-article-preferences'][:security][:sign][:comment]).to be_nil
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:success]).to be false
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:comment]).to eq('The private PGP key could not be found.')
- end
- it_behaves_like 'HttpLog writer', 'failed'
- end
- end
- context 'with signature verification and decryption' do
- let(:security_preferences) do
- {
- type: 'PGP',
- sign: {
- success: true,
- },
- encryption: {
- success: true,
- },
- }
- end
- context 'when the mail is signed and encrypted separately' do
- before do
- create(:pgp_key, :with_private, fixture: sender_email_address)
- create(:pgp_key, :with_private, fixture: recipient_email_address)
- create(:pgp_key, fixture: cc_recipient_email_address)
- end
- let(:mail) do
- pgp_mail = build_mail
- mail = Channel::EmailParser.new.parse(pgp_mail.to_s)
- SecureMailing.incoming(mail)
- mail
- end
- it_behaves_like 'decrypting and verifying signature'
- end
- context 'when the mail is signed and encrypted (detached signature)' do
- let(:sender_key) { create(:pgp_key, :with_private, fixture: sender_email_address) }
- let(:recipient_key) { create(:pgp_key, :with_private, fixture: recipient_email_address) }
- let(:cc_recipient_key) { create(:pgp_key, :with_private, fixture: cc_recipient_email_address) }
- let(:mail) do
- # Import a mail that was signed + encrypted with a detached signature.
- pgp_mail = Rails.root.join('spec/fixtures/files/pgp/mail/mail-detached.box').read
- mail = Channel::EmailParser.new.parse(pgp_mail.to_s)
- SecureMailing.incoming(mail)
- mail
- end
- context 'when all keys are present' do
- before do
- sender_key
- recipient_key
- cc_recipient_key
- end
- it_behaves_like 'decrypting and verifying signature'
- end
- context 'when only cc recipient key is present for decryption' do
- before do
- sender_key
- cc_recipient_key
- end
- it_behaves_like 'decrypting and verifying signature'
- end
- context 'when only decryption key is present' do
- before do
- recipient_key
- cc_recipient_key
- end
- it 'decrypts, but verifies signature fails' do
- expect(mail[:body]).to include(raw_body)
- expect(mail['x-zammad-article-preferences'][:security][:sign][:success]).to be false
- expect(mail['x-zammad-article-preferences'][:security][:sign][:comment]).to eq('The public PGP key could not be found.')
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:success]).to be true
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:comment]).to eq ''
- end
- end
- context 'when all keys are present, but addresses are in upcase' do
- let(:mail) do
- # Import a mail and change the case of the sender address.
- pgp_mail = Rails.root.join('spec/fixtures/files/pgp/mail/mail-detached.box').read
- pgp_mail = pgp_mail.sub!('pgp1@example.com', 'PGP1@EXAMPLE.COM')
- pgp_mail = pgp_mail.sub!('pgp2@example.com', 'PGP2@EXAMPLE.COM')
- pgp_mail = pgp_mail.sub!('pgp3@example.com', 'PGP3@EXAMPLE.COM')
- mail = Channel::EmailParser.new.parse(pgp_mail.to_s)
- SecureMailing.incoming(mail)
- mail
- end
- before do
- sender_key
- recipient_key
- cc_recipient_key
- end
- it_behaves_like 'decrypting and verifying signature'
- end
- end
- context 'when the mail is signed and encrypted (attached signature)' do
- let(:sender_key) { create(:pgp_key, :with_private, fixture: sender_email_address) }
- let(:recipient_key) { create(:pgp_key, :with_private, fixture: recipient_email_address) }
- let(:cc_recipient_key) { create(:pgp_key, :with_private, fixture: cc_recipient_email_address) }
- let(:mail) do
- # Import a mail that was signed + encrypted with an attached signature.
- pgp_mail = Rails.root.join('spec/fixtures/files/pgp/mail/mail-attached.box').read
- mail = Channel::EmailParser.new.parse(pgp_mail.to_s)
- SecureMailing.incoming(mail)
- mail
- end
- context 'when all keys are present' do
- before do
- sender_key
- recipient_key
- cc_recipient_key
- end
- it_behaves_like 'decrypting and verifying signature'
- end
- context 'when only cc recipient key is present for decryption' do
- before do
- sender_key
- cc_recipient_key
- end
- it_behaves_like 'decrypting and verifying signature'
- end
- context 'when only decryption key is present' do
- before do
- recipient_key
- cc_recipient_key
- end
- it 'decrypts, but verifies signature fails' do
- expect(mail[:body]).to include(raw_body)
- expect(mail['x-zammad-article-preferences'][:security][:sign][:success]).to be false
- expect(mail['x-zammad-article-preferences'][:security][:sign][:comment]).to eq('The public PGP key could not be found.')
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:success]).to be true
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:comment]).to eq ''
- end
- end
- end
- context 'when the mail is signed and encrypted in the same go (combined)' do
- let(:sender_key) { create(:pgp_key, :with_private, fixture: sender_email_address) }
- let(:recipient_key) { create(:pgp_key, :with_private, fixture: recipient_email_address) }
- let(:cc_recipient_key) { create(:pgp_key, :with_private, fixture: cc_recipient_email_address) }
- let(:mail) do
- # Import a mail that was signed + encrypted with the same command.
- pgp_mail = Rails.root.join('spec/fixtures/files/pgp/mail/mail-combined.box').read
- mail = Channel::EmailParser.new.parse(pgp_mail.to_s)
- SecureMailing.incoming(mail)
- mail
- end
- context 'when all keys are present' do
- before do
- sender_key
- recipient_key
- cc_recipient_key
- end
- it_behaves_like 'decrypting and verifying signature'
- end
- context 'when only cc recipient key is present for decryption' do
- before do
- sender_key
- cc_recipient_key
- end
- it_behaves_like 'decrypting and verifying signature'
- end
- context 'when only decryption key is present' do
- before do
- recipient_key
- cc_recipient_key
- end
- it 'decrypts, but verifies signature fails' do
- expect(mail[:body]).to include(raw_body)
- expect(mail['x-zammad-article-preferences'][:security][:sign][:success]).to be false
- expect(mail['x-zammad-article-preferences'][:security][:sign][:comment]).to eq('The public PGP key could not be found.')
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:success]).to be true
- expect(mail['x-zammad-article-preferences'][:security][:encryption][:comment]).to eq ''
- end
- end
- end
- context 'when domain alias support is used' do
- before do
- Setting.set('pgp_recipient_alias_configuration', true)
- create(:pgp_key, :with_private, fixture: 'pgp1@example.com', domain_alias: 'domain1.com')
- create(:pgp_key, :with_private, fixture: 'pgp2@example.com', domain_alias: 'domain2.com')
- create(:pgp_key, fixture: 'pgp3@example.com', domain_alias: 'domain3.com')
- end
- let(:system_email_address) { 'pgp1@domain1.com' }
- let(:customer_email_address) { 'pgp2@domain2.com' }
- let(:cc_customer_email_address) { 'pgp3@domain3.com' }
- let(:mail) do
- pgp_mail = build_mail
- mail = Channel::EmailParser.new.parse(pgp_mail.to_s)
- SecureMailing.incoming(mail)
- mail
- end
- it_behaves_like 'decrypting and verifying signature'
- end
- end
- end
- describe '.required_version?' do
- context 'with GnuPG being present on the system' do
- it 'succeeds' do
- expect(described_class.required_version?).to be true
- end
- end
- context 'without GnuPG being present on the system' do
- it 'fails' do
- allow(SecureMailing::PGP::Tool).to receive(:version).and_raise(Errno::ENOENT)
- expect(described_class.required_version?).to be false
- end
- end
- context 'with and outdated version of GnuPG' do
- it 'fails' do
- allow(SecureMailing::PGP::Tool).to receive(:version).and_return('1.8.0')
- expect(described_class.required_version?).to be false
- end
- end
- end
- describe '.retry' do
- let(:sender_email_address) { customer_email_address }
- let(:recipient_email_address) { system_email_address }
- let(:cc_recipient_email_address) { nil }
- let(:security_preferences) do
- {
- type: 'PGP',
- sign: {
- success: false,
- },
- encryption: {
- success: true,
- },
- }
- end
- let(:mail) do
- sender_pgp_key = create(:pgp_key, :with_private, fixture: sender_email_address)
- recipient_pgp_key = create(:pgp_key, :with_private, fixture: system_email_address)
- pgp_mail = Channel::EmailBuild.build(
- from: sender_email_address,
- to: recipient_email_address,
- body: raw_body,
- content_type: 'text/plain',
- security: security_preferences,
- attachments: [
- {
- content_type: 'text/plain',
- content: 'blub',
- filename: 'test-file1.txt',
- },
- ],
- )
- mail = Channel::EmailParser.new.parse(pgp_mail.to_s)
- sender_pgp_key.destroy
- recipient_pgp_key.destroy
- mail
- end
- let!(:article) do
- _ticket, article, _user, _mail = Channel::EmailParser.new.process({}, mail['raw'])
- article
- end
- context 'when private key added' do
- before do
- create(:pgp_key, :with_private, fixture: recipient_email_address)
- end
- it 'succeeds' do
- SecureMailing.retry(article)
- expect(article.preferences[:security][:sign][:success]).to be false
- expect(article.preferences[:security][:sign][:comment]).to be_nil
- expect(article.preferences[:security][:encryption][:success]).to be true
- expect(article.preferences[:security][:encryption][:comment]).to eq ''
- expect(article.body).to include(raw_body)
- expect(article.attachments.count).to eq(1)
- expect(article.attachments.first.filename).to eq('test-file1.txt')
- end
- context 'when PGP activated' do
- before do
- Setting.set('pgp_integration', false)
- end
- it 'succeeds' do
- Setting.set('pgp_integration', true)
- SecureMailing.retry(article)
- expect(article.preferences[:security][:sign][:success]).to be false
- expect(article.preferences[:security][:sign][:comment]).to be_nil
- expect(article.preferences[:security][:encryption][:success]).to be true
- expect(article.preferences[:security][:encryption][:comment]).to eq ''
- expect(article.body).to include(raw_body)
- expect(article.attachments.count).to eq(1)
- expect(article.attachments.first.filename).to eq('test-file1.txt')
- end
- end
- end
- end
- end
|