Skip to content

Commit

Permalink
handle undefined security handlers when security is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Oct 12, 2019
1 parent 5bc1ab6 commit 8787246
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/middlewares/openapi.security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export function security(
return next(validationError(500, path, message));
}

if (securities.length > 0 && !securityHandlers) {
const names = securities.reduce((a, i) => {
const p = Object.keys(i);
return a.concat(p);
}, []);
const message = `attempt to use securities ${names}, but no securityHandlers defined.`;
return next(validationError(500, path, message));
}

try {
const results = await new SecuritySchemes(
securitySchemes,
Expand Down Expand Up @@ -75,13 +84,6 @@ class SecuritySchemes {
}

executeHandlers(req: OpenApiRequest): Promise<SecurityHandlerResult[]> {
if (this.securities && !this.securityHandlers) {
const names = Object.keys(this.securities).join(', ');
throw {
status: 500,
message: `attempt to use securities ${names}, but no securityHandlers defined.`,
};
}
const promises = this.securities.map(async s => {
try {
const securityKey = Object.keys(s)[0];
Expand Down

0 comments on commit 8787246

Please sign in to comment.