Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated unit tests to use nodeunit, not tap. Also fixed small smtp_pr…

…oxy bug.
  • Loading branch information...
commit 22748606ae45013a01903dc636f06b5ee7e042cd 1 parent bac7a8e
Eric Day authored
View
4 plugins/queue/smtp_proxy.js
@@ -21,6 +21,10 @@ exports.hook_mail = function (next, connection, params) {
delete connection.notes.smtp_client;
});
+ smtp_client.on('error', function () {
+ delete connection.notes.smtp_client;
+ });
+
smtp_client.on('bad_code', function (code, msg) {
if (smtp_client.command !== 'rcpt') {
// errors are OK for rcpt, but nothing else
View
2  run_tests
@@ -18,4 +18,4 @@ catch(e) {
}
process.chdir(__dirname);
-reporter.run(['tests/plugins']);
+reporter.run(['tests', 'tests/plugins']);
View
5 smtp_client.js
@@ -203,6 +203,7 @@ SMTPClient.prototype.release = function () {
this.send_command('RSET');
};
+// Separate pools are kept for each set of server attributes.
exports.get_pool = function (server, port, host, timeout, enable_tls, max) {
var port = port || 25;
var host = host || 'localhost';
@@ -250,11 +251,15 @@ exports.get_pool = function (server, port, host, timeout, enable_tls, max) {
return server.notes.pool[name];
};
+// Get a smtp_client for the given attributes.
exports.get_client = function (server, port, host, timeout, enable_tls, max) {
var pool = exports.get_pool(server, port, host, timeout, enable_tls, max);
pool.acquire(callback);
};
+// Get a smtp_client for the given attributes and set it up the common
+// config and listeners for plugins. Currently this is what smtp_proxy and
+// smtp_forward have in common.
exports.get_client_plugin = function (plugin, connection, config, callback) {
var pool = exports.get_pool(connection.server, config.main.port,
config.main.host, config.main.timeout, config.main.enable_tls,
View
74 tests/address.js
@@ -1,44 +1,50 @@
-var test = require("tap").test;
-require('../configfile').watch_files = false;
var Address = require("../address").Address;
-var addresses = [
-'<>', {user: null, host: null},
-'<postmaster>', {user: 'postmaster', host: null},
-'<foo@example.com>', {user: 'foo', host: 'example.com'},
-'<"musa_ibrah@caramail.comandrea.luger"@wifo.ac.at>', {user: 'musa_ibrah@caramail.comandrea.luger', host: 'wifo.ac.at'},
-'<foo bar@example.com>', {user: 'foo bar', host: 'example.com'},
-'foo@example.com', {user: 'foo', host: 'example.com'},
-'<foo@foo.x.example.com>', {user: 'foo', host: 'foo.x.example.com'},
-'foo@foo.x.example.com', {user: 'foo', host: 'foo.x.example.com'},
-];
+function _check(test, address, user, host) {
+ test.expect(2);
+ var address = new Address(address);
+ test.equal(address.user, user);
+ test.equal(address.host, host);
+ test.done();
+}
-test("Email Address Parsing", function(t) {
- // t.plan(addresses.length);
- for (var i=1,l=addresses.length; i<l; i = i+2) {
- var addr = new Address(addresses[i-1]);
- var result = addresses[i];
- t.equal(addr.user, result.user, "Check " + addresses[i-1] + " user");
- t.equal(addr.host, result.host, "Check " + addresses[i-1] + " host");
+exports.good = {
+ '<>': function (test) {
+ _check(test, '<>', null, null);
+ },
+ '<postmaster>': function (test) {
+ _check(test, '<postmaster>', 'postmaster', null);
+ },
+ '<foo@example.com>': function (test) {
+ _check(test, '<foo@example.com>', 'foo', 'example.com');
+ },
+ '<"musa_ibrah@caramail.comandrea.luger"@wifo.ac.at>': function (test) {
+ _check(test, '<"musa_ibrah@caramail.comandrea.luger"@wifo.ac.at>',
+ 'musa_ibrah@caramail.comandrea.luger', 'wifo.ac.at');
+ },
+ '<foo bar@example.com>': function (test) {
+ _check(test, '<foo bar@example.com>', 'foo bar', 'example.com');
+ },
+ 'foo@example.com': function (test) {
+ _check(test, 'foo@example.com', 'foo', 'example.com');
+ },
+ '<foo@foo.x.example.com>': function (test) {
+ _check(test, '<foo@foo.x.example.com>', 'foo', 'foo.x.example.com');
+ },
+ 'foo@foo.x.example.com': function (test) {
+ _check(test, 'foo@foo.x.example.com', 'foo', 'foo.x.example.com');
}
- t.end();
-});
+};
-var bad_addresses = [
-'<user@example.com#>',
-]
-
-test("Addresses that fail", function (t) {
- t.plan(bad_addresses.length);
- for (var i=0; i < bad_addresses.length; i++) {
+exports.bad = {
+ '<user@example.com#>': function (test) {
+ test.expect(1);
try {
- var a = new Address(bad_addresses[i]);
- // shouldn't get here...
- t.ok(false, "Parse worked? " + bad_addresses[i])
+ var address = new Address('<user@example.com#>');
}
catch (e) {
- t.ok(1, "Exception occurred for: " + bad_addresses[i]);
+ test.ok(true);
}
+ test.done();
}
- t.end();
-})
+};
View
52 tests/net_utils.js
@@ -1,30 +1,36 @@
-var test = require("tap").test;
require('../configfile').watch_files = false;
var net_utils = require("../net_utils");
-var static = [
-['74.125.82.182', 'mail-we0-f182.google.com'],
-['74.125.82.53', 'mail-ww0-f53.google.com'],
-];
+function _check(test, ip, host, ok) {
+ test.expect(1);
+ test.equals(net_utils.is_ip_in_str(ip, host), ok);
+ test.done();
+}
-test("Static rDNS", function (t) {
- for (var i=0; i<static.length; i++) {
- t.equals(net_utils.is_ip_in_str(static[i][0],static[i][1]), false);
+exports.static_rdns = {
+ '74.125.82.182': function (test) {
+ _check(test, '74.125.82.182', 'mail-we0-f182.google.com', false);
+ },
+ '74.125.82.53': function (test) {
+ _check(test, '74.125.82.53', 'mail-ww0-f53.google.com', false);
}
- t.end();
-});
+};
-var dynamic = [
-['109.168.232.131','host-109-168-232-131.stv.ru'],
-['62.198.236.129','0x3ec6ec81.inet.dsl.telianet.dk'],
-['123.58.178.17','m17-178.vip.126.com'],
-['100.42.67.92','92-67-42-100-dedicated.multacom.com'],
-['101.0.57.5','static-bpipl-101.0.57-5.com'],
-];
-
-test("Dynamic rDNS", function (t) {
- for (var i=0; i<dynamic.length; i++) {
- t.equals(net_utils.is_ip_in_str(dynamic[i][0],dynamic[i][1]), true);
+exports.dynamic_rdns = {
+ '109.168.232.131': function (test) {
+ _check(test, '109.168.232.131', 'host-109-168-232-131.stv.ru', true);
+ },
+ '62.198.236.129': function (test) {
+ _check(test, '62.198.236.129', '0x3ec6ec81.inet.dsl.telianet.dk', true);
+ },
+ '123.58.178.17': function (test) {
+ _check(test, '123.58.178.17', 'm17-178.vip.126.com', true);
+ },
+ '100.42.67.92': function (test) {
+ _check(test, '100.42.67.92', '92-67-42-100-dedicated.multacom.com',
+ true);
+ },
+ '101.0.57.5': function (test) {
+ _check(test, '101.0.57.5', 'static-bpipl-101.0.57-5.com', true);
}
- t.end();
-});
+};
View
4 tests/plugins/aliases.js
@@ -1,12 +1,8 @@
var stub = require('../fixtures/stub'),
- constants = require('../../constants'),
Address = require('../../address').Address,
Connection = require('../fixtures/stub_connection'),
Plugin = require('../fixtures/stub_plugin');
-// huge hack here, but plugin tests need constants
-constants.import(global);
-
function _set_up(callback) {
this.backup = {};
View
61 tests/rfc1869.js
@@ -1,23 +1,46 @@
-var test = require("tap").test;
var parse = require("../rfc1869").parse;
-var dump = require('util').inspect;
-var p = function (t) {
- var match = /^(MAIL|RCPT)\s+(.*)$/.exec(t);
- var out = parse(match[1].toLowerCase(), match[2]);
- //console.log("in: " + t + ", out: " + dump(out));
- return out;
+function _check(test, line, expected) {
+ test.expect(1 + expected.length);
+ var match = /^(MAIL|RCPT)\s+(.*)$/.exec(line);
+ var parsed = parse(match[1].toLowerCase(), match[2]);
+ test.equal(parsed.length, expected.length);
+ for (var x = 0; x < expected.length; x++) {
+ test.equal(parsed[x], expected[x]);
+ }
+ test.done();
}
-test("Basic rfc1869 tests", function (t) {
- t.equals(p("MAIL FROM:<>")[0], "<>");
- t.equals(p("MAIL FROM:")[0], "<>");
- t.equals(p("MAIL FROM:<postmaster>")[0], '<postmaster>');
- t.equals(p("MAIL FROM:user")[0], 'user');
- t.equals(p("MAIL FROM:user size=1234")[0], 'user');
- t.equals(p("MAIL FROM:user@domain size=1234")[0], 'user@domain');
- t.equals(p("MAIL FROM:<user@domain> size=1234")[1], 'size=1234');
- t.equals(p("MAIL FROM:<user@domain> somekey")[1], 'somekey');
- t.equals(p("MAIL FROM:<user@domain> somekey other=foo")[2], 'other=foo');
- t.end();
-});
+exports.basic = {
+ 'MAIL FROM:<>': function (test) {
+ _check(test, 'MAIL FROM:<>', ['<>']);
+ },
+ 'MAIL FROM:': function (test) {
+ _check(test, 'MAIL FROM:', ['<>']);
+ },
+ 'MAIL FROM:<postmaster>': function (test) {
+ _check(test, 'MAIL FROM:<postmaster>', ['<postmaster>']);
+ },
+ 'MAIL FROM:user': function (test) {
+ _check(test, 'MAIL FROM:user', ['user']);
+ },
+ 'MAIL FROM:user size=1234': function (test) {
+ _check(test, 'MAIL FROM:user size=1234', ['user', 'size=1234']);
+ },
+ 'MAIL FROM:user@domain size=1234': function (test) {
+ _check(test, 'MAIL FROM:user@domain size=1234',
+ ['user@domain', 'size=1234']);
+ },
+ 'MAIL FROM:<user@domain> size=1234': function (test) {
+ _check(test, 'MAIL FROM:<user@domain> size=1234',
+ ['<user@domain>', 'size=1234']);
+ },
+ 'MAIL FROM:<user@domain> somekey': function (test) {
+ _check(test, 'MAIL FROM:<user@domain> somekey',
+ ['<user@domain>', 'somekey']);
+ },
+ 'MAIL FROM:<user@domain> somekey other=foo': function (test) {
+ _check(test, 'MAIL FROM:<user@domain> somekey other=foo',
+ ['<user@domain>', 'somekey', 'other=foo']);
+ }
+};
Please sign in to comment.
Something went wrong with that request. Please try again.