diff --git a/src/app.js b/src/app.js index 0857a0c..db94091 100644 --- a/src/app.js +++ b/src/app.js @@ -66,7 +66,7 @@ router.get('/api/v1/removeKey', function *() { router.get('/api/v1/verifyRemove', function *() { yield rest.verifyRemove(this); }); -router.get('/user/:email', function *() { +router.get('/user/:search', function *() { yield rest.share(this); }); diff --git a/src/route/rest.js b/src/route/rest.js index dbb094d..477ff5f 100644 --- a/src/route/rest.js +++ b/src/route/rest.js @@ -59,7 +59,10 @@ class REST { ctx.throw(400, 'Invalid request!'); } yield this._publicKey.verify(q); - ctx.body = 'Key successfully verified!'; + // create link for sharing + let link = util.url(util.origin(ctx), '/user/' + q.keyId.toUpperCase()); + ctx.body = `

Key successfully verified!

Link to share your key: ${link}

`; + ctx.set('Content-Type', 'text/html; charset=utf-8'); } /** @@ -79,8 +82,15 @@ class REST { * @param {Object} ctx The koa request/response context */ *share(ctx) { - let q = { email:ctx.params.email }; - if (!util.isEmail(q.email)) { + let q, search = ctx.params.search; + if (util.isEmail(search)) { + q = { email:search }; + } else if (util.isKeyId(search)) { + q = { keyId:search }; + } else if (util.isFingerPrint(search)) { + q = { fingerprint:search }; + } + if (!q) { ctx.throw(400, 'Invalid request!'); } ctx.body = (yield this._publicKey.get(q)).publicKeyArmored; diff --git a/test/integration/app-test.js b/test/integration/app-test.js index 6cf6a7b..9e4f176 100644 --- a/test/integration/app-test.js +++ b/test/integration/app-test.js @@ -190,7 +190,7 @@ describe('Koa App (HTTP Server) Integration Tests', function() { }); }); - describe('GET /user/:email (sharing link)', () => { + describe('GET /user/:search (sharing link)', () => { beforeEach(done => { request(app.listen()) .post('/api/v1/key') @@ -216,13 +216,27 @@ describe('Koa App (HTTP Server) Integration Tests', function() { .end(done); }); - it('should return 200 for correct email address', done => { + it('should return 200 for email address', done => { request(app.listen()) .get('/user/' + primaryEmail) .expect(200, publicKeyArmored) .end(done); }); + it('should return 200 for key id', done => { + request(app.listen()) + .get('/user/' + emailParams.keyId) + .expect(200, publicKeyArmored) + .end(done); + }); + + it('should return 200 for fingerprint', done => { + request(app.listen()) + .get('/user/' + fingerprint) + .expect(200, publicKeyArmored) + .end(done); + }); + it('should return 400 for invalid email', done => { request(app.listen()) .get('/user/a@bco')