debian-mirror-gitlab/spec/lib/gitlab/email/attachment_uploader_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

85 lines
2.8 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2015-09-25 12:07:36 +05:30
require "spec_helper"
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Email::AttachmentUploader do
2015-09-25 12:07:36 +05:30
describe "#execute" do
2018-03-27 19:54:05 +05:30
let(:project) { create(:project) }
2015-09-25 12:07:36 +05:30
let(:message_raw) { fixture_file("emails/attachment.eml") }
let(:message) { Mail::Message.new(message_raw) }
2022-05-07 20:08:51 +05:30
before do
allow_next_instance_of(Gitlab::Sanitizers::Exif) do |instance|
allow(instance).to receive(:clean_existing_path).and_call_original
end
end
def expect_exif_sanitizer_called
expect_next_instance_of(Gitlab::Sanitizers::Exif) do |sanitizer|
expect(sanitizer).to receive(:clean_existing_path) do |path, **options|
expect(File.exist?(path)).to be true
file = File.open(path, "rb")
expect(options).to eql(content: file.read, skip_unallowed_types: true)
file.close
end
end
end
2015-09-25 12:07:36 +05:30
it "uploads all attachments and returns their links" do
2022-05-07 20:08:51 +05:30
expect_exif_sanitizer_called
2020-03-13 15:44:24 +05:30
links = described_class.new(message).execute(upload_parent: project, uploader_class: FileUploader)
2015-09-25 12:07:36 +05:30
link = links.first
expect(link).not_to be_nil
expect(link[:alt]).to eq("bricks")
expect(link[:url]).to include("bricks.png")
end
2020-03-13 15:44:24 +05:30
context 'with a signed message' do
let(:message_raw) { fixture_file("emails/valid_reply_signed_smime.eml") }
it 'uploads all attachments except the signature' do
2022-05-07 20:08:51 +05:30
expect_exif_sanitizer_called
2020-03-13 15:44:24 +05:30
links = described_class.new(message).execute(upload_parent: project, uploader_class: FileUploader)
expect(links).not_to include(a_hash_including(alt: 'smime.p7s'))
image_link = links.first
expect(image_link).not_to be_nil
expect(image_link[:alt]).to eq('gitlab_logo')
expect(image_link[:url]).to include('gitlab_logo.png')
end
end
2020-04-22 19:07:51 +05:30
context 'with a signed message with mixed protocol prefix' do
let(:message_raw) { fixture_file("emails/valid_reply_signed_smime_mixed_protocol_prefix.eml") }
it 'uploads all attachments except the signature' do
2022-05-07 20:08:51 +05:30
expect_exif_sanitizer_called
2020-04-22 19:07:51 +05:30
links = described_class.new(message).execute(upload_parent: project, uploader_class: FileUploader)
expect(links).not_to include(a_hash_including(alt: 'smime.p7s'))
image_link = links.first
expect(image_link).not_to be_nil
expect(image_link[:alt]).to eq('gitlab_logo')
expect(image_link[:url]).to include('gitlab_logo.png')
end
end
2021-06-08 01:23:25 +05:30
context 'with a message with no content type' do
let(:message_raw) { fixture_file("emails/no_content_type.eml") }
it 'uploads all attachments except the signature' do
links = described_class.new(message).execute(upload_parent: project, uploader_class: FileUploader)
expect(links).to eq([])
end
end
2015-09-25 12:07:36 +05:30
end
end