fix(network-proxy, route-utils, route-manager): Normalize IPv6-mapped IPv4 addresses in IP matching functions and remove deprecated legacy configuration methods in NetworkProxy. Update route-utils and route-manager to compare both canonical and IPv6-mapped IP forms, adjust tests accordingly, and clean up legacy exports.
This commit is contained in:
@@ -1,24 +1,22 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as plugins from '../ts/plugins.js';
|
||||
import { NetworkProxy } from '../ts/proxies/network-proxy/index.js';
|
||||
import type { IRouteConfig } from '../ts/proxies/smart-proxy/models/route-types.js';
|
||||
import type { IRouteContext } from '../ts/core/models/route-context.js';
|
||||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
import * as http2 from 'http2';
|
||||
|
||||
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
// Declare variables for tests
|
||||
let networkProxy: NetworkProxy;
|
||||
let testServer: http.Server;
|
||||
let testServerHttp2: http2.Http2Server;
|
||||
let testServer: plugins.http.Server;
|
||||
let testServerHttp2: plugins.http2.Http2Server;
|
||||
let serverPort: number;
|
||||
let serverPortHttp2: number;
|
||||
|
||||
// Setup test environment
|
||||
tap.test('setup NetworkProxy function-based targets test environment', async () => {
|
||||
// Create simple HTTP server to respond to requests
|
||||
testServer = http.createServer((req, res) => {
|
||||
testServer = plugins.http.createServer((req, res) => {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({
|
||||
url: req.url,
|
||||
@@ -29,7 +27,7 @@ tap.test('setup NetworkProxy function-based targets test environment', async ()
|
||||
});
|
||||
|
||||
// Create simple HTTP/2 server to respond to requests
|
||||
testServerHttp2 = http2.createServer();
|
||||
testServerHttp2 = plugins.http2.createServer();
|
||||
testServerHttp2.on('stream', (stream, headers) => {
|
||||
stream.respond({
|
||||
'content-type': 'application/json',
|
||||
@@ -82,10 +80,10 @@ tap.test('should support static host/port routes', async () => {
|
||||
const routes: IRouteConfig[] = [
|
||||
{
|
||||
name: 'static-route',
|
||||
domain: 'example.com',
|
||||
priority: 100,
|
||||
match: {
|
||||
domain: 'example.com'
|
||||
domains: 'example.com',
|
||||
ports: 0
|
||||
},
|
||||
action: {
|
||||
type: 'forward',
|
||||
@@ -124,10 +122,10 @@ tap.test('should support function-based host', async () => {
|
||||
const routes: IRouteConfig[] = [
|
||||
{
|
||||
name: 'function-host-route',
|
||||
domain: 'function.example.com',
|
||||
priority: 100,
|
||||
match: {
|
||||
domain: 'function.example.com'
|
||||
domains: 'function.example.com',
|
||||
ports: 0
|
||||
},
|
||||
action: {
|
||||
type: 'forward',
|
||||
@@ -169,10 +167,10 @@ tap.test('should support function-based port', async () => {
|
||||
const routes: IRouteConfig[] = [
|
||||
{
|
||||
name: 'function-port-route',
|
||||
domain: 'function-port.example.com',
|
||||
priority: 100,
|
||||
match: {
|
||||
domain: 'function-port.example.com'
|
||||
domains: 'function-port.example.com',
|
||||
ports: 0
|
||||
},
|
||||
action: {
|
||||
type: 'forward',
|
||||
@@ -214,10 +212,10 @@ tap.test('should support function-based host AND port', async () => {
|
||||
const routes: IRouteConfig[] = [
|
||||
{
|
||||
name: 'function-both-route',
|
||||
domain: 'function-both.example.com',
|
||||
priority: 100,
|
||||
match: {
|
||||
domain: 'function-both.example.com'
|
||||
domains: 'function-both.example.com',
|
||||
ports: 0
|
||||
},
|
||||
action: {
|
||||
type: 'forward',
|
||||
@@ -260,10 +258,10 @@ tap.test('should support context-based routing with path', async () => {
|
||||
const routes: IRouteConfig[] = [
|
||||
{
|
||||
name: 'context-path-route',
|
||||
domain: 'context.example.com',
|
||||
priority: 100,
|
||||
match: {
|
||||
domain: 'context.example.com'
|
||||
domains: 'context.example.com',
|
||||
ports: 0
|
||||
},
|
||||
action: {
|
||||
type: 'forward',
|
||||
@@ -338,10 +336,10 @@ tap.test('cleanup NetworkProxy function-based targets test environment', async (
|
||||
});
|
||||
|
||||
// Helper function to make HTTPS requests with self-signed certificate support
|
||||
async function makeRequest(options: http.RequestOptions): Promise<{ statusCode: number, headers: http.IncomingHttpHeaders, body: string }> {
|
||||
async function makeRequest(options: plugins.http.RequestOptions): Promise<{ statusCode: number, headers: plugins.http.IncomingHttpHeaders, body: string }> {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Use HTTPS with rejectUnauthorized: false to accept self-signed certificates
|
||||
const req = https.request({
|
||||
const req = plugins.https.request({
|
||||
...options,
|
||||
rejectUnauthorized: false, // Accept self-signed certificates
|
||||
}, (res) => {
|
||||
|
||||
Reference in New Issue
Block a user