smtp-server
Advanced tools
Comparing version 1.0.2 to 1.1.0
'use strict'; | ||
// Replace '../lib/smtp-server' with 'smtp-server' when running this script outside this directory | ||
var SMTPServer = require('../lib/smtp-server').SMTPServer; | ||
@@ -4,0 +5,0 @@ |
@@ -381,3 +381,3 @@ 'use strict'; | ||
if (!this.secure && this._isSupported('STARTTLS')) { | ||
if (!this.secure && this._isSupported('STARTTLS') && !this._server.options.hideSTARTTLS) { | ||
features.push('STARTTLS'); | ||
@@ -523,3 +523,3 @@ } | ||
if (!this.secure && this._isSupported('STARTTLS')) { | ||
if (!this.secure && this._isSupported('STARTTLS') && !this._server.options.hideSTARTTLS) { | ||
this.send(538, 'Error: Must issue a STARTTLS command first'); | ||
@@ -526,0 +526,0 @@ return callback(); |
@@ -44,3 +44,13 @@ 'use strict'; | ||
// setup logger | ||
this.logger = this.options.logger || this._createDefaultLogger(); | ||
if ('logger' in this.options) { | ||
// use provided logger or use vanity logger | ||
this.logger = this.options.logger || { | ||
info: function() {}, | ||
debug: function() {}, | ||
error: function() {} | ||
}; | ||
} else { | ||
// create default console logger | ||
this.logger = this._createDefaultLogger(); | ||
} | ||
@@ -47,0 +57,0 @@ ['onAuth', 'onMailFrom', 'onRcptTo', 'onData'].forEach(function(handler) { |
{ | ||
"name": "smtp-server", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Create custom SMTP servers on the fly", | ||
@@ -13,9 +13,9 @@ "main": "lib/smtp-server.js", | ||
"devDependencies": { | ||
"chai": "^2.0.0", | ||
"chai": "^2.1.1", | ||
"grunt": "^0.4.5", | ||
"grunt-contrib-jshint": "^0.11.0", | ||
"grunt-mocha-test": "^0.12.7", | ||
"mocha": "^2.1.0", | ||
"sinon": "^1.12.2", | ||
"smtp-connection": "^1.1.0" | ||
"mocha": "^2.2.1", | ||
"sinon": "^1.13.0", | ||
"smtp-connection": "^1.2.0" | ||
}, | ||
@@ -22,0 +22,0 @@ "engines": { |
@@ -24,3 +24,3 @@ # smtp-server | ||
var SMTPServer = require('smtp-server'); | ||
var SMTPServer = require('smtp-server').SMTPServer; | ||
@@ -41,3 +41,4 @@ ### Create SMTPServer instance | ||
* **options.disabledCommands** optional array of disabled commands (see all supported commands [here](#commands)). For example if you want to disable authentication, use `['AUTH']` as this value. If you want to allow authentication in clear text, set it to `['STARTTLS']`. | ||
* **options.logger** optional [bunyan](https://github.com/trentm/node-bunyan) compatible logger instance. By default logs to console | ||
* **hideSTARTTLS** optional boolean, if set to true then allow using STARTTLS but do not advertise or require it. It only makes sense when creating integration test servers for testing the scenario where you want to try STARTTLS even when it is not advertised | ||
* **options.logger** optional [bunyan](https://github.com/trentm/node-bunyan) compatible logger instance. By default logs to console. If set to `false` then nothing is logged | ||
* **options.maxClients** sets the maximum number of concurrently connected clients, defaults to `Infinity` | ||
@@ -140,3 +141,3 @@ * **options.socketTimeout** how many milliseconds of inactivity to allow before disconnecting the client (defaults to 1 minute) | ||
onAuth: function(auth, session, callback){ | ||
if(auth.method !== 'XOAUTH'){ | ||
if(auth.method !== 'XOAUTH2'){ | ||
// should never occur in this case as only XOAUTH2 is allowed | ||
@@ -178,3 +179,3 @@ return callback(new Error('Expecting XOAUTH2')); | ||
var server = new SMTPServer({ | ||
onMailFrom = function(address, session, callback){ | ||
onMailFrom: function(address, session, callback){ | ||
if(address.address !== 'allowed@example.com'){ | ||
@@ -207,3 +208,3 @@ return callback(new Error('Only allowed@example.com is allowed to send mail')); | ||
var server = new SMTPServer({ | ||
onRcptTo = function(address, session, callback){ | ||
onRcptTo: function(address, session, callback){ | ||
if(address.address !== 'allowed@example.com'){ | ||
@@ -235,3 +236,3 @@ return callback(new Error('Only allowed@example.com is allowed to receive mail')); | ||
var server = new SMTPServer({ | ||
onData = function(stream, session, callback){ | ||
onData: function(stream, session, callback){ | ||
stream.pipe(process.stdout); // print message to console | ||
@@ -324,2 +325,2 @@ stream.on('end', callback); | ||
**MIT** | ||
**MIT** |
@@ -19,7 +19,3 @@ 'use strict'; | ||
maxClients: 5, | ||
logger: { | ||
info: function() {}, | ||
debug: function() {}, | ||
error: function() {} | ||
}, | ||
logger: false, | ||
socketTimeout: 2 * 1000 | ||
@@ -213,2 +209,114 @@ }); | ||
describe('Plaintext server with hidden STARTTLS', function() { | ||
var PORT = 1336; | ||
var server = new SMTPServer({ | ||
maxClients: 5, | ||
hideSTARTTLS: true, | ||
logger: false, | ||
socketTimeout: 2 * 1000 | ||
}); | ||
beforeEach(function(done) { | ||
server.listen(PORT, '127.0.0.1', done); | ||
}); | ||
afterEach(function(done) { | ||
server.close(done); | ||
}); | ||
it('should connect without TLS', function(done) { | ||
var connection = new SMTPConnection({ | ||
port: PORT, | ||
host: '127.0.0.1' | ||
}); | ||
connection.on('end', done); | ||
connection.connect(function() { | ||
expect(connection.secure).to.be.false; | ||
connection.quit(); | ||
}); | ||
}); | ||
it('should connect with TLS', function(done) { | ||
var connection = new SMTPConnection({ | ||
port: PORT, | ||
host: '127.0.0.1', | ||
requireTLS: true, | ||
tls: { | ||
rejectUnauthorized: false | ||
} | ||
}); | ||
connection.on('end', done); | ||
connection.connect(function() { | ||
expect(connection.secure).to.be.true; | ||
connection.quit(); | ||
}); | ||
}); | ||
}); | ||
describe('Plaintext server with no STARTTLS', function() { | ||
var PORT = 1336; | ||
var server = new SMTPServer({ | ||
maxClients: 5, | ||
disabledCommands: ['STARTTLS'], | ||
loggers: false, | ||
socketTimeout: 2 * 1000 | ||
}); | ||
beforeEach(function(done) { | ||
server.listen(PORT, '127.0.0.1', done); | ||
}); | ||
afterEach(function(done) { | ||
server.close(done); | ||
}); | ||
it('should connect without TLS', function(done) { | ||
var connection = new SMTPConnection({ | ||
port: PORT, | ||
host: '127.0.0.1' | ||
}); | ||
connection.on('end', done); | ||
connection.connect(function() { | ||
expect(connection.secure).to.be.false; | ||
connection.quit(); | ||
}); | ||
}); | ||
it('should not connect with TLS', function(done) { | ||
var connection = new SMTPConnection({ | ||
port: PORT, | ||
host: '127.0.0.1', | ||
requireTLS: true, | ||
tls: { | ||
rejectUnauthorized: false | ||
} | ||
}); | ||
var error; | ||
connection.on('error', function(err) { | ||
error = err; | ||
}); | ||
connection.on('end', function() { | ||
expect(error).to.exist; | ||
done(); | ||
}); | ||
connection.connect(function() { | ||
// should not be called | ||
expect(false).to.be.true; | ||
connection.quit(); | ||
}); | ||
}); | ||
}); | ||
describe('Secure server', function() { | ||
@@ -219,7 +327,3 @@ var PORT = 1336; | ||
secure: true, | ||
logger: { | ||
info: function() {}, | ||
debug: function() {}, | ||
error: function() {} | ||
} | ||
logger: false | ||
}); | ||
@@ -260,7 +364,3 @@ | ||
maxClients: 5, | ||
logger: { | ||
info: function() {}, | ||
debug: function() {}, | ||
error: function() {} | ||
}, | ||
logger: false, | ||
authMethods: ['PLAIN', 'LOGIN', 'XOAUTH2'] | ||
@@ -458,7 +558,3 @@ }); | ||
maxClients: 5, | ||
logger: { | ||
info: function() {}, | ||
debug: function() {}, | ||
error: function() {} | ||
}, | ||
logger: false, | ||
authMethods: ['PLAIN', 'LOGIN', 'XOAUTH2'] | ||
@@ -642,7 +738,3 @@ }); | ||
var server = new SMTPServer({ | ||
logger: { | ||
info: function() {}, | ||
debug: function() {}, | ||
error: function() {} | ||
}, | ||
logger: false, | ||
disabledCommands: ['AUTH', 'STARTTLS'] | ||
@@ -688,7 +780,3 @@ }); | ||
var server = new SMTPServer({ | ||
logger: { | ||
info: function() {}, | ||
debug: function() {}, | ||
error: function() {} | ||
}, | ||
logger: false, | ||
disabledCommands: ['AUTH', 'STARTTLS'] | ||
@@ -695,0 +783,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89118
16
1950
320