CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
header-overflow.test.js67 linesDownload Raw Back to test
1'use strict'2 3const { test } = require('node:test')4const Fastify = require('..')5const sget = require('simple-get').concat6 7const maxHeaderSize = 10248 9test('Should return 431 if request header fields are too large', (t, done) => {10  t.plan(3)11 12  const fastify = Fastify({ http: { maxHeaderSize } })13  fastify.route({14    method: 'GET',15    url: '/',16    handler: (_req, reply) => {17      reply.send({ hello: 'world' })18    }19  })20 21  fastify.listen({ port: 0 }, function (err) {22    t.assert.ifError(err)23 24    sget({25      method: 'GET',26      url: 'http://localhost:' + fastify.server.address().port,27      headers: {28        'Large-Header': 'a'.repeat(maxHeaderSize)29      }30    }, (err, res) => {31      t.assert.ifError(err)32      t.assert.strictEqual(res.statusCode, 431)33      done()34    })35  })36 37  t.after(() => fastify.close())38})39 40test('Should return 431 if URI is too long', (t, done) => {41  t.plan(3)42 43  const fastify = Fastify({ http: { maxHeaderSize } })44  fastify.route({45    method: 'GET',46    url: '/',47    handler: (_req, reply) => {48      reply.send({ hello: 'world' })49    }50  })51 52  fastify.listen({ port: 0 }, function (err) {53    t.assert.ifError(err)54 55    sget({56      method: 'GET',57      url: 'http://localhost:' + fastify.server.address().port + `/${'a'.repeat(maxHeaderSize)}`58    }, (err, res) => {59      t.assert.ifError(err)60      t.assert.strictEqual(res.statusCode, 431)61      done()62    })63  })64 65  t.after(() => fastify.close())66})67