From d52b65618a4ce25301c4fc0063e9f2725c9eb98e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Tue, 11 Mar 2025 11:06:09 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BC=98=E5=8C=96dns=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mitmproxy/test/dnsTest.mjs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/mitmproxy/test/dnsTest.mjs b/packages/mitmproxy/test/dnsTest.mjs index 75a36b0..1f177ad 100644 --- a/packages/mitmproxy/test/dnsTest.mjs +++ b/packages/mitmproxy/test/dnsTest.mjs @@ -33,6 +33,7 @@ const dnsProviders = dns.initDNS({ safe360: { server: 'https://doh.360.cn/dns-query', cacheSize: 1000, + forSNI: true, }, rubyfish: { server: 'https://rubyfish.cn/dns-query', @@ -93,7 +94,9 @@ const dnsProviders = dns.initDNS({ }, preSetIpList) -const presetHostname = 'xxx.com' +const hasPresetHostname = 'xxx.com' +const noPresetHostname = 'yyy.com' + const hostname1 = 'github.com' const hostname2 = 'api.github.com' const hostname3 = 'hk.docmirror.cn' @@ -104,15 +107,25 @@ const hostname6 = 'gh2.docmirror.top' let ip +console.log('\n--------------- test ForSNI ---------------\n') +console.log(`===> test ForSNI: ${dnsProviders.ForSNI.dnsName}`, '\n\n') +assert.strictEqual(dnsProviders.ForSNI, dnsProviders.safe360) + + console.log('\n--------------- test PreSet ---------------\n') -ip = await dnsProviders.PreSet.lookup(presetHostname) -console.log('===> test PreSet:', ip, '\n\n') +ip = await dnsProviders.PreSet.lookup(hasPresetHostname) +console.log(`===> test PreSet: ${hasPresetHostname} ->`, ip, '\n\n') console.log('\n\n') -assert.strictEqual(ip, presetIp) // test preset +assert.strictEqual(ip, presetIp) // 预设过IP,等于预设的IP + +ip = await dnsProviders.PreSet.lookup(noPresetHostname) +console.log(`===> test PreSet: ${noPresetHostname} ->`, ip, '\n\n') +console.log('\n\n') +assert.strictEqual(ip, noPresetHostname) // 未预设IP,等于域名自己 console.log('\n--------------- test https ---------------\n') -ip = await dnsProviders.cloudflare.lookup(presetHostname) +ip = await dnsProviders.cloudflare.lookup(hasPresetHostname) assert.strictEqual(ip, presetIp) // test preset console.log('\n\n') @@ -146,7 +159,7 @@ assert.strictEqual(dnsProviders.py233.dnsType, 'HTTPS') console.log('\n--------------- test TLS ---------------\n') -ip = await dnsProviders.cloudflareTLS.lookup(presetHostname) +ip = await dnsProviders.cloudflareTLS.lookup(hasPresetHostname) assert.strictEqual(ip, presetIp) // test preset console.log('\n\n') @@ -172,7 +185,7 @@ console.log(`===> test safe360TLS: ${hostname1} ->`, ip, '\n\n') console.log('\n--------------- test TCP ---------------\n') -ip = await dnsProviders.googleTCP.lookup(presetHostname) +ip = await dnsProviders.googleTCP.lookup(hasPresetHostname) assert.strictEqual(ip, presetIp) // test preset console.log('\n\n') @@ -186,7 +199,7 @@ console.log(`===> test aliyunTCP: ${hostname1} ->`, ip, '\n\n') console.log('\n--------------- test UDP ---------------\n') -ip = await dnsProviders.googleUDP.lookup(presetHostname) +ip = await dnsProviders.googleUDP.lookup(hasPresetHostname) assert.strictEqual(ip, presetIp) // test preset console.log('\n\n')