-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
58 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,56 @@ | ||
'use strict'; | ||
|
||
const server = require('./server'); | ||
const Boom = require('@hapi/boom'); | ||
const jwt = require('jsonwebtoken'); | ||
const seedData = require('../testData/seeds'); | ||
const config = require('../config')[process.env.NODE_ENV || 'testing']; | ||
const mergeDefaults = require('./mergeDefaults'); | ||
|
||
const testRoute = { | ||
method: 'GET', | ||
path: '/', | ||
handler: async function (request, h) { | ||
try { | ||
await request.server.auth.verify(request); | ||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
|
||
} catch (err) { | ||
return Boom.unauthorize() | ||
const authTestRoute = { | ||
method: 'GET', | ||
config: { | ||
auth: 'default', | ||
handler: async function (request, h) { | ||
try { | ||
return request.auth.isAuthenticated; | ||
} catch (err) { | ||
return Boom.unauthorized(); | ||
} | ||
} | ||
} | ||
}, | ||
path: '/authTest' | ||
} | ||
|
||
|
||
before(async () => await server.liftOff()); | ||
before(async () => await server.liftOff(authTestRoute)); | ||
describe('post', () => { | ||
it ('replies 200 if provided valid signed JWT', async () => {}) | ||
it ('replies 200 when provided valid JWT', async () => { | ||
const request = mergeDefaults({ | ||
method: 'GET', | ||
headers: { Authorization: `Bearer ${seedData.fakeToken}` }, | ||
url: '/authTest' | ||
}); | ||
|
||
const r = await server.inject(request); | ||
expect(r.statusCode).to.eql(200); | ||
expect(r.result).to.eql(true); // result === isAuthenticated bool... | ||
}); | ||
|
||
it ('replies 401 when provided invalid or no JWT', async() => { | ||
let request = mergeDefaults({ | ||
method: 'GET', | ||
headers: { Authorization: 'Bearer blimBlam' }, | ||
url: '/authTest' | ||
}); | ||
let r = await server.inject(request); | ||
expect(r.statusCode).to.eql(401); | ||
|
||
request = mergeDefaults({ method: 'GET', url: '/authTest' }); | ||
r = await server.inject(request); | ||
expect(r.statusCode).to.eql(401); | ||
}); | ||
}); |