From 0975c0548ba1bb85037112356b85d6acb1ebf924 Mon Sep 17 00:00:00 2001 From: Soledad Pano Date: Wed, 23 Nov 2016 15:50:42 -0300 Subject: [PATCH] allow key to be a buffer --- lib/index.js | 2 +- test/index.js | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index a2a53d1..07d1ed9 100755 --- a/lib/index.js +++ b/lib/index.js @@ -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())), diff --git a/test/index.js b/test/index.js index 809ed09..64444ca 100755 --- a/test/index.js +++ b/test/index.js @@ -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();