Skip to content

Commit

Permalink
allow key to be a buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Soledad Pano committed Nov 23, 2016
1 parent c483e8b commit 0975c05
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var jwt = require('jsonwebtoken');
var Joi = require('joi');

var optionsSchema = Joi.object().keys({
key: Joi.alternatives().try(Joi.string(),Joi.func()).required(),
key: Joi.alternatives().try(Joi.binary(),Joi.func()).required(),
validateFunc: Joi.func(),
algorithms: Joi.array().items(Joi.string()),
audience: Joi.alternatives().try(Joi.string(),Joi.array().items(Joi.string())),
Expand Down
17 changes: 16 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,12 +723,27 @@ describe('Strategy', function(){
}
catch(err){
expect(err).to.exist;
expect(err.message).to.equal('child "key" fails because ["key" must be a string, "key" must be a Function]');
expect(err.message).to.equal('child "key" fails because ["key" must be a buffer or a string, "key" must be a Function]');
done();
}
});
});

it('should work if strategy is initialized with a Bugger as key in options', function (done) {
var server = new Hapi.Server({ debug: false });
server.connection();
server.register(require('../'), function (err) {
expect(err).to.not.exist;
try {
server.auth.strategy('default', 'jwt', 'required', {key: new Buffer('mySuperSecret', 'base64')});
done();
}
catch(err){
done(err);
}
});
});

it('should fail if strategy is initialized with an invalid audience type in options', function (done) {
var server = new Hapi.Server({ debug: false });
server.connection();
Expand Down

0 comments on commit 0975c05

Please sign in to comment.