| 21 | } |
| 22 | |
| 23 | const 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 | } |
| 32 | if (options.hostname) { |
| 33 | t.assert.ok(req.hostname, 'hostname is defined') |
| 34 | t.assert.strictEqual(req.hostname, options.hostname, 'gets hostname from x-forwarded-host') |
| 35 | } |
| 36 | if (options.ips) { |
| 37 | t.assert.deepStrictEqual(req.ips, options.ips, 'gets ips from x-forwarded-for') |
| 38 | } |
| 39 | if (options.protocol) { |
| 40 | t.assert.ok(req.protocol, 'protocol is defined') |
| 41 | t.assert.strictEqual(req.protocol, options.protocol, 'gets protocol from x-forwarded-proto') |
| 42 | } |
| 43 | if ('port' in options) { |
| 44 | t.assert.strictEqual(req.port, options.port, 'port is parsed from x-forwarded-host') |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | let localhost |
| 49 | before(async function () { |