Skip to content

test: add test for out-of-band error event #1294

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

Merged
merged 1 commit into from
Mar 20, 2025
Merged
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
45 changes: 45 additions & 0 deletions test/express-integration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env mocha */

var assert = require('assert')
var http = require('http')

var multer = require('../')
var util = require('./_util')
Expand Down Expand Up @@ -106,4 +107,48 @@ describe('Express Integration', function () {
done()
})
})

it('should not crash on malformed request', function (done) {
var upload = multer()

app.post('/upload', upload.single('file'), function (req, res) {
res.status(500).end('Request should not be processed')
})

app.use(function (err, req, res, next) {
assert.strictEqual(err.message, 'Unexpected end of multipart data')
res.status(200).end('Correct error')
})

var boundary = 'AaB03x'
var body = [
'--' + boundary,
'Content-Disposition: form-data; name="file"; filename="test.txt"',
'Content-Type: text/plain',
'',
'test without end boundary'
].join('\r\n')
var options = {
hostname: 'localhost',
port: port,
path: '/upload',
method: 'POST',
headers: {
'content-type': 'multipart/form-data; boundary=' + boundary,
'content-length': body.length
}
}

var req = http.request(options, function (res) {
assert.strictEqual(res.statusCode, 200)
done()
})

req.on('error', function (err) {
done(err)
})

req.write(body)
req.end()
})
})
Loading