Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"c8": "^10.1.2",
"eslint": "^9.17.0",
"neostandard": "^0.12.0",
"tape": "^5.7.5",
"tsd": "^0.32.0"
},
"scripts": {
Expand All @@ -70,6 +69,6 @@
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:typescript": "tsd",
"test:unit": "c8 tape test/**/*.js"
"test:unit": "c8 --100 node --test"
}
}
2 changes: 0 additions & 2 deletions test/.eslintrc.yml

This file was deleted.

23 changes: 8 additions & 15 deletions test/all.js → test/all.test.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,48 @@
'use strict'

const test = require('tape')
const { test } = require('node:test')
const proxyaddr = require('..')

test('argument req should be required', function (t) {
t.throws(proxyaddr.all, /req.*required/u)
t.end()
t.assert.throws(proxyaddr.all, /req.*required/u)
})

test('argument trustshould be optional', function (t) {
const req = createReq('127.0.0.1')
t.doesNotThrow(proxyaddr.all.bind(null, req))
t.end()
t.assert.doesNotThrow(proxyaddr.all.bind(null, req))
})

test('with no headers should return socket address', function (t) {
const req = createReq('127.0.0.1')
t.same(proxyaddr.all(req), ['127.0.0.1'])
t.end()
t.assert.deepStrictEqual(proxyaddr.all(req), ['127.0.0.1'])
})

test('with x-forwarded-for header should include x-forwarded-for', function (t) {
const req = createReq('127.0.0.1', {
'x-forwarded-for': '10.0.0.1'
})
t.same(proxyaddr.all(req), ['127.0.0.1', '10.0.0.1'])
t.end()
t.assert.deepStrictEqual(proxyaddr.all(req), ['127.0.0.1', '10.0.0.1'])
})

test('with x-forwarded-for header should include x-forwarded-for in correct order', function (t) {
const req = createReq('127.0.0.1', {
'x-forwarded-for': '10.0.0.1, 10.0.0.2'
})
t.same(proxyaddr.all(req), ['127.0.0.1', '10.0.0.2', '10.0.0.1'])
t.end()
t.assert.deepStrictEqual(proxyaddr.all(req), ['127.0.0.1', '10.0.0.2', '10.0.0.1'])
})

test('with trust argument should stop at first untrusted', function (t) {
const req = createReq('127.0.0.1', {
'x-forwarded-for': '10.0.0.1, 10.0.0.2'
})
t.same(proxyaddr.all(req, '127.0.0.1'), ['127.0.0.1', '10.0.0.2'])
t.end()
t.assert.deepStrictEqual(proxyaddr.all(req, '127.0.0.1'), ['127.0.0.1', '10.0.0.2'])
})

test('with trust argument should be only socket address for no trust', function (t) {
const req = createReq('127.0.0.1', {
'x-forwarded-for': '10.0.0.1, 10.0.0.2'
})
t.same(proxyaddr.all(req, []), ['127.0.0.1'])
t.end()
t.assert.deepStrictEqual(proxyaddr.all(req, []), ['127.0.0.1'])
})

function createReq (socketAddr, headers) {
Expand Down
Loading
Loading