Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Parser and test #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ Jwt.prototype.isNotBefore = function() {
};

function Parser(options){
if(!(this instanceof Parser)){
return new Parser(options);
}
return this;
}

Expand Down Expand Up @@ -402,6 +405,7 @@ var jwtLib = {
Jwt: Jwt,
JwtBody: JwtBody,
JwtHeader: JwtHeader,
Parser: Parser,
Verifier: Verifier,
base64urlEncode: base64urlEncode,
base64urlUnescape:base64urlUnescape,
Expand Down
29 changes: 29 additions & 0 deletions test/parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var assert = require('chai').assert;
var uuid = require('uuid');
var nJwt = require('../');


describe('Parser', function () {
it('should construct itself if called without new', function () {
assert(nJwt.Parser() instanceof nJwt.Parser);
});
});
describe('Parser.parse()', function () {
var result = null
var claims = {hello: 'world'}
before(function(done){
var token = new nJwt.Jwt(claims, false)
.setSigningAlgorithm('none')
.compact();
var parser = nJwt.Parser();
parser.parse(token, function(err,res){
result = [err,res];
done();
});
});
it('should parse a valid token', function () {
assert.isNull(result[0], 'An error was not returned');
assert.equal(result[1].body.hello,claims.hello);
});

});