Skip to content

Commit 2aae445

Browse files
committed
validation error audits
1 parent e403aae commit 2aae445

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

src/audits/server.ts

+48-3
Original file line numberDiff line numberDiff line change
@@ -491,24 +491,69 @@ export function serverAudits(opts: ServerAuditOptions): Audit[] {
491491
await ressert(res).bodyAsExecutionResult.notToHaveProperty('errors');
492492
},
493493
),
494+
...['string', 0, false, ['array']].map((invalid, index) =>
495+
audit(
496+
`028${index}`,
497+
`MUST use 4xx or 5xx status codes on ${extendedTypeof(
498+
invalid,
499+
)} {extensions} parameter when accepting application/graphql-response+json`,
500+
async () => {
501+
const res = await fetchFn(await getUrl(opts.url), {
502+
method: 'POST',
503+
headers: {
504+
'content-type': 'application/json',
505+
accept: 'application/graphql-response+json',
506+
},
507+
body: JSON.stringify({
508+
query: '{ __typename }',
509+
extensions: invalid,
510+
}),
511+
});
512+
ressert(res).status.toBeBetween(400, 599);
513+
},
514+
),
515+
),
516+
...['string', 0, false, ['array']].map((invalid, index) =>
517+
audit(
518+
`233${index}`,
519+
`SHOULD use 4xx status code on ${extendedTypeof(
520+
invalid,
521+
)} {extensions} parameter when accepting application/graphql-response+json`,
522+
async () => {
523+
const res = await fetchFn(await getUrl(opts.url), {
524+
method: 'POST',
525+
headers: {
526+
'content-type': 'application/json',
527+
accept: 'application/graphql-response+json',
528+
},
529+
body: JSON.stringify({
530+
query: '{ __typename }',
531+
extensions: invalid,
532+
}),
533+
});
534+
ressert(res).status.toBeBetween(400, 499);
535+
},
536+
),
537+
),
494538
...['string', 0, false, ['array']].map((invalid, index) =>
495539
audit(
496540
`58B${index}`,
497-
`MUST use 400 status code on ${extendedTypeof(
541+
`SHOULD use 4xx or 5xx status codes on ${extendedTypeof(
498542
invalid,
499-
)} {extensions} parameter`,
543+
)} {extensions} parameter when accepting application/json`,
500544
async () => {
501545
const res = await fetchFn(await getUrl(opts.url), {
502546
method: 'POST',
503547
headers: {
504548
'content-type': 'application/json',
549+
accept: 'application/json',
505550
},
506551
body: JSON.stringify({
507552
query: '{ __typename }',
508553
extensions: invalid,
509554
}),
510555
});
511-
ressert(res).status.toBe(400);
556+
ressert(res).status.toBeBetween(400, 599);
512557
},
513558
),
514559
),

0 commit comments

Comments
 (0)