Rebase onto dev/pgp-inline, fix unit tests

This commit is contained in:
Martin Hauck
2019-02-08 17:04:28 +01:00
parent a2b941b0ae
commit 1651571d36
14 changed files with 58 additions and 77 deletions

View File

@@ -34,8 +34,8 @@ class Mongo {
async init({uri, user, pass}) {
log.info('mongo', 'Connecting to MongoDB ...');
const url = `mongodb://${user}:${pass}@${uri}`;
const client = await MongoClient.connect(url, {useNewUrlParser: true});
this._db = client.db();
this._client = await MongoClient.connect(url, {useNewUrlParser: true});
this._db = this._client.db();
}
/**
@@ -43,7 +43,7 @@ class Mongo {
* @yield {undefined}
*/
disconnect() {
return this._db.close();
return this._client.close();
}
/**

View File

@@ -37,7 +37,7 @@ class Email {
* @param {boolean} pgp (optional) if outgoing emails are encrypted to the user's public key.
*/
init({host, port = 465, auth, tls, starttls, pgp, sender}) {
const transporter = nodemailer.createTransport({
this._transporter = nodemailer.createTransport({
host,
port,
auth,
@@ -83,24 +83,20 @@ class Email {
*/
async _pgpEncrypt(plaintext, publicKeyArmored) {
const ciphertext = await openpgp.encrypt({
data: plaintext,
publicKeys: openpgp.key.readArmored(publicKeyArmored).keys,
message: openpgp.message.fromText(plaintext),
publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys,
});
return ciphertext.data;
}
/**
* A generic method to send an email message via nodemailer.
* @param {Object} from sender object: { name:'Jon Smith', address:'j@smith.com' }
* @param {Object} to recipient object: { name:'Jon Smith', address:'j@smith.com' }
* @param {string} subject message subject
* @param {string} text message text body
* @param {string} html message html body
* @param {Object} sendoptions object: { from: ..., to: ..., subject: ..., text: ... }
* @yield {Object} reponse object containing SMTP info
*/
async _sendHelper(sendOptions) {
try {
const info = await this._transport.sendMail(sendOptions);
const info = await this._transporter.sendMail(sendOptions);
if (!this._checkResponse(info)) {
log.warn('email', 'Message may not have been received.', info);
}

View File

@@ -3,11 +3,9 @@
exports.verifyKey = ({name, baseUrl, keyId, nonce}) => ({
subject: `Verify Your Key`,
text: `Hello ${name},\n\nplease click here to verify your key:\n\n${baseUrl}/api/v1/key?op=verify&keyId=${keyId}&nonce=${nonce}`,
html: `<p>Hello ${name},</p><p>please <a href="${baseUrl}/api/v1/key?op=verify&keyId=${keyId}&nonce=${nonce}">click here to verify</a> your key.</p>`
});
exports.verifyRemove = ({name, baseUrl, keyId, nonce}) => ({
subject: `Verify Key Removal`,
text: `Hello ${name},\n\nplease click here to verify the removal of your key:\n\n${baseUrl}/api/v1/key?op=verifyRemove&keyId=${keyId}&nonce=${nonce}`,
html: `<p>Hello ${name},</p><p>please <a href="${baseUrl}/api/v1/key?op=verifyRemove&keyId=${keyId}&nonce=${nonce}">click here to verify</a> the removal of your key.</p>`
});

View File

@@ -1,2 +0,0 @@
<p>Hello <%= name %>,</p>
<p>please <a href="<%= `${baseUrl}/api/v1/key?op=verify&keyId=${keyId}&nonce=${nonce}` %>">click here to verify</a> your key.</p>

View File

@@ -1 +0,0 @@
Verify Your Key

View File

@@ -1,2 +0,0 @@
<p>Hello <%= name %>,</p>
<p>please <a href="<%= `${baseUrl}/api/v1/key?op=verifyRemove&keyId=${keyId}&nonce=${nonce}` %>">click here to verify</a> the removal of your key.</p>

View File

@@ -1 +0,0 @@
Verify Key Removal