debian-mirror-gitlab/spec/lib/gitlab/incoming_email_spec.rb

126 lines
3.5 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2015-09-25 12:07:36 +05:30
require "spec_helper"
2017-09-10 17:25:29 +05:30
describe Gitlab::IncomingEmail do
2015-09-25 12:07:36 +05:30
describe "self.enabled?" do
context "when reply by email is enabled" do
before do
stub_incoming_email_setting(enabled: true)
end
2016-06-02 11:05:42 +05:30
it 'returns true' do
expect(described_class.enabled?).to be_truthy
2015-09-25 12:07:36 +05:30
end
end
context "when reply by email is disabled" do
before do
stub_incoming_email_setting(enabled: false)
end
it "returns false" do
expect(described_class.enabled?).to be_falsey
end
end
end
2017-08-17 22:00:37 +05:30
describe 'self.supports_wildcard?' do
2018-10-15 14:42:47 +05:30
context 'address contains the wildcard placeholder' do
2017-08-17 22:00:37 +05:30
before do
stub_incoming_email_setting(address: 'replies+%{key}@example.com')
end
it 'confirms that wildcard is supported' do
expect(described_class.supports_wildcard?).to be_truthy
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
expect(described_class.supports_wildcard?).to be_falsey
end
end
context 'address is not set' do
before do
stub_incoming_email_setting(address: nil)
end
2018-10-15 14:42:47 +05:30
it 'returns that wildcard is not supported' do
2017-08-17 22:00:37 +05:30
expect(described_class.supports_wildcard?).to be_falsey
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
2019-02-15 15:39:39 +05:30
expect(described_class.unsubscribe_address('key')).to eq("replies+key#{Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX}@example.com")
2017-08-17 22:00:37 +05:30
end
end
2015-09-25 12:07:36 +05:30
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-11-08 19:23:39 +05:30
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-04-08 14:13:33 +05:30
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-25 12:07:36 +05:30
end
2016-06-02 11:05:42 +05:30
2016-09-13 17:45:13 +05:30
context 'self.key_from_fallback_message_id' do
2016-06-02 11:05:42 +05:30
it 'returns reply key' do
2016-09-13 17:45:13 +05:30
expect(described_class.key_from_fallback_message_id('reply-key@localhost')).to eq('key')
2016-06-02 11:05:42 +05:30
end
end
2017-08-17 22:00:37 +05:30
context 'self.scan_fallback_references' do
let(:references) do
2020-03-09 13:42:32 +05:30
'<issue_1@localhost>' \
' <reply-59d8df8370b7e95c5a49fbf86aeb2c93@localhost>' \
2017-08-17 22:00:37 +05:30
',<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-25 12:07:36 +05:30
end