Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

Fallback security to root api if missing in verb or path specification #62

Merged
merged 5 commits into from
Nov 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/buildroutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function buildroutes(options) {
name: operation.operationId,
description: operation.description,
method: verb,
security: buildSecurity(options, api.securityDefinitions, operation.security || def.security),
security: buildSecurity(options, api.securityDefinitions, operation.security || def.security || api.security),
validators: [],
handler : undefined,
consumes: operation.consumes || api.consumes,
Expand Down
13 changes: 5 additions & 8 deletions test/fixtures/defs/pets.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"produces": [
"application/json"
],
"security": [
{
"default": ["read"]
}
],
"paths": {
"/pets": {
"x-handler": "extensions/pets.js",
Expand All @@ -33,14 +38,6 @@
"produces": [
"application/json"
],
"security": [
{
"default": ["read"]
},
{
"secondary": ["read"]
}
],
"jsonp": "callback",
"cache":{
"statuses":[200]
Expand Down
50 changes: 25 additions & 25 deletions test/test-routebuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ test('routebuilder', function (t) {
t.strictEqual(routes.length, 4, 'added 4 routes.');

routes.forEach(function (route) {
t.ok(route.hasOwnProperty('method'), 'has method property.');
t.ok(route.hasOwnProperty('description'), 'has validate property.');
t.ok(route.hasOwnProperty('name'), 'has name property.');
t.ok(route.hasOwnProperty('path'), 'has path property.');
t.ok(route.hasOwnProperty('security'), 'has security property.');
t.ok(route.hasOwnProperty('validators'), 'has before property.');
t.notEqual(route.method, 'has method property.');
t.notEqual(route.description, undefined, 'has validate property.');
t.notEqual(route.name, undefined, 'has name property.');
t.notEqual(route.path, undefined, 'has path property.');
t.notEqual(route.security, undefined, 'has security property.');
t.notEqual(route.validators, undefined, 'has before property.');
if(route.method === 'get' && route.path === '/pets'){
t.ok(route.jsonp === 'callback', 'options property is the right one.');
t.ok(route.cache.statuses.join(',') === '200', 'options property is the right one.');
t.ok(route.config.plugins.policies.join(', ') === 'isLoggedIn, addTracking, logThis', 'options property is the right one.');
}
t.ok(route.hasOwnProperty('handler'), 'has handler property.');
t.ok(route.hasOwnProperty('produces'), 'has validate property.');
t.notEqual(route.handler, undefined, 'has handler property.');
t.notEqual(route.produces, undefined, 'has validate property.');
});

t.end();
Expand All @@ -58,14 +58,14 @@ test('routebuilder', function (t) {
t.strictEqual(routes.length, 2, 'added 2 routes.');

routes.forEach(function (route) {
t.ok(route.hasOwnProperty('method'), 'has method property.');
t.ok(route.hasOwnProperty('description'), 'has validate property.');
t.ok(route.hasOwnProperty('name'), 'has name property.');
t.ok(route.hasOwnProperty('path'), 'has path property.');
t.ok(route.hasOwnProperty('security'), 'has security property.');
t.ok(route.hasOwnProperty('validators'), 'has before property.');
t.ok(route.hasOwnProperty('handler'), 'has handler property.');
t.ok(route.hasOwnProperty('produces'), 'has validate property.');
t.notEqual(route.method, undefined, 'has method property.');
t.notEqual(route.description, undefined, 'has validate property.');
t.notEqual(route.name, undefined, 'has name property.');
t.notEqual(route.path, undefined, 'has path property.');
t.notEqual(route.security, undefined, 'has security property.');
t.notEqual(route.validators, undefined, 'has before property.');
t.notEqual(route.handler, undefined, 'has handler property.');
t.notEqual(route.produces, undefined, 'has validate property.');
});

t.end();
Expand Down Expand Up @@ -171,15 +171,15 @@ test('routebuilder', function (t) {
t.strictEqual(routes.length, 2, 'added 1 routes.');

routes.forEach(function (route) {
t.ok(route.hasOwnProperty('method'), 'has method property.');
t.ok(route.hasOwnProperty('description'), 'has validate property.');
t.ok(route.hasOwnProperty('name'), 'has name property.');
t.ok(route.hasOwnProperty('path'), 'has path property.');
t.ok(route.hasOwnProperty('security'), 'has security property.');
t.ok(route.hasOwnProperty('validators'), 'has validators property.');
t.ok(route.hasOwnProperty('handler'), 'has handler property.');
t.ok(route.hasOwnProperty('produces'), 'has produces property.');
t.ok(route.hasOwnProperty('consumes'), 'has consumes property.');
t.notEqual(route.method, undefined, 'has method property.');
t.equal(route.description, undefined, 'has no description property.');
t.notEqual(route.name, undefined, 'has name property.');
t.notEqual(route.path, undefined, 'has path property.');
t.equal(route.security, undefined, 'has no security property.');
t.notEqual(route.validators, undefined, 'has validators property.');
t.notEqual(route.handler, undefined, 'has handler property.');
t.notEqual(route.produces, undefined, 'has produces property.');
t.notEqual(route.consumes, undefined, 'has consumes property.');
});

t.end();
Expand Down