Skip to content

Commit ab74a44

Browse files
test: DNS单测调整。
1 parent 46024e5 commit ab74a44

File tree

3 files changed

+115
-55
lines changed

3 files changed

+115
-55
lines changed

packages/mitmproxy/src/options.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const fs = require('node:fs')
22
const path = require('node:path')
33
const lodash = require('lodash')
4-
const jsonApi = require('./json')
54
const dnsUtil = require('./lib/dns')
65
const interceptorImpls = require('./lib/interceptor')
76
const scriptInterceptor = require('./lib/interceptor/impl/res/script')
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import assert from 'node:assert'
2+
import dns from '../src/lib/dns/index.js'
3+
import matchUtil from '../src/utils/util.match.js'
4+
5+
const presetIp = '100.100.100.100'
6+
const preSetIpList = matchUtil.domainMapRegexply({
7+
'xxx.com': [
8+
presetIp
9+
]
10+
})
11+
12+
// 境外DNS测试
13+
const dnsProviders = dns.initDNS({
14+
// https
15+
cloudflare: {
16+
type: 'https',
17+
server: 'https://1.1.1.1/dns-query',
18+
cacheSize: 1000,
19+
},
20+
quad9: {
21+
server: 'https://9.9.9.9/dns-query',
22+
cacheSize: 1000,
23+
forSNI: true,
24+
},
25+
rubyfish: {
26+
server: 'https://rubyfish.cn/dns-query',
27+
cacheSize: 1000,
28+
},
29+
py233: {
30+
server: ' https://i.233py.com/dns-query',
31+
cacheSize: 1000,
32+
},
33+
34+
// tls
35+
cloudflareTLS: {
36+
type: 'tls',
37+
server: '1.1.1.1',
38+
servername: 'cloudflare-dns.com',
39+
cacheSize: 1000,
40+
},
41+
quad9TLS: {
42+
server: 'tls://9.9.9.9',
43+
servername: 'dns.quad9.net',
44+
cacheSize: 1000,
45+
},
46+
}, preSetIpList)
47+
48+
49+
const hasPresetHostname = 'xxx.com'
50+
const noPresetHostname = 'yyy.com'
51+
52+
const hostname1 = 'github.com'
53+
const hostname2 = 'api.github.com'
54+
const hostname3 = 'hk.docmirror.cn'
55+
const hostname4 = 'github.docmirror.cn'
56+
const hostname5 = 'gh.docmirror.top'
57+
const hostname6 = 'gh2.docmirror.top'
58+
59+
let ip
60+
61+
62+
console.log('\n--------------- test ForSNI ---------------\n')
63+
console.log(`===> test ForSNI: ${dnsProviders.ForSNI.dnsName}`, '\n\n')
64+
assert.strictEqual(dnsProviders.ForSNI, dnsProviders.quad9)
65+
66+
67+
console.log('\n--------------- test PreSet ---------------\n')
68+
ip = await dnsProviders.PreSet.lookup(hasPresetHostname)
69+
console.log(`===> test PreSet: ${hasPresetHostname} ->`, ip, '\n\n')
70+
console.log('\n\n')
71+
assert.strictEqual(ip, presetIp) // 预设过IP,等于预设的IP
72+
73+
ip = await dnsProviders.PreSet.lookup(noPresetHostname)
74+
console.log(`===> test PreSet: ${noPresetHostname} ->`, ip, '\n\n')
75+
console.log('\n\n')
76+
assert.strictEqual(ip, noPresetHostname) // 未预设IP,等于域名自己
77+
78+
79+
console.log('\n--------------- test https ---------------\n')
80+
ip = await dnsProviders.cloudflare.lookup(hasPresetHostname)
81+
assert.strictEqual(ip, presetIp) // test preset
82+
console.log('\n\n')
83+
84+
assert.strictEqual(dnsProviders.cloudflare.dnsType, 'HTTPS')
85+
ip = await dnsProviders.cloudflare.lookup(hostname1)
86+
console.log(`===> test cloudflare: ${hostname1} ->`, ip, '\n\n')
87+
88+
assert.strictEqual(dnsProviders.quad9.dnsType, 'HTTPS')
89+
ip = await dnsProviders.quad9.lookup(hostname1)
90+
console.log(`===> test quad9: ${hostname1} ->`, ip, '\n\n')
91+
92+
assert.strictEqual(dnsProviders.rubyfish.dnsType, 'HTTPS')
93+
ip = await dnsProviders.rubyfish.lookup(hostname1)
94+
console.log(`===> test rubyfish: ${hostname1} ->`, ip, '\n\n')
95+
96+
assert.strictEqual(dnsProviders.py233.dnsType, 'HTTPS')
97+
ip = await dnsProviders.py233.lookup(hostname1)
98+
console.log(`===> test py233: ${hostname1} ->`, ip, '\n\n')
99+
100+
101+
console.log('\n--------------- test TLS ---------------\n')
102+
ip = await dnsProviders.cloudflareTLS.lookup(hasPresetHostname)
103+
assert.strictEqual(ip, presetIp) // test preset
104+
console.log('\n\n')
105+
106+
assert.strictEqual(dnsProviders.cloudflareTLS.dnsType, 'TLS')
107+
ip = await dnsProviders.cloudflareTLS.lookup(hostname1)
108+
console.log(`===> test cloudflareTLS: ${hostname1} ->`, ip, '\n\n')
109+
110+
assert.strictEqual(dnsProviders.quad9TLS.dnsType, 'TLS')
111+
ip = await dnsProviders.quad9TLS.lookup(hostname1)
112+
console.log(`===> test quad9TLS: ${hostname1} ->`, ip, '\n\n')

