Skip to content

Commit

Permalink
Fix inconsistency for results associated to skipped blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
satazor committed Aug 3, 2024
1 parent 29e5e01 commit 0df7319
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/parser/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const parseSecurity = (operation, spec, securityHandlers) => {
const blockHasMissingValues = Object.keys(block).some(name => readSchemeValue(name) == null);

if (blockHasMissingValues) {
report.push({ schemes: {}, status: 'skipped' });
report.push({ ok: false, schemes: {} });
continue;
}

Expand Down
19 changes: 18 additions & 1 deletion src/parser/security.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,29 @@ describe('parseSecurity()', () => {

const onRequest = parseSecurity(operation, spec, securityHandlers);

expect.assertions(2);
expect.assertions(3);

await onRequest(request);

expect(securityHandlers.ApiKey).not.toHaveBeenCalled();
expect(securityHandlers.OAuth2).toHaveBeenCalledTimes(1);
expect(request[DECORATOR_NAME].securityReport).toMatchInlineSnapshot(`
[
{
"ok": false,
"schemes": {},
},
{
"ok": true,
"schemes": {
"OAuth2": {
"data": "OAuth2 data",
"ok": true,
},
},
},
]
`);
});

it('should validate scopes', async () => {
Expand Down
15 changes: 3 additions & 12 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare module 'fastify' {
[DECORATOR_NAME]: {
operation: OpenAPI.OpenAPIV3_1.OperationObject,
security: RequestSecurity
securityReport: RequestSecurityReportEntry[]
securityReport: RequestSecurityReport
}
}

Expand All @@ -20,11 +20,9 @@ declare module 'fastify' {
}
}

export interface RequestSecurity {
[key:string]: any
}
export interface RequestSecurityReport extends Array<RequestSecurityReportBlock> {}

export interface RequestSecurityReportEntry {
export interface RequestSecurityReportBlock {
ok: boolean
schemes: {
[key:string]: {
Expand All @@ -35,13 +33,6 @@ export interface RequestSecurityReportEntry {
}
}

export interface RequestSecurityReportResult {
ok: boolean
schemes: {
[key:string]: RequestSecurityReportResult
}
}

export type SecurityHandler = (value: string, request: FastifyRequest) => SecurityHandlerReturn | undefined

export interface SecurityHandlerReturn { data?: any, scopes?: string[] }
Expand Down

0 comments on commit 0df7319

Please sign in to comment.