From 8b08b35ce399b06e2fe3ac6f4ad331123d66e0b0 Mon Sep 17 00:00:00 2001 From: pengshiyu <1940607002@qq.com> Date: Tue, 30 May 2023 16:45:54 +0800 Subject: [PATCH] fix --- docs/domain-expect.txt | 99 +++++++++++++++++++++++++++++++ docs/domain.txt | 3 +- domain_admin/utils/domain_util.py | 7 ++- tests/utils/test_domain_util.py | 18 ++++++ 4 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 docs/domain-expect.txt diff --git a/docs/domain-expect.txt b/docs/domain-expect.txt new file mode 100644 index 0000000000..f20a956907 --- /dev/null +++ b/docs/domain-expect.txt @@ -0,0 +1,99 @@ +www.jd.com +www.qq.com +www.360.com +www.vip.com +www.baidu.com +www.toutiao.com +www.taobao.com +www.xiaomi.com +www.apple.com +www.bilibili.tv +www.baidu.com +www.python.org +www.pconline.com.cn +www.xiaomi.cn +www.csdn.net +www.gov.xyz +expired.badssl.com +hsts.badssl.com +self-signed.badssl.com +sha256.badssl.com +tls-v1-2.badssl.com:1012 +untrusted-root.badssl.com +wrong.host.badssl.com +www.mysite.com +expired.badssl.com +wrong.host.badssl.com +self-signed.badssl.com +untrusted-root.badssl.com +revoked.badssl.com +pinning-test.badssl.com +no-common-name.badssl.com +no-subject.badssl.com +incomplete-chain.badssl.com +sha256.badssl.com +sha384.badssl.com +sha512.badssl.com +1000-sans.badssl.com +10000-sans.badssl.com +ecc256.badssl.com +ecc384.badssl.com +rsa2048.badssl.com +rsa4096.badssl.com +rsa8192.badssl.com +extended-validation.badssl.com +badssl.com +client.badssl.com +client-cert-missing.badssl.com +mixed-script.badssl.com +very.badssl.com +mixed.badssl.com +mixed-favicon.badssl.com +mixed-form.badssl.com +http.badssl.com +http-textarea.badssl.com +http-password.badssl.com +http-login.badssl.com +http-dynamic-login.badssl.com +http-credit-card.badssl.com +cbc.badssl.com +rc4-md5.badssl.com +rc4.badssl.com +3des.badssl.com +null.badssl.com +mozilla-old.badssl.com +mozilla-intermediate.badssl.com +mozilla-modern.badssl.com +dh480.badssl.com +dh512.badssl.com +dh1024.badssl.com +dh2048.badssl.com +dh-small-subgroup.badssl.com +dh-composite.badssl.com +static-rsa.badssl.com +tls-v1-0.badssl.com:1010 +tls-v1-1.badssl.com:1011 +tls-v1-2.badssl.com:1012 +no-sct.badssl.com +hsts.badssl.com +upgrade.badssl.com +preloaded-hsts.badssl.com +subdomain.preloaded-hsts.badssl.com +https-everywhere.badssl.com +spoofed-favicon.badssl.com +lock-title.badssl.com +long-extended-subdomain-name-containing-many-letters-and-dashes.badssl.com +longextendedsubdomainnamewithoutdashesinordertotestwordwrapping.badssl.com +superfish.badssl.com +edellroot.badssl.com +dsdtestprovider.badssl.com +preact-cli.badssl.com +webpack-dev-server.badssl.com +captive-portal.badssl.com +mitm-software.badssl.com +sha1-2016.badssl.com +sha1-2017.badssl.com +sha1-intermediate.badssl.com +invalid-expected-sct.badssl.com +testsafebrowsing.appspot.com +www.米梵家居.com diff --git a/docs/domain.txt b/docs/domain.txt index 7c6cd962e5..b9e152ab26 100644 --- a/docs/domain.txt +++ b/docs/domain.txt @@ -21,7 +21,7 @@ sha256.badssl.com tls-v1-2.badssl.com:1012 untrusted-root.badssl.com wrong.host.badssl.com -www.mysite.com +http://www.mysite.com https://expired.badssl.com/ https://wrong.host.badssl.com/ https://self-signed.badssl.com/ @@ -96,3 +96,4 @@ https://sha1-2017.badssl.com/ https://sha1-intermediate.badssl.com/ https://invalid-expected-sct.badssl.com/ https://testsafebrowsing.appspot.com/ +www.米梵家居.com diff --git a/domain_admin/utils/domain_util.py b/domain_admin/utils/domain_util.py index aa1a40a42b..51a32438f7 100644 --- a/domain_admin/utils/domain_util.py +++ b/domain_admin/utils/domain_util.py @@ -12,9 +12,12 @@ def parse_domain(domain): :param domain: :return: """ - ret = re.match('.*?/?/?([a-zA-Z\\.0-9_:-]+)/?.*?', domain) + # print(domain) + + ret = re.match('((http(s)?:)?//)?(?P[\\w\\._:-]+)/?.*?', domain) if ret: - return ret.groups()[0] + # print(ret.groups()) + return ret.groupdict().get("domain") else: return None diff --git a/tests/utils/test_domain_util.py b/tests/utils/test_domain_util.py index 9e3cbc7b71..9fc17b5783 100644 --- a/tests/utils/test_domain_util.py +++ b/tests/utils/test_domain_util.py @@ -25,3 +25,21 @@ def test_extract_domain(): lst = domain_util.parse_domain_from_file(filename) for line in lst: print(domain_util.extract_domain(line)) + + +def test_parse_domain_from_txt_file(): + """ + 测试域名解析函数 + :return: + """ + domain_filename = '../../docs/domain.txt' + domain_expect_filename = '../../docs/domain-expect.txt' + + expect_domains = None + with open(domain_expect_filename, 'r') as f: + expect_domains = [row.strip() for row in f.readlines()] + + if os.path.exists(domain_filename): + lst = domain_util.parse_domain_from_txt_file(domain_filename) + for index, row in enumerate(lst): + assert row['domain'] == expect_domains[index]