2018-05-14 23:02:16 +00:00
|
|
|
describe('authorize plain', function() {
|
2018-05-27 04:25:08 +00:00
|
|
|
const { simpleParser: parser } = require('mailparser');
|
|
|
|
const { SMTPServer: smtpServer } = require('smtp-server');
|
|
|
|
const { expect } = require('chai');
|
|
|
|
const email = require('../email');
|
2018-05-14 23:02:16 +00:00
|
|
|
const port = 2526;
|
|
|
|
|
2018-05-27 04:25:08 +00:00
|
|
|
let server = null;
|
|
|
|
let smtp = null;
|
2018-05-14 23:02:16 +00:00
|
|
|
|
2018-05-27 04:25:08 +00:00
|
|
|
const send = function(message, verify, done) {
|
|
|
|
smtp.onData = function(stream, session, callback) {
|
|
|
|
parser(stream)
|
|
|
|
.then(verify)
|
|
|
|
.then(done)
|
|
|
|
.catch(done);
|
|
|
|
stream.on('end', callback);
|
|
|
|
};
|
2018-05-14 23:02:16 +00:00
|
|
|
|
2018-05-27 04:25:08 +00:00
|
|
|
server.send(message, function(err) {
|
2018-06-04 16:40:23 +00:00
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
2018-05-27 04:25:08 +00:00
|
|
|
});
|
|
|
|
};
|
2018-05-14 23:02:16 +00:00
|
|
|
|
2018-05-27 04:25:08 +00:00
|
|
|
before(function(done) {
|
|
|
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; // prevent CERT_HAS_EXPIRED errors
|
2013-01-22 17:04:50 +00:00
|
|
|
|
2018-05-27 04:25:08 +00:00
|
|
|
smtp = new smtpServer({ secure: true, authMethods: ['LOGIN'] });
|
|
|
|
smtp.listen(port, function() {
|
|
|
|
smtp.onAuth = function(auth, session, callback) {
|
|
|
|
if (auth.username == 'pooh' && auth.password == 'honey') {
|
|
|
|
callback(null, { user: 'pooh' });
|
|
|
|
} else {
|
|
|
|
return callback(new Error('invalid user / pass'));
|
|
|
|
}
|
|
|
|
};
|
2013-01-22 17:04:50 +00:00
|
|
|
|
2018-05-27 04:25:08 +00:00
|
|
|
server = email.server.connect({
|
|
|
|
port: port,
|
|
|
|
user: 'pooh',
|
|
|
|
password: 'honey',
|
|
|
|
ssl: true,
|
2018-05-14 23:02:16 +00:00
|
|
|
});
|
|
|
|
|
2018-05-27 04:25:08 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-05-14 23:02:16 +00:00
|
|
|
|
2018-05-27 04:25:08 +00:00
|
|
|
after(function(done) {
|
|
|
|
smtp.close(done);
|
|
|
|
});
|
2018-05-14 23:02:16 +00:00
|
|
|
|
2018-05-27 04:25:08 +00:00
|
|
|
it('login', function(done) {
|
2018-05-14 23:02:16 +00:00
|
|
|
const message = {
|
2018-05-27 04:25:08 +00:00
|
|
|
subject: 'this is a test TEXT message from emailjs',
|
|
|
|
from: 'piglet@gmail.com',
|
|
|
|
to: 'pooh@gmail.com',
|
|
|
|
text: "It is hard to be brave when you're only a Very Small Animal.",
|
2018-05-14 23:02:16 +00:00
|
|
|
};
|
|
|
|
|
2018-05-27 04:25:08 +00:00
|
|
|
const created = email.message.create(message);
|
2018-05-14 23:02:16 +00:00
|
|
|
|
|
|
|
const callback = function(mail) {
|
|
|
|
expect(mail.text).to.equal(message.text + '\n\n\n');
|
|
|
|
expect(mail.subject).to.equal(message.subject);
|
|
|
|
expect(mail.from.text).to.equal(message.from);
|
|
|
|
expect(mail.to.text).to.equal(message.to);
|
|
|
|
};
|
2014-07-06 08:15:40 +00:00
|
|
|
|
2018-05-27 04:25:08 +00:00
|
|
|
send(created, callback, done);
|
|
|
|
});
|
2013-01-22 17:04:50 +00:00
|
|
|
});
|