summaryrefslogtreecommitdiff
path: root/tests/server-tests/helpers/smtp_helper.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2016-08-29 16:35:14 -0700
committerelijah <elijah@riseup.net>2016-09-01 10:13:31 -0700
commit07c0e60e6bdc5b8bfe1f42f76dae9f0a79e7abb0 (patch)
tree9f79f8fbb207896dcfe38f24831d9b2b857199a4 /tests/server-tests/helpers/smtp_helper.rb
parentd5bac5850e4a895da5f9cfacb641fab15de1cf7b (diff)
moved infrastructure tests run by `leap run` to tests/server-tests
Diffstat (limited to 'tests/server-tests/helpers/smtp_helper.rb')
-rw-r--r--tests/server-tests/helpers/smtp_helper.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/server-tests/helpers/smtp_helper.rb b/tests/server-tests/helpers/smtp_helper.rb
new file mode 100644
index 00000000..ea7fb9fa
--- /dev/null
+++ b/tests/server-tests/helpers/smtp_helper.rb
@@ -0,0 +1,45 @@
+require 'net/smtp'
+
+class LeapTest
+
+ TEST_EMAIL_USER = "test_user_email"
+ TEST_BAD_USER = "test_user_bad"
+
+ MSG_BODY = %(Since it seems that any heart which beats for freedom has the right only to a
+lump of lead, I too claim my share. If you let me live, I shall never stop
+crying for revenge and I shall avenge my brothers. I have finished. If you are
+not cowards, kill me!
+
+--Louise Michel)
+
+ def send_email(recipient, options={})
+ sender = options[:sender] || recipient
+ helo_domain = property('domain.full_suffix')
+ headers = {
+ "Date" => Time.now.utc,
+ "From" => sender,
+ "To" => recipient,
+ "Subject" => "Test Message",
+ "X-LEAP-TEST" => "true"
+ }.merge(options[:headers]||{})
+ message = []
+ headers.each do |key, value|
+ message << "#{key}: #{value}"
+ end
+ message << ""
+ message << MSG_BODY
+ Net::SMTP.start('localhost', 25, helo_domain) do |smtp|
+ smtp.send_message message.join("\n"), recipient, sender
+ end
+ end
+
+ def assert_send_email(recipient, options={})
+ begin
+ send_email(recipient, options)
+ rescue IOError, Net::OpenTimeout,
+ Net::ReadTimeout, Net::SMTPError => e
+ fail "Could not send mail to #{recipient} (#{e})"
+ end
+ end
+
+end \ No newline at end of file