Skip to content

Commit

Permalink
Merge pull request #7 from firstandthird/no-default-auth
Browse files Browse the repository at this point in the history
default auth no
  • Loading branch information
orthagonal authored Aug 17, 2018
2 parents 72868f0 + db7cf22 commit d83eacf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ const register = function(server, options) {
path: settings.endpoint,
handler
};
// set auth to false to explicitly turn off the
// registered default server strategy:
// if auth is undefined set it to false to avoid the default auth:
if (options.auth === undefined || options.auth === null) {
options.auth = false;
}
if (options.auth || options.auth === false) {
routeConfig.config = {
auth: options.auth
Expand Down
30 changes: 30 additions & 0 deletions test/healthcheck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,36 @@ lab.test('if auth is false, turn off the default auth', async() => {
code.expect(result.payload.memory).to.be.an.object();
});

lab.test('if auth is undeclared, also turn off the default auth', async() => {
const boom = require('boom');
server.auth.scheme('custom', () => ({
authenticate(request, h) {
const authorization = request.query ? request.query.authorization : undefined;
if (!authorization) {
throw boom.unauthorized(null, 'Custom');
}
return h.authenticated({ credentials: { user: 'john' } });
}
}));
server.auth.strategy('default', 'custom');
server.auth.default('default');
await server.register({
plugin: hapiHealthcheck,
options: {
}
});
await server.start();

const result = await wreck.get('http://localhost:8000/health', { json: 'force' });
code.expect(result.payload).to.be.an.object();
code.expect(result.payload.host).to.equal(server.info.host);
code.expect(result.payload.env).to.equal(process.env.NODE_ENV);
code.expect(result.payload.uptime).to.exist();
code.expect(result.payload.cpu).to.be.an.object();
code.expect(result.payload.version).to.be.a.string();
code.expect(result.payload.memory).to.be.an.object();
});

lab.test('default options', async() => {
await server.register({
plugin: hapiHealthcheck,
Expand Down

0 comments on commit d83eacf

Please sign in to comment.