Skip to content

Commit

Permalink
Fixed lib and tests for default strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-LyN-10 committed Nov 14, 2017
1 parent eb77487 commit c67c665
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
8 changes: 4 additions & 4 deletions lib/index.js
Expand Up @@ -99,18 +99,18 @@ internals.getRouteInfo = function (server, options) {
routes: []
};

internals.connectionInfo(routingTable, options, connectionInfo);
internals.connectionInfo(server, routingTable, options, connectionInfo);

return [connectionInfo];
};

internals.connectionInfo = function (routes, options, connectionInfo) {
internals.connectionInfo = function (server, routes, options, connectionInfo) {

for (let i = 0; i < routes.length; ++i) {
const route = routes[i];

const defaultStrategy = Hoek.reach(route, 'server.auth.settings.default.strategies');
let authStrategy = route.settings.auth ? route.settings.auth.strategies.toString() : false;
const defaultStrategy = Hoek.reach(server, 'auth.settings.default.strategies');
let authStrategy = typeof route.settings.auth === 'object' ? route.settings.auth.strategies.toString() : false;

if (route.settings.auth === undefined) {
authStrategy = defaultStrategy ? String(defaultStrategy) : false;
Expand Down
27 changes: 10 additions & 17 deletions test/index.js
Expand Up @@ -28,11 +28,11 @@ const internals = {
authResult: [{
routes: [
{ method: 'GET', path: '/', description: 'main index', auth: false },
{ method: 'GET', path: '/all', description: 'a route on all connections', auth: 'findme' },
{ method: 'GET', path: '/api', description: 'api routes', auth: 'findme' },
{ method: 'POST', path: '/apost/{foo}/comment/{another}', description: '', auth: 'findme' },
{ method: 'GET', path: '/all', description: 'a route on all connections', auth: false },
{ method: 'GET', path: '/api', description: 'api routes', auth: false },
{ method: 'POST', path: '/apost/{foo}/comment/{another}', description: '', auth: false },
{ method: 'GET', path: '/hi', description: '', auth: 'findme' },
{ method: 'DELETE', path: '/post/{id}', description: '', auth: 'findme' }
{ method: 'DELETE', path: '/post/{id}', description: '', auth: false }
]
}],
defaultAuthResult: [{
Expand Down Expand Up @@ -77,7 +77,6 @@ internals.prepareServer = async function (options) {
path: '/api',
options: {
description: 'api routes',
auth: options.authType ? 'findme' : null,
handler: function (request, h) {

return 'index!';
Expand Down Expand Up @@ -121,24 +120,18 @@ internals.prepareServer = async function (options) {
plugin.route({
method: 'POST',
path: '/apost/{foo}/comment/{another}',
options: {
auth: options.authType ? 'findme' : null,
handler: function (request, h) {
handler: function (request, h) {

return '';
}
return '';
}
});

plugin.route({
method: 'DELETE',
path: '/post/{id}',
options: {
auth: options.authType ? 'findme' : null,
handler: function (request, h) {
handler: function (request, h) {

return '';
}
return '';
}
});
}
Expand All @@ -152,7 +145,6 @@ internals.prepareServer = async function (options) {
path: '/all',
options: {
description: 'a route on all connections',
auth: options.authType ? 'findme' : null,
handler: function (request, h) {

return 'index!';
Expand Down Expand Up @@ -193,6 +185,7 @@ describe('routes', () => {

console.log = saved;
expect(out).to.not.match(/none.*main index/);
expect(out).to.not.match(/none.*api index/);
expect(out).to.match(/DELETE.*post/);

});
Expand Down Expand Up @@ -228,7 +221,7 @@ describe('routes', () => {

const text = server.plugins[Pkg.name].text();
expect(text).to.match(/none.*main index/);
expect(text).to.match(/findme.*api routes/);
expect(text).to.match(/none.*api routes/);
expect(text).to.match(/hi.*findme/);
});

Expand Down

0 comments on commit c67c665

Please sign in to comment.