Permalink
Browse files

Fixed aliases plugin from setting transaction.rcpt_to to a string rat…

…her than

an array.  Checked in here because I needed my stub_plugin fixture to tests
the fix and regression tests the bug.
  • Loading branch information...
1 parent 4dc1df4 commit 4b0dbfa745b8da61aefc9a95fc349c48ed481806 @godsflaw godsflaw committed Mar 21, 2012
Showing with 31 additions and 17 deletions.
  1. +0 −1 address.js
  2. +6 −1 plugins/aliases.js
  3. +4 −0 tests/fixtures/stub_plugin.js
  4. +21 −15 tests/plugins/aliases.js
View
@@ -7,7 +7,6 @@
// add your logs and uncomment this require. Just make sure to comment
// out again when everything is working. If you don't tests will hang.
// var logger = require('./logger');
-
var qchar = /([^a-zA-Z0-9!#\$\%\&\x27\*\+\x2D\/=\?\^_`{\|}~.])/;
function Address (user, host) {
View
@@ -1,5 +1,6 @@
// This is the aliases plugin
// One must not run this plugin with the queue/smtp_proxy plugin.
+var Address = require('./address').Address;
exports.register = function () {
this.inherits('queue/discard');
@@ -48,6 +49,7 @@ function _drop(plugin, connection, rcpt) {
function _alias(plugin, connection, key, config, host) {
var to;
+ var toAddress;
if (config.to) {
if (config.to.search("@") !== -1) {
@@ -59,7 +61,10 @@ function _alias(plugin, connection, key, config, host) {
connection.logdebug(plugin, "aliasing " +
connection.transaction.rcpt_to + " to " + to);
- connection.transaction.rcpt_to = to;
+
+ toAddress = new Address('<' + to + '>');
+ connection.transaction.rcpt_to.pop();
+ connection.transaction.rcpt_to.push(toAddress);
}
else {
connection.loginfo(plugin, 'alias failed for ' + key +
@@ -42,6 +42,10 @@ Plugin.prototype.load_plugin = function(name) {
}
var code = '"use strict";' + rf;
+
+ // hax for testing
+ code = code.replace("./address", "../../address");
+
var sandbox = {
require: require,
__filename: full_paths[i],
View
@@ -22,6 +22,7 @@ function _set_up(callback) {
this.connection.notes = stub();
this.connection.transaction = stub();
this.connection.transaction.notes = stub();
+ this.connection.transaction.rcpt_to = [ this.params ];
// some test data
this.configfile = {
@@ -117,13 +118,14 @@ exports.aliases = {
// these will get reset in _set_up everytime
this.recip = new Address('<test2-specific@example.com>');
this.params = [this.recip];
+ var result = new Address('<test2@example.com>');
var next = function (action) {
- test.expect(3);
+ test.expect(4);
test.isUndefined(this.connection.transaction.notes.discard);
test.isNotNull(this.connection.transaction.rcpt_to);
- test.equals(this.connection.transaction.rcpt_to,
- "test2@example.com");
+ test.isArray(this.connection.transaction.rcpt_to);
+ test.deepEqual(this.connection.transaction.rcpt_to.pop(), result);
test.done();
}.bind(this);
@@ -133,12 +135,13 @@ exports.aliases = {
// these will get reset in _set_up everytime
this.recip = new Address('<test3@example.com>');
this.params = [this.recip];
+ var result = new Address('<test3-works@example.com>');
var next = function (action) {
- test.expect(2);
+ test.expect(3);
test.isNotNull(this.connection.transaction.rcpt_to);
- test.equals(this.connection.transaction.rcpt_to,
- "test3-works@example.com");
+ test.isArray(this.connection.transaction.rcpt_to);
+ test.deepEqual(this.connection.transaction.rcpt_to.pop(), result);
test.done();
}.bind(this);
@@ -148,12 +151,13 @@ exports.aliases = {
// these will get reset in _set_up everytime
this.recip = new Address('<test4-testing@example.com>');
this.params = [this.recip];
+ var result = new Address('<test4@example.com>');
var next = function (action) {
- test.expect(2);
+ test.expect(3);
test.isNotNull(this.connection.transaction.rcpt_to);
- test.equals(this.connection.transaction.rcpt_to,
- "test4@example.com");
+ test.isArray(this.connection.transaction.rcpt_to);
+ test.deepEqual(this.connection.transaction.rcpt_to.pop(), result);
test.done();
}.bind(this);
@@ -163,12 +167,13 @@ exports.aliases = {
// these will get reset in _set_up everytime
this.recip = new Address('<test5@example.com>');
this.params = [this.recip];
+ var result = new Address('<test5-works@success.com>');
var next = function (action) {
- test.expect(2);
+ test.expect(3);
test.isNotNull(this.connection.transaction.rcpt_to);
- test.equals(this.connection.transaction.rcpt_to,
- "test5-works@success.com");
+ test.isArray(this.connection.transaction.rcpt_to);
+ test.deepEqual(this.connection.transaction.rcpt_to.pop(), result);
test.done();
}.bind(this);
@@ -178,12 +183,13 @@ exports.aliases = {
// these will get reset in _set_up everytime
this.recip = new Address('<test6-testing@example.com>');
this.params = [this.recip];
+ var result = new Address('<test6-works@success.com>');
var next = function (action) {
- test.expect(2);
+ test.expect(3);
test.isNotNull(this.connection.transaction.rcpt_to);
- test.equals(this.connection.transaction.rcpt_to,
- "test6-works@success.com");
+ test.isArray(this.connection.transaction.rcpt_to);
+ test.deepEqual(this.connection.transaction.rcpt_to.pop(), result);
test.done();
}.bind(this);

0 comments on commit 4b0dbfa

Please sign in to comment.