Skip to content

feat(audit): graphql-response+json parsing failure handling #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions src/audits/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,21 @@ export function serverAudits(opts: ServerAuditOptions): Audit[] {
ressert(res).status.toBe(400);
},
),
audit(
'B7N8',
'SHOULD use 400 status code on JSON parsing failure when accepting application/graphql-response+json',
async () => {
const res = await fetchFn(await getUrl(opts.url), {
method: 'POST',
headers: {
'content-type': 'application/json',
accept: 'application/graphql-response+json',
},
body: '{ "not a JSON',
});
ressert(res).status.toBe(400);
},
),
audit(
'8764',
'MAY use 4xx or 5xx status codes if parameters are invalid',
Expand Down
4 changes: 4 additions & 0 deletions tests/__snapshots__/audits.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ exports[`should not change globally unique audit ids 1`] = `
"id": "BCF8",
"name": "MAY use 400 status code on JSON parsing failure",
},
{
"id": "B7N8",
"name": "SHOULD use 400 status code on JSON parsing failure when accepting application/graphql-response+json",
},
{
"id": "8764",
"name": "MAY use 4xx or 5xx status codes if parameters are invalid",
Expand Down
Loading