refactor dnscrypt parse
add test
This commit is contained in:
parent
ee37b9e95e
commit
a53b9c7a8e
10 changed files with 608 additions and 540 deletions
57
testing/test_dnscrypt.py
Normal file
57
testing/test_dnscrypt.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import unittest
|
||||
|
||||
from dnscrypt import parse, DNSCrypt, DNSoverHTTPS, DNSoverTLS, DNSoverQUIC, ObliviousDoH, DNSCryptRelay, \
|
||||
ObliviousDoHRelay, PlainDNS
|
||||
|
||||
|
||||
def comman_parse_test(test_case, stamp, instance, except_result_json):
|
||||
result = parse(stamp)
|
||||
test_case.assertIsInstance(result, instance)
|
||||
test_case.assertEqual(except_result_json, result.to_json())
|
||||
|
||||
|
||||
class TestDNSCryptStampParse(unittest.TestCase):
|
||||
|
||||
def test_DNSCrypt(self):
|
||||
stamp = "sdns://AQMAAAAAAAAAETk0LjE0MC4xNC4xNTo1NDQzILgxXdexS27jIKRw3C7Wsao5jMnlhvhdRUXWuMm1AFq6ITIuZG5zY3J5cHQuZmFtaWx5Lm5zMS5hZGd1YXJkLmNvbQ"
|
||||
except_result_json = '{"dnssec": true, "nolog": true, "nofilter": false, "addr": "94.140.14.15:5443", "pk": "B831:5DD7:B14B:6EE3:20A4:70DC:2ED6:B1AA:398C:C9E5:86F8:5D45:45D6:B8C9:B500:5ABA", "provider": "2.dnscrypt.family.ns1.adguard.com"}'
|
||||
comman_parse_test(self, stamp, DNSCrypt, except_result_json)
|
||||
|
||||
def test_DNSoverHTTPS(self):
|
||||
stamp = "sdns://AgMAAAAAAAAADjE2My40Ny4xMTcuMTc2oMwQYNOcgym2K2-8fQ1t-TCYabmB5-Y5LVzY-kCPTYDmoPf1ryiAHod9ffOivij-FJ8ydKftKfE2_VA845jLqAsNoLNeBZUM-9gln5N1uhAYcLjDxMDsWlKXV-YxZ-neJqnooEROvWe7g_iAezkh6TiskXi4gr1QqtsRIx8ETPXwjffOoOZEumlj4zX-dly5l2sSsQ61QpS0JHd2TMs6OsyjrLL8ICquP7e_BeTIHEGU3KRFEdT5rzBHhuwa5yGECc9ioINVEGFkbC5hZGZpbHRlci5uZXQKL2Rucy1xdWVyeQ"
|
||||
except_result_json = '{"dnssec": true, "nolog": true, "nofilter": false, "addr": "163.47.117.176", "hashs": ["cc1060d39c8329b62b6fbc7d0d6df9309869b981e7e6392d5cd8fa408f4d80e6", "f7f5af28801e877d7df3a2be28fe149f3274a7ed29f136fd503ce398cba80b0d", "b35e05950cfbd8259f9375ba101870b8c3c4c0ec5a529757e63167e9de26a9e8", "444ebd67bb83f8807b3921e938ac9178b882bd50aadb11231f044cf5f08df7ce", "e644ba6963e335fe765cb9976b12b10eb54294b42477764ccb3a3acca3acb2fc", "2aae3fb7bf05e4c81c4194dca44511d4f9af304786ec1ae7218409cf62a08355"], "hostname": "adl.adfilter.net", "path": "/dns-query"}'
|
||||
comman_parse_test(self, stamp, DNSoverHTTPS, except_result_json)
|
||||
|
||||
def test_DNSoverTLS(self):
|
||||
stamp = "sdns://AwcAAAAAAAAABzEuMS4xLjEAD29uZS5vbmUub25lLm9uZQ"
|
||||
except_result_json = '{"dnssec": true, "nolog": true, "nofilter": true, "addr": "1.1.1.1", "hashs": [], "hostname": "one.one.one.one"}'
|
||||
comman_parse_test(self, stamp, DNSoverTLS, except_result_json)
|
||||
|
||||
def test_DNSoverQUIC(self):
|
||||
stamp = "sdns://BAcAAAAAAAAABzEuMS4xLjEAD29uZS5vbmUub25lLm9uZQ"
|
||||
except_result_json = '{"dnssec": true, "nolog": true, "nofilter": true, "addr": "1.1.1.1", "hashs": [], "hostname": "one.one.one.one"}'
|
||||
comman_parse_test(self, stamp, DNSoverQUIC, except_result_json)
|
||||
|
||||
def test_ObliviousDoH(self):
|
||||
stamp = "sdns://BQcAAAAAAAAADWpwLnRpYXJhcC5vcmcFL29kb2g"
|
||||
except_result_json = '{"dnssec": true, "nolog": true, "nofilter": true, "hostname": "jp.tiarap.org", "path": "/odoh"}'
|
||||
comman_parse_test(self, stamp, ObliviousDoH, except_result_json)
|
||||
|
||||
def test_DNSCryptRelay(self):
|
||||
stamp = "sdns://gQ04Ni4xMDYuNzQuMjE5"
|
||||
except_result_json = '{"addr": "86.106.74.219"}'
|
||||
comman_parse_test(self, stamp, DNSCryptRelay, except_result_json)
|
||||
|
||||
def test_ObliviousDoHRelay(self):
|
||||
stamp = "sdns://hQcAAAAAAAAADDg5LjM4LjEzMS4zOAAYb2RvaC1ubC5hbGVrYmVyZy5uZXQ6NDQzBi9wcm94eQ"
|
||||
except_result_json = '{"dnssec": true, "nolog": true, "nofilter": true, "addr": "89.38.131.38", "hashs": [], "hostname": "odoh-nl.alekberg.net:443", "path": "/proxy"}'
|
||||
comman_parse_test(self, stamp, ObliviousDoHRelay, except_result_json)
|
||||
|
||||
def test_PlainDNS(self):
|
||||
stamp = "sdns://AAUAAAAAAAAABzEuMS4xLjE"
|
||||
except_result_json = '{"dnssec": true, "nolog": false, "nofilter": true, "addr": "1.1.1.1"}'
|
||||
comman_parse_test(self, stamp, PlainDNS, except_result_json)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
14
testing/test_dnscrypt_to_smartdns.py
Normal file
14
testing/test_dnscrypt_to_smartdns.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import unittest
|
||||
|
||||
from dnscrypt_to_smartdns import get_smartdns_config
|
||||
|
||||
|
||||
class MyTestCase(unittest.TestCase):
|
||||
def test_get_smartdns_config(self):
|
||||
conf_text = get_smartdns_config()
|
||||
# print(conf_text)
|
||||
self.assertIsInstance(conf_text, str)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
19
testing/test_gfwlist_to_dns.py
Normal file
19
testing/test_gfwlist_to_dns.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import unittest
|
||||
|
||||
from gfwlist_to_dns import get_dnsmasq_text, get_smartdns_domain_set
|
||||
|
||||
|
||||
class MyTestCase(unittest.TestCase):
|
||||
def test_get_dnsmasq_text(self):
|
||||
dnsmasq_text = get_dnsmasq_text()
|
||||
# print(dnsmasq_text)
|
||||
self.assertIsInstance(dnsmasq_text, str)
|
||||
|
||||
def test_get_smartdns_domain_set(self):
|
||||
domain_set = get_smartdns_domain_set()
|
||||
# print(domain_set)
|
||||
self.assertIsInstance(domain_set, str)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue