Use DELETE method instead of GET for key removal
This commit is contained in:
parent
1a7b57777b
commit
7d93b882a5
@ -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
|
||||||
|
@ -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) {
|
||||||
|
@ -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
|
||||||
|
@ -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);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user