1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00
node-red-nodes/test/social/email/61-email_spec.js

273 lines
9.2 KiB
JavaScript
Raw Normal View History

2015-06-13 19:48:17 +02:00
var should = require("should");
var sinon = require("sinon");
var helper = require("node-red-node-test-helper");
2015-06-13 19:48:17 +02:00
var emailNode = require('../../../social/email/61-email.js');
describe('email Node', function () {
2015-06-13 19:48:17 +02:00
beforeEach(function (done) {
2015-06-13 19:48:17 +02:00
helper.startServer(done);
});
afterEach(function (done) {
2015-06-13 19:48:17 +02:00
helper.unload();
helper.stopServer(done);
});
describe('email in', function () {
it('should load with defaults', function (done) {
var flow = [{
id: "n1",
type: "e-mail in",
name: "emailin",
wires: [
[]
]
}];
helper.load(emailNode, flow, function () {
var n1 = helper.getNode("n1");
n1.should.have.property('name', "emailin");
n1.should.have.property("repeat", 300000);
n1.should.have.property("inserver", "imap.gmail.com");
n1.should.have.property("inport", "993");
XOAuth2 for Email-In node (#975) * Update PULL_REQUEST_TEMPLATE.md * Add new UI elements to Email In node Locale for en-US Added Auth type and Token field to Email IN Dynamically appear based on selection * XOAUTH2 IMAP Minor UI changes. Exposing only XOAuth2. Picks up raw access token from input message specified. Only works for IMAP Token formatted by node for Exchange and GMail, won't work on other providers. Only works on trigger, not timer TODO: Add POP XOAUTH2 capability Add SMTP XOAUTH2 capability Add option to pass SASL XAOUTH2 token rather than raw OAUTH2 token * SASL Format Added checkbox to turn off SASL formatting if the user wants to do this themselves * XOAuth2 forces input Using XOauth2 forces triggered node, and automatic trigger sets auth to basic; XOAuth2 needs token from flow * Error reporting Password missing error only occurs if set to basic authentication. Token missing only occurs if set to XOAuth2. * Unit tests Make sure basic authentication is selected by default, and that an additional input is created and timed triggers are turned off for XOauth2 * Cleanup and README Remove old code, update readme * XOauth2 IMAP Release Prevent XOAuth2 being used for POP. Update PR Template. Updated help file. Bumped version to 1.19-beta * Update POP3 dependency Removed dependency to poplib.js, moved to node-pop3. Re-wrote checkPOP3 function asynchronously using the new library. Added some node.status changes to mimic IMAP behaviour. * XOAUTH2 POP3 Added checking for authentication type to allow XOauth2 tokens to be sent to POP server. Turned off UI restrictions for this functionality. * XOAUTH2 POP3 Release Updated help docs and version to reflect changes. * Add new UI elements to Email Out node Add option for XAouth2 for SMTP node * XOAUTH2 SMTP Exposing functionality for OAuth2 through Nodemailer. Added some error reporting if credentials are missing to match the Email-In node. * XOAUTH2 SMTP Release Updated help file to reflect changes. * Unit Tests for Email Out Modified tests to allow these unit tests to pass, but does not address the fault caused by the Node Test Helper - credentials only loaded after the flow has been loaded. --------- Co-authored-by: Dave Conway-Jones <dceejay@users.noreply.github.com>
2023-03-27 21:27:47 +02:00
n1.should.have.property("authtype", "BASIC");
done();
});
});
it('should force input on XOAuth2', function (done) {
var flow = [{
id: "n1",
type: "e-mail in",
name: "emailin",
authtype: "XOAUTH2",
wires: [
[]
]
}];
helper.load(emailNode, flow, function () {
var n1 = helper.getNode("n1");
n1.should.have.property("repeat", 0);
n1.should.have.property("inputs", 1);
done();
});
});
});
describe('email out', function () {
2015-06-13 19:48:17 +02:00
it('should load with defaults', function (done) {
var flow = [{
id: "n1",
type: "e-mail",
name: "emailout",
port: 1025,
wires: [
[]
]
}];
helper.load(emailNode, flow, function () {
2015-06-13 19:48:17 +02:00
var n1 = helper.getNode("n1");
n1.should.have.property('name', "emailout");
XOAuth2 for Email-In node (#975) * Update PULL_REQUEST_TEMPLATE.md * Add new UI elements to Email In node Locale for en-US Added Auth type and Token field to Email IN Dynamically appear based on selection * XOAUTH2 IMAP Minor UI changes. Exposing only XOAuth2. Picks up raw access token from input message specified. Only works for IMAP Token formatted by node for Exchange and GMail, won't work on other providers. Only works on trigger, not timer TODO: Add POP XOAUTH2 capability Add SMTP XOAUTH2 capability Add option to pass SASL XAOUTH2 token rather than raw OAUTH2 token * SASL Format Added checkbox to turn off SASL formatting if the user wants to do this themselves * XOAuth2 forces input Using XOauth2 forces triggered node, and automatic trigger sets auth to basic; XOAuth2 needs token from flow * Error reporting Password missing error only occurs if set to basic authentication. Token missing only occurs if set to XOAuth2. * Unit tests Make sure basic authentication is selected by default, and that an additional input is created and timed triggers are turned off for XOauth2 * Cleanup and README Remove old code, update readme * XOauth2 IMAP Release Prevent XOAuth2 being used for POP. Update PR Template. Updated help file. Bumped version to 1.19-beta * Update POP3 dependency Removed dependency to poplib.js, moved to node-pop3. Re-wrote checkPOP3 function asynchronously using the new library. Added some node.status changes to mimic IMAP behaviour. * XOAUTH2 POP3 Added checking for authentication type to allow XOauth2 tokens to be sent to POP server. Turned off UI restrictions for this functionality. * XOAUTH2 POP3 Release Updated help docs and version to reflect changes. * Add new UI elements to Email Out node Add option for XAouth2 for SMTP node * XOAUTH2 SMTP Exposing functionality for OAuth2 through Nodemailer. Added some error reporting if credentials are missing to match the Email-In node. * XOAUTH2 SMTP Release Updated help file to reflect changes. * Unit Tests for Email Out Modified tests to allow these unit tests to pass, but does not address the fault caused by the Node Test Helper - credentials only loaded after the flow has been loaded. --------- Co-authored-by: Dave Conway-Jones <dceejay@users.noreply.github.com>
2023-03-27 21:27:47 +02:00
n1.should.have.property("authtype", "BASIC");
2015-06-13 19:48:17 +02:00
done();
});
});
it('should fail with no payload', function (done) {
var flow = [{
id: "n1",
type: "e-mail",
name: "emailout",
wires: [
[]
]
}];
helper.load(emailNode, flow, function () {
var n1 = helper.getNode("n1");
n1.credentials = {
userid: "test",
password: "test",
};
n1.emit("input", {});
//done();
});
setTimeout(function () {
try {
var logEvents = helper.log().args.filter(function (evt) {
//console.log(evt[0].msg);
return evt[0].type == "e-mail";
});
//console.log(helper.log().args);
//console.log(helper.log());
//logEvents.should.have.length(3);
logEvents[0][0].should.have.a.property('msg');
XOAuth2 for Email-In node (#975) * Update PULL_REQUEST_TEMPLATE.md * Add new UI elements to Email In node Locale for en-US Added Auth type and Token field to Email IN Dynamically appear based on selection * XOAUTH2 IMAP Minor UI changes. Exposing only XOAuth2. Picks up raw access token from input message specified. Only works for IMAP Token formatted by node for Exchange and GMail, won't work on other providers. Only works on trigger, not timer TODO: Add POP XOAUTH2 capability Add SMTP XOAUTH2 capability Add option to pass SASL XAOUTH2 token rather than raw OAUTH2 token * SASL Format Added checkbox to turn off SASL formatting if the user wants to do this themselves * XOAuth2 forces input Using XOauth2 forces triggered node, and automatic trigger sets auth to basic; XOAuth2 needs token from flow * Error reporting Password missing error only occurs if set to basic authentication. Token missing only occurs if set to XOAuth2. * Unit tests Make sure basic authentication is selected by default, and that an additional input is created and timed triggers are turned off for XOauth2 * Cleanup and README Remove old code, update readme * XOauth2 IMAP Release Prevent XOAuth2 being used for POP. Update PR Template. Updated help file. Bumped version to 1.19-beta * Update POP3 dependency Removed dependency to poplib.js, moved to node-pop3. Re-wrote checkPOP3 function asynchronously using the new library. Added some node.status changes to mimic IMAP behaviour. * XOAUTH2 POP3 Added checking for authentication type to allow XOauth2 tokens to be sent to POP server. Turned off UI restrictions for this functionality. * XOAUTH2 POP3 Release Updated help docs and version to reflect changes. * Add new UI elements to Email Out node Add option for XAouth2 for SMTP node * XOAUTH2 SMTP Exposing functionality for OAuth2 through Nodemailer. Added some error reporting if credentials are missing to match the Email-In node. * XOAUTH2 SMTP Release Updated help file to reflect changes. * Unit Tests for Email Out Modified tests to allow these unit tests to pass, but does not address the fault caused by the Node Test Helper - credentials only loaded after the flow has been loaded. --------- Co-authored-by: Dave Conway-Jones <dceejay@users.noreply.github.com>
2023-03-27 21:27:47 +02:00
logEvents[2][0].msg.toString().should.startWith("email.errors.nopayload");
done();
} catch (e) {
done(e);
}
//finally { smtpTransport.sendMail.restore(); }
}, 1500);
});
it('should fail to send an email (invalid creds)', function (done) {
//var smtpTransport = require("nodemailer").createTransport();
//var spy = sinon.stub(smtpTransport, 'sendMail', function(arg1,arg2,arg3,arg4) {
//console.log("HELLO");
//console.log(arg1,arg2,arg3,arg4);
//done();
//});
var flow = [{
id: "n1",
type: "e-mail",
name: "test@gmail.com",
server: "smtp.gmail.com",
secure: true,
port: "465",
wires: [
[]
]
}];
helper.load(emailNode, flow, function () {
var n1 = helper.getNode("n1");
n1.credentials = {
userid: "test",
password: "test",
};
n1.should.have.property('name', "test@gmail.com");
n1.emit("input", {
payload: "Hello World",
to: "test@gmail.com"
});
//done();
});
setTimeout(function () {
try {
var logEvents = helper.log().args.filter(function (evt) {
//console.log(evt[0].msg);
return evt[0].type == "e-mail";
});
// console.log(helper.log().args);
// console.log(helper.log());
// console.log(logEvents[0][0].msg.toString());
//logEvents.should.have.length(3);
logEvents[0][0].should.have.a.property('msg');
XOAuth2 for Email-In node (#975) * Update PULL_REQUEST_TEMPLATE.md * Add new UI elements to Email In node Locale for en-US Added Auth type and Token field to Email IN Dynamically appear based on selection * XOAUTH2 IMAP Minor UI changes. Exposing only XOAuth2. Picks up raw access token from input message specified. Only works for IMAP Token formatted by node for Exchange and GMail, won't work on other providers. Only works on trigger, not timer TODO: Add POP XOAUTH2 capability Add SMTP XOAUTH2 capability Add option to pass SASL XAOUTH2 token rather than raw OAUTH2 token * SASL Format Added checkbox to turn off SASL formatting if the user wants to do this themselves * XOAuth2 forces input Using XOauth2 forces triggered node, and automatic trigger sets auth to basic; XOAuth2 needs token from flow * Error reporting Password missing error only occurs if set to basic authentication. Token missing only occurs if set to XOAuth2. * Unit tests Make sure basic authentication is selected by default, and that an additional input is created and timed triggers are turned off for XOauth2 * Cleanup and README Remove old code, update readme * XOauth2 IMAP Release Prevent XOAuth2 being used for POP. Update PR Template. Updated help file. Bumped version to 1.19-beta * Update POP3 dependency Removed dependency to poplib.js, moved to node-pop3. Re-wrote checkPOP3 function asynchronously using the new library. Added some node.status changes to mimic IMAP behaviour. * XOAUTH2 POP3 Added checking for authentication type to allow XOauth2 tokens to be sent to POP server. Turned off UI restrictions for this functionality. * XOAUTH2 POP3 Release Updated help docs and version to reflect changes. * Add new UI elements to Email Out node Add option for XAouth2 for SMTP node * XOAUTH2 SMTP Exposing functionality for OAuth2 through Nodemailer. Added some error reporting if credentials are missing to match the Email-In node. * XOAUTH2 SMTP Release Updated help file to reflect changes. * Unit Tests for Email Out Modified tests to allow these unit tests to pass, but does not address the fault caused by the Node Test Helper - credentials only loaded after the flow has been loaded. --------- Co-authored-by: Dave Conway-Jones <dceejay@users.noreply.github.com>
2023-03-27 21:27:47 +02:00
logEvents[2][0].msg.toString().should.startWith("Error:");
done();
} catch (e) {
done(e);
}
//finally { smtpTransport.sendMail.restore(); }
}, 1900);
})
it('should fail to send an email (no creds provided)', function (done) {
//var smtpTransport = require("nodemailer").createTransport();
//var spy = sinon.stub(smtpTransport, 'sendMail', function(arg1,arg2,arg3,arg4) {
//console.log("HELLO");
//console.log(arg1,arg2,arg3,arg4);
//done();
//});
var flow = [{
id: "n1",
type: "e-mail",
name: "test@gmail.com",
server: "smtp.gmail.com",
secure: true,
port: "465",
wires: [
[]
]
}];
helper.load(emailNode, flow, function () {
2015-06-13 19:48:17 +02:00
var n1 = helper.getNode("n1");
n1.should.have.property('name', "test@gmail.com");
n1.emit("input", {
payload: "Hello World",
to: "test@gmail.com"
});
2015-06-13 19:48:17 +02:00
//done();
});
setTimeout(function () {
2015-06-13 19:48:17 +02:00
try {
var logEvents = helper.log().args.filter(function (evt) {
//console.log(evt[0].msg);
2015-06-13 19:48:17 +02:00
return evt[0].type == "e-mail";
});
//console.log(helper.log().args);
//logEvents.should.have.length(3);
logEvents[0][0].should.have.a.property('msg');
XOAuth2 for Email-In node (#975) * Update PULL_REQUEST_TEMPLATE.md * Add new UI elements to Email In node Locale for en-US Added Auth type and Token field to Email IN Dynamically appear based on selection * XOAUTH2 IMAP Minor UI changes. Exposing only XOAuth2. Picks up raw access token from input message specified. Only works for IMAP Token formatted by node for Exchange and GMail, won't work on other providers. Only works on trigger, not timer TODO: Add POP XOAUTH2 capability Add SMTP XOAUTH2 capability Add option to pass SASL XAOUTH2 token rather than raw OAUTH2 token * SASL Format Added checkbox to turn off SASL formatting if the user wants to do this themselves * XOAuth2 forces input Using XOauth2 forces triggered node, and automatic trigger sets auth to basic; XOAuth2 needs token from flow * Error reporting Password missing error only occurs if set to basic authentication. Token missing only occurs if set to XOAuth2. * Unit tests Make sure basic authentication is selected by default, and that an additional input is created and timed triggers are turned off for XOauth2 * Cleanup and README Remove old code, update readme * XOauth2 IMAP Release Prevent XOAuth2 being used for POP. Update PR Template. Updated help file. Bumped version to 1.19-beta * Update POP3 dependency Removed dependency to poplib.js, moved to node-pop3. Re-wrote checkPOP3 function asynchronously using the new library. Added some node.status changes to mimic IMAP behaviour. * XOAUTH2 POP3 Added checking for authentication type to allow XOauth2 tokens to be sent to POP server. Turned off UI restrictions for this functionality. * XOAUTH2 POP3 Release Updated help docs and version to reflect changes. * Add new UI elements to Email Out node Add option for XAouth2 for SMTP node * XOAUTH2 SMTP Exposing functionality for OAuth2 through Nodemailer. Added some error reporting if credentials are missing to match the Email-In node. * XOAUTH2 SMTP Release Updated help file to reflect changes. * Unit Tests for Email Out Modified tests to allow these unit tests to pass, but does not address the fault caused by the Node Test Helper - credentials only loaded after the flow has been loaded. --------- Co-authored-by: Dave Conway-Jones <dceejay@users.noreply.github.com>
2023-03-27 21:27:47 +02:00
logEvents[2][0].msg.toString().should.startWith("Error:");
2015-06-13 19:48:17 +02:00
done();
} catch (e) {
done(e);
2015-06-13 19:48:17 +02:00
}
//finally { smtpTransport.sendMail.restore(); }
}, 1900);
2015-06-13 19:48:17 +02:00
})
});
describe('email mta', function () {
it('should catch an email send to localhost 1025', function (done) {
var flow = [{
id: "n1",
type: "e-mail mta",
name: "emailmta",
port: 1025,
wires: [
["n2"]
]
},
{
id:"n2",
type:"helper"
},
{
id: "n3",
type: "e-mail",
dname: "testout",
server: "localhost",
secure: false,
port: 1025,
wires: [
[]
]
}];
helper.load(emailNode, flow, function () {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var n3 = helper.getNode("n3");
n1.should.have.property('port', 1025);
n2.on("input", function(msg) {
//console.log("GOT",msg);
try {
msg.should.have.a.property("payload",'Hello World\n');
msg.should.have.a.property("topic","Test");
msg.should.have.a.property("from",'foo@example.com');
msg.should.have.a.property("to",'bar@example.com');
msg.should.have.a.property("attachments");
msg.should.have.a.property("header");
done();
}
catch(e) {
done(e)
}
});
n3.emit("input", {
payload: "Hello World",
topic: "Test",
from: "foo@example.com",
to: "bar@example.com"
});
//done();
});
});
});
});