-
-
Notifications
You must be signed in to change notification settings - Fork 850
Expand file tree
/
Copy pathissue-5520.js
More file actions
54 lines (43 loc) · 1.57 KB
/
Copy pathissue-5520.js
File metadata and controls
54 lines (43 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict'
const { test } = require('node:test')
const { createServer } = require('node:http')
const { createServer: createH2Server } = require('node:http2')
const { once } = require('node:events')
const { request, H2CClient, errors } = require('..')
// https://github.com/nodejs/undici/issues/5520
test('request() rejects a cross-realm (Node builtin) FormData body', { timeout: 60000 }, async (t) => {
const server = createServer((req, res) => {
req.on('data', () => {})
req.on('end', () => res.end('{}'))
})
t.after(() => {
server.closeAllConnections?.()
server.close()
})
server.listen(0)
await once(server, 'listening')
const form = new globalThis.FormData()
form.append('field', 'value')
form.append('file', new Blob(['file contents'], { type: 'text/plain' }), 'hello.txt')
await t.assert.rejects(
request(`http://localhost:${server.address().port}/`, { method: 'POST', body: form }),
errors.InvalidArgumentError
)
})
test('HTTP/2 client rejects a cross-realm (Node builtin) FormData body', { timeout: 60000 }, async (t) => {
const server = createH2Server((req, res) => {
req.on('data', () => {})
req.on('end', () => res.end('{}'))
})
t.after(() => server.close())
server.listen(0)
await once(server, 'listening')
const client = new H2CClient(`http://localhost:${server.address().port}`)
t.after(() => client.close())
const form = new globalThis.FormData()
form.append('field', 'value')
await t.assert.rejects(
client.request({ path: '/', method: 'POST', body: form }),
errors.InvalidArgumentError
)
})