diff --git a/.travis.yml b/.travis.yml index 0645e6e..46e9da8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,4 @@ notifications: services: - mongodb env: - - MONGO_URI=127.0.0.1:27017/test_db MONGO_USER=travis MONGO_PASS=test SMTP_HOST=127.0.0.1 SMTP_USER=smtp_user SMTP_PASS=smtp_pass SENDER_NAME=Travis SENDER_EMAIL=travis@mailvelope.com \ No newline at end of file + - MONGO_URI=127.0.0.1:27017/test_db MONGO_USER=travis MONGO_PASS=test SMTP_HOST=127.0.0.1 SMTP_PORT=465 SMTP_TLS=true SMTP_USER=smtp_user SMTP_PASS=smtp_pass SENDER_NAME=Travis SENDER_EMAIL=travis@mailvelope.com \ No newline at end of file diff --git a/README.md b/README.md index 058f862..a4cc20f 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ GET /api/v1/key?email=user@example.com #### By email address (shorthand link for sharing) ``` -GET /user@example.com +GET /user/user@example.com ``` ### Request key removal @@ -194,7 +194,7 @@ db.createUser({ user:"keyserver-user", pwd:"trfepCpjhVrqgpXFWsEF", roles:[{ role ## Setup SMTP user -The key server uses [nodemailer](https://nodemailer.com) to send out emails upon public key upload to verify email address ownership. To test this feature locally, open the `credentials.json` file and change the `user@gmail.com` to your Gmail test account. Be sure that `smtp.user` and `sender.email` match. Otherwise the Gmail SMTP server will block any emails you try to send. Also, be sure to enable the "less secure apps" in the Gmail security settings. You can read how to do this in the [Nodemailer documentation](https://nodemailer.com/using-gmail/). +The key server uses [nodemailer](https://nodemailer.com) to send out emails upon public key upload to verify email address ownership. To test this feature locally, open the `credentials.json` file and change the `smtp.user` and `smtp.pass` attributes to your Gmail test account. Make sure that `smtp.user` and `sender.email` match. Otherwise the Gmail SMTP server will block any emails you try to send. Also, make sure to enable `Allow less secure apps` in the [Gmail security settings](https://myaccount.google.com/security#connectedapps). You can read more on this in the [Nodemailer documentation](https://nodemailer.com/using-gmail/). For production you should use a service like [Amazon SES](https://aws.amazon.com/ses/), [Mailgun](https://www.mailgun.com/) or [Sendgrid](https://sendgrid.com/solutions/transactional-email/). Nodemailer supports all of these out of the box. @@ -221,9 +221,11 @@ The `credentials.json` file can be used to configure a local development install * MONGO_USER=db_user * MONGO_PASS=db_password * SMTP_HOST=127.0.0.1 +* SMTP_PORT=465 +* SMTP_TLS=true * SMTP_USER=smtp_user * SMTP_PASS=smtp_pass -* SENDER_NAME=Sender +* SENDER_NAME="OpenPGP Key Server" * SENDER_EMAIL=noreply@example.com diff --git a/res/credentials.json b/res/credentials.json index 1deefa9..0c3de75 100644 --- a/res/credentials.json +++ b/res/credentials.json @@ -6,6 +6,8 @@ }, "smtp": { "host": "smtp.gmail.com", + "port": "465", + "tls": "true", "user": "user@gmail.com", "pass": "password" }, diff --git a/src/app.js b/src/app.js index 40b4095..4926cf0 100644 --- a/src/app.js +++ b/src/app.js @@ -63,7 +63,7 @@ router.get('/api/v1/verify', function *() { // ?keyid=keyid&nonce=nonce router.get('/api/v1/verifyRemove', function *() { // ?keyid=keyid&nonce=nonce yield rest.verifyRemove(this); }); -router.get('/:email', function *() { // shorthand link for sharing +router.get('/user/:email', function *() { // shorthand link for sharing yield rest.share(this); }); @@ -103,6 +103,8 @@ function injectDependencies() { email = new Email(nodemailer); email.init({ host: process.env.SMTP_HOST || credentials.smtp.host, + port: process.env.SMTP_PORT || credentials.smtp.port, + secure: (process.env.SMTP_TLS || credentials.smtp.tls) === 'true', auth: { user: process.env.SMTP_USER || credentials.smtp.user, pass: process.env.SMTP_PASS || credentials.smtp.pass diff --git a/src/email/email.js b/src/email/email.js index 56d4d80..c732330 100644 --- a/src/email/email.js +++ b/src/email/email.js @@ -47,8 +47,8 @@ class Email { host: options.host, port: options.port || 465, auth: options.auth, - secure: options.secure || true, - requireTLS: options.requireTLS || true + secure: (options.secure !== undefined) ? options.secure : true, + requireTLS: (options.secure !== undefined) ? options.secure : true }); this._sender = options.sender; } diff --git a/test/integration/app-test.js b/test/integration/app-test.js index 5ba312f..403b5a3 100644 --- a/test/integration/app-test.js +++ b/test/integration/app-test.js @@ -200,7 +200,7 @@ describe('Koa App (HTTP Server) Integration Tests', function() { }); }); - describe('GET /:email (sharing link)', () => { + describe('GET /user/:email (sharing link)', () => { beforeEach(done => { request(app.listen()) .post('/api/v1/key') @@ -212,7 +212,7 @@ describe('Koa App (HTTP Server) Integration Tests', function() { describe('Not yet verified', () => { it('should return 404', done => { request(app.listen()) - .get('/' + primaryEmail) + .get('/user/' + primaryEmail) .expect(404) .end(done); }); @@ -228,28 +228,28 @@ describe('Koa App (HTTP Server) Integration Tests', function() { it('should return 200 for correct email address', done => { request(app.listen()) - .get('/' + primaryEmail) + .get('/user/' + primaryEmail) .expect(200, publicKeyArmored) .end(done); }); it('should return 400 for invalid email', done => { request(app.listen()) - .get('/a@bco') + .get('/user/a@bco') .expect(400) .end(done); }); it('should return 404 for unkown email', done => { request(app.listen()) - .get('/a@b.co') + .get('/user/a@b.co') .expect(404) .end(done); }); it('should return 404 for missing email', done => { request(app.listen()) - .get('/') + .get('/user/') .expect(404) .end(done); }); diff --git a/test/integration/email-test.js b/test/integration/email-test.js index 6a3751b..d44b06b 100644 --- a/test/integration/email-test.js +++ b/test/integration/email-test.js @@ -37,6 +37,8 @@ describe('Email Integration Tests', function() { email = new Email(nodemailer); email.init({ host: process.env.SMTP_HOST || credentials.smtp.host, + port: process.env.SMTP_PORT || credentials.smtp.port, + secure: (process.env.SMTP_TLS || credentials.smtp.tls) === 'true', auth: { user: process.env.SMTP_USER || credentials.smtp.user, pass: process.env.SMTP_PASS || credentials.smtp.pass