aboutsummaryrefslogtreecommitdiffstats
path: root/tools/node_modules/nodemailer/node_modules/simplesmtp/test
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/nodemailer/node_modules/simplesmtp/test')
-rw-r--r--tools/node_modules/nodemailer/node_modules/simplesmtp/test/client.js444
-rw-r--r--tools/node_modules/nodemailer/node_modules/simplesmtp/test/pool.js275
-rw-r--r--tools/node_modules/nodemailer/node_modules/simplesmtp/test/server.js590
-rw-r--r--tools/node_modules/nodemailer/node_modules/simplesmtp/test/testmessage.eml5
4 files changed, 1314 insertions, 0 deletions
diff --git a/tools/node_modules/nodemailer/node_modules/simplesmtp/test/client.js b/tools/node_modules/nodemailer/node_modules/simplesmtp/test/client.js
new file mode 100644
index 0000000..a6fe624
--- /dev/null
+++ b/tools/node_modules/nodemailer/node_modules/simplesmtp/test/client.js
@@ -0,0 +1,444 @@
+var testCase = require('nodeunit').testCase,
+ runClientMockup = require("rai").runClientMockup,
+ simplesmtp = require("../index"),
+ fs = require("fs");
+
+var PORT_NUMBER = 8397;
+
+
+
+exports["General tests"] = {
+ setUp: function (callback) {
+ this.server = new simplesmtp.createServer();
+ this.server.listen(PORT_NUMBER, function(err){
+ if(err){
+ throw err;
+ }else{
+ callback();
+ }
+ });
+
+ },
+
+ tearDown: function (callback) {
+ this.server.end(callback);
+ },
+
+ "Connect and setup": function(test){
+ var client = simplesmtp.connect(PORT_NUMBER);
+
+ client.once("idle", function(){
+ // Client is ready to take messages
+ test.ok(true);
+ client.close();
+ });
+
+ client.on("error", function(err){
+ test.ok(false);
+ });
+
+ client.on("end", function(){
+ test.done();
+ });
+ }
+};
+
+exports["Secure server"] = {
+ setUp: function (callback) {
+ this.server = new simplesmtp.createServer({
+ secureConnection: true
+ });
+ this.server.listen(PORT_NUMBER, function(err){
+ if(err){
+ throw err;
+ }else{
+ callback();
+ }
+ });
+
+ },
+
+ tearDown: function (callback) {
+ this.server.end(callback);
+ },
+
+ "Connect and setup": function(test){
+ var client = simplesmtp.connect(PORT_NUMBER, false, {
+ secureConnection: true
+ });
+
+ client.once("idle", function(){
+ // Client is ready to take messages
+ test.ok(true);
+ client.close();
+ });
+
+ client.on("error", function(err){
+ test.ok(false);
+ });
+
+ client.on("end", function(){
+ test.done();
+ });
+ }
+};
+
+exports["Disabled EHLO"] = {
+ setUp: function (callback) {
+ this.server = new simplesmtp.createServer({disableEHLO: true});
+ this.server.listen(PORT_NUMBER, function(err){
+ if(err){
+ throw err;
+ }else{
+ callback();
+ }
+ });
+
+ },
+
+ tearDown: function (callback) {
+ this.server.end(callback);
+ },
+
+ "Connect and setup": function(test){
+ var client = simplesmtp.connect(PORT_NUMBER, false, {});
+
+ client.once("idle", function(){
+ // Client is ready to take messages
+ test.ok(true);
+ client.close();
+ });
+
+ client.on("error", function(err){
+ test.ok(false);
+ });
+
+ client.on("end", function(){
+ test.done();
+ });
+ }
+};
+
+exports["Authentication needed"] = {
+ setUp: function (callback) {
+ this.server = new simplesmtp.createServer({
+ requireAuthentication: true
+ });
+
+ this.server.on("authorizeUser", function(envelope, user, pass, callback){
+ callback(null, user=="test1" && pass == "test2");
+ });
+
+ this.server.listen(PORT_NUMBER, function(err){
+ if(err){
+ throw err;
+ }else{
+ callback();
+ }
+ });
+
+ },
+
+ tearDown: function (callback) {
+ this.server.end(callback);
+ },
+
+ "Auth success": function(test){
+ var client = simplesmtp.connect(PORT_NUMBER, false, {
+ auth: {
+ user: "test1",
+ pass: "test2"
+ }
+ });
+
+ client.once("idle", function(){
+ // Client is ready to take messages
+ test.ok(true);
+ client.close();
+ });
+
+ client.on("error", function(err){
+ test.ok(false);
+ });
+
+ client.on("end", function(){
+ test.done();
+ });
+ },
+
+ "Auth fails": function(test){
+ var client = simplesmtp.connect(PORT_NUMBER, false, {
+ auth: {
+ user: "test3",
+ pass: "test4"
+ }
+ });
+
+ client.once("idle", function(){
+ // Client is ready to take messages
+ test.ok(false); // should not occur
+ client.close();
+ });
+
+ client.on("error", function(err){
+ test.ok(true); // login failed
+ });
+
+ client.on("end", function(){
+ test.done();
+ });
+ }
+};
+
+exports["Message tests"] = {
+ setUp: function (callback) {
+ this.server = new simplesmtp.createServer({
+ validateSender: true,
+ validateRecipients: true
+ });
+
+ this.server.on("validateSender", function(envelope, email, callback){
+ callback(email != "test@node.ee"?new Error("Failed sender") : null);
+ });
+
+ this.server.on("validateRecipient", function(envelope, email, callback){
+ callback(email.split("@").pop() != "node.ee"?new Error("Failed recipient") : null);
+ });
+
+ this.server.on("dataReady", function(envelope, callback){
+ callback(null, "ABC1"); // ABC1 is the queue id to be advertised to the client
+ // callback(new Error("That was clearly a spam!"));
+ });
+
+ this.server.listen(PORT_NUMBER, function(err){
+ if(err){
+ throw err;
+ }else{
+ callback();
+ }
+ });
+
+ },
+
+ tearDown: function (callback) {
+ this.server.end(callback);
+ },
+
+ "Set envelope success": function(test){
+ test.expect(2);
+
+ var client = simplesmtp.connect(PORT_NUMBER, false, {});
+
+ client.once("idle", function(){
+ // Client is ready to take messages
+ test.ok(true); // waiting for envelope
+
+ client.useEnvelope({
+ from: "test@node.ee",
+ to: [
+ "test1@node.ee",
+ "test2@node.ee"
+ ]
+ });
+ });
+
+ client.on("message", function(){
+ // Client is ready to take messages
+ test.ok(true); // waiting for message
+ client.close();
+ });
+
+ client.on("error", function(err){
+ test.ok(false);
+ });
+
+ client.on("end", function(){
+ test.done();
+ });
+ },
+
+ "Set envelope fails for sender": function(test){
+ test.expect(2);
+
+ var client = simplesmtp.connect(PORT_NUMBER, false, {});
+
+ client.once("idle", function(){
+ // Client is ready to take messages
+ test.ok(true); // waiting for envelope
+
+ client.useEnvelope({
+ from: "test3@node.ee",
+ to: [
+ "test1@node.ee",
+ "test2@node.ee"
+ ]
+ });
+ });
+
+ client.on("message", function(){
+ // Client is ready to take messages
+ test.ok(false); // waiting for message
+ client.close();
+ });
+
+ client.on("error", function(err){
+ test.ok(true);
+ });
+
+ client.on("end", function(){
+ test.done();
+ });
+ },
+
+ "Set envelope fails for receiver": function(test){
+ test.expect(2);
+
+ var client = simplesmtp.connect(PORT_NUMBER, false, {});
+
+ client.once("idle", function(){
+ // Client is ready to take messages
+ test.ok(true); // waiting for envelope
+
+ client.useEnvelope({
+ from: "test@node.ee",
+ to: [
+ "test1@kreata.ee",
+ "test2@kreata.ee"
+ ]
+ });
+ });
+
+ client.on("message", function(){
+ // Client is ready to take messages
+ test.ok(false); // waiting for message
+ client.close();
+ });
+
+ client.on("error", function(err){
+ test.ok(true);
+ });
+
+ client.on("end", function(){
+ test.done();
+ });
+ },
+
+ "Set envelope partly fails": function(test){
+ test.expect(3);
+
+ var client = simplesmtp.connect(PORT_NUMBER, false, {});
+
+ client.once("idle", function(){
+ // Client is ready to take messages
+ test.ok(true); // waiting for envelope
+
+ client.useEnvelope({
+ from: "test@node.ee",
+ to: [
+ "test1@node.ee",
+ "test2@kreata.ee"
+ ]
+ });
+ });
+
+ client.on("rcptFailed", function(){
+ // Client is ready to take messages
+ test.ok(true); // waiting for message
+ });
+
+ client.on("message", function(){
+ // Client is ready to take messages
+ test.ok(true); // waiting for message
+ client.close();
+ });
+
+ client.on("error", function(err){
+ test.ok(false);
+ });
+
+ client.on("end", function(){
+ test.done();
+ });
+ },
+
+ "Send message success": function(test){
+ test.expect(3);
+
+ var client = simplesmtp.connect(PORT_NUMBER, false, {});
+
+ client.once("idle", function(){
+ // Client is ready to take messages
+ test.ok(true); // waiting for envelope
+
+ client.useEnvelope({
+ from: "test@node.ee",
+ to: [
+ "test1@node.ee",
+ "test2@node.ee"
+ ]
+ });
+ });
+
+ client.on("message", function(){
+ // Client is ready to take messages
+ test.ok(true); // waiting for message
+
+ client.write("From: abc@example.com\r\nTo:cde@example.com\r\nSubject: test\r\n\r\nHello World!");
+ client.end();
+ });
+
+ client.on("ready", function(success){
+ test.ok(success);
+ client.close();
+ });
+
+ client.on("error", function(err){
+ test.ok(false);
+ });
+
+ client.on("end", function(){
+ test.done();
+ });
+ },
+
+ "Stream message": function(test){
+ test.expect(3);
+
+ var client = simplesmtp.connect(PORT_NUMBER, false, {});
+
+ client.once("idle", function(){
+ // Client is ready to take messages
+ test.ok(true); // waiting for envelope
+
+ client.useEnvelope({
+ from: "test@node.ee",
+ to: [
+ "test1@node.ee",
+ "test2@node.ee"
+ ]
+ });
+ });
+
+ client.on("message", function(){
+ // Client is ready to take messages
+ test.ok(true); // waiting for message
+
+ // pipe file to client
+ fs.createReadStream(__dirname+"/testmessage.eml").pipe(client);
+ });
+
+ client.on("ready", function(success){
+ test.ok(success);
+ client.close();
+ });
+
+ client.on("error", function(err){
+ test.ok(false);
+ });
+
+ client.on("end", function(){
+ test.done();
+ });
+ }
+
+}; \ No newline at end of file
diff --git a/tools/node_modules/nodemailer/node_modules/simplesmtp/test/pool.js b/tools/node_modules/nodemailer/node_modules/simplesmtp/test/pool.js
new file mode 100644
index 0000000..84a5c05
--- /dev/null
+++ b/tools/node_modules/nodemailer/node_modules/simplesmtp/test/pool.js
@@ -0,0 +1,275 @@
+var testCase = require('nodeunit').testCase,
+ runClientMockup = require("rai").runClientMockup,
+ simplesmtp = require("../index"),
+ MailComposer = require("mailcomposer").MailComposer,
+ fs = require("fs");
+
+var PORT_NUMBER = 8397;
+
+exports["General tests"] = {
+ setUp: function (callback) {
+ this.server = new simplesmtp.createServer({});
+ this.server.listen(PORT_NUMBER, function(err){
+ if(err){
+ throw err;
+ }else{
+ callback();
+ }
+ });
+
+ },
+
+ tearDown: function (callback) {
+ this.server.end(callback);
+ },
+
+ "Send single message": function(test){
+
+ var pool = simplesmtp.createClientPool(PORT_NUMBER),
+ mc = new MailComposer({escapeSMTP: true});
+
+ mc.setMessageOption({
+ from: "andmekala@hot.ee",
+ to: "andris@node.ee",
+ subject:"Hello!",
+ body: "Hello world!",
+ html: "<b>Hello world!</b>"
+ });
+
+ this.server.on("dataReady", function(envelope, callback){
+ test.ok(true);
+ callback();
+ });
+
+ pool.sendMail(mc, function(error){
+ test.ifError(error);
+ pool.close(function(){
+ test.ok(true);
+ test.done();
+ });
+ });
+ },
+
+ "Send several messages": function(test){
+ var total = 10;
+
+ test.expect(total*2);
+
+ var pool = simplesmtp.createClientPool(PORT_NUMBER),
+ mc;
+
+ this.server.on("dataReady", function(envelope, callback){
+ process.nextTick(callback);
+ });
+
+ var completed = 0;
+ for(var i=0; i<total; i++){
+ mc = new MailComposer({escapeSMTP: true});
+ mc.setMessageOption({
+ from: "andmekala@hot.ee",
+ to: "andris@node.ee",
+ subject:"Hello!",
+ body: "Hello world!",
+ html: "<b>Hello world!</b>"
+ });
+ pool.sendMail(mc, function(error){
+ test.ifError(error);
+ test.ok(true);
+ completed++;
+ if(completed >= total){
+ pool.close(function(){
+ test.done();
+ });
+ }
+ });
+ }
+ },
+
+ "Delivery error once": function(test){
+
+ var pool = simplesmtp.createClientPool(PORT_NUMBER),
+ mc = new MailComposer({escapeSMTP: true});
+
+ mc.setMessageOption({
+ from: "andmekala@hot.ee",
+ to: "andris@node.ee",
+ subject:"Hello!",
+ body: "Hello world!",
+ html: "<b>Hello world!</b>"
+ });
+
+ this.server.on("dataReady", function(envelope, callback){
+ test.ok(true);
+ callback(new Error("Spam!"));
+ });
+
+ pool.sendMail(mc, function(error){
+ test.equal(error && error.name, "DeliveryError");
+ pool.close(function(){
+ test.ok(true);
+ test.done();
+ });
+ });
+ },
+
+ "Delivery error several times": function(test){
+ var total = 10;
+
+ test.expect(total);
+
+ var pool = simplesmtp.createClientPool(PORT_NUMBER),
+ mc;
+
+ this.server.on("dataReady", function(envelope, callback){
+ process.nextTick(function(){callback(new Error("Spam!"));});
+ });
+
+ var completed = 0;
+ for(var i=0; i<total; i++){
+ mc = new MailComposer({escapeSMTP: true});
+ mc.setMessageOption({
+ from: "andmekala@hot.ee",
+ to: "andris@node.ee",
+ subject:"Hello!",
+ body: "Hello world!",
+ html: "<b>Hello world!</b>"
+ });
+
+ pool.sendMail(mc, function(error){
+ test.equal(error && error.name, "DeliveryError");
+ completed++;
+ if(completed >= total){
+ pool.close(function(){
+ test.done();
+ });
+ }
+ });
+ }
+ }
+};
+
+exports["Auth fail tests"] = {
+ setUp: function (callback) {
+ this.server = new simplesmtp.createServer({
+ requireAuthentication: true
+ });
+
+ this.server.listen(PORT_NUMBER, function(err){
+ if(err){
+ throw err;
+ }else{
+ callback();
+ }
+ });
+
+ this.server.on("authorizeUser", function(envelope, username, password, callback){
+ callback(null, username == password);
+ });
+ },
+
+ tearDown: function (callback) {
+ this.server.end(callback);
+ },
+
+ "Authentication passes once": function(test){
+ var pool = simplesmtp.createClientPool(PORT_NUMBER, false, {
+ auth: {
+ "user": "test",
+ "pass": "test"
+ }
+ }),
+ mc = new MailComposer({escapeSMTP: true});
+
+ mc.setMessageOption({
+ from: "andmekala2@hot.ee",
+ to: "andris2@node.ee",
+ subject:"Hello2!",
+ body: "Hello2 world!",
+ html: "<b>Hello2 world!</b>"
+ });
+
+ this.server.on("dataReady", function(envelope, callback){
+ test.ok(true);
+ callback();
+ });
+
+ pool.sendMail(mc, function(error){
+ test.ifError(error);
+ pool.close(function(){
+ test.ok(true);
+ test.done();
+ });
+ });
+
+ },
+
+ "Authentication error once": function(test){
+ var pool = simplesmtp.createClientPool(PORT_NUMBER, false, {
+ auth: {
+ "user": "test1",
+ "pass": "test2"
+ }
+ }),
+ mc = new MailComposer({escapeSMTP: true});
+
+ mc.setMessageOption({
+ from: "andmekala2@hot.ee",
+ to: "andris2@node.ee",
+ subject:"Hello2!",
+ body: "Hello2 world!",
+ html: "<b>Hello2 world!</b>"
+ });
+
+ this.server.on("dataReady", function(envelope, callback){
+ test.ok(true);
+ callback();
+ });
+
+ pool.sendMail(mc, function(error){
+ test.equal(error && error.name, "AuthError");
+ pool.close(function(){
+ test.ok(true);
+ test.done();
+ });
+ });
+
+ },
+
+ "Authentication error several times": function(test){
+ var total = 10;
+ test.expect(total);
+
+ var pool = simplesmtp.createClientPool(PORT_NUMBER, false, {
+ auth: {
+ "user": "test1",
+ "pass": "test2"
+ }
+ }),
+ mc;
+ this.server.on("dataReady", function(envelope, callback){
+ process.nextTick(function(){callback(new Error("Spam!"));});
+ });
+
+ var completed = 0;
+ for(var i=0; i<total; i++){
+ mc = new MailComposer({escapeSMTP: true});
+ mc.setMessageOption({
+ from: "andmekala@hot.ee",
+ to: "andris@node.ee",
+ subject:"Hello!",
+ body: "Hello world!",
+ html: "<b>Hello world!</b>"
+ });
+
+ pool.sendMail(mc, function(error){
+ test.equal(error && error.name, "AuthError");
+ completed++;
+ if(completed >= total){
+ pool.close(function(){
+ test.done();
+ });
+ }
+ });
+ }
+ }
+}; \ No newline at end of file
diff --git a/tools/node_modules/nodemailer/node_modules/simplesmtp/test/server.js b/tools/node_modules/nodemailer/node_modules/simplesmtp/test/server.js
new file mode 100644
index 0000000..32b1ec8
--- /dev/null
+++ b/tools/node_modules/nodemailer/node_modules/simplesmtp/test/server.js
@@ -0,0 +1,590 @@
+var testCase = require('nodeunit').testCase,
+ runClientMockup = require("rai").runClientMockup,
+ simplesmtp = require("../index"),
+ netlib = require("net");
+
+var PORT_NUMBER = 8397;
+
+// monkey patch net and tls to support nodejs 0.4
+if(!netlib.connect && netlib.createConnection){
+ netlib.connect = netlib.createConnection;
+}
+
+exports["General tests"] = {
+ setUp: function (callback) {
+
+ this.smtp = new simplesmtp.createServer({
+ SMTPBanner: "SCORPIO",
+ name: "MYRDO",
+ maxSize: 1234
+ });
+ this.smtp.listen(PORT_NUMBER, function(err){
+ if(err){
+ throw err;
+ }else{
+ callback();
+ }
+ });
+
+ },
+ tearDown: function (callback) {
+ this.smtp.end(callback);
+ },
+ "QUIT": function(test){
+ var cmds = ["QUIT"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("221",resp.toString("utf-8").trim().substr(0,3));
+ test.done();
+ });
+
+ },
+ "HELO": function(test){
+ var cmds = ["HELO FOO"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("250",resp.toString("utf-8").trim().substr(0,3));
+ test.done();
+ });
+
+ },
+ "HELO fails": function(test){
+ var cmds = ["HELO"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "EHLO": function(test){
+ var cmds = ["EHLO FOO"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ resp = resp.toString("utf-8").trim();
+ var lines = resp.split("\r\n");
+ for(var i=0; i<lines.length-1; i++){
+ test.equal("250-", lines[i].substr(0,4));
+ }
+ test.equal("250 ", lines[i].substr(0,4));
+ test.done();
+ });
+ },
+ "EHLO fails": function(test){
+ var cmds = ["EHLO"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "HELO after STARTTLS": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "HELO FOO"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("250",resp.toString("utf-8").trim().substr(0,3));
+ test.done();
+ });
+ },
+ "HELO fails after STARTTLS": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "HELO"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "EHLO after STARTTLS": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "HELO FOO"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ resp = resp.toString("utf-8").trim();
+ var lines = resp.split("\r\n");
+ for(var i=0; i<lines.length-1; i++){
+ test.equal("250-", lines[i].substr(0,4));
+ }
+ test.equal("250 ", lines[i].substr(0,4));
+ test.done();
+ });
+ },
+ "EHLO fails after STARTTLS": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH fails if not required": function(test){
+ var cmds = ["EHLO FOO", "AUTH LOGIN"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH fails if not required TLS": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "AUTH LOGIN"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "Custom Greeting banner": function(test){
+ var client = netlib.connect(PORT_NUMBER, function(){
+ client.on("data", function(chunk){
+ test.equal("SCORPIO", (chunk || "").toString().trim().split(" ").pop());
+ client.end();
+ });
+ client.on('end', function() {
+ test.done();
+ });
+ });
+ },
+ "HELO name": function(test){
+ var cmds = ["HELO FOO"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("MYRDO",resp.toString("utf-8").trim().substr(4).split(" ").shift());
+ test.done();
+ });
+ },
+ "EHLO name": function(test){
+ var cmds = ["EHLO FOO"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("MYRDO",resp.toString("utf-8").trim().substr(4).split(" ").shift());
+ test.done();
+ });
+ },
+ "MAXSIZE": function(test){
+ var cmds = ["EHLO FOO"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.ok(resp.toString("utf-8").trim().match(/^250[\- ]SIZE 1234$/mi));
+ test.done();
+ });
+ }
+};
+
+exports["EHLO setting"] = {
+ setUp: function (callback) {
+
+ this.smtp = new simplesmtp.createServer({
+ disableEHLO: true
+ });
+ this.smtp.listen(PORT_NUMBER, function(err){
+ if(err){
+ throw err;
+ }else{
+ callback();
+ }
+ });
+
+ },
+ tearDown: function (callback) {
+ this.smtp.end(callback);
+ },
+ "Disable EHLO": function(test){
+ runClientMockup(PORT_NUMBER, "localhost", ["EHLO foo"], function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ runClientMockup(PORT_NUMBER, "localhost", ["HELO foo"], function(resp){
+ test.equal("2",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ });
+
+ }
+};
+
+exports["Client disconnect"] = {
+
+ "Client disconnect": function(test){
+
+ var smtp = new simplesmtp.createServer(),
+ clientEnvelope;
+ smtp.listen(PORT_NUMBER, function(err){
+ if(err){
+ throw err;
+ }
+
+ runClientMockup(PORT_NUMBER, "localhost", ["EHLO foo", "MAIL FROM:<andris@node.ee>", "RCPT TO:<andris@node.ee>", "DATA"], function(resp){
+ test.equal("3",resp.toString("utf-8").trim().substr(0,1));
+ });
+
+ });
+ smtp.on("startData", function(envelope){
+ clientEnvelope = envelope;
+ });
+ smtp.on("close", function(envelope){
+ test.equal(envelope, clientEnvelope);
+ smtp.end(function(){});
+ test.done();
+ });
+
+ }
+};
+
+exports["Require AUTH"] = {
+ setUp: function (callback) {
+
+ this.smtp = new simplesmtp.createServer({requireAuthentication: true});
+ this.smtp.listen(PORT_NUMBER, function(err){
+ if(err){
+ throw err;
+ }else{
+ callback();
+ }
+ });
+
+ this.smtp.on("authorizeUser", function(envelope, username, password, callback){
+ callback(null, username=="andris" && password=="test");
+ });
+
+ },
+ tearDown: function (callback) {
+ this.smtp.end(callback);
+ },
+ "Fail without AUTH": function(test){
+ var cmds = ["EHLO FOO", "MAIL FROM:<andris@node.ee>"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "Unknown AUTH": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH CRAM"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH fails before STARTTLS": function(test){
+ var cmds = ["EHLO FOO", "AUTH LOGIN"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH LOGIN": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH LOGIN"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("3",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH LOGIN Invalid login": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH LOGIN",
+ new Buffer("inv").toString("base64"),
+ new Buffer("alid").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH LOGIN Invalid username": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH LOGIN",
+ new Buffer("inv").toString("base64"),
+ new Buffer("test").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH LOGIN Invalid password": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH LOGIN",
+ new Buffer("andris").toString("base64"),
+ new Buffer("alid").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH LOGIN Login success": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH LOGIN",
+ new Buffer("andris").toString("base64"),
+ new Buffer("test").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("2",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH PLAIN": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH PLAIN"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("3",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH PLAIN Invalid login": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH PLAIN "+
+ new Buffer("inv\u0000inv\u0000alid").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH PLAIN Invalid user": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH PLAIN "+
+ new Buffer("inv\u0000inv\u0000test").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH PLAIN Invalid password": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH PLAIN "+
+ new Buffer("andris\u0000andris\u0000alid").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH PLAIN Login success": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH PLAIN "+
+ new Buffer("andris\u0000andris\u0000test").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("2",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH PLAIN Yet another login success": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH PLAIN",
+ new Buffer("andris\u0000andris\u0000test").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("2",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ }
+};
+
+exports["Enable AUTH"] = {
+ setUp: function (callback) {
+
+ this.smtp = new simplesmtp.createServer({enableAuthentication: true});
+ this.smtp.listen(PORT_NUMBER, function(err){
+ if(err){
+ throw err;
+ }else{
+ callback();
+ }
+ });
+
+ this.smtp.on("authorizeUser", function(envelope, username, password, callback){
+ callback(null, username=="andris" && password=="test");
+ });
+
+ },
+ tearDown: function (callback) {
+ this.smtp.end(callback);
+ },
+ "Pass without AUTH": function(test){
+ var cmds = ["EHLO FOO", "MAIL FROM:<andris@node.ee>"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("2",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "Unknown AUTH": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH CRAM"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH fails before STARTTLS": function(test){
+ var cmds = ["EHLO FOO", "AUTH LOGIN"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH LOGIN": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH LOGIN"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("3",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH LOGIN Invalid login": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH LOGIN",
+ new Buffer("inv").toString("base64"),
+ new Buffer("alid").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH LOGIN Invalid username": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH LOGIN",
+ new Buffer("inv").toString("base64"),
+ new Buffer("test").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH LOGIN Invalid password": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH LOGIN",
+ new Buffer("andris").toString("base64"),
+ new Buffer("alid").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH LOGIN Login success": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH LOGIN",
+ new Buffer("andris").toString("base64"),
+ new Buffer("test").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("2",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH PLAIN": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH PLAIN"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("3",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH PLAIN Invalid login": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH PLAIN "+
+ new Buffer("inv\u0000inv\u0000alid").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH PLAIN Invalid user": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH PLAIN "+
+ new Buffer("inv\u0000inv\u0000test").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH PLAIN Invalid password": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH PLAIN "+
+ new Buffer("andris\u0000andris\u0000alid").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH PLAIN Login success": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH PLAIN "+
+ new Buffer("andris\u0000andris\u0000test").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("2",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "AUTH PLAIN Yet another login success": function(test){
+ var cmds = ["EHLO FOO", "STARTTLS", "EHLO FOO", "AUTH PLAIN",
+ new Buffer("andris\u0000andris\u0000test").toString("base64")];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("2",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ }
+};
+
+exports["ignoreTLS"] = {
+ setUp: function (callback) {
+
+ this.smtp = new simplesmtp.createServer({requireAuthentication: true, ignoreTLS: true});
+ this.smtp.listen(PORT_NUMBER, function(err){
+ if(err){
+ throw err;
+ }else{
+ callback();
+ }
+ });
+
+ this.smtp.on("authorizeUser", function(envelope, username, password, callback){
+ callback(null, username=="d3ph" && password=="test");
+ });
+ },
+ tearDown: function (callback) {
+ this.smtp.end(callback);
+ },
+ "Fail without AUTH": function(test){
+ var cmds = ["EHLO FOO", "MAIL FROM:<d3ph.ru@gmail.com>"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "Fail MAIL FROM without HELO": function(test){
+ var cmds = ["MAIL FROM:<d3ph.ru@gmail.com>"];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("5",resp.toString("utf-8").trim().substr(0,1));
+ test.done();
+ });
+ },
+ "Success AUTH & SEND MAIL with <CR><LF>.<CR><LF>": function(test){
+ var cmds = ["EHLO FOO",
+ "AUTH PLAIN",
+ new Buffer("\u0000d3ph\u0000test").toString("base64"),
+ "MAIL FROM:<d3ph@github.com>",
+ "RCPT TO:<andris@node.ee>",
+ "DATA",
+ "Test mail\015\012.\015\012",
+ ];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ var resp = resp.toString("utf-8").trim();
+ test.equal("2",resp.substr(0,1));
+ test.ok(resp.match('FOOBARBAZ'));
+ test.done();
+ });
+ }
+};
+
+exports["Sending mail listen for dataReady"] = {
+ setUp: function (callback) {
+ var data = "";
+
+ this.smtp = new simplesmtp.createServer({ignoreTLS: true});
+ this.smtp.listen(PORT_NUMBER, function(err){
+ if(err){
+ throw err;
+ }else{
+ callback();
+ }
+ });
+
+ this.smtp.on("authorizeUser", function(envelope, username, password, callback){
+ callback(null, username=="d3ph" && password=="test");
+ });
+
+ this.smtp.on("data", function(envelope, chunk){
+ data += chunk;
+ });
+
+ this.smtp.on("dataReady", function(envelope, callback){
+ if (data.match('spam')) {
+ callback(true);
+ } else {
+ callback(null, '#ID');
+ }
+ });
+ },
+ tearDown: function (callback) {
+ this.smtp.end(callback);
+ },
+ "Fail send mail if body contains 'spam'": function(test){
+ var cmds = ["EHLO FOO",
+ "MAIL FROM:<d3ph@github.com>",
+ "RCPT TO:<andris@node.ee>",
+ "DATA",
+ "Test mail with spam!\015\012.\015\012",
+ ];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ test.equal("550 FAILED",resp.toString("utf-8").trim());
+ test.done();
+ });
+ },
+ "Create #ID for mail": function(test){
+ var cmds = ["EHLO FOO",
+ "MAIL FROM:<d3ph@github.com>",
+ "RCPT TO:<andris@node.ee>",
+ "DATA",
+ "Clear mail body\015\012.\015\012",
+ ];
+ runClientMockup(PORT_NUMBER, "localhost", cmds, function(resp){
+ var resp = resp.toString("utf-8").trim();
+ test.equal("2",resp.substr(0,1));
+ test.ok(resp.match('#ID'));
+ test.done();
+ });
+ }
+}
+
diff --git a/tools/node_modules/nodemailer/node_modules/simplesmtp/test/testmessage.eml b/tools/node_modules/nodemailer/node_modules/simplesmtp/test/testmessage.eml
new file mode 100644
index 0000000..5e0523e
--- /dev/null
+++ b/tools/node_modules/nodemailer/node_modules/simplesmtp/test/testmessage.eml
@@ -0,0 +1,5 @@
+From: test@node.ee
+To: test@node.ee
+Subject: Test
+
+Hello world! \ No newline at end of file