56 lines
2.3 KiB
TypeScript
56 lines
2.3 KiB
TypeScript
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
|
import * as plugins from '../ts/plugins.js';
|
|
|
|
import type { IRouteConfig } from '../ts/proxies/smart-proxy/models/route-types.js';
|
|
|
|
function findRouteForDomain(routes: any[], domain: string): any {
|
|
return routes.find(route => {
|
|
const domains = Array.isArray(route.match.domains)
|
|
? route.match.domains
|
|
: [route.match.domains];
|
|
return domains.includes(domain);
|
|
});
|
|
}
|
|
|
|
tap.test('Route Helpers - Create HTTP routes', async () => {
|
|
const route: IRouteConfig = {
|
|
match: { ports: 80, domains: 'example.com' },
|
|
action: { type: 'forward', targets: [{ host: 'localhost', port: 3000 }] }
|
|
};
|
|
expect(route.action.type).toEqual('forward');
|
|
expect(route.match.domains).toEqual('example.com');
|
|
expect(route.action.targets?.[0]).toEqual({ host: 'localhost', port: 3000 });
|
|
});
|
|
|
|
tap.test('Route Helpers - Create HTTPS terminate to HTTP routes', async () => {
|
|
const route: IRouteConfig = {
|
|
match: { ports: 443, domains: 'secure.example.com' },
|
|
action: { type: 'forward', targets: [{ host: 'localhost', port: 3000 }], tls: { mode: 'terminate', certificate: 'auto' } }
|
|
};
|
|
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 () => {
|
|
const route: IRouteConfig = {
|
|
match: { ports: 443, domains: 'passthrough.example.com' },
|
|
action: { type: 'forward', targets: [{ host: 'backend', port: 443 }], tls: { mode: 'passthrough' } }
|
|
};
|
|
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 () => {
|
|
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' } }
|
|
};
|
|
expect(route.action.type).toEqual('forward');
|
|
expect(route.match.domains).toEqual('reencrypt.example.com');
|
|
expect(route.action.tls?.mode).toEqual('terminate-and-reencrypt');
|
|
});
|
|
|
|
export default tap.start();
|