%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home2/rezakur1/api.rezakurnia.com/zh-router/node_modules/@fastify/proxy-addr/test/
Upload File :
Create Path :
Current File : //home2/rezakur1/api.rezakurnia.com/zh-router/node_modules/@fastify/proxy-addr/test/compile.test.js

'use strict'

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

test('trust arg should be required', function (t) {
  t.assert.throws(proxyaddr.compile, /argument.*required/u)
})

test('trust arg should accept an array', function (t) {
  t.assert.strictEqual(typeof proxyaddr.compile([]), 'function')
})

test('trust arg should accept a string', function (t) {
  t.assert.strictEqual(typeof proxyaddr.compile('127.0.0.1'), 'function')
})

test('trust arg should reject a number', function (t) {
  t.assert.throws(proxyaddr.compile.bind(null, 42), /unsupported trust argument/u)
})

test('trust arg should accept IPv4', function (t) {
  t.assert.strictEqual(typeof proxyaddr.compile('127.0.0.1'), 'function')
})

test('trust arg should accept IPv6', function (t) {
  t.assert.strictEqual(typeof proxyaddr.compile('::1'), 'function')
})

test('zoned IPv6 trust should require the same zone', function (t) {
  const trust = proxyaddr.compile('fe80::1%proxy0')

  t.assert.strictEqual(trust('fe80::1%proxy0'), true)
  t.assert.strictEqual(trust('fe80::1%edge0'), false)
  t.assert.strictEqual(trust('fe80::1'), false)
})

test('zoned IPv6 trust in an array should require the same zone', function (t) {
  const trust = proxyaddr.compile(['127.0.0.1', 'fe80::1%proxy0'])

  t.assert.strictEqual(trust('fe80::1%proxy0'), true)
  t.assert.strictEqual(trust('fe80::1%edge0'), false)
  t.assert.strictEqual(trust('fe80::1'), false)
})

test('trust arg should accept IPv4-style IPv6', function (t) {
  t.assert.strictEqual(typeof proxyaddr.compile('::ffff:127.0.0.1'), 'function')
})

test('trust arg should accept pre-defined names', function (t) {
  t.assert.strictEqual(typeof proxyaddr.compile('loopback'), 'function')
})

test('trust arg should accept pre-defined names in array', function (t) {
  t.assert.strictEqual(typeof proxyaddr.compile(['loopback', '10.0.0.1']), 'function')
})

test('trust arg should reject non-IP', function (t) {
  t.assert.throws(proxyaddr.compile.bind(null, 'blargh'), /invalid IP address/u)
  t.assert.throws(proxyaddr.compile.bind(null, '-1'), /invalid IP address/u)
})

test('trust arg should reject bad CIDR', function (t) {
  t.assert.throws(proxyaddr.compile.bind(null, '10.0.0.1/6000'), /invalid range on address/u)
  t.assert.throws(proxyaddr.compile.bind(null, '::1/6000'), /invalid range on address/u)
  t.assert.throws(proxyaddr.compile.bind(null, '::ffff:a00:2/136'), /invalid range on address/u)
  t.assert.throws(proxyaddr.compile.bind(null, '::ffff:a00:2/-46'), /invalid range on address/u)
})

test('trust arg should not alter input array', function (t) {
  const arr = ['loopback', '10.0.0.1']
  t.assert.strictEqual(typeof proxyaddr.compile(arr), 'function')
  t.assert.deepStrictEqual(arr, ['loopback', '10.0.0.1'])
})

Zerion Mini Shell 1.0