2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-09 11:13:19 -04:00
|
|
|
require 'spec_helper'
|
2016-02-26 21:48:13 -05:00
|
|
|
|
2020-06-03 23:08:05 -04:00
|
|
|
RSpec.describe 'mail_room.yml' do
|
2017-03-15 20:36:20 -04:00
|
|
|
include StubENV
|
|
|
|
|
2017-03-15 18:21:45 -04:00
|
|
|
let(:mailroom_config_path) { 'config/mail_room.yml' }
|
|
|
|
let(:gitlab_config_path) { 'config/mail_room.yml' }
|
2017-07-10 23:35:47 -04:00
|
|
|
let(:queues_config_path) { 'config/redis.queues.yml' }
|
2016-02-26 21:48:13 -05:00
|
|
|
|
2017-03-15 18:21:45 -04:00
|
|
|
let(:configuration) do
|
|
|
|
vars = {
|
|
|
|
'MAIL_ROOM_GITLAB_CONFIG_FILE' => absolute_path(gitlab_config_path),
|
2017-07-10 23:35:47 -04:00
|
|
|
'GITLAB_REDIS_QUEUES_CONFIG_FILE' => absolute_path(queues_config_path)
|
2017-03-15 18:21:45 -04:00
|
|
|
}
|
|
|
|
cmd = "puts ERB.new(File.read(#{absolute_path(mailroom_config_path).inspect})).result"
|
2016-02-26 21:48:13 -05:00
|
|
|
|
2021-04-07 17:09:01 -04:00
|
|
|
result = Gitlab::Popen.popen_with_detail(%W(ruby -rerb -e #{cmd}), absolute_path('config'), vars)
|
|
|
|
output = result.stdout
|
|
|
|
status = result.status
|
2020-08-04 14:09:49 -04:00
|
|
|
raise "Error interpreting #{mailroom_config_path}: #{output}" unless status == 0
|
2017-03-15 18:21:45 -04:00
|
|
|
|
2021-04-23 23:09:38 -04:00
|
|
|
YAML.safe_load(output, permitted_classes: [Symbol])
|
2017-03-15 18:21:45 -04:00
|
|
|
end
|
|
|
|
|
2017-08-10 18:31:42 -04:00
|
|
|
before do
|
2017-07-10 23:35:47 -04:00
|
|
|
stub_env('GITLAB_REDIS_QUEUES_CONFIG_FILE', absolute_path(queues_config_path))
|
|
|
|
clear_queues_raw_config
|
2017-03-15 18:21:45 -04:00
|
|
|
end
|
|
|
|
|
2017-08-10 18:31:42 -04:00
|
|
|
after do
|
2017-07-10 23:35:47 -04:00
|
|
|
clear_queues_raw_config
|
2017-03-15 18:21:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when incoming email is disabled' do
|
|
|
|
let(:gitlab_config_path) { 'spec/fixtures/config/mail_room_disabled.yml' }
|
2016-02-26 21:48:13 -05:00
|
|
|
|
2016-07-09 11:13:19 -04:00
|
|
|
it 'contains no configuration' do
|
2016-02-26 21:48:13 -05:00
|
|
|
expect(configuration[:mailboxes]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-31 16:08:52 -05:00
|
|
|
context 'when both incoming email and service desk email are enabled' do
|
2017-03-15 18:21:45 -04:00
|
|
|
let(:gitlab_config_path) { 'spec/fixtures/config/mail_room_enabled.yml' }
|
2017-07-10 23:35:47 -04:00
|
|
|
let(:queues_config_path) { 'spec/fixtures/config/redis_queues_new_format_host.yml' }
|
|
|
|
let(:gitlab_redis_queues) { Gitlab::Redis::Queues.new(Rails.env) }
|
2016-02-26 21:48:13 -05:00
|
|
|
|
2016-07-09 11:13:19 -04:00
|
|
|
it 'contains the intended configuration' do
|
2020-01-31 16:08:52 -05:00
|
|
|
expected_mailbox = {
|
|
|
|
host: 'imap.gmail.com',
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
start_tls: false,
|
|
|
|
email: 'gitlab-incoming@gmail.com',
|
|
|
|
password: '[REDACTED]',
|
|
|
|
name: 'inbox',
|
2020-05-12 20:07:50 -04:00
|
|
|
idle_timeout: 60,
|
|
|
|
expunge_deleted: true
|
2020-01-31 16:08:52 -05:00
|
|
|
}
|
|
|
|
expected_options = {
|
|
|
|
redis_url: gitlab_redis_queues.url,
|
|
|
|
sentinels: gitlab_redis_queues.sentinels
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(configuration[:mailboxes].length).to eq(2)
|
|
|
|
expect(configuration[:mailboxes]).to all(include(expected_mailbox))
|
|
|
|
expect(configuration[:mailboxes].map { |m| m[:delivery_options] }).to all(include(expected_options))
|
|
|
|
expect(configuration[:mailboxes].map { |m| m[:arbitration_options] }).to all(include(expected_options))
|
2016-02-26 21:48:13 -05:00
|
|
|
end
|
|
|
|
end
|
2016-10-25 09:50:41 -04:00
|
|
|
|
2021-04-07 17:09:01 -04:00
|
|
|
context 'when both incoming email and service desk email are enabled for Microsoft Graph' do
|
|
|
|
let(:gitlab_config_path) { 'spec/fixtures/config/mail_room_enabled_ms_graph.yml' }
|
|
|
|
let(:queues_config_path) { 'spec/fixtures/config/redis_queues_new_format_host.yml' }
|
|
|
|
let(:gitlab_redis_queues) { Gitlab::Redis::Queues.new(Rails.env) }
|
|
|
|
|
|
|
|
it 'contains the intended configuration' do
|
|
|
|
expected_mailbox = {
|
|
|
|
email: 'gitlab-incoming@gmail.com',
|
|
|
|
name: 'inbox',
|
|
|
|
idle_timeout: 60,
|
|
|
|
expunge_deleted: true
|
|
|
|
}
|
|
|
|
expected_options = {
|
|
|
|
redis_url: gitlab_redis_queues.url,
|
|
|
|
sentinels: gitlab_redis_queues.sentinels
|
|
|
|
}
|
|
|
|
expected_inbox_options = {
|
|
|
|
tenant_id: '12345',
|
|
|
|
client_id: 'MY-CLIENT-ID',
|
|
|
|
client_secret: 'MY-CLIENT-SECRET',
|
|
|
|
poll_interval: 60
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(configuration[:mailboxes].length).to eq(2)
|
|
|
|
expect(configuration[:mailboxes]).to all(include(expected_mailbox))
|
|
|
|
expect(configuration[:mailboxes].map { |m| m[:inbox_method] }).to all(eq('microsoft_graph'))
|
|
|
|
expect(configuration[:mailboxes].map { |m| m[:inbox_options] }).to all(eq(expected_inbox_options))
|
|
|
|
expect(configuration[:mailboxes].map { |m| m[:delivery_options] }).to all(include(expected_options))
|
|
|
|
expect(configuration[:mailboxes].map { |m| m[:delivery_options] }).to all(include(expected_options))
|
|
|
|
expect(configuration[:mailboxes].map { |m| m[:arbitration_options] }).to all(include(expected_options))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-10 23:35:47 -04:00
|
|
|
def clear_queues_raw_config
|
|
|
|
Gitlab::Redis::Queues.remove_instance_variable(:@_raw_config)
|
2016-10-25 09:50:41 -04:00
|
|
|
rescue NameError
|
|
|
|
# raised if @_raw_config was not set; ignore
|
|
|
|
end
|
2017-03-15 18:21:45 -04:00
|
|
|
|
|
|
|
def absolute_path(path)
|
|
|
|
Rails.root.join(path).to_s
|
|
|
|
end
|
2016-02-26 21:48:13 -05:00
|
|
|
end
|