fix(tests): update tests and test helpers to current email/DNS APIs, use non-privileged ports, and improve robustness and resilience

This commit is contained in:
2026-02-01 18:10:30 +00:00
parent 2206abd04b
commit b90650c660
23 changed files with 2006 additions and 1756 deletions

View File

@@ -9,17 +9,17 @@ import { DcRouter } from '../ts/classes.dcrouter.js';
let dcRouter: DcRouter;
tap.test('DNS route generation with dnsDomain', async () => {
tap.test('DNS route generation with dnsNsDomains', async () => {
dcRouter = new DcRouter({
dnsDomain: 'dns.unit.test'
dnsNsDomains: ['dns.unit.test']
});
// Test the route generation directly
const dnsRoutes = (dcRouter as any).generateDnsRoutes();
expect(dnsRoutes).toBeDefined();
expect(dnsRoutes.length).toEqual(2);
// Check /dns-query route
const dnsQueryRoute = dnsRoutes[0];
expect(dnsQueryRoute.name).toEqual('dns-over-https-dns-query');
@@ -28,7 +28,7 @@ tap.test('DNS route generation with dnsDomain', async () => {
expect(dnsQueryRoute.match.path).toEqual('/dns-query');
expect(dnsQueryRoute.action.type).toEqual('socket-handler');
expect(dnsQueryRoute.action.socketHandler).toBeDefined();
// Check /resolve route
const resolveRoute = dnsRoutes[1];
expect(resolveRoute.name).toEqual('dns-over-https-resolve');
@@ -39,13 +39,13 @@ tap.test('DNS route generation with dnsDomain', async () => {
expect(resolveRoute.action.socketHandler).toBeDefined();
});
tap.test('DNS route generation without dnsDomain', async () => {
tap.test('DNS route generation without dnsNsDomains', async () => {
dcRouter = new DcRouter({
// No dnsDomain set
// No dnsNsDomains set
});
const dnsRoutes = (dcRouter as any).generateDnsRoutes();
expect(dnsRoutes).toBeDefined();
expect(dnsRoutes.length).toEqual(0); // No routes generated
});
@@ -134,7 +134,7 @@ tap.test('Email TLS modes are set correctly', async () => {
tap.test('Combined DNS and email configuration', async () => {
dcRouter = new DcRouter({
dnsDomain: 'dns.combined.test',
dnsNsDomains: ['dns.combined.test'],
emailConfig: {
ports: [25],
hostname: 'mail.combined.test',
@@ -143,18 +143,18 @@ tap.test('Combined DNS and email configuration', async () => {
useSocketHandler: true
}
});
// Generate both types of routes
const dnsRoutes = (dcRouter as any).generateDnsRoutes();
const emailRoutes = (dcRouter as any).generateEmailRoutes(dcRouter.options.emailConfig);
// Check DNS routes
expect(dnsRoutes.length).toEqual(2);
dnsRoutes.forEach((route: any) => {
expect(route.action.type).toEqual('socket-handler');
expect(route.match.domains).toEqual(['dns.combined.test']);
});
// Check email routes
expect(emailRoutes.length).toEqual(1);
expect(emailRoutes[0].action.type).toEqual('socket-handler');
@@ -163,7 +163,7 @@ tap.test('Combined DNS and email configuration', async () => {
tap.test('Socket handler functions are created correctly', async () => {
dcRouter = new DcRouter({
dnsDomain: 'dns.handler.test',
dnsNsDomains: ['dns.handler.test'],
emailConfig: {
ports: [25, 465],
hostname: 'mail.handler.test',