-
Notifications
You must be signed in to change notification settings - Fork 1
/
jwtSpec.js
49 lines (36 loc) · 1.99 KB
/
jwtSpec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
describe('jwt', function() {
beforeEach(function() {
module('angular-jwt.jwt');
});
describe('no expiration tokens', function() {
var infiniteToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEyMzQ1Njc4OTAsIm5hbWUiOiJKb2huIERvZSIsImFkbWluIjp0cnVlfQ.eoaDVGTClRdfxUZXiPs3f8FmJDkDE_VCQFXqKxpLsts';
it('should correctly decode it', inject(function (jwtHelper) {
var token = jwtHelper.decodeToken(infiniteToken);
expect(token.name).to.equal('John Doe');
}));
var multipleUrlCharactersToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEyMzQ1Njc4OTAsIm5hbWUiOiJKb2huIERvZWxsbO-jv2xsbO-jvyIsImFkbWluIjp0cnVlfQ.NCPM3vNwuvJGMIjR0csEFQDrSLcjm5P7ORumVq4ezmo';
it('should correctly decode tokens with multiple URL-safe characters', inject(function (jwtHelper) {
var token = jwtHelper.decodeToken(multipleUrlCharactersToken);
expect(token.name).to.equal('John Doellllll');
}));
it('should return no expiration', inject(function (jwtHelper) {
var date = jwtHelper.getTokenExpirationDate(infiniteToken);
expect(date).not.to.exist;
}));
it('should return not expired', inject(function (jwtHelper) {
expect(jwtHelper.isTokenExpired(infiniteToken)).to.be.false;
}));
});
describe('tokens with expiration', function() {
var expToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3NhbXBsZXMuYXV0aDAuY29tLyIsInN1YiI6ImZhY2Vib29rfDEwMTU0Mjg3MDI3NTEwMzAyIiwiYXVkIjoiQlVJSlNXOXg2MHNJSEJ3OEtkOUVtQ2JqOGVESUZ4REMiLCJleHAiOjE0MTIyMzQ3MzAsImlhdCI6MTQxMjE5ODczMH0.7M5sAV50fF1-_h9qVbdSgqAnXVF7mz3I6RjS6JiH0H8';
it('should correctly decode it', inject(function (jwtHelper) {
var token = jwtHelper.decodeToken(expToken);
expect(token.sub).to.equal('facebook|10154287027510302');
}));
it('should return an expiration', inject(function (jwtHelper) {
var date = jwtHelper.getTokenExpirationDate(expToken);
expect(date).to.eql(new Date(1412234730000));
}));
});
});