packages/mitmproxy/test/dnsTest.mjs

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,9 @@ const preSetIpList = matchUtil.domainMapRegexply({
99
]
1010
})
1111

12+
// 常用DNS测试
1213
const dnsProviders = dns.initDNS({
1314
// https
14-
cloudflare: {
15-
type: 'https',
16-
server: 'https://1.1.1.1/dns-query',
17-
cacheSize: 1000,
18-
},
19-
quad9: {
20-
server: 'https://9.9.9.9/dns-query',
21-
cacheSize: 1000,
22-
},
2315
aliyun: {
2416
type: 'https',
2517
server: 'https://dns.alidns.com/dns-query',
@@ -35,27 +27,8 @@ const dnsProviders = dns.initDNS({
3527
cacheSize: 1000,
3628
forSNI: true,
3729
},
38-
rubyfish: {
39-
server: 'https://rubyfish.cn/dns-query',
40-
cacheSize: 1000,
41-
},
42-
py233: {
43-
server: ' https://i.233py.com/dns-query',
44-
cacheSize: 1000,
45-
},
4630

4731
// tls
48-
cloudflareTLS: {
49-
type: 'tls',
50-
server: '1.1.1.1',
51-
servername: 'cloudflare-dns.com',
52-
cacheSize: 1000,
53-
},
54-
quad9TLS: {
55-
server: 'tls://9.9.9.9',
56-
servername: 'dns.quad9.net',
57-
cacheSize: 1000,
58-
},
5932
aliyunTLS: {
6033
server: 'tls://223.5.5.5:853',
6134
cacheSize: 1000,
@@ -133,18 +106,10 @@ assert.strictEqual(ip, noPresetHostname) // 未预设IP,等于域名自己
133106

134107

135108
console.log('\n--------------- test https ---------------\n')
136-
ip = await dnsProviders.cloudflare.lookup(hasPresetHostname)
109+
ip = await dnsProviders.aliyun.lookup(hasPresetHostname)
137110
assert.strictEqual(ip, presetIp) // test preset
138111
console.log('\n\n')
139112

140-
assert.strictEqual(dnsProviders.cloudflare.dnsType, 'HTTPS')
141-
// ip = await dnsProviders.cloudflare.lookup(hostname1)
142-
// console.log(`===> test cloudflare: ${hostname1} ->`, ip, '\n\n')
143-
144-
assert.strictEqual(dnsProviders.quad9.dnsType, 'HTTPS')
145-
// ip = await dnsProviders.quad9.lookup(hostname1)
146-
// console.log(`===> test quad9: ${hostname1} ->`, ip, '\n\n')
147-
148113
assert.strictEqual(dnsProviders.aliyun.dnsType, 'HTTPS')
149114
ip = await dnsProviders.aliyun.lookup(hostname1)
150115
console.log(`===> test aliyun: ${hostname1} ->`, ip, '\n\n')
@@ -157,28 +122,12 @@ assert.strictEqual(dnsProviders.safe360.dnsType, 'HTTPS')
157122
ip = await dnsProviders.safe360.lookup(hostname1)
158123
console.log(`===> test safe360: ${hostname1} ->`, ip, '\n\n')
159124

160-
assert.strictEqual(dnsProviders.rubyfish.dnsType, 'HTTPS')
161-
// ip = await dnsProviders.rubyfish.lookup(hostname1)
162-
// console.log(`===> test rubyfish: ${hostname1} ->`, ip, '\n\n')
163-
164-
assert.strictEqual(dnsProviders.py233.dnsType, 'HTTPS')
165-
// ip = await dnsProviders.py233.lookup(hostname1)
166-
// console.log(`===> test py233: ${hostname1} ->`, ip, '\n\n')
167-
168125

169126
console.log('\n--------------- test TLS ---------------\n')
170-
ip = await dnsProviders.cloudflareTLS.lookup(hasPresetHostname)
127+
ip = await dnsProviders.aliyunTLS.lookup(hasPresetHostname)
171128
assert.strictEqual(ip, presetIp) // test preset
172129
console.log('\n\n')
173130

174-
assert.strictEqual(dnsProviders.cloudflareTLS.dnsType, 'TLS')
175-
// ip = await dnsProviders.cloudflareTLS.lookup(hostname1)
176-
// console.log(`===> test cloudflareTLS: ${hostname1} ->`, ip, '\n\n')
177-
178-
assert.strictEqual(dnsProviders.quad9TLS.dnsType, 'TLS')
179-
// ip = await dnsProviders.quad9TLS.lookup(hostname1)
180-
// console.log(`===> test quad9TLS: ${hostname1} ->`, ip, '\n\n')
181-
182131
assert.strictEqual(dnsProviders.aliyunTLS.dnsType, 'TLS')
183132
ip = await dnsProviders.aliyunTLS.lookup(hostname1)
184133
console.log(`===> test aliyunTLS: ${hostname1} ->`, ip, '\n\n')

0 commit comments

Comments
 (0)