Skip to content

Commit caffcae

Browse files
committed
feat(audit): graphql-response+json parsing failure handling
Relevant section: 6.4.2 application/graphql-response+json https://graphql.github.io/graphql-over-http/draft/#sel-FANNNRCAACENz5F https://graphql.github.io/graphql-over-http/draft/#sel-HANNNXFFCAACCP8kC
1 parent 5587c03 commit caffcae

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/audits/server.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,21 @@ export function serverAudits(opts: ServerAuditOptions): Audit[] {
586586
ressert(res).status.toBe(400);
587587
},
588588
),
589+
audit(
590+
'B7N8',
591+
'SHOULD use 400 status code on JSON parsing failure when accepting application/graphql-response+json',
592+
async () => {
593+
const res = await fetchFn(await getUrl(opts.url), {
594+
method: 'POST',
595+
headers: {
596+
'content-type': 'application/json',
597+
accept: 'application/graphql-response+json',
598+
},
599+
body: '{ "not a JSON',
600+
});
601+
ressert(res).status.toBe(400);
602+
},
603+
),
589604
audit(
590605
'8764',
591606
'MAY use 4xx or 5xx status codes if parameters are invalid',

tests/__snapshots__/audits.test.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ exports[`should not change globally unique audit ids 1`] = `
194194
"id": "BCF8",
195195
"name": "MAY use 400 status code on JSON parsing failure",
196196
},
197+
{
198+
"id": "B7N8",
199+
"name": "SHOULD use 400 status code on JSON parsing failure when accepting application/graphql-response+json",
200+
},
197201
{
198202
"id": "8764",
199203
"name": "MAY use 4xx or 5xx status codes if parameters are invalid",

0 commit comments

Comments
 (0)