-
-
Notifications
You must be signed in to change notification settings - Fork 686
fix: enforce maxFileSize/maxTotalFileSize on octet-stream uploads #1113
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,3 +52,35 @@ test("octet stream", (done) => { | |
| createReadStream(testFilePath).pipe(request); | ||
| }); | ||
| }); | ||
|
|
||
| test("octet stream enforces maxFileSize", (done) => { | ||
| const PORT2 = PORT + 1; | ||
| const server = createServer((req, res) => { | ||
| const form = formidable({ maxFileSize: 1024, maxTotalFileSize: 2048 }); | ||
|
|
||
| form.parse(req, (err, fields, files) => { | ||
| // a 256KB octet-stream body must be rejected, not written to disk | ||
| assert(err, "expected an error for over-sized octet-stream upload"); | ||
| strictEqual(err.code, 1016); // biggerThanMaxFileSize | ||
| strictEqual(Object.keys(files).length, 0); | ||
|
|
||
| res.end(); | ||
| server.close(); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| server.listen(PORT2, (err) => { | ||
| assert(!err, "should not have error, but be falsey"); | ||
|
|
||
| const request = _request({ | ||
| port: PORT2, | ||
| method: "POST", | ||
| headers: { | ||
| "Content-Type": "application/octet-stream", | ||
| }, | ||
| }); | ||
|
|
||
| request.end(Buffer.alloc(256 * 1024, 0x42)); | ||
| }); | ||
| }); | ||
|
Comment on lines
+56
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The test sets |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import FormidableError, * as errors from "./FormidableError.js"inFormidable.js).Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!