Use ES6 destructuring (not available in node v4)

This commit is contained in:
Tankred Hase 2017-01-21 11:51:33 +00:00
parent 2fcedd9f09
commit a47a0162a6
5 changed files with 29 additions and 39 deletions

View File

@ -1,9 +1,7 @@
sudo: false
language: node_js
node_js:
- "4"
- "6"
- "7"
before_script:
- npm install -g grunt-cli
- mongo test_db --eval 'db.addUser("travis", "test");'

View File

@ -7,7 +7,7 @@
"url": "https://github.com/mailvelope/keyserver.git"
},
"engines": {
"node": ">=4"
"node": ">=6"
},
"scripts": {
"start": ": ${NODE_ENV=development} && node index.js",

View File

@ -31,9 +31,9 @@ class Mongo {
* @param {String} pass The database user's password
* @yield {undefined}
*/
*init(options) {
let uri = 'mongodb://' + options.user + ':' + options.pass + '@' + options.uri;
this._db = yield MongoClient.connect(uri);
*init({ uri, user, pass }) {
let url = 'mongodb://' + user + ':' + pass + '@' + uri;
this._db = yield MongoClient.connect(url);
}
/**

View File

@ -37,18 +37,18 @@ class Email {
* @param {boolean} starttls (optional) force STARTTLS to prevent downgrade attack. Defaults to true.
* @param {boolean} pgp (optional) if outgoing emails are encrypted to the user's public key.
*/
init(options) {
init({ host, port=465, auth, tls, starttls, pgp, sender }) {
this._transport = nodemailer.createTransport({
host: options.host,
port: options.port || 465,
auth: options.auth,
secure: (options.tls !== undefined) ? util.isTrue(options.tls) : true,
requireTLS: (options.starttls !== undefined) ? util.isTrue(options.starttls) : true,
host,
port,
auth,
secure: (tls !== undefined) ? util.isTrue(tls) : true,
requireTLS: (starttls !== undefined) ? util.isTrue(starttls) : true,
});
if (util.isTrue(options.pgp)) {
if (util.isTrue(pgp)) {
this._transport.use('stream', openpgpEncrypt());
}
this._sender = options.sender;
this._sender = sender;
}
/**
@ -59,8 +59,7 @@ class Email {
* @param {Object} origin origin of the server
* @yield {Object} send response from the SMTP server
*/
*send(options) {
let template = options.template, userId = options.userId, keyId = options.keyId, origin = options.origin;
*send({ template, userId, keyId, origin }) {
let message = {
from: this._sender,
to: userId,
@ -87,26 +86,25 @@ class Email {
* @param {Object} params (optional) nodermailer template parameters
* @yield {Object} reponse object containing SMTP info
*/
*_sendHelper(options) {
*_sendHelper({ from, to, subject, text, html, params={} }) {
let template = {
subject: options.subject,
text: options.text,
html: options.html,
encryptionKeys: [options.to.publicKeyArmored]
subject,
text,
html,
encryptionKeys: [to.publicKeyArmored]
};
let sender = {
from: {
name: options.from.name,
address: options.from.email
name: from.name,
address: from.email
}
};
let recipient = {
to: {
name: options.to.name,
address: options.to.email
name: to.name,
address: to.email
}
};
let params = options.params || {};
try {
let sendFn = this._transport.templateSender(template, sender);
@ -116,7 +114,7 @@ class Email {
}
return info;
} catch(error) {
log.error('email', 'Sending message failed.', error, options);
log.error('email', 'Sending message failed.', error);
util.throw(500, 'Sending email to user failed');
}
}

View File

@ -66,9 +66,8 @@ class PublicKey {
* @param {Object} origin Required for links to the keyserver e.g. { protocol:'https', host:'openpgpkeys@example.com' }
* @yield {undefined}
*/
*put(options) {
*put({ publicKeyArmored, primaryEmail, origin }) {
// parse key block
let publicKeyArmored = options.publicKeyArmored, primaryEmail = options.primaryEmail, origin = options.origin;
let key = this._pgp.parseKey(publicKeyArmored);
// check for existing verfied key by id or email addresses
let verified = yield this.getVerified(key);
@ -128,8 +127,7 @@ class PublicKey {
* @param {string} nonce The verification nonce proving email address ownership
* @yield {undefined}
*/
*verify(options) {
let keyId = options.keyId, nonce = options.nonce;
*verify({ keyId, nonce }) {
// look for verification nonce in database
let query = { keyId, 'userIds.nonce':nonce };
let key = yield this._mongo.get(query, DB_TYPE);
@ -157,8 +155,7 @@ class PublicKey {
* @param {string} keyId (optional) The public key id
* @yield {Object} The verified key document
*/
*getVerified(options) {
let fingerprint = options.fingerprint, userIds = options.userIds, keyId = options.keyId;
*getVerified({ userIds, fingerprint, keyId }) {
let queries = [];
// query by fingerprint
if (fingerprint) {
@ -196,8 +193,7 @@ class PublicKey {
* @param {String} email (optional) The user's email address
* @yield {Object} The public key document
*/
*get(options) {
let fingerprint = options.fingerprint, keyId = options.keyId, email = options.email;
*get({ fingerprint, keyId, email }) {
// look for verified key
let userIds = email ? [{ email:email }] : undefined;
let key = yield this.getVerified({ keyId, fingerprint, userIds });
@ -224,8 +220,7 @@ class PublicKey {
* @param {Object} origin Required for links to the keyserver e.g. { protocol:'https', host:'openpgpkeys@example.com' }
* @yield {undefined}
*/
*requestRemove(options) {
let keyId = options.keyId, email = options.email, origin = options.origin;
*requestRemove({ keyId, email, origin }) {
// flag user ids for removal
let key = yield this._flagForRemove(keyId, email);
if (!key) {
@ -277,8 +272,7 @@ class PublicKey {
* @param {string} nonce The verification nonce proving email address ownership
* @yield {undefined}
*/
*verifyRemove(options) {
let keyId = options.keyId, nonce = options.nonce;
*verifyRemove({ keyId, nonce }) {
// check if key exists in database
let flagged = yield this._mongo.get({ keyId, 'userIds.nonce':nonce }, DB_TYPE);
if (!flagged) {