Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add busboy tests #2924

Merged
merged 5 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup
  • Loading branch information
KhafraDev committed Mar 5, 2024
commit a69f4d742c3e87ad5cde53a59a83bc364024179f
17 changes: 15 additions & 2 deletions test/busboy/test-types-multipart-charsets.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,25 @@ const expected = [

for (const [name, value] of fd) {
if (typeof value === 'string') { // field
results.push({ type: 'field', name, val: value })
results.push({
type: 'field',
name,
val: value,
info: {
encoding: '7bit',
mimeType: 'text/plain'
}
})
} else { // File
results.push({
type: 'file',
name,
data: Buffer.from(await value.arrayBuffer())
data: Buffer.from(await value.arrayBuffer()),
info: {
filename: value.name,
encoding: '7bit',
mimeType: value.type
}
})
}
}
Expand Down
47 changes: 29 additions & 18 deletions test/busboy/test-types-multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const tests = [
name: 'upload_file_0',
data: Buffer.from('ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
info: {
filename: '1k_a.dat',
filename: '/tmp/1k_a.dat',
encoding: '7bit',
mimeType: 'application/octet-stream'
}
Expand All @@ -174,7 +174,7 @@ const tests = [
name: 'upload_file_1',
data: Buffer.from('ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
info: {
filename: '1k_b.dat',
filename: 'C:\\files\\1k_b.dat',
encoding: '7bit',
mimeType: 'application/octet-stream'
}
Expand All @@ -184,13 +184,13 @@ const tests = [
name: 'upload_file_2',
data: Buffer.from('ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
info: {
filename: '1k_c.dat',
filename: 'relative/1k_c.dat',
encoding: '7bit',
mimeType: 'application/octet-stream'
}
}
],
what: 'Files with filenames containing paths'
what: 'Files with filenames containing paths preserve path'
},
{
source: [
Expand Down Expand Up @@ -316,8 +316,7 @@ const tests = [
],
boundary: 'asdasdasdasd',
expected: [
{ error: 'Malformed part header' },
{ error: 'Unexpected end of form' }
{ error: 'Malformed part header' }
],
what: 'Stopped mid-header'
},
Expand All @@ -339,7 +338,8 @@ const tests = [
val: '{}',
info: {
encoding: '7bit',
mimeType: 'application/json'
// TODO: there's no way to get the content-type of a field
mimeType: 'text/plain' // 'application/json'
}
}
],
Expand Down Expand Up @@ -406,7 +406,7 @@ const tests = [
info: {
filename: 'notes.txt',
encoding: '7bit',
mimeType: 'text/plain'
mimeType: 'text/plain; charset=utf8'
}
}
],
Expand Down Expand Up @@ -471,15 +471,25 @@ const tests = [
],
boundary: '---------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
expected: [
{ error: 'Malformed part header' },
// TODO: the RFC does not mention the max size of a filename?
{
type: 'file',
name: 'upload_file_0',
data: Buffer.from('ab'),
info: {
filename: `${'a'.repeat(64 * 1024)}.txt`,
encoding: '7bit',
mimeType: 'text/plain; charset=utf8'
}
}, // { error: 'Malformed part header' },
{
type: 'file',
name: 'upload_file_1',
data: Buffer.from('cd'),
info: {
filename: 'notes2.txt',
encoding: '7bit',
mimeType: 'text/plain'
mimeType: 'text/plain; charset=utf8'
}
}
],
Expand All @@ -506,7 +516,7 @@ const tests = [
info: {
filename: 'notes.txt',
encoding: '7bit',
mimeType: 'text/plain'
mimeType: 'text/plain; charset=utf8'
}
}
],
Expand Down Expand Up @@ -544,7 +554,7 @@ const tests = [
info: {
filename: `${'a'.repeat(8 * 1024)}.txt`,
encoding: '7bit',
mimeType: 'text/plain'
mimeType: 'text/plain; charset=utf8'
}
},
{
Expand All @@ -554,7 +564,7 @@ const tests = [
info: {
filename: `${'b'.repeat(8 * 1024)}.txt`,
encoding: '7bit',
mimeType: 'text/plain'
mimeType: 'text/plain; charset=utf8'
}
},
{
Expand All @@ -564,7 +574,7 @@ const tests = [
info: {
filename: `${'c'.repeat(8 * 1024)}.txt`,
encoding: '7bit',
mimeType: 'text/plain'
mimeType: 'text/plain; charset=utf8'
}
}
],
Expand Down Expand Up @@ -616,10 +626,11 @@ const tests = [
fd = await response.formData()
} catch (e) {
results.push({ error: e.message })
}

if (!fd[Symbol.iterator]) {
// TODO:
if (test.expected.length === 1 && test.expected[0].error) {
active.delete(test)
}

continue
}

Expand Down Expand Up @@ -670,7 +681,7 @@ const tests = [
if (exception || active.size === 0) { return }
process.exitCode = 1
console.error('==========================')
console.error(`${active.size} test(s) did not finish:`)
console.error(`${active.size}/${tests.length} test(s) did not finish:`)
console.error('==========================')
console.error(Array.from(active.keys()).map((v) => v.what).join('\n'))
})
Expand Down
Loading