From 7d93b882a5cd2e573d6325187f8eb6ff0f9ee5b0 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Tue, 14 Jun 2016 16:46:17 +0200 Subject: [PATCH] Use DELETE method instead of GET for key removal --- README.md | 2 +- src/app.js | 3 +++ src/route/rest.js | 2 +- test/integration/app-test.js | 12 ++++++------ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index af7f93a..f2043ee 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ GET /api/v1/key?op=verify&keyId=b8e4105cc9dedc77&nonce=6a314915c09368224b11df0fe ### Request key removal ``` -GET /api/v1/key?op=remove&keyId=b8e4105cc9dedc77 OR ?email=user@example.com +DELETE /api/v1/key?keyId=b8e4105cc9dedc77 OR ?email=user@example.com ``` ### Verify key removal diff --git a/src/app.js b/src/app.js index 5353ede..1c66c9a 100644 --- a/src/app.js +++ b/src/app.js @@ -51,6 +51,9 @@ router.post('/api/v1/key', function *() { router.get('/api/v1/key', function *() { yield rest.query(this); }); +router.del('/api/v1/key', function *() { + yield rest.remove(this); +}); // Redirect all http traffic to https app.use(function *(next) { diff --git a/src/route/rest.js b/src/route/rest.js index 18adcf6..bf60bf3 100644 --- a/src/route/rest.js +++ b/src/route/rest.js @@ -56,7 +56,7 @@ class REST { */ *query(ctx) { let op = ctx.query.op; - if (this[op]) { + if (op === 'verify' || op === 'verifyRemove') { return yield this[op](ctx); // delegate operation } // do READ if no 'op' provided diff --git a/test/integration/app-test.js b/test/integration/app-test.js index e511c74..e87fb47 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 /api/v1/key?op=remove', () => { + describe('DELETE /api/v1/key', () => { beforeEach(done => { request(app.listen()) .post('/api/v1/key') @@ -201,28 +201,28 @@ describe('Koa App (HTTP Server) Integration Tests', function() { it('should return 202 for key id', done => { request(app.listen()) - .get('/api/v1/key?op=remove&keyId=' + emailParams.keyId) + .del('/api/v1/key?keyId=' + emailParams.keyId) .expect(202) .end(done); }); it('should return 202 for email address', done => { request(app.listen()) - .get('/api/v1/key?op=remove&email=' + primaryEmail) + .del('/api/v1/key?email=' + primaryEmail) .expect(202) .end(done); }); it('should return 400 for invalid params', done => { request(app.listen()) - .get('/api/v1/key?op=remove') + .del('/api/v1/key') .expect(400) .end(done); }); it('should return 404 for unknown email address', done => { request(app.listen()) - .get('/api/v1/key?op=remove&email=a@foo.com') + .del('/api/v1/key?email=a@foo.com') .expect(404) .end(done); }); @@ -236,7 +236,7 @@ describe('Koa App (HTTP Server) Integration Tests', function() { .expect(201) .end(function() { request(app.listen()) - .get('/api/v1/key?op=remove&keyId=' + emailParams.keyId) + .del('/api/v1/key?keyId=' + emailParams.keyId) .expect(202) .end(done); });