-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge verify-token into /entities?token=
- Loading branch information
1 parent
975c345
commit b99c278
Showing
4 changed files
with
39 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ var request = require('supertest'); | |
var _ = require('lodash'); | ||
var entities = require('root/test/fixtures/entities'); | ||
var r = require('root/lib/r'); | ||
var jwt = require('jsonwebtoken'); | ||
|
||
const key = process.env.API_KEY; | ||
|
||
|
@@ -169,6 +170,35 @@ test('it should not return any Entity given an invalid token', function(t) { | |
.expect(403, pass(t, 'return 403 forbidden')) | ||
}); | ||
|
||
test('it should respond 404 for a valid token that contains a non-existent email', (t) => { | ||
var token = jwt.sign({email: '[email protected]'}, process.env.JWT_SECRET); | ||
request(server) | ||
.get('/entities?token='+token) | ||
.auth('test', key) | ||
.expect(404, pass(t, 'return 404 not found')) | ||
}); | ||
|
||
test('it should respond 401 Unauthorized if token expired', (t) => { | ||
var attr = {expiresIn: 1}; | ||
var token = jwt.sign({}, process.env.JWT_SECRET, attr); | ||
|
||
setTimeout(() => { | ||
request(server) | ||
.get('/entities?token='+token) | ||
.auth('test', key) | ||
.expect(401, pass(t, 'return 401 unauthorized')) | ||
}, 1100); | ||
}); | ||
|
||
test('it should respond 403 Forbidden if token invalid signature', (t) => { | ||
var token = jwt.sign({}, 'nope'); | ||
|
||
request(server) | ||
.get('/entities?token='+token) | ||
.auth('test', key) | ||
.expect(403, pass(t, 'return 403 Forbidden')) | ||
}); | ||
|
||
test('it should return the Entity associated with a valid email', function(t) { | ||
const entity = genEntity(); | ||
|
||
|