2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2015-08-23 20:21:04 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class EmailHelperTest < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
test 'a mx_records' do
|
|
|
|
|
2020-02-05 12:50:49 +00:00
|
|
|
domain = 'zammad.com'
|
2015-08-23 20:21:04 +00:00
|
|
|
mx_domains = EmailHelper.mx_records(domain)
|
2020-02-05 12:50:49 +00:00
|
|
|
assert_equal('mx2.zammad.com', mx_domains[0])
|
2015-08-23 20:21:04 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'a email parser test' do
|
|
|
|
|
|
|
|
user, domain = EmailHelper.parse_email('somebody@example.com')
|
|
|
|
assert_equal('somebody', user)
|
|
|
|
assert_equal('example.com', domain)
|
|
|
|
|
|
|
|
user, domain = EmailHelper.parse_email('somebody+test@example.com')
|
|
|
|
assert_equal('somebody+test', user)
|
|
|
|
assert_equal('example.com', domain)
|
|
|
|
|
|
|
|
user, domain = EmailHelper.parse_email('somebody+testexample.com')
|
|
|
|
assert_not(user)
|
|
|
|
assert_not(domain)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'provider test' do
|
|
|
|
email = 'linus@kernel.org'
|
|
|
|
password = 'some_pw'
|
|
|
|
map = EmailHelper.provider(email, password)
|
|
|
|
|
2015-09-06 07:50:51 +00:00
|
|
|
assert_equal('imap', map[:google_imap][:inbound][:adapter])
|
|
|
|
assert_equal('imap.gmail.com', map[:google_imap][:inbound][:options][:host])
|
|
|
|
assert_equal(993, map[:google_imap][:inbound][:options][:port])
|
|
|
|
assert_equal(email, map[:google_imap][:inbound][:options][:user])
|
|
|
|
assert_equal(password, map[:google_imap][:inbound][:options][:password])
|
|
|
|
|
|
|
|
assert_equal('smtp', map[:google_imap][:outbound][:adapter])
|
|
|
|
assert_equal('smtp.gmail.com', map[:google_imap][:outbound][:options][:host])
|
|
|
|
assert_equal(25, map[:google_imap][:outbound][:options][:port])
|
|
|
|
assert_equal(true, map[:google_imap][:outbound][:options][:start_tls])
|
|
|
|
assert_equal(email, map[:google_imap][:outbound][:options][:user])
|
|
|
|
assert_equal(password, map[:google_imap][:outbound][:options][:password])
|
2015-08-23 20:21:04 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'provider_inbound_mx' do
|
|
|
|
|
2020-02-05 12:50:49 +00:00
|
|
|
email = 'linus@zammad.com'
|
2015-08-23 20:21:04 +00:00
|
|
|
password = 'some_pw'
|
|
|
|
user, domain = EmailHelper.parse_email(email)
|
|
|
|
mx_domains = EmailHelper.mx_records(domain)
|
|
|
|
map = EmailHelper.provider_inbound_mx(user, email, password, mx_domains)
|
|
|
|
|
|
|
|
assert_equal('imap', map[0][:adapter])
|
2020-02-05 12:50:49 +00:00
|
|
|
assert_equal('mx2.zammad.com', map[0][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
assert_equal(993, map[0][:options][:port])
|
|
|
|
assert_equal(user, map[0][:options][:user])
|
|
|
|
assert_equal(password, map[0][:options][:password])
|
|
|
|
|
|
|
|
assert_equal('imap', map[1][:adapter])
|
2020-02-05 12:50:49 +00:00
|
|
|
assert_equal('mx2.zammad.com', map[1][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
assert_equal(993, map[1][:options][:port])
|
|
|
|
assert_equal(email, map[1][:options][:user])
|
|
|
|
assert_equal(password, map[1][:options][:password])
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'provider_inbound_guess' do
|
|
|
|
|
2020-02-05 12:50:49 +00:00
|
|
|
email = 'linus@zammad.com'
|
2015-08-23 20:21:04 +00:00
|
|
|
password = 'some_pw'
|
|
|
|
user, domain = EmailHelper.parse_email(email)
|
|
|
|
map = EmailHelper.provider_inbound_guess(user, email, password, domain)
|
|
|
|
|
|
|
|
assert_equal('imap', map[0][:adapter])
|
2020-02-05 12:50:49 +00:00
|
|
|
assert_equal('mail.zammad.com', map[0][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
assert_equal(993, map[0][:options][:port])
|
|
|
|
assert_equal(user, map[0][:options][:user])
|
|
|
|
assert_equal(password, map[0][:options][:password])
|
|
|
|
|
|
|
|
assert_equal('imap', map[1][:adapter])
|
2020-02-05 12:50:49 +00:00
|
|
|
assert_equal('mail.zammad.com', map[1][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
assert_equal(993, map[1][:options][:port])
|
|
|
|
assert_equal(email, map[1][:options][:user])
|
|
|
|
assert_equal(password, map[1][:options][:password])
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'provider_outbound_mx' do
|
|
|
|
|
2020-02-05 12:50:49 +00:00
|
|
|
email = 'linus@zammad.com'
|
2015-08-23 20:21:04 +00:00
|
|
|
password = 'some_pw'
|
|
|
|
user, domain = EmailHelper.parse_email(email)
|
|
|
|
mx_domains = EmailHelper.mx_records(domain)
|
|
|
|
map = EmailHelper.provider_outbound_mx(user, email, password, mx_domains)
|
|
|
|
|
|
|
|
assert_equal('smtp', map[0][:adapter])
|
2020-02-05 12:50:49 +00:00
|
|
|
assert_equal('mx2.zammad.com', map[0][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
assert_equal(25, map[0][:options][:port])
|
|
|
|
assert_equal(true, map[0][:options][:start_tls])
|
|
|
|
assert_equal(user, map[0][:options][:user])
|
|
|
|
assert_equal(password, map[0][:options][:password])
|
|
|
|
|
|
|
|
assert_equal('smtp', map[1][:adapter])
|
2020-02-05 12:50:49 +00:00
|
|
|
assert_equal('mx2.zammad.com', map[1][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
assert_equal(25, map[1][:options][:port])
|
|
|
|
assert_equal(true, map[1][:options][:start_tls])
|
|
|
|
assert_equal(email, map[1][:options][:user])
|
|
|
|
assert_equal(password, map[1][:options][:password])
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'provider_outbound_guess' do
|
|
|
|
|
2020-02-05 12:50:49 +00:00
|
|
|
email = 'linus@zammad.com'
|
2015-08-23 20:21:04 +00:00
|
|
|
password = 'some_pw'
|
|
|
|
user, domain = EmailHelper.parse_email(email)
|
|
|
|
map = EmailHelper.provider_outbound_guess(user, email, password, domain)
|
|
|
|
|
|
|
|
assert_equal('smtp', map[0][:adapter])
|
2020-02-05 12:50:49 +00:00
|
|
|
assert_equal('mail.zammad.com', map[0][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
assert_equal(25, map[0][:options][:port])
|
|
|
|
assert_equal(true, map[0][:options][:start_tls])
|
|
|
|
assert_equal(user, map[0][:options][:user])
|
|
|
|
assert_equal(password, map[0][:options][:password])
|
|
|
|
|
|
|
|
assert_equal('smtp', map[1][:adapter])
|
2020-02-05 12:50:49 +00:00
|
|
|
assert_equal('mail.zammad.com', map[1][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
assert_equal(25, map[1][:options][:port])
|
|
|
|
assert_equal(true, map[1][:options][:start_tls])
|
|
|
|
assert_equal(email, map[1][:options][:user])
|
|
|
|
assert_equal(password, map[1][:options][:password])
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'z probe_inbound' do
|
|
|
|
|
2015-08-30 11:58:05 +00:00
|
|
|
# invalid adapter
|
|
|
|
result = EmailHelper::Probe.inbound(
|
|
|
|
adapter: 'imap2',
|
|
|
|
options: {
|
2021-08-18 09:07:37 +00:00
|
|
|
host: 'nonexisting_host',
|
2018-12-19 17:31:51 +00:00
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: 'some@example.com',
|
2015-08-30 11:58:05 +00:00
|
|
|
password: 'password',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal('failed', result[:result])
|
|
|
|
|
2015-08-23 20:21:04 +00:00
|
|
|
# network issues
|
|
|
|
result = EmailHelper::Probe.inbound(
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2021-08-18 09:07:37 +00:00
|
|
|
host: 'nonexisting_host',
|
2018-12-19 17:31:51 +00:00
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: 'some@example.com',
|
2015-08-23 20:21:04 +00:00
|
|
|
password: 'password',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal('invalid', result[:result])
|
|
|
|
assert_equal('Hostname not found!', result[:message_human])
|
2021-08-18 09:07:37 +00:00
|
|
|
assert_equal('nonexisting_host', result[:settings][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
|
2019-04-12 13:43:28 +00:00
|
|
|
# try to access imap on host with blocked port to force a "Connection refused!" error
|
2015-08-23 20:21:04 +00:00
|
|
|
result = EmailHelper::Probe.inbound(
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2021-08-18 09:07:37 +00:00
|
|
|
host: '127.0.0.1',
|
|
|
|
port: 8, # no service to be expected
|
2018-12-19 17:31:51 +00:00
|
|
|
ssl: true,
|
|
|
|
user: 'some@example.com',
|
2015-08-23 20:21:04 +00:00
|
|
|
password: 'password',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
assert_equal('invalid', result[:result])
|
|
|
|
assert_equal('Connection refused!', result[:message_human])
|
2021-08-18 09:07:37 +00:00
|
|
|
assert_equal('127.0.0.1', result[:settings][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
|
|
|
|
result = EmailHelper::Probe.inbound(
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: '172.42.42.42',
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: 'some@example.com',
|
2015-08-23 20:21:04 +00:00
|
|
|
password: 'password',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
assert_equal('invalid', result[:result])
|
2021-05-12 11:37:44 +00:00
|
|
|
assert_match(%r{Host not reachable|No route to host}, result[:message_human])
|
2015-08-23 20:21:04 +00:00
|
|
|
assert_equal('172.42.42.42', result[:settings][:options][:host])
|
|
|
|
|
|
|
|
# gmail
|
|
|
|
result = EmailHelper::Probe.inbound(
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: 'imap.gmail.com',
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: 'some@example.com',
|
2015-08-23 20:21:04 +00:00
|
|
|
password: 'password',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
assert_equal('invalid', result[:result])
|
2021-05-12 11:37:44 +00:00
|
|
|
assert_match(%r{Authentication failed, username incorrect|Authentication failed, invalid credentials}, result[:message_human])
|
2015-08-23 20:21:04 +00:00
|
|
|
assert_equal('imap.gmail.com', result[:settings][:options][:host])
|
|
|
|
|
|
|
|
result = EmailHelper::Probe.inbound(
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: 'imap.gmail.com',
|
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: 'frank.tailor05@googlemail.com',
|
2015-08-23 20:21:04 +00:00
|
|
|
password: 'password',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
assert_equal('invalid', result[:result])
|
2015-08-24 07:24:32 +00:00
|
|
|
|
|
|
|
# if we have to many failed logins, we need to handle another error message
|
2017-09-23 06:25:55 +00:00
|
|
|
if result[:message_human].present?
|
2021-05-12 11:37:44 +00:00
|
|
|
assert_match(%r{Authentication failed, username incorrect|Authentication failed, invalid credentials}, result[:message_human])
|
2015-08-24 07:24:32 +00:00
|
|
|
else
|
2021-05-12 11:37:44 +00:00
|
|
|
assert_match(%r{Web login required}, result[:message])
|
2015-08-24 07:24:32 +00:00
|
|
|
end
|
2015-08-23 20:21:04 +00:00
|
|
|
assert_equal('imap.gmail.com', result[:settings][:options][:host])
|
|
|
|
|
|
|
|
# dovecot
|
|
|
|
result = EmailHelper::Probe.inbound(
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2020-02-05 12:50:49 +00:00
|
|
|
host: 'mx2.zammad.com',
|
2018-12-19 17:31:51 +00:00
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
|
|
|
user: 'some@example.com',
|
2015-08-23 20:21:04 +00:00
|
|
|
password: 'password',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
assert_equal('invalid', result[:result])
|
|
|
|
assert_equal('Authentication failed!', result[:message_human])
|
2020-02-05 12:50:49 +00:00
|
|
|
assert_equal('mx2.zammad.com', result[:settings][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
|
|
|
|
# realtest - test I
|
|
|
|
if !ENV['EMAILHELPER_MAILBOX_1']
|
2020-02-05 12:50:49 +00:00
|
|
|
raise "Need EMAILHELPER_MAILBOX_1 as ENV variable like export EMAILHELPER_MAILBOX_1='unittestemailhelper01@zammad.com:somepass'"
|
2015-08-23 20:21:04 +00:00
|
|
|
end
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2015-08-23 20:21:04 +00:00
|
|
|
mailbox_user = ENV['EMAILHELPER_MAILBOX_1'].split(':')[0]
|
|
|
|
mailbox_password = ENV['EMAILHELPER_MAILBOX_1'].split(':')[1]
|
|
|
|
result = EmailHelper::Probe.inbound(
|
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2020-02-05 12:50:49 +00:00
|
|
|
host: 'mx2.zammad.com',
|
2018-12-19 17:31:51 +00:00
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
2020-02-05 12:50:49 +00:00
|
|
|
user: mailbox_user,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: mailbox_password,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
assert_equal('ok', result[:result])
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'z probe_outbound' do
|
|
|
|
|
2015-08-30 11:58:05 +00:00
|
|
|
# invalid adapter
|
|
|
|
result = EmailHelper::Probe.outbound(
|
|
|
|
{
|
|
|
|
adapter: 'smtp2',
|
|
|
|
options: {
|
2021-08-18 09:07:37 +00:00
|
|
|
host: 'nonexisting_host',
|
2018-12-19 17:31:51 +00:00
|
|
|
port: 25,
|
2015-08-30 11:58:05 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: 'some@example.com',
|
|
|
|
password: 'password',
|
2015-08-30 11:58:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
'some@example.com',
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal('failed', result[:result])
|
|
|
|
|
2015-08-23 20:21:04 +00:00
|
|
|
# network issues
|
|
|
|
result = EmailHelper::Probe.outbound(
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2021-08-18 09:07:37 +00:00
|
|
|
host: 'nonexisting_host',
|
2018-12-19 17:31:51 +00:00
|
|
|
port: 25,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: 'some@example.com',
|
|
|
|
password: 'password',
|
2015-08-23 20:21:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'some@example.com',
|
|
|
|
)
|
|
|
|
|
|
|
|
assert_equal('invalid', result[:result])
|
|
|
|
assert_equal('Hostname not found!', result[:message_human])
|
2021-08-18 09:07:37 +00:00
|
|
|
assert_equal('nonexisting_host', result[:settings][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
|
2019-04-12 13:43:28 +00:00
|
|
|
# try to access SMTP on host with blocked port to force a "Connection refused!" error
|
2015-08-23 20:21:04 +00:00
|
|
|
result = EmailHelper::Probe.outbound(
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2021-08-18 09:07:37 +00:00
|
|
|
host: '127.0.0.1',
|
|
|
|
port: 8, # no service to be expected
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: 'some@example.com',
|
|
|
|
password: 'password',
|
2015-08-23 20:21:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'some@example.com',
|
|
|
|
)
|
|
|
|
assert_equal('invalid', result[:result])
|
|
|
|
assert_equal('Connection refused!', result[:message_human])
|
2021-08-18 09:07:37 +00:00
|
|
|
assert_equal('127.0.0.1', result[:settings][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
|
|
|
|
result = EmailHelper::Probe.outbound(
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: '172.42.42.42',
|
|
|
|
port: 25,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: 'some@example.com',
|
|
|
|
password: 'password',
|
2015-08-23 20:21:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'some@example.com',
|
|
|
|
)
|
|
|
|
assert_equal('invalid', result[:result])
|
2021-05-12 11:37:44 +00:00
|
|
|
assert_match(%r{Host not reachable|No route to host}, result[:message_human])
|
2015-08-23 20:21:04 +00:00
|
|
|
assert_equal('172.42.42.42', result[:settings][:options][:host])
|
|
|
|
|
|
|
|
# gmail
|
|
|
|
result = EmailHelper::Probe.outbound(
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: 'smtp.gmail.com',
|
|
|
|
port: 25,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: 'some@example.com',
|
|
|
|
password: 'password',
|
2015-08-23 20:21:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'some@example.com',
|
|
|
|
)
|
|
|
|
assert_equal('invalid', result[:result])
|
|
|
|
assert_equal('Authentication failed!', result[:message_human])
|
|
|
|
assert_equal('smtp.gmail.com', result[:settings][:options][:host])
|
|
|
|
|
|
|
|
result = EmailHelper::Probe.outbound(
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: 'smtp.gmail.com',
|
|
|
|
port: 25,
|
2015-08-23 20:21:04 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: 'frank.tailor05@googlemail.com',
|
|
|
|
password: 'password',
|
2015-08-23 20:21:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'some@example.com',
|
|
|
|
)
|
|
|
|
assert_equal('invalid', result[:result])
|
2015-08-24 07:24:32 +00:00
|
|
|
|
|
|
|
# if we have to many failed logins, we need to handle another error message
|
2017-11-23 08:09:44 +00:00
|
|
|
if result[:message_human].present?
|
2015-08-24 07:24:32 +00:00
|
|
|
assert_equal('Authentication failed!', result[:message_human])
|
|
|
|
else
|
2021-05-12 11:37:44 +00:00
|
|
|
assert_match(%r{Please log in with your web browser and then try again}, result[:message])
|
2015-08-24 07:24:32 +00:00
|
|
|
end
|
2015-08-23 20:21:04 +00:00
|
|
|
assert_equal('smtp.gmail.com', result[:settings][:options][:host])
|
|
|
|
|
|
|
|
# dovecot
|
|
|
|
result = EmailHelper::Probe.outbound(
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2020-02-05 12:50:49 +00:00
|
|
|
host: 'mx2.zammad.com',
|
|
|
|
port: 587,
|
|
|
|
user: 'some@example.com',
|
|
|
|
password: 'password',
|
2015-08-23 20:21:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'some@example.com',
|
|
|
|
)
|
|
|
|
assert_equal('invalid', result[:result])
|
|
|
|
assert_equal('Authentication failed!', result[:message_human])
|
2020-02-05 12:50:49 +00:00
|
|
|
assert_equal('mx2.zammad.com', result[:settings][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
|
|
|
|
# realtest - test I
|
|
|
|
if !ENV['EMAILHELPER_MAILBOX_1']
|
2020-02-05 12:50:49 +00:00
|
|
|
raise "Need EMAILHELPER_MAILBOX_1 as ENV variable like export EMAILHELPER_MAILBOX_1='unittestemailhelper01@zammad.com:somepass'"
|
2015-08-23 20:21:04 +00:00
|
|
|
end
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2015-08-23 20:21:04 +00:00
|
|
|
mailbox_user = ENV['EMAILHELPER_MAILBOX_1'].split(':')[0]
|
|
|
|
mailbox_password = ENV['EMAILHELPER_MAILBOX_1'].split(':')[1]
|
|
|
|
result = EmailHelper::Probe.outbound(
|
|
|
|
{
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2020-02-05 12:50:49 +00:00
|
|
|
host: 'mx2.zammad.com',
|
|
|
|
port: 587,
|
|
|
|
user: mailbox_user,
|
|
|
|
password: mailbox_password,
|
2015-08-23 20:21:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mailbox_user,
|
|
|
|
)
|
|
|
|
assert_equal('ok', result[:result])
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'zz probe' do
|
|
|
|
|
|
|
|
result = EmailHelper::Probe.full(
|
2018-12-19 17:31:51 +00:00
|
|
|
email: 'invalid_format',
|
2015-08-23 20:21:04 +00:00
|
|
|
password: 'somepass',
|
|
|
|
)
|
|
|
|
assert_equal('invalid', result[:result])
|
|
|
|
assert_not(result[:setting])
|
|
|
|
|
2015-09-06 07:50:51 +00:00
|
|
|
# realtest - test I, with imap
|
2015-08-23 20:21:04 +00:00
|
|
|
if !ENV['EMAILHELPER_MAILBOX_1']
|
2020-02-05 12:50:49 +00:00
|
|
|
raise "Need EMAILHELPER_MAILBOX_1 as ENV variable like export EMAILHELPER_MAILBOX_1='unittestemailhelper01@zammad.com:somepass'"
|
2015-08-23 20:21:04 +00:00
|
|
|
end
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2015-08-23 20:21:04 +00:00
|
|
|
mailbox_user = ENV['EMAILHELPER_MAILBOX_1'].split(':')[0]
|
|
|
|
mailbox_password = ENV['EMAILHELPER_MAILBOX_1'].split(':')[1]
|
|
|
|
|
|
|
|
result = EmailHelper::Probe.full(
|
2018-12-19 17:31:51 +00:00
|
|
|
email: mailbox_user,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: mailbox_password,
|
|
|
|
)
|
|
|
|
assert_equal('ok', result[:result])
|
2020-02-05 12:50:49 +00:00
|
|
|
assert_equal('mx2.zammad.com', result[:setting][:inbound][:options][:host])
|
|
|
|
assert_equal('mx2.zammad.com', result[:setting][:outbound][:options][:host])
|
2015-08-23 20:21:04 +00:00
|
|
|
|
2015-09-06 07:50:51 +00:00
|
|
|
# realtest - test II, gmail with only pop3
|
|
|
|
if !ENV['EMAILHELPER_MAILBOX_2']
|
2016-03-01 14:26:46 +00:00
|
|
|
raise "Need EMAILHELPER_MAILBOX_2 as ENV variable like export EMAILHELPER_MAILBOX_2='hansb36621@gmail.com:somepass'"
|
2015-09-06 07:50:51 +00:00
|
|
|
end
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2015-09-06 07:50:51 +00:00
|
|
|
mailbox_user = ENV['EMAILHELPER_MAILBOX_2'].split(':')[0]
|
|
|
|
mailbox_password = ENV['EMAILHELPER_MAILBOX_2'].split(':')[1]
|
|
|
|
|
|
|
|
result = EmailHelper::Probe.full(
|
2018-12-19 17:31:51 +00:00
|
|
|
email: mailbox_user,
|
2015-09-06 07:50:51 +00:00
|
|
|
password: mailbox_password,
|
|
|
|
)
|
2017-09-23 06:25:55 +00:00
|
|
|
assert_nil(result[:reason])
|
2015-09-06 07:50:51 +00:00
|
|
|
assert_equal('ok', result[:result])
|
|
|
|
assert_equal('pop.gmail.com', result[:setting][:inbound][:options][:host])
|
|
|
|
assert_equal('smtp.gmail.com', result[:setting][:outbound][:options][:host])
|
|
|
|
|
2015-08-23 20:21:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'zz verify' do
|
|
|
|
|
2015-09-06 07:50:51 +00:00
|
|
|
# realtest - test I, with imap
|
2015-08-23 20:21:04 +00:00
|
|
|
if !ENV['EMAILHELPER_MAILBOX_1']
|
2020-02-05 12:50:49 +00:00
|
|
|
raise "Need EMAILHELPER_MAILBOX_1 as ENV variable like export EMAILHELPER_MAILBOX_1='unittestemailhelper01@zammad.com:somepass'"
|
2015-08-23 20:21:04 +00:00
|
|
|
end
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2015-08-23 20:21:04 +00:00
|
|
|
mailbox_user = ENV['EMAILHELPER_MAILBOX_1'].split(':')[0]
|
|
|
|
mailbox_password = ENV['EMAILHELPER_MAILBOX_1'].split(':')[1]
|
|
|
|
result = EmailHelper::Verify.email(
|
2018-12-19 17:31:51 +00:00
|
|
|
inbound: {
|
2015-08-23 20:21:04 +00:00
|
|
|
adapter: 'imap',
|
|
|
|
options: {
|
2020-02-05 12:50:49 +00:00
|
|
|
host: 'mx2.zammad.com',
|
2018-12-19 17:31:51 +00:00
|
|
|
port: 993,
|
|
|
|
ssl: true,
|
2020-02-05 12:50:49 +00:00
|
|
|
user: mailbox_user,
|
2015-08-23 20:21:04 +00:00
|
|
|
password: mailbox_password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
outbound: {
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2020-02-05 12:50:49 +00:00
|
|
|
host: 'mx2.zammad.com',
|
|
|
|
port: 587,
|
|
|
|
user: mailbox_user,
|
|
|
|
password: mailbox_password,
|
2015-08-23 20:21:04 +00:00
|
|
|
},
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
sender: mailbox_user,
|
2015-08-23 20:21:04 +00:00
|
|
|
)
|
|
|
|
assert_equal('ok', result[:result])
|
2015-09-06 07:50:51 +00:00
|
|
|
|
|
|
|
# realtest - test II, gmail with pop3
|
|
|
|
if !ENV['EMAILHELPER_MAILBOX_2']
|
2016-03-01 14:26:46 +00:00
|
|
|
raise "Need EMAILHELPER_MAILBOX_2 as ENV variable like export EMAILHELPER_MAILBOX_2='hansb36621@gmail.com:somepass'"
|
2015-09-06 07:50:51 +00:00
|
|
|
end
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2015-09-06 07:50:51 +00:00
|
|
|
mailbox_user = ENV['EMAILHELPER_MAILBOX_2'].split(':')[0]
|
|
|
|
mailbox_password = ENV['EMAILHELPER_MAILBOX_2'].split(':')[1]
|
2019-06-28 11:38:49 +00:00
|
|
|
|
|
|
|
EmailHelper.parse_email(mailbox_user)
|
|
|
|
|
2015-09-06 07:50:51 +00:00
|
|
|
result = EmailHelper::Verify.email(
|
2018-12-19 17:31:51 +00:00
|
|
|
inbound: {
|
2015-09-06 07:50:51 +00:00
|
|
|
adapter: 'pop3',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: 'pop.gmail.com',
|
|
|
|
port: 995,
|
|
|
|
ssl: true,
|
|
|
|
user: mailbox_user,
|
2015-09-06 07:50:51 +00:00
|
|
|
password: mailbox_password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
outbound: {
|
|
|
|
adapter: 'smtp',
|
|
|
|
options: {
|
2018-12-19 17:31:51 +00:00
|
|
|
host: 'smtp.gmail.com',
|
|
|
|
port: 25,
|
2015-09-06 07:50:51 +00:00
|
|
|
start_tls: true,
|
2018-12-19 17:31:51 +00:00
|
|
|
user: mailbox_user,
|
|
|
|
password: mailbox_password,
|
2015-09-06 07:50:51 +00:00
|
|
|
},
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
sender: mailbox_user,
|
2015-09-06 07:50:51 +00:00
|
|
|
)
|
|
|
|
assert_equal('ok', result[:result])
|
|
|
|
|
2015-08-23 20:21:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|