2019-11-07 22:06:48 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-08-18 05:11:27 -04:00
|
|
|
require 'fast_spec_helper'
|
2015-09-21 03:46:47 -04:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::IncomingEmail do
|
2015-09-21 03:46:47 -04:00
|
|
|
describe "self.enabled?" do
|
|
|
|
context "when reply by email is enabled" do
|
|
|
|
before do
|
|
|
|
stub_incoming_email_setting(enabled: true)
|
|
|
|
end
|
|
|
|
|
2016-03-17 15:03:51 -04:00
|
|
|
it 'returns true' do
|
2020-07-22 14:09:27 -04:00
|
|
|
expect(described_class.enabled?).to be(true)
|
2015-09-21 03:46:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when reply by email is disabled" do
|
|
|
|
before do
|
|
|
|
stub_incoming_email_setting(enabled: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false" do
|
2020-07-22 14:09:27 -04:00
|
|
|
expect(described_class.enabled?).to be(false)
|
2015-09-21 03:46:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-12 13:07:36 -04:00
|
|
|
describe 'self.supports_wildcard?' do
|
2018-05-02 17:34:05 -04:00
|
|
|
context 'address contains the wildcard placeholder' do
|
2016-10-12 13:07:36 -04:00
|
|
|
before do
|
|
|
|
stub_incoming_email_setting(address: 'replies+%{key}@example.com')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'confirms that wildcard is supported' do
|
2020-07-22 14:09:27 -04:00
|
|
|
expect(described_class.supports_wildcard?).to be(true)
|
2016-10-12 13:07:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "address doesn't contain the wildcard placeholder" do
|
|
|
|
before do
|
|
|
|
stub_incoming_email_setting(address: 'replies@example.com')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns that wildcard is not supported' do
|
2020-07-22 14:09:27 -04:00
|
|
|
expect(described_class.supports_wildcard?).to be(false)
|
2016-10-12 13:07:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'address is not set' do
|
|
|
|
before do
|
|
|
|
stub_incoming_email_setting(address: nil)
|
|
|
|
end
|
|
|
|
|
2018-05-02 17:34:05 -04:00
|
|
|
it 'returns that wildcard is not supported' do
|
2020-07-22 14:09:27 -04:00
|
|
|
expect(described_class.supports_wildcard?).to be(false)
|
2016-10-12 13:07:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'self.unsubscribe_address' do
|
|
|
|
before do
|
|
|
|
stub_incoming_email_setting(address: 'replies+%{key}@example.com')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the address with interpolated reply key and unsubscribe suffix' do
|
2018-12-11 13:01:02 -05:00
|
|
|
expect(described_class.unsubscribe_address('key')).to eq("replies+key#{Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX}@example.com")
|
2016-10-12 13:07:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-21 03:46:47 -04:00
|
|
|
context "self.reply_address" do
|
|
|
|
before do
|
|
|
|
stub_incoming_email_setting(address: "replies+%{key}@example.com")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the address with an interpolated reply key" do
|
|
|
|
expect(described_class.reply_address("key")).to eq("replies+key@example.com")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "self.key_from_address" do
|
|
|
|
before do
|
|
|
|
stub_incoming_email_setting(address: "replies+%{key}@example.com")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns reply key" do
|
|
|
|
expect(described_class.key_from_address("replies+key@example.com")).to eq("key")
|
|
|
|
end
|
2018-05-11 14:05:14 -04:00
|
|
|
|
|
|
|
it 'does not match emails with extra bits' do
|
|
|
|
expect(described_class.key_from_address('somereplies+somekey@example.com.someotherdomain.com')).to be nil
|
|
|
|
end
|
2020-02-27 13:09:21 -05:00
|
|
|
|
|
|
|
context 'when a custom wildcard address is used' do
|
|
|
|
let(:wildcard_address) { 'custom.address+%{key}@example.com' }
|
|
|
|
|
|
|
|
it 'finds key if email matches address pattern' do
|
|
|
|
key = described_class.key_from_address(
|
|
|
|
'custom.address+foo@example.com', wildcard_address: wildcard_address
|
|
|
|
)
|
|
|
|
expect(key).to eq('foo')
|
|
|
|
end
|
|
|
|
end
|
2015-09-21 03:46:47 -04:00
|
|
|
end
|
2016-03-17 15:03:51 -04:00
|
|
|
|
2016-05-20 19:21:58 -04:00
|
|
|
context 'self.key_from_fallback_message_id' do
|
2016-03-17 15:03:51 -04:00
|
|
|
it 'returns reply key' do
|
2016-05-20 19:21:58 -04:00
|
|
|
expect(described_class.key_from_fallback_message_id('reply-key@localhost')).to eq('key')
|
2016-03-17 15:03:51 -04:00
|
|
|
end
|
|
|
|
end
|
2017-01-17 14:50:49 -05:00
|
|
|
|
|
|
|
context 'self.scan_fallback_references' do
|
|
|
|
let(:references) do
|
2020-01-23 10:08:46 -05:00
|
|
|
'<issue_1@localhost>' \
|
|
|
|
' <reply-59d8df8370b7e95c5a49fbf86aeb2c93@localhost>' \
|
2017-01-17 14:50:49 -05:00
|
|
|
',<exchange@microsoft.com>'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns reply key' do
|
|
|
|
expect(described_class.scan_fallback_references(references))
|
|
|
|
.to eq(%w[issue_1@localhost
|
|
|
|
reply-59d8df8370b7e95c5a49fbf86aeb2c93@localhost
|
|
|
|
exchange@microsoft.com])
|
|
|
|
end
|
|
|
|
end
|
2015-09-21 03:46:47 -04:00
|
|
|
end
|