Use nodemailer-openpgp plugin to encrypt verification emails
This commit is contained in:
@@ -46,7 +46,8 @@ describe('Koa App (HTTP Server) Integration Tests', function() {
|
||||
return !!params.nonce;
|
||||
}));
|
||||
sinon.stub(nodemailer, 'createTransport').returns({
|
||||
templateSender: () => { return sendEmailStub; }
|
||||
templateSender: () => { return sendEmailStub; },
|
||||
use: function() {}
|
||||
});
|
||||
|
||||
global.testing = true;
|
||||
|
||||
@@ -7,6 +7,7 @@ const log = require('npmlog');
|
||||
const config = require('config');
|
||||
const Email = require('../../src/email/email');
|
||||
const nodemailer = require('nodemailer');
|
||||
const openpgpEncrypt = require('nodemailer-openpgp').openpgpEncrypt;
|
||||
const tpl = require('../../src/email/templates.json');
|
||||
|
||||
log.level = config.log.level;
|
||||
@@ -14,7 +15,7 @@ log.level = config.log.level;
|
||||
describe('Email Integration Tests', function() {
|
||||
this.timeout(20000);
|
||||
|
||||
let email, credentials, userId, origin;
|
||||
let email, credentials, userId, origin, publicKeyArmored;
|
||||
|
||||
before(function() {
|
||||
try {
|
||||
@@ -24,22 +25,18 @@ describe('Email Integration Tests', function() {
|
||||
this.skip();
|
||||
return;
|
||||
}
|
||||
userId = {
|
||||
name: credentials.sender.name,
|
||||
email: credentials.sender.email,
|
||||
keyid: '0123456789ABCDF0',
|
||||
nonce: 'qwertzuioasdfghjkqwertzuio'
|
||||
};
|
||||
publicKeyArmored = require('fs').readFileSync(__dirname + '/../key1.asc', 'utf8');
|
||||
origin = {
|
||||
protocol: 'http',
|
||||
host: 'localhost:' + config.server.port
|
||||
};
|
||||
email = new Email(nodemailer);
|
||||
email = new Email(nodemailer, openpgpEncrypt);
|
||||
email.init({
|
||||
host: process.env.SMTP_HOST || credentials.smtp.host,
|
||||
port: process.env.SMTP_PORT || credentials.smtp.port,
|
||||
tls: (process.env.SMTP_TLS || credentials.smtp.tls) === 'true',
|
||||
starttls: (process.env.SMTP_STARTTLS || credentials.smtp.starttls) === 'true',
|
||||
pgp: (process.env.SMTP_PGP || credentials.smtp.pgp) === 'true',
|
||||
auth: {
|
||||
user: process.env.SMTP_USER || credentials.smtp.user,
|
||||
pass: process.env.SMTP_PASS || credentials.smtp.pass
|
||||
@@ -51,6 +48,16 @@ describe('Email Integration Tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
userId = {
|
||||
name: credentials.sender.name,
|
||||
email: credentials.sender.email,
|
||||
keyid: '0123456789ABCDF0',
|
||||
nonce: 'qwertzuioasdfghjkqwertzuio',
|
||||
publicKeyArmored
|
||||
};
|
||||
});
|
||||
|
||||
describe("_sendHelper", () => {
|
||||
it('should work', function *() {
|
||||
let mailOptions = {
|
||||
@@ -66,13 +73,23 @@ describe('Email Integration Tests', function() {
|
||||
});
|
||||
|
||||
describe("send verifyKey template", () => {
|
||||
it('should work', function *() {
|
||||
it('should send plaintext email', function *() {
|
||||
delete userId.publicKeyArmored;
|
||||
yield email.send({ template:tpl.verifyKey, userId, origin });
|
||||
});
|
||||
|
||||
it('should send pgp encrypted email', function *() {
|
||||
yield email.send({ template:tpl.verifyKey, userId, origin });
|
||||
});
|
||||
});
|
||||
|
||||
describe("send verifyRemove template", () => {
|
||||
it('should work', function *() {
|
||||
it('should send plaintext email', function *() {
|
||||
delete userId.publicKeyArmored;
|
||||
yield email.send({ template:tpl.verifyRemove, userId, origin });
|
||||
});
|
||||
|
||||
it('should send pgp encrypted email', function *() {
|
||||
yield email.send({ template:tpl.verifyRemove, userId, origin });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user