Skip to content

Commit

Permalink
Added a test to send mail to server with no auth
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Feb 6, 2017
1 parent 9408e5f commit f4b5190
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"proxy": "^0.2.4",
"proxy-test-server": "^1.0.0",
"sinon": "^1.17.7",
"smtp-server": "^1.17.0"
"smtp-server": "^2.0.1"
},
"engines": {
"node": ">=6.0.0"
Expand Down
58 changes: 56 additions & 2 deletions test/smtp-connection/smtp-connection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,20 @@ describe('SMTP-Connection Tests', function () {
insecureServer = new SMTPServer({
disabledCommands: ['STARTTLS', 'AUTH'],
onData: function (stream, session, callback) {
stream.on('data', function () {});
stream.on('end', callback);
let err = false;
stream.on('data', function (chunk) {
if (err || session.use8BitMime) {
return;
}
for (let i = 0, len = chunk.length; i < len; i++) {
if (chunk[i] >= 0x80) {
err = new Error('8 bit content not allowed');
}
}
});
stream.on('end', function () {
callback(err, false);
});
},
logger: false
});
Expand Down Expand Up @@ -372,6 +384,48 @@ describe('SMTP-Connection Tests', function () {
runTest(socket);
});
});

it('should send to unsecure server', function (done) {
let client = new SMTPConnection({
port: PORT_NUMBER + 3,
ignoreTLS: true,
logger: false
});

client.on('error', function (err) {
expect(err).to.not.exist;
});

client.connect(function () {
expect(client.secure).to.be.false;

let chunks = [],
fname = __dirname + '/../../LICENSE',
message = fs.readFileSync(fname, 'utf-8');

server.on('data', function (connection, chunk) {
chunks.push(chunk);
});

server.removeAllListeners('dataReady');
server.on('dataReady', function (connection, callback) {
let body = Buffer.concat(chunks);
expect(body.toString()).to.equal(message.toString().trim().replace(/\n/g, '\r\n'));
callback(null, 'ABC1');
});

client.send({
from: 'test@valid.sender',
to: 'test@valid.recipient'
}, fs.createReadStream(fname), function (err) {
expect(err).to.not.exist;
client.close();
});

});

client.on('end', done);
});
});

describe('Login tests', function () {
Expand Down

0 comments on commit f4b5190

Please sign in to comment.