From 5674a2e8c9ea2e8e36bf3860ba6d9bebcfc1a428 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Sat, 21 Jan 2017 11:30:26 +0000 Subject: [PATCH 1/9] Replace grunt with npm scripts --- .jshintrc | 2 ++ Gruntfile.js | 41 ----------------------------- package.json | 12 +++++---- test/integration/app-test.js | 4 --- test/integration/email-test.js | 3 --- test/integration/mongo-test.js | 3 --- test/integration/public-key-test.js | 4 --- test/mocha.opts | 2 ++ test/setup.js | 9 +++++++ test/unit/email-test.js | 5 ---- test/unit/pgp-test.js | 2 -- test/unit/util-test.js | 1 - 12 files changed, 20 insertions(+), 68 deletions(-) delete mode 100644 Gruntfile.js create mode 100644 test/mocha.opts create mode 100644 test/setup.js diff --git a/.jshintrc b/.jshintrc index acc3c51..598d3c1 100644 --- a/.jshintrc +++ b/.jshintrc @@ -15,6 +15,8 @@ "esnext": true, "globals": { + "expect": true, + "sinon": true, "describe" : true, "it" : true, "before" : true, diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index 985e5cc..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -module.exports = function(grunt) { - - grunt.initConfig({ - jshint: { - all: ['*.js', 'src/**/*.js', 'test/**/*.js'], - options: { - jshintrc: '.jshintrc' - } - }, - - jscs: { - src: ['*.js', 'src/**/*.js', 'test/**/*.js'], - options: { - config: ".jscsrc" - } - }, - - mochaTest: { - test: { - options: { - reporter: 'spec' - }, - src: [ - 'test/unit/*.js', - 'test/integration/*.js', - ] - } - } - }); - - // Load the plugin(s) - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-jscs'); - grunt.loadNpmTasks('grunt-mocha-test'); - - // Default task(s). - grunt.registerTask('test', ['jshint', 'jscs', 'mochaTest']); - -}; \ No newline at end of file diff --git a/package.json b/package.json index 6b999f7..5f93dc9 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,11 @@ }, "scripts": { "start": ": ${NODE_ENV=development} && node index.js", - "test": ": ${NODE_ENV=development} && grunt test" + "test": ": ${NODE_ENV=development} && npm run test:jshint && npm run test:jscs && npm run test:unit && npm run test:integration", + "test:jshint": "jshint *.js src/**/*.js test/**/*.js", + "test:jscs": "jscs *.js src/**/*.js test/**/*.js", + "test:unit": "mocha --opts test/mocha.opts ./test/unit/", + "test:integration": "mocha --opts test/mocha.opts ./test/integration" }, "dependencies": { "addressparser": "^1.0.1", @@ -30,10 +34,8 @@ "devDependencies": { "chai": "^3.5.0", "co-mocha": "^1.1.2", - "grunt": "^1.0.1", - "grunt-contrib-jshint": "^1.0.0", - "grunt-jscs": "^3.0.1", - "grunt-mocha-test": "^0.13.2", + "jscs": "^3.0.7", + "jshint": "^2.9.4", "mocha": "^3.2.0", "sinon": "^1.17.4", "supertest": "^2.0.1" diff --git a/test/integration/app-test.js b/test/integration/app-test.js index e87fb47..7615287 100644 --- a/test/integration/app-test.js +++ b/test/integration/app-test.js @@ -1,14 +1,10 @@ 'use strict'; -require('co-mocha')(require('mocha')); // monkey patch mocha for generators - const request = require('supertest'); const Mongo = require('../../src/dao/mongo'); const nodemailer = require('nodemailer'); const config = require('config'); const fs = require('fs'); -const expect = require('chai').expect; -const sinon = require('sinon'); describe('Koa App (HTTP Server) Integration Tests', function() { this.timeout(20000); diff --git a/test/integration/email-test.js b/test/integration/email-test.js index bab0319..2b0101b 100644 --- a/test/integration/email-test.js +++ b/test/integration/email-test.js @@ -1,8 +1,5 @@ 'use strict'; -require('co-mocha')(require('mocha')); // monkey patch mocha for generators - -const expect = require('chai').expect; const config = require('config'); const Email = require('../../src/email/email'); const tpl = require('../../src/email/templates.json'); diff --git a/test/integration/mongo-test.js b/test/integration/mongo-test.js index e7a7316..b7254c8 100644 --- a/test/integration/mongo-test.js +++ b/test/integration/mongo-test.js @@ -1,10 +1,7 @@ 'use strict'; -require('co-mocha')(require('mocha')); // monkey patch mocha for generators - const config = require('config'); const Mongo = require('../../src/dao/mongo'); -const expect = require('chai').expect; describe('Mongo Integration Tests', function() { this.timeout(20000); diff --git a/test/integration/public-key-test.js b/test/integration/public-key-test.js index 6f27bfc..a682f11 100644 --- a/test/integration/public-key-test.js +++ b/test/integration/public-key-test.js @@ -1,15 +1,11 @@ 'use strict'; -require('co-mocha')(require('mocha')); // monkey patch mocha for generators - const config = require('config'); const nodemailer = require('nodemailer'); const Email = require('../../src/email/email'); const Mongo = require('../../src/dao/mongo'); const PGP = require('../../src/service/pgp'); const PublicKey = require('../../src/service/public-key'); -const expect = require('chai').expect; -const sinon = require('sinon'); describe('Public Key Integration Tests', function() { this.timeout(20000); diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 0000000..b43dd66 --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1,2 @@ +--recursive +-r ./test/setup.js diff --git a/test/setup.js b/test/setup.js new file mode 100644 index 0000000..31e9669 --- /dev/null +++ b/test/setup.js @@ -0,0 +1,9 @@ +'use strict'; + +require('co-mocha')(require('mocha')); // monkey patch mocha for generators + +const expect = require('chai').expect; +const sinon = require('sinon'); + +global.expect = expect; +global.sinon = sinon; diff --git a/test/unit/email-test.js b/test/unit/email-test.js index 0e88a42..5905787 100644 --- a/test/unit/email-test.js +++ b/test/unit/email-test.js @@ -1,13 +1,8 @@ 'use strict'; -require('co-mocha')(require('mocha')); // monkey patch mocha for generators - -const expect = require('chai').expect; const log = require('npmlog'); const Email = require('../../src/email/email'); const nodemailer = require('nodemailer'); -const sinon = require('sinon'); - describe('Email Unit Tests', () => { let email, sendFnStub; diff --git a/test/unit/pgp-test.js b/test/unit/pgp-test.js index d4b31c1..e56a5e3 100644 --- a/test/unit/pgp-test.js +++ b/test/unit/pgp-test.js @@ -1,11 +1,9 @@ 'use strict'; const fs = require('fs'); -const expect = require('chai').expect; const log = require('npmlog'); const openpgp = require('openpgp'); const PGP = require('../../src/service/pgp'); -const sinon = require('sinon'); describe('PGP Unit Tests', () => { let pgp, key1Armored, key2Armored, key3Armored; diff --git a/test/unit/util-test.js b/test/unit/util-test.js index ec7a5ee..7f989d7 100644 --- a/test/unit/util-test.js +++ b/test/unit/util-test.js @@ -1,6 +1,5 @@ 'use strict'; -const expect = require('chai').expect; const util = require('../../src/service/util'); describe('Util Unit Tests', () => { From a47a0162a6677187bd529ea73b81b40486643d2c Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Sat, 21 Jan 2017 11:51:33 +0000 Subject: [PATCH 2/9] Use ES6 destructuring (not available in node v4) --- .travis.yml | 2 -- package.json | 2 +- src/dao/mongo.js | 6 +++--- src/email/email.js | 40 +++++++++++++++++++-------------------- src/service/public-key.js | 18 ++++++------------ 5 files changed, 29 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index e4d9c61..ce22855 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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");' diff --git a/package.json b/package.json index 6b999f7..82c2072 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "url": "https://github.com/mailvelope/keyserver.git" }, "engines": { - "node": ">=4" + "node": ">=6" }, "scripts": { "start": ": ${NODE_ENV=development} && node index.js", diff --git a/src/dao/mongo.js b/src/dao/mongo.js index 2416d16..6658729 100644 --- a/src/dao/mongo.js +++ b/src/dao/mongo.js @@ -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); } /** diff --git a/src/email/email.js b/src/email/email.js index f047c87..92f4b67 100644 --- a/src/email/email.js +++ b/src/email/email.js @@ -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'); } } diff --git a/src/service/public-key.js b/src/service/public-key.js index 64b45f8..f2d9a93 100644 --- a/src/service/public-key.js +++ b/src/service/public-key.js @@ -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) { From cb37c834d8e44f8dcf398904d27a16d4ff2d0b11 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Sat, 21 Jan 2017 12:16:03 +0000 Subject: [PATCH 3/9] Remove grunt from travis.yml --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e4d9c61..356d933 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ node_js: - "6" - "7" before_script: - - npm install -g grunt-cli - mongo test_db --eval 'db.addUser("travis", "test");' notifications: email: From 9898383230c682a8aebdae4e2fdf005299a135b4 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Mon, 30 Jan 2017 00:24:15 +0000 Subject: [PATCH 4/9] chore(package): update supertest to version 3.0.0 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6b999f7..803cf92 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,6 @@ "grunt-mocha-test": "^0.13.2", "mocha": "^3.2.0", "sinon": "^1.17.4", - "supertest": "^2.0.1" + "supertest": "^3.0.0" } } From b2455393b2312c1233640b4f3c5c780ab33178f2 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Fri, 24 Mar 2017 03:31:00 +0000 Subject: [PATCH 5/9] fix(package): update co-body to version 5.1.1 Closes #23 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6b999f7..3fe5832 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "dependencies": { "addressparser": "^1.0.1", "co": "^4.6.0", - "co-body": "^4.2.0", + "co-body": "^5.1.1", "config": "^1.20.4", "koa": "^1.2.0", "koa-router": "^5.4.0", From 505b337d9a970edf8a09379fa459fd675c969058 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Sat, 5 Aug 2017 07:58:26 +0000 Subject: [PATCH 6/9] chore(package): update chai to version 4.1.1 Closes #33 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6b999f7..e9a745c 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "openpgp": "^2.3.0" }, "devDependencies": { - "chai": "^3.5.0", + "chai": "^4.1.1", "co-mocha": "^1.1.2", "grunt": "^1.0.1", "grunt-contrib-jshint": "^1.0.0", From 469afdac912046dee5de40e73a643eb2a62cfad1 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Mon, 14 Aug 2017 11:57:55 +0800 Subject: [PATCH 7/9] Update to current mongoldb driver --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f1c9739..ce34a41 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "koa": "^1.2.0", "koa-router": "^5.4.0", "koa-static": "^2.0.0", - "mongodb": "^2.1.20", + "mongodb": "^2.2.31", "nodemailer": "^2.4.2", "nodemailer-openpgp": "^1.0.2", "npmlog": "^4.0.2", From 252053dd138c0737be3654b3804d72a3576bc40c Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Mon, 14 Aug 2017 12:05:33 +0800 Subject: [PATCH 8/9] Ignore npm v5+ package-lock.json to let greenkeeper monitor updates. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 7d33200..2e047d1 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,6 @@ node_modules # Optional REPL history .node_repl_history + +# npm v5+ lockfile +package-lock.json From b397fa00cd828c5ba83a697443354d02a3f30775 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Mon, 14 Aug 2017 12:18:16 +0800 Subject: [PATCH 9/9] Ignore incompatible nodemailer updates. Nodemailer v3+ no longer has an internal template engine. Closes #20 --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index 44512b6..54da635 100644 --- a/package.json +++ b/package.json @@ -39,5 +39,10 @@ "mocha": "^3.2.0", "sinon": "^1.17.4", "supertest": "^3.0.0" + }, + "greenkeeper": { + "ignore": [ + "nodemailer" + ] } }