MCPcopy
hub / github.com/fastify/fastify / testRequestValues

Function testRequestValues

test/trust-proxy.test.js:23–45  ·  view source on GitHub ↗
(t, req, options)

Source from the content-addressed store, hash-verified

21}
22
23const testRequestValues = (t, req, options) => {
24 if (options.ip) {
25 t.assert.ok(req.ip, 'ip is defined')
26 t.assert.strictEqual(req.ip, options.ip, 'gets ip from x-forwarded-for')
27 }
28 if (options.host) {
29 t.assert.ok(req.host, 'host is defined')
30 t.assert.strictEqual(req.host, options.host, 'gets host from x-forwarded-host')
31 t.assert.ok(req.hostname)
32 t.assert.strictEqual(req.hostname, options.host, 'gets hostname from x-forwarded-host')
33 }
34 if (options.ips) {
35 t.assert.deepStrictEqual(req.ips, options.ips, 'gets ips from x-forwarded-for')
36 }
37 if (options.protocol) {
38 t.assert.ok(req.protocol, 'protocol is defined')
39 t.assert.strictEqual(req.protocol, options.protocol, 'gets protocol from x-forwarded-proto')
40 }
41 if (options.port) {
42 t.assert.ok(req.port, 'port is defined')
43 t.assert.strictEqual(req.port, options.port, 'port is taken from x-forwarded-for or host')
44 }
45}
46
47let localhost
48before(async function () {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected