Skip to content

Commit

Permalink
tests: add limit + inflate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Jan 12, 2022
1 parent b356758 commit 82c8a7c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/json.js
Expand Up @@ -142,6 +142,15 @@ describe('bodyParser.json()', function () {
test.expect(413, done)
})

it('should 413 when inflated body over limit', function (done) {
var server = createServer({ limit: '1kb' })
var test = request(server).post('/')
test.set('Content-Encoding', 'gzip')
test.set('Content-Type', 'application/json')
test.write(Buffer.from('1f8b080000000000000aab562a2e2952b252d21b05a360148c58a0540b0066f7ce1e0a040000', 'hex'))
test.expect(413, done)
})

it('should accept number of bytes', function (done) {
var buf = Buffer.alloc(1024, '.')
request(createServer({ limit: 1024 }))
Expand Down
9 changes: 9 additions & 0 deletions test/raw.js
Expand Up @@ -87,6 +87,15 @@ describe('bodyParser.raw()', function () {
test.expect(413, done)
})

it('should 413 when inflated body over limit', function (done) {
var server = createServer({ limit: '1kb' })
var test = request(server).post('/')
test.set('Content-Encoding', 'gzip')
test.set('Content-Type', 'application/octet-stream')
test.write(Buffer.from('1f8b080000000000000ad3d31b05a360148c64000087e5a14704040000', 'hex'))
test.expect(413, done)
})

it('should accept number of bytes', function (done) {
var buf = Buffer.alloc(1028, '.')
var server = createServer({ limit: 1024 })
Expand Down
9 changes: 9 additions & 0 deletions test/text.js
Expand Up @@ -105,6 +105,15 @@ describe('bodyParser.text()', function () {
test.expect(413, done)
})

it('should 413 when inflated body over limit', function (done) {
var server = createServer({ limit: '1kb' })
var test = request(server).post('/')
test.set('Content-Encoding', 'gzip')
test.set('Content-Type', 'text/plain')
test.write(Buffer.from('1f8b080000000000000ad3d31b05a360148c64000087e5a14704040000', 'hex'))
test.expect(413, done)
})

it('should accept number of bytes', function (done) {
var buf = Buffer.alloc(1028, '.')
request(createServer({ limit: 1024 }))
Expand Down
9 changes: 9 additions & 0 deletions test/urlencoded.js
Expand Up @@ -251,6 +251,15 @@ describe('bodyParser.urlencoded()', function () {
test.expect(413, done)
})

it('should 413 when inflated body over limit', function (done) {
var server = createServer({ limit: '1kb' })
var test = request(server).post('/')
test.set('Content-Encoding', 'gzip')
test.set('Content-Type', 'application/x-www-form-urlencoded')
test.write(Buffer.from('1f8b080000000000000a2b2e29b2d51b05a360148c580000a0351f9204040000', 'hex'))
test.expect(413, done)
})

it('should accept number of bytes', function (done) {
var buf = Buffer.alloc(1024, '.')
request(createServer({ limit: 1024 }))
Expand Down

0 comments on commit 82c8a7c

Please sign in to comment.