Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/multipart-body-schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test('should be able to use JSON schema to validate request', function (t, done)
reply.code(200).send()
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -102,7 +102,7 @@ test('should throw because JSON schema is invalid', function (t, done) {
reply.code(200).send()
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down
4 changes: 2 additions & 2 deletions test/multipart-concat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('should be able to get whole buffer by accessing "content" on part', functi
reply.code(200).send()
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -81,7 +81,7 @@ test('should be able to access "content" multiple times without reading the stre
reply.code(200).send()
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down
24 changes: 11 additions & 13 deletions test/multipart-http2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ const streamToNull = require('../lib/stream-consumer')

const filePath = path.join(__dirname, '../README.md')

test('should respond when all files are processed', function (t, done) {
test('should respond when all files are processed', async function (t) {
t.plan(3)

const fastify = Fastify({ http2: true })
t.after(() => fastify.close())

Expand All @@ -28,18 +27,17 @@ test('should respond when all files are processed', function (t, done) {
reply.code(200).send()
})

fastify.listen({ port: 0 }, async function () {
const url = `http://localhost:${fastify.server.address().port}`
const form = new FormData()
await fastify.listen({ port: 0 })

form.append('upload', fs.createReadStream(filePath))
form.append('upload2', fs.createReadStream(filePath))
form.append('hello', 'world')
form.append('willbe', 'dropped')
const url = `http://localhost:${fastify.server.address().port}`
const form = new FormData()

const res = await h2url.concat({ url, method: 'POST', headers: form.getHeaders(), body: form })
form.append('upload', fs.createReadStream(filePath))
form.append('upload2', fs.createReadStream(filePath))
form.append('hello', 'world')
form.append('willbe', 'dropped')

t.assert.strictEqual(res.headers[':status'], 200)
done()
})
const res = await h2url.concat({ url, method: 'POST', headers: form.getHeaders(), body: form })

t.assert.strictEqual(res.headers[':status'], 200)
})
16 changes: 8 additions & 8 deletions test/multipart-json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('should parse JSON fields forms if content-type is set', function (t, done)
reply.code(200).send()
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -68,7 +68,7 @@ test('should not parse JSON fields forms if no content-type is set', function (t
reply.code(200).send()
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -113,7 +113,7 @@ test('should not parse JSON fields forms if non-json content-type is set', funct
reply.code(200).send()
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -161,7 +161,7 @@ test('should throw error when parsing JSON fields failed', function (t, done) {
}
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -208,7 +208,7 @@ test('should always reject JSON parsing if the value was truncated', function (t
}
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -270,7 +270,7 @@ test('should be able to use JSON schema to validate request when value is a stri
}
)

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -329,7 +329,7 @@ test('should be able to use JSON schema to validate request when value is a JSON
}
)

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -384,7 +384,7 @@ test('should return 400 when the field validation fails', function (t, done) {
}
)

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down
12 changes: 6 additions & 6 deletions test/multipart-security.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('should not allow __proto__ as file name', function (t, done) {
}
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -80,7 +80,7 @@ test('should not allow __proto__ as field name', function (t, done) {
}
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -126,7 +126,7 @@ test('should not allow toString as field name', function (t, done) {
}
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -172,7 +172,7 @@ test('should not allow hasOwnProperty as field name', function (t, done) {
}
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -218,7 +218,7 @@ test('should not allow propertyIsEnumerable as field name', function (t, done) {
}
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -319,7 +319,7 @@ test('should use default for parts - 1000', function (t, done) {
}
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down
16 changes: 8 additions & 8 deletions test/multipart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test('should parse forms', function (t, done) {
reply.code(200).send()
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -95,7 +95,7 @@ test('should respond when all files are processed', function (t, done) {
reply.code(200).send()
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -149,7 +149,7 @@ test('should group parts with the same name to an array', function (t, done) {
reply.code(200).send()
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -241,7 +241,7 @@ test('should error if boundary is empty', function (t, done) {
}
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -284,7 +284,7 @@ test('should throw error due to filesLimit (The max number of file fields (Defau
}
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -451,7 +451,7 @@ test('should throw error due to partsLimit (The max number of parts (fields + fi
}
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -501,7 +501,7 @@ test('should throw error due to file size limit exceed (Default: true)', functio
}
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down Expand Up @@ -546,7 +546,7 @@ test('should not throw error due to file size limit exceed - files setting (Defa
reply.code(200).send()
})

fastify.listen({ port: 0 }, async function () {
fastify.listen({ port: 0 }, function () {
// request
const form = new FormData()
const opts = {
Expand Down