2025-05-19 12:04:26 +00:00
|
|
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
2025-05-09 14:15:45 +00:00
|
|
|
import * as plugins from '../ts/plugins.js';
|
|
|
|
|
|
2026-03-26 20:45:41 +00:00
|
|
|
import type { IRouteConfig } from '../ts/proxies/smart-proxy/models/route-types.js';
|
2025-05-09 14:15:45 +00:00
|
|
|
|
2025-05-10 13:59:34 +00:00
|
|
|
function findRouteForDomain(routes: any[], domain: string): any {
|
|
|
|
|
return routes.find(route => {
|
|
|
|
|
const domains = Array.isArray(route.match.domains)
|
|
|
|
|
? route.match.domains
|
|
|
|
|
: [route.match.domains];
|
2025-05-15 19:39:09 +00:00
|
|
|
return domains.includes(domain);
|
2025-05-10 13:59:34 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-15 19:39:09 +00:00
|
|
|
tap.test('Route Helpers - Create HTTP routes', async () => {
|
2026-03-26 20:45:41 +00:00
|
|
|
const route: IRouteConfig = {
|
|
|
|
|
match: { ports: 80, domains: 'example.com' },
|
|
|
|
|
action: { type: 'forward', targets: [{ host: 'localhost', port: 3000 }] }
|
|
|
|
|
};
|
2025-05-15 19:39:09 +00:00
|
|
|
expect(route.action.type).toEqual('forward');
|
|
|
|
|
expect(route.match.domains).toEqual('example.com');
|
2025-07-21 08:45:13 +00:00
|
|
|
expect(route.action.targets?.[0]).toEqual({ host: 'localhost', port: 3000 });
|
2025-05-15 19:39:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tap.test('Route Helpers - Create HTTPS terminate to HTTP routes', async () => {
|
2026-03-26 20:45:41 +00:00
|
|
|
const route: IRouteConfig = {
|
|
|
|
|
match: { ports: 443, domains: 'secure.example.com' },
|
|
|
|
|
action: { type: 'forward', targets: [{ host: 'localhost', port: 3000 }], tls: { mode: 'terminate', certificate: 'auto' } }
|
|
|
|
|
};
|
2025-05-15 19:39:09 +00:00
|
|
|
expect(route.action.type).toEqual('forward');
|
|
|
|
|
expect(route.match.domains).toEqual('secure.example.com');
|
|
|
|
|
expect(route.action.tls?.mode).toEqual('terminate');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tap.test('Route Helpers - Create HTTPS passthrough routes', async () => {
|
2026-03-26 20:45:41 +00:00
|
|
|
const route: IRouteConfig = {
|
|
|
|
|
match: { ports: 443, domains: 'passthrough.example.com' },
|
|
|
|
|
action: { type: 'forward', targets: [{ host: 'backend', port: 443 }], tls: { mode: 'passthrough' } }
|
|
|
|
|
};
|
2025-05-15 19:39:09 +00:00
|
|
|
expect(route.action.type).toEqual('forward');
|
|
|
|
|
expect(route.match.domains).toEqual('passthrough.example.com');
|
|
|
|
|
expect(route.action.tls?.mode).toEqual('passthrough');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tap.test('Route Helpers - Create HTTPS to HTTPS routes', async () => {
|
2026-03-26 20:45:41 +00:00
|
|
|
const route: IRouteConfig = {
|
|
|
|
|
match: { ports: 443, domains: 'reencrypt.example.com' },
|
|
|
|
|
action: { type: 'forward', targets: [{ host: 'backend', port: 443 }], tls: { mode: 'terminate-and-reencrypt', certificate: 'auto' } }
|
|
|
|
|
};
|
2025-05-15 19:39:09 +00:00
|
|
|
expect(route.action.type).toEqual('forward');
|
|
|
|
|
expect(route.match.domains).toEqual('reencrypt.example.com');
|
|
|
|
|
expect(route.action.tls?.mode).toEqual('terminate-and-reencrypt');
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-26 20:45:41 +00:00
|
|
|
export default tap.start();
|