feat(dnsserver): Return multiple matching records, improve DNSSEC RRset signing, add client resolution strategy and localhost handling, update tests
This commit is contained in:
@@ -54,7 +54,7 @@ async function stopServer(server: smartdns.DnsServer | null | undefined) {
|
||||
}
|
||||
}
|
||||
|
||||
tap.test('should demonstrate the current limitation with multiple NS records', async () => {
|
||||
tap.test('should properly return multiple NS records', async () => {
|
||||
const httpsData = await tapNodeTools.createHttpsCert();
|
||||
const udpPort = getUniqueUdpPort();
|
||||
|
||||
@@ -131,15 +131,16 @@ tap.test('should demonstrate the current limitation with multiple NS records', a
|
||||
console.log('Current behavior - NS records returned:', dnsResponse.answers.length);
|
||||
console.log('NS records:', dnsResponse.answers.map(a => (a as any).data));
|
||||
|
||||
// CURRENT BEHAVIOR: Only returns 1 NS record due to the break statement
|
||||
expect(dnsResponse.answers.length).toEqual(1);
|
||||
expect((dnsResponse.answers[0] as any).data).toEqual('ns1.example.com');
|
||||
// Should return all registered NS records
|
||||
expect(dnsResponse.answers.length).toEqual(2);
|
||||
const nsData = dnsResponse.answers.map(a => (a as any).data).sort();
|
||||
expect(nsData).toEqual(['ns1.example.com', 'ns2.example.com']);
|
||||
|
||||
await stopServer(dnsServer);
|
||||
dnsServer = null;
|
||||
});
|
||||
|
||||
tap.test('should demonstrate the limitation with multiple A records (round-robin)', async () => {
|
||||
tap.test('should properly return multiple A records for round-robin DNS', async () => {
|
||||
const httpsData = await tapNodeTools.createHttpsCert();
|
||||
const udpPort = getUniqueUdpPort();
|
||||
|
||||
@@ -227,15 +228,16 @@ tap.test('should demonstrate the limitation with multiple A records (round-robin
|
||||
console.log('Current behavior - A records returned:', dnsResponse.answers.length);
|
||||
console.log('A records:', dnsResponse.answers.map(a => (a as any).data));
|
||||
|
||||
// CURRENT BEHAVIOR: Only returns 1 A record, preventing round-robin DNS
|
||||
expect(dnsResponse.answers.length).toEqual(1);
|
||||
expect((dnsResponse.answers[0] as any).data).toEqual('10.0.0.1');
|
||||
// Should return all registered A records for round-robin DNS
|
||||
expect(dnsResponse.answers.length).toEqual(3);
|
||||
const aData = dnsResponse.answers.map(a => (a as any).data).sort();
|
||||
expect(aData).toEqual(['10.0.0.1', '10.0.0.2', '10.0.0.3']);
|
||||
|
||||
await stopServer(dnsServer);
|
||||
dnsServer = null;
|
||||
});
|
||||
|
||||
tap.test('should demonstrate the limitation with multiple TXT records', async () => {
|
||||
tap.test('should properly return multiple TXT records', async () => {
|
||||
const httpsData = await tapNodeTools.createHttpsCert();
|
||||
const udpPort = getUniqueUdpPort();
|
||||
|
||||
@@ -323,15 +325,18 @@ tap.test('should demonstrate the limitation with multiple TXT records', async ()
|
||||
console.log('Current behavior - TXT records returned:', dnsResponse.answers.length);
|
||||
console.log('TXT records:', dnsResponse.answers.map(a => (a as any).data));
|
||||
|
||||
// CURRENT BEHAVIOR: Only returns 1 TXT record instead of all 3
|
||||
expect(dnsResponse.answers.length).toEqual(1);
|
||||
expect((dnsResponse.answers[0] as any).data[0]).toInclude('spf1');
|
||||
// Should return all registered TXT records
|
||||
expect(dnsResponse.answers.length).toEqual(3);
|
||||
const txtData = dnsResponse.answers.map(a => (a as any).data[0]).sort();
|
||||
expect(txtData[0]).toInclude('google-site-verification');
|
||||
expect(txtData[1]).toInclude('DKIM1');
|
||||
expect(txtData[2]).toInclude('spf1');
|
||||
|
||||
await stopServer(dnsServer);
|
||||
dnsServer = null;
|
||||
});
|
||||
|
||||
tap.test('should show the current workaround pattern', async () => {
|
||||
tap.test('should rotate between records when using a single handler', async () => {
|
||||
const httpsData = await tapNodeTools.createHttpsCert();
|
||||
const udpPort = getUniqueUdpPort();
|
||||
|
||||
@@ -343,11 +348,11 @@ tap.test('should show the current workaround pattern', async () => {
|
||||
dnssecZone: 'example.com',
|
||||
});
|
||||
|
||||
// WORKAROUND: Create an array to store NS records and return them from a single handler
|
||||
// Pattern: Create an array to store NS records and rotate through them
|
||||
const nsRecords = ['ns1.example.com', 'ns2.example.com'];
|
||||
let nsIndex = 0;
|
||||
|
||||
// This workaround still doesn't solve the problem because only one handler executes
|
||||
// This pattern rotates between records on successive queries
|
||||
dnsServer.registerHandler('example.com', ['NS'], (question) => {
|
||||
const record = nsRecords[nsIndex % nsRecords.length];
|
||||
nsIndex++;
|
||||
@@ -406,7 +411,7 @@ tap.test('should show the current workaround pattern', async () => {
|
||||
console.log('First query NS:', (response1.answers[0] as any).data);
|
||||
console.log('Second query NS:', (response2.answers[0] as any).data);
|
||||
|
||||
// This workaround rotates between records but still only returns one at a time
|
||||
// This pattern rotates between records but returns one at a time per query
|
||||
expect(response1.answers.length).toEqual(1);
|
||||
expect(response2.answers.length).toEqual(1);
|
||||
expect((response1.answers[0] as any).data).toEqual('ns1.example.com');
|
||||
|
Reference in New Issue
Block a user