Skip to content

Commit

Permalink
Merge 4ca2166 into 79fa146
Browse files Browse the repository at this point in the history
  • Loading branch information
siyb committed Dec 2, 2019
2 parents 79fa146 + 4ca2166 commit 85d18e6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/route/route-exposure-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ class RouteExposureHandler {
}

isRouteExposed(httpVerb, route) {
const result = !this.exposedRoutes[route] || !this.exposedRoutes[route][httpVerb] === false;
const result =
!this.exposedRoutes[route] ||
(this.exposedRoutes[route][httpVerb] === null || this.exposedRoutes[route][httpVerb] === undefined) ||
!this.exposedRoutes[route][httpVerb] === false;
if (this.exposedRoutes[route] && this.exposedRoutes[route][httpVerb] === true && route === '/search' && httpVerb === 'get') {
console.error('exposing /search via GET will be removed.');
}
Expand Down
18 changes: 15 additions & 3 deletions test/lib/route/route-exposure-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,33 @@ const sinon = require('sinon');

describe('RouteExposureHandler', () => {
describe('isRouteExposed', () => {
it('should expose a route if no rule was specified', () => {
it('should expose a route if no rules were specified', () => {
expect(new RouteExposureHandler({}).isRouteExposed('get', '/:id')).to.be.true;
});
it('should expose a route if no rules for the method were specified but rules for other methods were specified', () => {
const rules = new RouteExposureHandler({
'/': {
post: false
}
});
expect(rules.isRouteExposed('get', '/')).to.be.true;
expect(rules.isRouteExposed('post', '/')).to.be.false;
expect(rules.isRouteExposed('head', '/')).to.be.true;
expect(rules.isRouteExposed('put', '/')).to.be.true;
expect(rules.isRouteExposed('patch', '/')).to.be.true;
});
it('should not expose a route if specified', () => {
expect(new RouteExposureHandler({
'/:id': {
get: false
}}).isRouteExposed('get', '/:id')).to.be.false;
});
it('should expose a route if specified', () => {
expect(new RouteExposureHandler(({
expect(new RouteExposureHandler({
'/:id': {
get: true
}
}).isRouteExposed('get', '/:id'))).to.be.true;
}).isRouteExposed('get', '/:id')).to.be.true;
});
it('should print an error if the user exposed /search via GET', () => {
const consoleStub = sinon.stub(console, 'error');
Expand Down
1 change: 1 addition & 0 deletions test/version-sequelize-4/sequelize4.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ describe('sequelize4', () => {
require('../lib/openapi/sequelize/model-converter.test')(Sequelize4);
require('../lib/data-mapper/sequelize/operator-table.test');
require('../lib/data-mapper/sequelize/query-builder.test')(Sequelize4);
require('../lib/route/route-exposure-handler.test');
});

1 change: 1 addition & 0 deletions test/version-sequelize-5/sequelize5.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ describe('sequelize5', () => {
require('../lib/openapi/sequelize/model-converter.test')(Sequelize5);
require('../lib/data-mapper/sequelize/operator-table.test');
require('../lib/data-mapper/sequelize/query-builder.test')(Sequelize5);
require('../lib/route/route-exposure-handler.test');
});

0 comments on commit 85d18e6

Please sign in to comment.