graphql-http 1.3.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -26
- package/lib/audits/common.d.ts +58 -0
- package/lib/audits/common.js +7 -0
- package/lib/audits/common.mjs +6 -0
- package/lib/audits/index.d.ts +2 -0
- package/lib/audits/index.js +18 -0
- package/lib/audits/index.mjs +2 -0
- package/lib/audits/server.d.ts +39 -0
- package/lib/audits/server.js +440 -0
- package/lib/audits/server.mjs +435 -0
- package/lib/audits/utils.d.ts +27 -0
- package/lib/audits/utils.js +100 -0
- package/lib/audits/utils.mjs +81 -0
- package/lib/handler.d.ts +8 -2
- package/lib/handler.js +13 -8
- package/lib/handler.mjs +13 -8
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.mjs +1 -0
- package/lib/utils.d.ts +3 -1
- package/lib/utils.js +12 -1
- package/lib/utils.mjs +10 -0
- package/package.json +20 -17
- package/umd/graphql-http.min.js.gz +0 -0
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* audit/server
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.auditServer = exports.serverAudits = void 0;
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
/**
|
|
11
|
+
* List of server audits required to check GraphQL over HTTP spec conformance.
|
|
12
|
+
*
|
|
13
|
+
* @category Audits
|
|
14
|
+
*/
|
|
15
|
+
function serverAudits(opts) {
|
|
16
|
+
const fetchFn = (opts.fetchFn || fetch);
|
|
17
|
+
return [
|
|
18
|
+
// Media Types
|
|
19
|
+
(0, utils_1.audit)('MUST accept application/graphql-response+json and match the content-type', async () => {
|
|
20
|
+
const url = new URL(opts.url);
|
|
21
|
+
url.searchParams.set('query', '{ __typename }');
|
|
22
|
+
const res = await fetchFn(url.toString(), {
|
|
23
|
+
headers: {
|
|
24
|
+
accept: 'application/graphql-response+json',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
28
|
+
(0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('application/graphql-response+json');
|
|
29
|
+
}),
|
|
30
|
+
(0, utils_1.audit)('MUST accept application/json and match the content-type', async () => {
|
|
31
|
+
const url = new URL(opts.url);
|
|
32
|
+
url.searchParams.set('query', '{ __typename }');
|
|
33
|
+
const res = await fetchFn(url.toString(), {
|
|
34
|
+
headers: {
|
|
35
|
+
accept: 'application/json',
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
39
|
+
(0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('application/json');
|
|
40
|
+
}),
|
|
41
|
+
(0, utils_1.audit)('MUST accept */* and use application/graphql-response+json for the content-type', async () => {
|
|
42
|
+
const url = new URL(opts.url);
|
|
43
|
+
url.searchParams.set('query', '{ __typename }');
|
|
44
|
+
const res = await fetchFn(url.toString(), {
|
|
45
|
+
headers: {
|
|
46
|
+
accept: '*/*',
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
50
|
+
(0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('application/graphql-response+json');
|
|
51
|
+
}),
|
|
52
|
+
(0, utils_1.audit)('MUST assume application/graphql-response+json content-type when accept is missing', async () => {
|
|
53
|
+
const url = new URL(opts.url);
|
|
54
|
+
url.searchParams.set('query', '{ __typename }');
|
|
55
|
+
const res = await fetchFn(url.toString());
|
|
56
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
57
|
+
(0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('application/graphql-response+json');
|
|
58
|
+
}),
|
|
59
|
+
(0, utils_1.audit)('MUST use utf-8 charset in response', async () => {
|
|
60
|
+
const url = new URL(opts.url);
|
|
61
|
+
url.searchParams.set('query', '{ __typename }');
|
|
62
|
+
const res = await fetchFn(url.toString());
|
|
63
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
64
|
+
(0, utils_1.assert)('Content-Type header', res.headers.get('content-type')).toContain('charset=utf-8');
|
|
65
|
+
}),
|
|
66
|
+
(0, utils_1.audit)('MUST accept only utf-8 charset', async () => {
|
|
67
|
+
const url = new URL(opts.url);
|
|
68
|
+
url.searchParams.set('query', '{ __typename }');
|
|
69
|
+
const res = await fetchFn(url.toString(), {
|
|
70
|
+
headers: {
|
|
71
|
+
accept: 'application/graphql-response+json; charset=iso-8859-1',
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
(0, utils_1.assert)('Status code', res.status).toBe(406);
|
|
75
|
+
(0, utils_1.assert)('Accept header', res.headers.get('accept')).toContain('charset=utf-8');
|
|
76
|
+
}),
|
|
77
|
+
// Request
|
|
78
|
+
(0, utils_1.audit)('MUST accept POST requests', async () => {
|
|
79
|
+
const res = await fetchFn(opts.url, {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: { 'content-type': 'application/json' },
|
|
82
|
+
body: JSON.stringify({ query: '{ __typename }' }),
|
|
83
|
+
});
|
|
84
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
85
|
+
}),
|
|
86
|
+
(0, utils_1.audit)('MAY accept application/x-www-form-urlencoded formatted GET requests', async () => {
|
|
87
|
+
const url = new URL(opts.url);
|
|
88
|
+
url.searchParams.set('query', '{ __typename }');
|
|
89
|
+
const res = await fetchFn(url.toString());
|
|
90
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
91
|
+
}),
|
|
92
|
+
// Request GET
|
|
93
|
+
(0, utils_1.audit)('MUST NOT allow executing mutations on GET requests', async () => {
|
|
94
|
+
const url = new URL(opts.url);
|
|
95
|
+
url.searchParams.set('query', 'mutation { __typename }');
|
|
96
|
+
const res = await fetchFn(url.toString(), {
|
|
97
|
+
headers: {
|
|
98
|
+
accept: 'application/graphql-response+json',
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
(0, utils_1.assert)('Status code', res.status).toBe(405);
|
|
102
|
+
}),
|
|
103
|
+
// Request POST
|
|
104
|
+
(0, utils_1.audit)('SHOULD respond with 4xx status code if content-type is not supplied on POST requests', async () => {
|
|
105
|
+
const res = await fetchFn(opts.url, {
|
|
106
|
+
method: 'POST',
|
|
107
|
+
});
|
|
108
|
+
(0, utils_1.assert)('Status code', res.status).toBeGreaterThanOrEqual(400);
|
|
109
|
+
(0, utils_1.assert)('Status code', res.status).toBeLessThanOrEqual(599);
|
|
110
|
+
}),
|
|
111
|
+
(0, utils_1.audit)('MUST accept application/json POST requests', async () => {
|
|
112
|
+
const res = await fetchFn(opts.url, {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
headers: { 'content-type': 'application/json' },
|
|
115
|
+
body: JSON.stringify({ query: '{ __typename }' }),
|
|
116
|
+
});
|
|
117
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
118
|
+
}),
|
|
119
|
+
(0, utils_1.audit)('MUST require a request body on POST', async () => {
|
|
120
|
+
const res = await fetchFn(opts.url, {
|
|
121
|
+
method: 'POST',
|
|
122
|
+
headers: { 'content-type': 'application/json' },
|
|
123
|
+
});
|
|
124
|
+
(0, utils_1.assert)('Status code', res.status).toBe(400);
|
|
125
|
+
}),
|
|
126
|
+
// Request Parameters
|
|
127
|
+
(0, utils_1.audit)('MUST require the {query} parameter', async () => {
|
|
128
|
+
const res = await fetchFn(opts.url, {
|
|
129
|
+
method: 'POST',
|
|
130
|
+
headers: {
|
|
131
|
+
'content-type': 'application/json',
|
|
132
|
+
accept: 'application/graphql-response+json',
|
|
133
|
+
},
|
|
134
|
+
body: JSON.stringify({ notquery: '{ __typename }' }),
|
|
135
|
+
});
|
|
136
|
+
(0, utils_1.assert)('Status code', res.status).toBe(400);
|
|
137
|
+
}),
|
|
138
|
+
...[{ obj: 'ect' }, 0, false, ['array']].map((invalid) => (0, utils_1.audit)(`MUST NOT allow ${(0, utils_1.extendedTypeof)(invalid)} for the {query} parameter`, async () => {
|
|
139
|
+
const res = await fetchFn(opts.url, {
|
|
140
|
+
method: 'POST',
|
|
141
|
+
headers: {
|
|
142
|
+
'content-type': 'application/json',
|
|
143
|
+
accept: 'application/graphql-response+json',
|
|
144
|
+
},
|
|
145
|
+
body: JSON.stringify({
|
|
146
|
+
query: invalid,
|
|
147
|
+
}),
|
|
148
|
+
});
|
|
149
|
+
(0, utils_1.assert)('Status code', res.status).toBe(400);
|
|
150
|
+
})),
|
|
151
|
+
(0, utils_1.audit)('MUST accept a string for the {query} parameter', async () => {
|
|
152
|
+
const res = await fetchFn(opts.url, {
|
|
153
|
+
method: 'POST',
|
|
154
|
+
headers: {
|
|
155
|
+
'content-type': 'application/json',
|
|
156
|
+
accept: 'application/graphql-response+json',
|
|
157
|
+
},
|
|
158
|
+
body: JSON.stringify({
|
|
159
|
+
query: '{ __typename }',
|
|
160
|
+
}),
|
|
161
|
+
});
|
|
162
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
163
|
+
}),
|
|
164
|
+
...[{ obj: 'ect' }, 0, false, ['array']].map((invalid) => (0, utils_1.audit)(`MUST NOT allow ${(0, utils_1.extendedTypeof)(invalid)} for the {operationName} parameter`, async () => {
|
|
165
|
+
const res = await fetchFn(opts.url, {
|
|
166
|
+
method: 'POST',
|
|
167
|
+
headers: {
|
|
168
|
+
'content-type': 'application/json',
|
|
169
|
+
accept: 'application/graphql-response+json',
|
|
170
|
+
},
|
|
171
|
+
body: JSON.stringify({
|
|
172
|
+
operationName: invalid,
|
|
173
|
+
query: '{ __typename }',
|
|
174
|
+
}),
|
|
175
|
+
});
|
|
176
|
+
(0, utils_1.assert)('Status code', res.status).toBe(400);
|
|
177
|
+
})),
|
|
178
|
+
(0, utils_1.audit)('MUST accept a string for the {operationName} parameter', async () => {
|
|
179
|
+
const res = await fetchFn(opts.url, {
|
|
180
|
+
method: 'POST',
|
|
181
|
+
headers: {
|
|
182
|
+
'content-type': 'application/json',
|
|
183
|
+
accept: 'application/graphql-response+json',
|
|
184
|
+
},
|
|
185
|
+
body: JSON.stringify({
|
|
186
|
+
operationName: 'Query',
|
|
187
|
+
query: 'query Query { __typename }',
|
|
188
|
+
}),
|
|
189
|
+
});
|
|
190
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
191
|
+
}),
|
|
192
|
+
...['string', 0, false, ['array']].map((invalid) => (0, utils_1.audit)(`MUST NOT allow ${(0, utils_1.extendedTypeof)(invalid)} for the {variables} parameter`, async () => {
|
|
193
|
+
const res = await fetchFn(opts.url, {
|
|
194
|
+
method: 'POST',
|
|
195
|
+
headers: {
|
|
196
|
+
'content-type': 'application/json',
|
|
197
|
+
accept: 'application/graphql-response+json',
|
|
198
|
+
},
|
|
199
|
+
body: JSON.stringify({
|
|
200
|
+
query: '{ __typename }',
|
|
201
|
+
variables: invalid,
|
|
202
|
+
}),
|
|
203
|
+
});
|
|
204
|
+
(0, utils_1.assert)('Status code', res.status).toBe(400);
|
|
205
|
+
})),
|
|
206
|
+
(0, utils_1.audit)('MUST accept a map for the {variables} parameter', async () => {
|
|
207
|
+
const res = await fetchFn(opts.url, {
|
|
208
|
+
method: 'POST',
|
|
209
|
+
headers: {
|
|
210
|
+
'content-type': 'application/json',
|
|
211
|
+
accept: 'application/graphql-response+json',
|
|
212
|
+
},
|
|
213
|
+
body: JSON.stringify({
|
|
214
|
+
query: 'query Type($name: String!) { __type(name: $name) { name } }',
|
|
215
|
+
variables: { name: 'sometype' },
|
|
216
|
+
}),
|
|
217
|
+
});
|
|
218
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
219
|
+
const result = (await res.json());
|
|
220
|
+
(0, utils_1.assert)('Execution result', result).notToHaveProperty('errors');
|
|
221
|
+
}),
|
|
222
|
+
(0, utils_1.audit)('MUST accept a URL-encoded JSON string for the {variables} parameter in GETs', async () => {
|
|
223
|
+
const url = new URL(opts.url);
|
|
224
|
+
url.searchParams.set('query', 'query Type($name: String!) { __type(name: $name) { name } }');
|
|
225
|
+
url.searchParams.set('variables', JSON.stringify({ name: 'sometype' }));
|
|
226
|
+
const res = await fetchFn(url.toString(), {
|
|
227
|
+
method: 'GET',
|
|
228
|
+
});
|
|
229
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
230
|
+
const result = (await res.json());
|
|
231
|
+
(0, utils_1.assert)('Execution result', result).notToHaveProperty('errors');
|
|
232
|
+
}),
|
|
233
|
+
...['string', 0, false, ['array']].map((invalid) => (0, utils_1.audit)(`MUST NOT allow ${(0, utils_1.extendedTypeof)(invalid)} for the {extensions} parameter`, async () => {
|
|
234
|
+
const res = await fetchFn(opts.url, {
|
|
235
|
+
method: 'POST',
|
|
236
|
+
headers: {
|
|
237
|
+
'content-type': 'application/json',
|
|
238
|
+
accept: 'application/graphql-response+json',
|
|
239
|
+
},
|
|
240
|
+
body: JSON.stringify({
|
|
241
|
+
query: '{ __typename }',
|
|
242
|
+
extensions: invalid,
|
|
243
|
+
}),
|
|
244
|
+
});
|
|
245
|
+
(0, utils_1.assert)('Status code', res.status).toBe(400);
|
|
246
|
+
})),
|
|
247
|
+
(0, utils_1.audit)('MUST accept a map for the {extensions} parameter', async () => {
|
|
248
|
+
const res = await fetchFn(opts.url, {
|
|
249
|
+
method: 'POST',
|
|
250
|
+
headers: {
|
|
251
|
+
'content-type': 'application/json',
|
|
252
|
+
accept: 'application/graphql-response+json',
|
|
253
|
+
},
|
|
254
|
+
body: JSON.stringify({
|
|
255
|
+
query: '{ __typename }',
|
|
256
|
+
extensions: { some: 'value' },
|
|
257
|
+
}),
|
|
258
|
+
});
|
|
259
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
260
|
+
}),
|
|
261
|
+
// TODO: audit('MUST accept a map for the {extensions} parameter'),
|
|
262
|
+
// Response application/json
|
|
263
|
+
(0, utils_1.audit)('SHOULD use 200 status code on JSON parsing failure when accepting application/json', async () => {
|
|
264
|
+
const res = await fetchFn(opts.url, {
|
|
265
|
+
method: 'POST',
|
|
266
|
+
headers: {
|
|
267
|
+
'content-type': 'application/json',
|
|
268
|
+
accept: 'application/json',
|
|
269
|
+
},
|
|
270
|
+
body: '{ "not a JSON',
|
|
271
|
+
});
|
|
272
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
273
|
+
}),
|
|
274
|
+
(0, utils_1.audit)('SHOULD use 200 status code if parameters are invalid when accepting application/json', async () => {
|
|
275
|
+
const url = new URL(opts.url);
|
|
276
|
+
url.searchParams.set('qeury' /* typo */, '{ __typename }');
|
|
277
|
+
const res = await fetchFn(url.toString(), {
|
|
278
|
+
method: 'GET',
|
|
279
|
+
headers: { accept: 'application/json' },
|
|
280
|
+
});
|
|
281
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
282
|
+
}),
|
|
283
|
+
(0, utils_1.audit)('SHOULD use 200 status code on document parsing failure when accepting application/json', async () => {
|
|
284
|
+
const url = new URL(opts.url);
|
|
285
|
+
url.searchParams.set('query', '{');
|
|
286
|
+
const res = await fetchFn(url.toString(), {
|
|
287
|
+
method: 'GET',
|
|
288
|
+
headers: { accept: 'application/json' },
|
|
289
|
+
});
|
|
290
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
291
|
+
}),
|
|
292
|
+
(0, utils_1.audit)('SHOULD use 200 status code on document validation failure when accepting application/json', async () => {
|
|
293
|
+
const url = new URL(opts.url);
|
|
294
|
+
url.searchParams.set('query', '{ 8f31403dfe404bccbb0e835f2629c6a7 }'); // making sure the field doesnt exist
|
|
295
|
+
const res = await fetchFn(url.toString(), {
|
|
296
|
+
method: 'GET',
|
|
297
|
+
headers: { accept: 'application/json' },
|
|
298
|
+
});
|
|
299
|
+
(0, utils_1.assert)('Status code', res.status).toBe(200);
|
|
300
|
+
}),
|
|
301
|
+
// Response application/graphql-response+json
|
|
302
|
+
(0, utils_1.audit)('MUST use 4xx or 5xx status codes on JSON parsing failure when accepting application/graphql-response+json', async () => {
|
|
303
|
+
const res = await fetchFn(opts.url, {
|
|
304
|
+
method: 'POST',
|
|
305
|
+
headers: {
|
|
306
|
+
'content-type': 'application/json',
|
|
307
|
+
accept: 'application/graphql-response+json',
|
|
308
|
+
},
|
|
309
|
+
body: '{ "not a JSON',
|
|
310
|
+
});
|
|
311
|
+
(0, utils_1.assert)('Status code', res.status).toBeGreaterThanOrEqual(400);
|
|
312
|
+
(0, utils_1.assert)('Status code', res.status).toBeLessThanOrEqual(599);
|
|
313
|
+
}),
|
|
314
|
+
(0, utils_1.audit)('SHOULD use 400 status code on JSON parsing failure when accepting application/graphql-response+json', async () => {
|
|
315
|
+
const res = await fetchFn(opts.url, {
|
|
316
|
+
method: 'POST',
|
|
317
|
+
headers: {
|
|
318
|
+
'content-type': 'application/json',
|
|
319
|
+
accept: 'application/graphql-response+json',
|
|
320
|
+
},
|
|
321
|
+
body: '{ "not a JSON',
|
|
322
|
+
});
|
|
323
|
+
(0, utils_1.assert)('Status code', res.status).toBe(400);
|
|
324
|
+
}),
|
|
325
|
+
(0, utils_1.audit)('SHOULD not contain the data entry on JSON parsing failure when accepting application/graphql-response+json', async () => {
|
|
326
|
+
const res = await fetchFn(opts.url, {
|
|
327
|
+
method: 'POST',
|
|
328
|
+
headers: {
|
|
329
|
+
'content-type': 'application/json',
|
|
330
|
+
accept: 'application/graphql-response+json',
|
|
331
|
+
},
|
|
332
|
+
body: '{ "not a JSON',
|
|
333
|
+
});
|
|
334
|
+
(0, utils_1.assert)('Data entry', (await res.json()).data).toBe(undefined);
|
|
335
|
+
}),
|
|
336
|
+
(0, utils_1.audit)('MUST use 4xx or 5xx status codes if parameters are invalid when accepting application/graphql-response+json', async () => {
|
|
337
|
+
const url = new URL(opts.url);
|
|
338
|
+
url.searchParams.set('qeury' /* typo */, '{ __typename }');
|
|
339
|
+
const res = await fetchFn(url.toString(), {
|
|
340
|
+
method: 'GET',
|
|
341
|
+
headers: { accept: 'application/graphql-response+json' },
|
|
342
|
+
});
|
|
343
|
+
(0, utils_1.assert)('Status code', res.status).toBeGreaterThanOrEqual(400);
|
|
344
|
+
(0, utils_1.assert)('Status code', res.status).toBeLessThanOrEqual(599);
|
|
345
|
+
}),
|
|
346
|
+
(0, utils_1.audit)('SHOULD use 400 status code if parameters are invalid when accepting application/graphql-response+json', async () => {
|
|
347
|
+
const url = new URL(opts.url);
|
|
348
|
+
url.searchParams.set('qeury' /* typo */, '{ __typename }');
|
|
349
|
+
const res = await fetchFn(url.toString(), {
|
|
350
|
+
method: 'GET',
|
|
351
|
+
headers: { accept: 'application/graphql-response+json' },
|
|
352
|
+
});
|
|
353
|
+
(0, utils_1.assert)('Status code', res.status).toBe(400);
|
|
354
|
+
}),
|
|
355
|
+
(0, utils_1.audit)('SHOULD not contain the data entry if parameters are invalid when accepting application/graphql-response+json', async () => {
|
|
356
|
+
const url = new URL(opts.url);
|
|
357
|
+
url.searchParams.set('qeury' /* typo */, '{ __typename }');
|
|
358
|
+
const res = await fetchFn(url.toString(), {
|
|
359
|
+
method: 'GET',
|
|
360
|
+
headers: { accept: 'application/graphql-response+json' },
|
|
361
|
+
});
|
|
362
|
+
(0, utils_1.assert)('Data entry', (await res.json()).data).toBe(undefined);
|
|
363
|
+
}),
|
|
364
|
+
(0, utils_1.audit)('MUST use 4xx or 5xx status codes on document parsing failure when accepting application/graphql-response+json', async () => {
|
|
365
|
+
const url = new URL(opts.url);
|
|
366
|
+
url.searchParams.set('query', '{');
|
|
367
|
+
const res = await fetchFn(url.toString(), {
|
|
368
|
+
method: 'GET',
|
|
369
|
+
headers: { accept: 'application/graphql-response+json' },
|
|
370
|
+
});
|
|
371
|
+
(0, utils_1.assert)('Status code', res.status).toBeGreaterThanOrEqual(400);
|
|
372
|
+
(0, utils_1.assert)('Status code', res.status).toBeLessThanOrEqual(599);
|
|
373
|
+
}),
|
|
374
|
+
(0, utils_1.audit)('SHOULD use 400 status code on document parsing failure when accepting application/graphql-response+json', async () => {
|
|
375
|
+
const url = new URL(opts.url);
|
|
376
|
+
url.searchParams.set('query', '{');
|
|
377
|
+
const res = await fetchFn(url.toString(), {
|
|
378
|
+
method: 'GET',
|
|
379
|
+
headers: { accept: 'application/graphql-response+json' },
|
|
380
|
+
});
|
|
381
|
+
(0, utils_1.assert)('Status code', res.status).toBe(400);
|
|
382
|
+
}),
|
|
383
|
+
(0, utils_1.audit)('SHOULD not contain the data entry on document parsing failure when accepting application/graphql-response+json', async () => {
|
|
384
|
+
const url = new URL(opts.url);
|
|
385
|
+
url.searchParams.set('query', '{');
|
|
386
|
+
const res = await fetchFn(url.toString(), {
|
|
387
|
+
method: 'GET',
|
|
388
|
+
headers: { accept: 'application/graphql-response+json' },
|
|
389
|
+
});
|
|
390
|
+
(0, utils_1.assert)('Data entry', (await res.json()).data).toBe(undefined);
|
|
391
|
+
}),
|
|
392
|
+
(0, utils_1.audit)('MUST use 4xx or 5xx status codes on document validation failure when accepting application/graphql-response+json', async () => {
|
|
393
|
+
const url = new URL(opts.url);
|
|
394
|
+
url.searchParams.set('query', '{ 8f31403dfe404bccbb0e835f2629c6a7 }'); // making sure the field doesnt exist
|
|
395
|
+
const res = await fetchFn(url.toString(), {
|
|
396
|
+
method: 'GET',
|
|
397
|
+
headers: { accept: 'application/graphql-response+json' },
|
|
398
|
+
});
|
|
399
|
+
(0, utils_1.assert)('Status code', res.status).toBeGreaterThanOrEqual(400);
|
|
400
|
+
(0, utils_1.assert)('Status code', res.status).toBeLessThanOrEqual(599);
|
|
401
|
+
}),
|
|
402
|
+
(0, utils_1.audit)('SHOULD use 400 status code on document validation failure when accepting application/graphql-response+json', async () => {
|
|
403
|
+
const url = new URL(opts.url);
|
|
404
|
+
url.searchParams.set('query', '{ 8f31403dfe404bccbb0e835f2629c6a7 }'); // making sure the field doesnt exist
|
|
405
|
+
const res = await fetchFn(url.toString(), {
|
|
406
|
+
method: 'GET',
|
|
407
|
+
headers: { accept: 'application/graphql-response+json' },
|
|
408
|
+
});
|
|
409
|
+
(0, utils_1.assert)('Status code', res.status).toBe(400);
|
|
410
|
+
}),
|
|
411
|
+
(0, utils_1.audit)('SHOULD not contain the data entry on document validation failure when accepting application/graphql-response+json', async () => {
|
|
412
|
+
const url = new URL(opts.url);
|
|
413
|
+
url.searchParams.set('query', '{ 8f31403dfe404bccbb0e835f2629c6a7 }'); // making sure the field doesnt exist
|
|
414
|
+
const res = await fetchFn(url.toString(), {
|
|
415
|
+
method: 'GET',
|
|
416
|
+
headers: { accept: 'application/graphql-response+json' },
|
|
417
|
+
});
|
|
418
|
+
(0, utils_1.assert)('Data entry', (await res.json()).data).toBe(undefined);
|
|
419
|
+
}),
|
|
420
|
+
// TODO: how to fail and have the data entry?
|
|
421
|
+
// audit('MUST use 2xx status code if response contains the data entry and it is not null when accepting application/graphql-response+json'),
|
|
422
|
+
// TODO: how to make an unauthorized request?
|
|
423
|
+
// https://graphql.github.io/graphql-over-http/draft/#sel-EANNNDTAAEVBAAqqc
|
|
424
|
+
// audit('SHOULD use 401 or 403 status codes when the request is not permitted')
|
|
425
|
+
];
|
|
426
|
+
}
|
|
427
|
+
exports.serverAudits = serverAudits;
|
|
428
|
+
/**
|
|
429
|
+
* Performs the full list of server audits required for GraphQL over HTTP spec conformance.
|
|
430
|
+
*
|
|
431
|
+
* Please consult the `AuditResult` for more information.
|
|
432
|
+
*
|
|
433
|
+
* @category Audits
|
|
434
|
+
*/
|
|
435
|
+
async function auditServer(opts) {
|
|
436
|
+
const audits = serverAudits(opts);
|
|
437
|
+
// audit tests will throw only on fatal errors, tests are contained within the AuditResult
|
|
438
|
+
return await Promise.all(audits.map(({ fn }) => fn()));
|
|
439
|
+
}
|
|
440
|
+
exports.auditServer = auditServer;
|