Skip to content

Commit

Permalink
fix(test): crash if missing config token object
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Mar 27, 2019
1 parent c9ce050 commit ac3fe81
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ function start () {
}

function launchServer (db) {
var Chance = require('chance')
var chance = new Chance()

if (!nconf.get('tokens')) {
nconf.set('tokens:secret', chance.hash() + chance.md5())
nconf.set('tokens:expires', 900)
nconf.save(function (err) {
if (err) winston.warn(err)
})
}

var ws = require('./src/webserver')
ws.init(db, function (err) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/passport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module.exports = function () {
new JwtStrategy(
{
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: nconf.get('tokens').secret,
secretOrKey: nconf.get('tokens') ? nconf.get('tokens').secret : false,
ignoreExpiration: true
},
function (jwtPayload, done) {
Expand Down
9 changes: 9 additions & 0 deletions test/source/installServer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
var nconf = require('nconf')
nconf.argv().env()
nconf.overrides({
tokens: {
secret: 'TestSecretKey',
expires: 900
}
})

var is = require('../../src/webserver')

describe('installServer.js', function () {
Expand Down

0 comments on commit ac3fe81

Please sign in to comment.