Skip to content

Commit fe6f60d

Browse files
committed
feat(server): Data entry audits when accepting application/graphql-response+json
1 parent f7b29a7 commit fe6f60d

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/audits/server.ts

+52
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,20 @@ export function serverAudits(opts: ServerAuditOptions): Audit[] {
438438
assert('Status code', res.status).toBe(400);
439439
},
440440
),
441+
audit(
442+
'SHOULD not contain the data entry on JSON parsing failure when accepting application/graphql-response+json',
443+
async () => {
444+
const res = await fetchFn(opts.url, {
445+
method: 'POST',
446+
headers: {
447+
'content-type': 'application/json',
448+
accept: 'application/graphql-response+json',
449+
},
450+
body: '{ "not a JSON',
451+
});
452+
assert('Data entry', (await res.json()).data).toBe(undefined);
453+
},
454+
),
441455
audit(
442456
'MUST use 4xx or 5xx status codes if parameters are invalid when accepting application/graphql-response+json',
443457
async () => {
@@ -463,6 +477,18 @@ export function serverAudits(opts: ServerAuditOptions): Audit[] {
463477
assert('Status code', res.status).toBe(400);
464478
},
465479
),
480+
audit(
481+
'SHOULD not contain the data entry if parameters are invalid when accepting application/graphql-response+json',
482+
async () => {
483+
const url = new URL(opts.url);
484+
url.searchParams.set('qeury' /* typo */, '{ __typename }');
485+
const res = await fetchFn(url.toString(), {
486+
method: 'GET',
487+
headers: { accept: 'application/graphql-response+json' },
488+
});
489+
assert('Data entry', (await res.json()).data).toBe(undefined);
490+
},
491+
),
466492
audit(
467493
'MUST use 4xx or 5xx status codes on document parsing failure when accepting application/graphql-response+json',
468494
async () => {
@@ -488,6 +514,18 @@ export function serverAudits(opts: ServerAuditOptions): Audit[] {
488514
assert('Status code', res.status).toBe(400);
489515
},
490516
),
517+
audit(
518+
'SHOULD not contain the data entry on document parsing failure when accepting application/graphql-response+json',
519+
async () => {
520+
const url = new URL(opts.url);
521+
url.searchParams.set('query', '{');
522+
const res = await fetchFn(url.toString(), {
523+
method: 'GET',
524+
headers: { accept: 'application/graphql-response+json' },
525+
});
526+
assert('Data entry', (await res.json()).data).toBe(undefined);
527+
},
528+
),
491529
audit(
492530
'MUST use 4xx or 5xx status codes on document validation failure when accepting application/graphql-response+json',
493531
async () => {
@@ -513,6 +551,20 @@ export function serverAudits(opts: ServerAuditOptions): Audit[] {
513551
assert('Status code', res.status).toBe(400);
514552
},
515553
),
554+
audit(
555+
'SHOULD not contain the data entry on document validation failure when accepting application/graphql-response+json',
556+
async () => {
557+
const url = new URL(opts.url);
558+
url.searchParams.set('query', '{ 8f31403dfe404bccbb0e835f2629c6a7 }'); // making sure the field doesnt exist
559+
const res = await fetchFn(url.toString(), {
560+
method: 'GET',
561+
headers: { accept: 'application/graphql-response+json' },
562+
});
563+
assert('Data entry', (await res.json()).data).toBe(undefined);
564+
},
565+
),
566+
// TODO: how to fail and have the data entry?
567+
// audit('MUST use 2xx status code if response contains the data entry and it is not null when accepting application/graphql-response+json'),
516568
// TODO: how to make an unauthorized request?
517569
// https://graphql.github.io/graphql-over-http/draft/#sel-EANNNDTAAEVBAAqqc
518570
// audit('SHOULD use 401 or 403 status codes when the request is not permitted')

0 commit comments

Comments
 (0)