Files
wehub-resource-sync 3a28426bf4
Lint and Format Check / lint-and-format (push) Failing after 0s
Check Migrations / Check for duplicate migration numbers (push) Failing after 1s
CI Pre-merge Check / CI Pre-merge Check (push) Failing after 2m17s
chore: import upstream snapshot with attribution
2026-07-13 12:23:40 +08:00

36 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { parseTrustProxySetting } from '../../src/utils/trust-proxy';
describe('parseTrustProxySetting', () => {
it('keeps the existing two-hop default for backwards compatibility', () => {
expect(parseTrustProxySetting(undefined)).toBe(2);
expect(parseTrustProxySetting('')).toBe(2);
});
it('parses explicit boolean values', () => {
expect(parseTrustProxySetting('true')).toBe(true);
expect(parseTrustProxySetting('FALSE')).toBe(false);
});
it('parses explicit proxy hop counts', () => {
expect(parseTrustProxySetting('0')).toBe(0);
expect(parseTrustProxySetting('1')).toBe(1);
expect(parseTrustProxySetting('3')).toBe(3);
});
it('passes through Express named or subnet trust proxy values', () => {
expect(parseTrustProxySetting('loopback')).toBe('loopback');
expect(parseTrustProxySetting('loopback, 10.0.0.0/8')).toBe('loopback, 10.0.0.0/8');
});
it('trims whitespace before parsing scalar values', () => {
expect(parseTrustProxySetting(' 2 ')).toBe(2);
expect(parseTrustProxySetting(' true ')).toBe(true);
});
it('rejects finite non-integer numeric values instead of passing them to Express', () => {
expect(() => parseTrustProxySetting('1.5')).toThrow(/non-negative integer/);
expect(() => parseTrustProxySetting('-1')).toThrow(/non-negative integer/);
});
});