|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | | -const test = require('tape') |
| 3 | +const { test } = require('node:test') |
4 | 4 | const proxyaddr = require('..') |
5 | 5 |
|
6 | 6 | test('argument req should be required', function (t) { |
7 | | - t.throws(proxyaddr.all, /req.*required/u) |
8 | | - t.end() |
| 7 | + t.assert.throws(proxyaddr.all, /req.*required/u) |
9 | 8 | }) |
10 | 9 |
|
11 | 10 | test('argument trustshould be optional', function (t) { |
12 | 11 | const req = createReq('127.0.0.1') |
13 | | - t.doesNotThrow(proxyaddr.all.bind(null, req)) |
14 | | - t.end() |
| 12 | + t.assert.doesNotThrow(proxyaddr.all.bind(null, req)) |
15 | 13 | }) |
16 | 14 |
|
17 | 15 | test('with no headers should return socket address', function (t) { |
18 | 16 | const req = createReq('127.0.0.1') |
19 | | - t.same(proxyaddr.all(req), ['127.0.0.1']) |
20 | | - t.end() |
| 17 | + t.assert.deepStrictEqual(proxyaddr.all(req), ['127.0.0.1']) |
21 | 18 | }) |
22 | 19 |
|
23 | 20 | test('with x-forwarded-for header should include x-forwarded-for', function (t) { |
24 | 21 | const req = createReq('127.0.0.1', { |
25 | 22 | 'x-forwarded-for': '10.0.0.1' |
26 | 23 | }) |
27 | | - t.same(proxyaddr.all(req), ['127.0.0.1', '10.0.0.1']) |
28 | | - t.end() |
| 24 | + t.assert.deepStrictEqual(proxyaddr.all(req), ['127.0.0.1', '10.0.0.1']) |
29 | 25 | }) |
30 | 26 |
|
31 | 27 | test('with x-forwarded-for header should include x-forwarded-for in correct order', function (t) { |
32 | 28 | const req = createReq('127.0.0.1', { |
33 | 29 | 'x-forwarded-for': '10.0.0.1, 10.0.0.2' |
34 | 30 | }) |
35 | | - t.same(proxyaddr.all(req), ['127.0.0.1', '10.0.0.2', '10.0.0.1']) |
36 | | - t.end() |
| 31 | + t.assert.deepStrictEqual(proxyaddr.all(req), ['127.0.0.1', '10.0.0.2', '10.0.0.1']) |
37 | 32 | }) |
38 | 33 |
|
39 | 34 | test('with trust argument should stop at first untrusted', function (t) { |
40 | 35 | const req = createReq('127.0.0.1', { |
41 | 36 | 'x-forwarded-for': '10.0.0.1, 10.0.0.2' |
42 | 37 | }) |
43 | | - t.same(proxyaddr.all(req, '127.0.0.1'), ['127.0.0.1', '10.0.0.2']) |
44 | | - t.end() |
| 38 | + t.assert.deepStrictEqual(proxyaddr.all(req, '127.0.0.1'), ['127.0.0.1', '10.0.0.2']) |
45 | 39 | }) |
46 | 40 |
|
47 | 41 | test('with trust argument should be only socket address for no trust', function (t) { |
48 | 42 | const req = createReq('127.0.0.1', { |
49 | 43 | 'x-forwarded-for': '10.0.0.1, 10.0.0.2' |
50 | 44 | }) |
51 | | - t.same(proxyaddr.all(req, []), ['127.0.0.1']) |
52 | | - t.end() |
| 45 | + t.assert.deepStrictEqual(proxyaddr.all(req, []), ['127.0.0.1']) |
53 | 46 | }) |
54 | 47 |
|
55 | 48 | function createReq (socketAddr, headers) { |
|
0 commit comments