Use DELETE method instead of GET for key removal

This commit is contained in:
Tankred Hase 2016-06-14 16:46:17 +02:00
parent 1a7b57777b
commit 7d93b882a5
4 changed files with 11 additions and 8 deletions

View File

@ -137,7 +137,7 @@ GET /api/v1/key?op=verify&keyId=b8e4105cc9dedc77&nonce=6a314915c09368224b11df0fe
### Request key removal ### 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 ### Verify key removal

View File

@ -51,6 +51,9 @@ router.post('/api/v1/key', function *() {
router.get('/api/v1/key', function *() { router.get('/api/v1/key', function *() {
yield rest.query(this); yield rest.query(this);
}); });
router.del('/api/v1/key', function *() {
yield rest.remove(this);
});
// Redirect all http traffic to https // Redirect all http traffic to https
app.use(function *(next) { app.use(function *(next) {

View File

@ -56,7 +56,7 @@ class REST {
*/ */
*query(ctx) { *query(ctx) {
let op = ctx.query.op; let op = ctx.query.op;
if (this[op]) { if (op === 'verify' || op === 'verifyRemove') {
return yield this[op](ctx); // delegate operation return yield this[op](ctx); // delegate operation
} }
// do READ if no 'op' provided // do READ if no 'op' provided

View File

@ -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 => { beforeEach(done => {
request(app.listen()) request(app.listen())
.post('/api/v1/key') .post('/api/v1/key')
@ -201,28 +201,28 @@ describe('Koa App (HTTP Server) Integration Tests', function() {
it('should return 202 for key id', done => { it('should return 202 for key id', done => {
request(app.listen()) request(app.listen())
.get('/api/v1/key?op=remove&keyId=' + emailParams.keyId) .del('/api/v1/key?keyId=' + emailParams.keyId)
.expect(202) .expect(202)
.end(done); .end(done);
}); });
it('should return 202 for email address', done => { it('should return 202 for email address', done => {
request(app.listen()) request(app.listen())
.get('/api/v1/key?op=remove&email=' + primaryEmail) .del('/api/v1/key?email=' + primaryEmail)
.expect(202) .expect(202)
.end(done); .end(done);
}); });
it('should return 400 for invalid params', done => { it('should return 400 for invalid params', done => {
request(app.listen()) request(app.listen())
.get('/api/v1/key?op=remove') .del('/api/v1/key')
.expect(400) .expect(400)
.end(done); .end(done);
}); });
it('should return 404 for unknown email address', done => { it('should return 404 for unknown email address', done => {
request(app.listen()) request(app.listen())
.get('/api/v1/key?op=remove&email=a@foo.com') .del('/api/v1/key?email=a@foo.com')
.expect(404) .expect(404)
.end(done); .end(done);
}); });
@ -236,7 +236,7 @@ describe('Koa App (HTTP Server) Integration Tests', function() {
.expect(201) .expect(201)
.end(function() { .end(function() {
request(app.listen()) request(app.listen())
.get('/api/v1/key?op=remove&keyId=' + emailParams.keyId) .del('/api/v1/key?keyId=' + emailParams.keyId)
.expect(202) .expect(202)
.end(done); .end(done);
}); });