2017-10-02 16:24:10 +02:00
|
|
|
require_relative '../spec_helper'
|
|
|
|
|
|
|
|
describe FoodsoftMailReceiver do
|
|
|
|
before :all do
|
2022-02-16 17:18:27 +01:00
|
|
|
@server = FoodsoftMailReceiver.new(ports: '2525', hosts: '127.0.0.1', max_processings: 4, logger_severity: 5)
|
2017-10-02 16:24:10 +02:00
|
|
|
@server.start
|
|
|
|
end
|
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
# TODO: Reanable this test.
|
|
|
|
# It raised "Mysql2::Error: Lock wait timeout exceeded" at time of writing.
|
|
|
|
# it 'accepts bounce mails via SMTP' do
|
|
|
|
# MailDeliveryStatus.delete_all
|
|
|
|
#
|
|
|
|
# Net::SMTP.start(@server.host, @server.port) do |smtp|
|
|
|
|
# address = "#{FoodsoftConfig[:default_scope]}.bounce+user=example.com"
|
|
|
|
# smtp.send_message 'report', 'from@example.com', address
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# mds = MailDeliveryStatus.last
|
|
|
|
# expect(mds.email).to eq 'user@example.com'
|
|
|
|
# expect(mds.attachment_mime).to eq 'message/rfc822'
|
|
|
|
# expect(mds.attachment_data).to include 'report'
|
|
|
|
# end
|
|
|
|
|
|
|
|
after :all do
|
|
|
|
@server.shutdown
|
|
|
|
end
|
|
|
|
|
2017-10-02 16:24:10 +02:00
|
|
|
it 'does not accept empty addresses' do
|
2023-05-12 13:01:12 +02:00
|
|
|
FoodsoftMailReceiver.received('', 'body')
|
|
|
|
rescue StandardError => e
|
|
|
|
expect(e.to_s).to include 'missing'
|
2017-10-02 16:24:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not accept invalid addresses' do
|
2023-05-12 13:01:12 +02:00
|
|
|
FoodsoftMailReceiver.received('invalid', 'body')
|
|
|
|
rescue StandardError => e
|
|
|
|
expect(e.to_s).to include 'has an invalid format'
|
2017-10-02 16:24:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not accept invalid scope in address' do
|
2023-05-12 13:01:12 +02:00
|
|
|
FoodsoftMailReceiver.received('invalid.invalid', 'body')
|
|
|
|
rescue StandardError => e
|
|
|
|
expect(e.to_s).to include 'could not be found'
|
2017-10-02 16:24:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not accept address without handler' do
|
2023-05-12 13:01:12 +02:00
|
|
|
address = "#{FoodsoftConfig[:default_scope]}.invalid"
|
|
|
|
FoodsoftMailReceiver.received(address, 'body')
|
|
|
|
rescue StandardError => e
|
|
|
|
expect(e.to_s).to include 'invalid format for recipient'
|
2017-10-02 16:24:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not accept invalid addresses via SMTP' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect do
|
2019-10-28 09:40:17 +01:00
|
|
|
Net::SMTP.start(@server.hosts.first, @server.ports.first) do |smtp|
|
2017-10-02 16:24:10 +02:00
|
|
|
smtp.send_message 'body', 'from@example.com', 'invalid'
|
|
|
|
end
|
2023-05-12 13:01:12 +02:00
|
|
|
end.to raise_error(Net::SMTPFatalError)
|
2017-10-02 16:24:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not accept invalid addresses via SMTP' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect do
|
2019-10-28 09:40:17 +01:00
|
|
|
Net::SMTP.start(@server.hosts.first, @server.ports.first) do |smtp|
|
2017-10-02 16:24:10 +02:00
|
|
|
smtp.send_message 'body', 'from@example.com', 'invalid'
|
|
|
|
end
|
2023-05-12 13:01:12 +02:00
|
|
|
end.to raise_error(Net::SMTPFatalError)
|
2017-10-02 16:24:10 +02:00
|
|
|
end
|
|
|
|
end
|