Skip to content

Commit 65d12df

Browse files
committed
Update SMTP proxy tests to use internal SMTP server.
To eliminate need for reliance on external connections during this test. Setting this up requires auth for the rest of our internal mail tests.
1 parent 7c94884 commit 65d12df

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

config/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ web:
7777
smtp_settings:
7878
address: 127.0.0.1
7979
port: 13102
80+
starttls: true
81+
ssl_host: ssltest.example.com
82+
ssl_verify: false
83+
user_name: api_umbrella
84+
password: dev_password
8085
contact_form_email: [email protected]
8186
analytics_v0_summary_start_time: "2013-07-01T00:00:00.000-06:00"
8287
analytics_v0_summary_end_time: "2013-08-31T23:59:59.999-06:00"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
LD_LIBRARY_PATH=<%- config["_embedded_root_dir"] %>/openresty/luajit/lib:<%- config["_embedded_root_dir"] %>/lib
2+
MP_SMTP_AUTH=api_umbrella:dev_password

templates/etc/perp/test-env-mailpit/rc.main.etlua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ if [ "${1}" = "start" ]; then
1717
fi
1818

1919
exec runtool ${run_args[@]+"${run_args[@]}"} mailpit \
20+
--smtp-tls-cert "<%- config['_src_root_dir'] %>/test/config/ssl_test.crt" \
21+
--smtp-tls-key "<%- config['_src_root_dir'] %>/test/config/ssl_test.key" \
2022
--smtp "<%- config['mailpit']['bind_addr'] %>:<%- config['mailpit']['smtp_port'] %>" \
2123
--listen "<%- config['mailpit']['bind_addr'] %>:<%- config['mailpit']['http_port'] %>"
2224
fi

test/proxy/envoy/test_smtp_proxy.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class Test::Proxy::Envoy::TestSmtpProxy < Minitest::Test
88
def setup
99
super
1010
setup_server
11+
@ssl_context_params = {
12+
ca_file: File.join(API_UMBRELLA_SRC_ROOT, "test/config/ssl_test.crt"),
13+
}
1114
end
1215

1316
def test_disabled_by_default
@@ -17,7 +20,7 @@ def test_disabled_by_default
1720
end
1821

1922
def test_direct_smtp_sanity_check
20-
smtp = Net::SMTP.new("in-v3.mailjet.com", 80, starttls: :always)
23+
smtp = Net::SMTP.new("127.0.0.1", $config["mailpit"]["smtp_port"], starttls: :always, ssl_context_params: @ssl_context_params, tls_hostname: "ssltest.example.com")
2124
smtp.open_timeout = 5
2225
smtp.start
2326
assert_equal(true, smtp.esmtp?)
@@ -31,8 +34,8 @@ def test_only_connects_to_single_target
3134
"smtp_proxy" => {
3235
"enabled" => true,
3336
"endpoint" => {
34-
"host" => "in-v3.mailjet.com",
35-
"port" => 80,
37+
"host" => "127.0.0.1",
38+
"port" => $config["mailpit"]["smtp_port"],
3639
},
3740
},
3841
},
@@ -41,15 +44,15 @@ def test_only_connects_to_single_target
4144
assert_equal(true, open)
4245

4346
# Verify that without an explict TLS host, we get a certificate error.
44-
smtp = Net::SMTP.new("127.0.0.1", 13003, starttls: :always)
47+
smtp = Net::SMTP.new("127.0.0.1", 13003, starttls: :always, ssl_context_params: @ssl_context_params)
4548
smtp.open_timeout = 5
4649
error = assert_raises OpenSSL::SSL::SSLError do
4750
smtp.start
4851
end
4952
assert_match("certificate verify failed (hostname mismatch)", error.message)
5053

5154
# Verify normal connection to the expected underlying host.
52-
smtp = Net::SMTP.new("127.0.0.1", 13003, starttls: :always, tls_hostname: "in-v3.mailjet.com")
55+
smtp = Net::SMTP.new("127.0.0.1", 13003, starttls: :always, ssl_context_params: @ssl_context_params, tls_hostname: "ssltest.example.com")
5356
smtp.open_timeout = 5
5457
smtp.start
5558
assert_equal(true, smtp.esmtp?)
@@ -58,7 +61,7 @@ def test_only_connects_to_single_target
5861

5962
# Verify that trying a different TLS host also results in a certificate
6063
# error.
61-
smtp = Net::SMTP.new("127.0.0.1", 13003, starttls: :always, tls_hostname: "email.us-east-1.amazonaws.com")
64+
smtp = Net::SMTP.new("127.0.0.1", 13003, starttls: :always, ssl_context_params: @ssl_context_params, tls_hostname: "email.us-east-1.amazonaws.com")
6265
smtp.open_timeout = 5
6366
error = assert_raises OpenSSL::SSL::SSLError do
6467
smtp.start
@@ -73,8 +76,8 @@ def test_web_app_uses_proxy
7376
"smtp_proxy" => {
7477
"enabled" => true,
7578
"endpoint" => {
76-
"host" => "in-v3.mailjet.com",
77-
"port" => 80,
79+
"host" => "127.0.0.1",
80+
"port" => $config["mailpit"]["smtp_port"],
7881
},
7982
},
8083
},

0 commit comments

Comments
 (0)