diff options
Diffstat (limited to 'spec/workers/emails_on_push_worker_spec.rb')
-rw-r--r-- | spec/workers/emails_on_push_worker_spec.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/workers/emails_on_push_worker_spec.rb b/spec/workers/emails_on_push_worker_spec.rb index 6c37c422aed..3e313610054 100644 --- a/spec/workers/emails_on_push_worker_spec.rb +++ b/spec/workers/emails_on_push_worker_spec.rb @@ -139,6 +139,43 @@ RSpec.describe EmailsOnPushWorker, :mailer do perform end + + context 'when SMIME signing is enabled' do + include SmimeHelper + + before :context do + @root_ca = generate_root + @cert = generate_cert(signer_ca: @root_ca) + end + + let(:root_certificate) do + Gitlab::X509::Certificate.new(@root_ca[:key], @root_ca[:cert]) + end + + let(:certificate) do + Gitlab::X509::Certificate.new(@cert[:key], @cert[:cert]) + end + + before do + allow(Gitlab::Email::Hook::SmimeSignatureInterceptor).to receive(:certificate).and_return(certificate) + + Mail.register_interceptor(Gitlab::Email::Hook::SmimeSignatureInterceptor) + end + + after do + Mail.unregister_interceptor(Gitlab::Email::Hook::SmimeSignatureInterceptor) + end + + it 'does not sign the email multiple times' do + perform + + ActionMailer::Base.deliveries.each do |mail| + expect(mail.header['Content-Type'].value).to match('multipart/signed').and match('protocol="application/x-pkcs7-signature"') + + expect(mail.to_s.scan(/Content-Disposition: attachment;\r\n filename=smime.p7s/).size).to eq(1) + end + end + end end context "when recipients are invalid" do |