debian-mirror-gitlab/spec/config/mail_room_spec.rb

96 lines
3.6 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2016-06-02 11:05:42 +05:30
2023-03-04 22:38:38 +05:30
RSpec.describe 'mail_room.yml', feature_category: :service_desk do
2017-08-17 22:00:37 +05:30
include StubENV
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
let(:mailroom_config_path) { 'config/mail_room.yml' }
let(:gitlab_config_path) { 'config/mail_room.yml' }
2017-09-10 17:25:29 +05:30
let(:queues_config_path) { 'config/redis.queues.yml' }
2016-06-02 11:05:42 +05:30
2023-07-09 08:55:56 +05:30
let(:configuration) { YAML.safe_load(ERB.new(File.read(mailroom_config_path)).result, permitted_classes: [Symbol]) }
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
before do
2023-07-09 08:55:56 +05:30
stub_env('MAIL_ROOM_GITLAB_CONFIG_FILE', absolute_path(gitlab_config_path))
allow(Gitlab::Redis::Queues).to receive(:config_file_name).and_return(queues_config_path)
Gitlab::MailRoom.instance_variable_set(:@enabled_configs, nil)
Gitlab::MailRoom.instance_variable_set(:@yaml, nil)
2017-08-17 22:00:37 +05:30
end
context 'when incoming email is disabled' do
let(:gitlab_config_path) { 'spec/fixtures/config/mail_room_disabled.yml' }
2016-06-02 11:05:42 +05:30
2016-09-13 17:45:13 +05:30
it 'contains no configuration' do
2016-06-02 11:05:42 +05:30
expect(configuration[:mailboxes]).to be_nil
end
end
2020-03-13 15:44:24 +05:30
context 'when both incoming email and service desk email are enabled' do
2017-08-17 22:00:37 +05:30
let(:gitlab_config_path) { 'spec/fixtures/config/mail_room_enabled.yml' }
2021-09-04 01:27:46 +05:30
let(:queues_config_path) { 'spec/fixtures/config/redis_new_format_host.yml' }
2017-09-10 17:25:29 +05:30
let(:gitlab_redis_queues) { Gitlab::Redis::Queues.new(Rails.env) }
2016-06-02 11:05:42 +05:30
2016-09-13 17:45:13 +05:30
it 'contains the intended configuration' do
2020-03-13 15:44:24 +05:30
expected_mailbox = {
host: 'imap.gmail.com',
port: 993,
ssl: true,
start_tls: false,
email: 'gitlab-incoming@gmail.com',
password: '[REDACTED]',
name: 'inbox',
2020-05-24 23:13:21 +05:30
idle_timeout: 60,
2023-03-17 16:20:25 +05:30
delete_after_delivery: true,
2020-05-24 23:13:21 +05:30
expunge_deleted: true
2020-03-13 15:44:24 +05:30
}
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-06-02 11:05:42 +05:30
end
end
2017-08-17 22:00:37 +05:30
2021-04-29 21:17:54 +05:30
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' }
2021-09-04 01:27:46 +05:30
let(:queues_config_path) { 'spec/fixtures/config/redis_new_format_host.yml' }
2021-04-29 21:17:54 +05:30
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,
2023-03-17 16:20:25 +05:30
delete_after_delivery: false
2021-04-29 21:17:54 +05:30
}
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-08-17 22:00:37 +05:30
def absolute_path(path)
Rails.root.join(path).to_s
end
2016-06-02 11:05:42 +05:30
end