2016-07-09 11:13:19 -04:00
|
|
|
require 'spec_helper'
|
2016-02-26 21:48:13 -05:00
|
|
|
|
2016-07-09 11:13:19 -04:00
|
|
|
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' }
|
|
|
|
let(:redis_config_path) { 'config/resque.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),
|
|
|
|
'GITLAB_REDIS_CONFIG_FILE' => absolute_path(redis_config_path)
|
|
|
|
}
|
|
|
|
cmd = "puts ERB.new(File.read(#{absolute_path(mailroom_config_path).inspect})).result"
|
2016-02-26 21:48:13 -05:00
|
|
|
|
2017-03-15 18:21:45 -04:00
|
|
|
output, status = Gitlab::Popen.popen(%W(ruby -rerb -e #{cmd}), absolute_path('config'), vars)
|
|
|
|
raise "Error interpreting #{mailroom_config_path}: #{output}" unless status.zero?
|
|
|
|
|
|
|
|
YAML.load(output)
|
|
|
|
end
|
|
|
|
|
|
|
|
before(:each) do
|
2017-03-15 20:36:20 -04:00
|
|
|
stub_env('GITLAB_REDIS_CONFIG_FILE', absolute_path(redis_config_path))
|
2017-03-15 18:21:45 -04:00
|
|
|
clear_redis_raw_config
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:each) do
|
|
|
|
clear_redis_raw_config
|
|
|
|
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
|
|
|
|
|
2016-07-09 11:13:19 -04:00
|
|
|
context 'when incoming email is enabled' do
|
2017-03-15 18:21:45 -04:00
|
|
|
let(:gitlab_config_path) { 'spec/fixtures/config/mail_room_enabled.yml' }
|
|
|
|
let(:redis_config_path) { 'spec/fixtures/config/redis_new_format_host.yml' }
|
2016-10-25 09:50:41 -04:00
|
|
|
|
2017-03-15 18:21:45 -04:00
|
|
|
let(:gitlab_redis) { Gitlab::Redis.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
|
2016-10-25 09:50:41 -04:00
|
|
|
expect(configuration[:mailboxes].length).to eq(1)
|
2016-02-26 21:48:13 -05:00
|
|
|
mailbox = configuration[:mailboxes].first
|
|
|
|
|
2016-07-09 11:13:19 -04:00
|
|
|
expect(mailbox[:host]).to eq('imap.gmail.com')
|
2016-02-26 21:48:13 -05:00
|
|
|
expect(mailbox[:port]).to eq(993)
|
|
|
|
expect(mailbox[:ssl]).to eq(true)
|
|
|
|
expect(mailbox[:start_tls]).to eq(false)
|
2016-07-09 11:13:19 -04:00
|
|
|
expect(mailbox[:email]).to eq('gitlab-incoming@gmail.com')
|
|
|
|
expect(mailbox[:password]).to eq('[REDACTED]')
|
|
|
|
expect(mailbox[:name]).to eq('inbox')
|
2016-11-11 09:40:19 -05:00
|
|
|
expect(mailbox[:idle_timeout]).to eq(60)
|
2016-07-09 11:13:19 -04:00
|
|
|
|
2016-10-25 09:50:41 -04:00
|
|
|
redis_url = gitlab_redis.url
|
|
|
|
sentinels = gitlab_redis.sentinels
|
2016-02-26 21:48:13 -05:00
|
|
|
|
2016-10-25 09:50:41 -04:00
|
|
|
expect(mailbox[:delivery_options][:redis_url]).to be_present
|
2016-02-26 21:48:13 -05:00
|
|
|
expect(mailbox[:delivery_options][:redis_url]).to eq(redis_url)
|
2016-10-25 09:50:41 -04:00
|
|
|
|
|
|
|
expect(mailbox[:delivery_options][:sentinels]).to be_present
|
|
|
|
expect(mailbox[:delivery_options][:sentinels]).to eq(sentinels)
|
|
|
|
|
|
|
|
expect(mailbox[:arbitration_options][:redis_url]).to be_present
|
2016-02-26 21:48:13 -05:00
|
|
|
expect(mailbox[:arbitration_options][:redis_url]).to eq(redis_url)
|
2016-10-25 09:50:41 -04:00
|
|
|
|
|
|
|
expect(mailbox[:arbitration_options][:sentinels]).to be_present
|
|
|
|
expect(mailbox[:arbitration_options][:sentinels]).to eq(sentinels)
|
2016-02-26 21:48:13 -05:00
|
|
|
end
|
|
|
|
end
|
2016-10-25 09:50:41 -04:00
|
|
|
|
2017-03-15 18:21:45 -04:00
|
|
|
def clear_redis_raw_config
|
2016-10-25 09:50:41 -04:00
|
|
|
Gitlab::Redis.remove_instance_variable(:@_raw_config)
|
|
|
|
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
|