fix(client,testing,build): improve TypeScript compatibility for DNS client parsing and test suite
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import * as plugins from '../ts_server/plugins.js';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import { tapNodeTools } from '@git.zone/tstest/tapbundle_serverside';
|
||||
import { TapNodeTools } from '@git.zone/tstest/tapbundle_serverside';
|
||||
import * as dnsPacket from 'dns-packet';
|
||||
import * as dgram from 'dgram';
|
||||
|
||||
import * as smartdns from '../ts_server/index.js';
|
||||
|
||||
let dnsServer: smartdns.DnsServer;
|
||||
const tapNodeTools = new TapNodeTools(tap);
|
||||
|
||||
let dnsServer: smartdns.DnsServer | null;
|
||||
|
||||
// Port management for tests
|
||||
let nextHttpsPort = 8300;
|
||||
@@ -34,7 +36,7 @@ async function stopServer(server: smartdns.DnsServer | null | undefined) {
|
||||
|
||||
await Promise.race([stopPromise, timeoutPromise]);
|
||||
} catch (e) {
|
||||
console.log('Handled error when stopping server:', e.message || e);
|
||||
console.log('Handled error when stopping server:', e instanceof Error ? e.message : e);
|
||||
|
||||
// Force close if normal stop fails
|
||||
try {
|
||||
@@ -49,7 +51,7 @@ async function stopServer(server: smartdns.DnsServer | null | undefined) {
|
||||
(server as any).udpServer = null;
|
||||
}
|
||||
} catch (forceError) {
|
||||
console.log('Force cleanup error:', forceError.message || forceError);
|
||||
console.log('Force cleanup error:', forceError instanceof Error ? forceError.message : forceError);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,13 +130,13 @@ tap.test('should now return multiple NS records after fix', async () => {
|
||||
|
||||
const dnsResponse = await responsePromise;
|
||||
|
||||
console.log('Fixed behavior - NS records returned:', dnsResponse.answers.length);
|
||||
console.log('NS records:', dnsResponse.answers.filter(a => a.type === 'NS').map(a => a.data));
|
||||
console.log('Fixed behavior - NS records returned:', dnsResponse.answers!.length);
|
||||
console.log('NS records:', dnsResponse.answers!.filter(a => a.type === 'NS').map(a => (a as any).data));
|
||||
|
||||
// FIXED BEHAVIOR: Should now return both NS records
|
||||
const nsAnswers = dnsResponse.answers.filter(a => a.type === 'NS');
|
||||
const nsAnswers = dnsResponse.answers!.filter(a => a.type === 'NS');
|
||||
expect(nsAnswers.length).toEqual(2);
|
||||
expect(nsAnswers.map(a => a.data).sort()).toEqual(['ns1.example.com', 'ns2.example.com']);
|
||||
expect(nsAnswers.map(a => (a as any).data).sort()).toEqual(['ns1.example.com', 'ns2.example.com']);
|
||||
|
||||
await stopServer(dnsServer);
|
||||
dnsServer = null;
|
||||
@@ -206,13 +208,13 @@ tap.test('should support round-robin DNS with multiple A records', async () => {
|
||||
|
||||
const dnsResponse = await responsePromise;
|
||||
|
||||
console.log('Fixed behavior - A records returned:', dnsResponse.answers.length);
|
||||
console.log('A records:', dnsResponse.answers.filter(a => a.type === 'A').map(a => a.data));
|
||||
console.log('Fixed behavior - A records returned:', dnsResponse.answers!.length);
|
||||
console.log('A records:', dnsResponse.answers!.filter(a => a.type === 'A').map(a => (a as any).data));
|
||||
|
||||
// FIXED BEHAVIOR: Should return all A records for round-robin
|
||||
const aAnswers = dnsResponse.answers.filter(a => a.type === 'A');
|
||||
const aAnswers = dnsResponse.answers!.filter(a => a.type === 'A');
|
||||
expect(aAnswers.length).toEqual(3);
|
||||
expect(aAnswers.map(a => a.data).sort()).toEqual(['10.0.0.1', '10.0.0.2', '10.0.0.3']);
|
||||
expect(aAnswers.map(a => (a as any).data).sort()).toEqual(['10.0.0.1', '10.0.0.2', '10.0.0.3']);
|
||||
|
||||
await stopServer(dnsServer);
|
||||
dnsServer = null;
|
||||
@@ -289,8 +291,8 @@ tap.test('should return multiple TXT records', async () => {
|
||||
|
||||
const dnsResponse = await responsePromise;
|
||||
|
||||
console.log('Fixed behavior - TXT records returned:', dnsResponse.answers.length);
|
||||
const txtAnswers = dnsResponse.answers.filter(a => a.type === 'TXT');
|
||||
console.log('Fixed behavior - TXT records returned:', dnsResponse.answers!.length);
|
||||
const txtAnswers = dnsResponse.answers!.filter(a => a.type === 'TXT');
|
||||
console.log('TXT records count:', txtAnswers.length);
|
||||
|
||||
// FIXED BEHAVIOR: Should return all TXT records
|
||||
@@ -388,10 +390,10 @@ tap.test('should handle DNSSEC correctly with multiple records', async () => {
|
||||
|
||||
const dnsResponse = await responsePromise;
|
||||
|
||||
console.log('DNSSEC response - total answers:', dnsResponse.answers.length);
|
||||
console.log('DNSSEC response - total answers:', dnsResponse.answers!.length);
|
||||
|
||||
const nsAnswers = dnsResponse.answers.filter(a => a.type === 'NS');
|
||||
const rrsigAnswers = dnsResponse.answers.filter(a => a.type === 'RRSIG');
|
||||
const nsAnswers = dnsResponse.answers!.filter(a => a.type === 'NS');
|
||||
const rrsigAnswers = dnsResponse.answers!.filter(a => a.type === 'RRSIG');
|
||||
|
||||
console.log('NS records:', nsAnswers.length);
|
||||
console.log('RRSIG records:', rrsigAnswers.length);
|
||||
@@ -417,7 +419,7 @@ tap.test('should not return duplicate records when same handler registered multi
|
||||
});
|
||||
|
||||
// Register the same handler multiple times (edge case)
|
||||
const sameHandler = (question) => {
|
||||
const sameHandler = (question: smartdns.IDnsQuestion) => {
|
||||
return {
|
||||
name: question.name,
|
||||
type: 'A',
|
||||
@@ -470,16 +472,16 @@ tap.test('should not return duplicate records when same handler registered multi
|
||||
|
||||
const dnsResponse = await responsePromise;
|
||||
|
||||
const aAnswers = dnsResponse.answers.filter(a => a.type === 'A');
|
||||
const aAnswers = dnsResponse.answers!.filter(a => a.type === 'A');
|
||||
console.log('Duplicate handler test - A records returned:', aAnswers.length);
|
||||
|
||||
// Even though handler is registered 3 times, we get 3 identical records
|
||||
// This is expected behavior - the DNS server doesn't deduplicate
|
||||
expect(aAnswers.length).toEqual(3);
|
||||
expect(aAnswers.every(a => a.data === '10.0.0.1')).toEqual(true);
|
||||
expect(aAnswers.every(a => (a as any).data === '10.0.0.1')).toEqual(true);
|
||||
|
||||
await stopServer(dnsServer);
|
||||
dnsServer = null;
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
export default tap.start();
|
||||
|
||||
Reference in New Issue
Block a user