From f7f84a5df3b28ced0ee463e01feef2a87bd0cc22 Mon Sep 17 00:00:00 2001 From: Yablargo Date: Wed, 26 Oct 2022 17:58:39 -0400 Subject: [PATCH] Address issue #1 and #3 by altering Domain() initializer --- tests/test_cdnengine.py | 46 +++++++++++++++++++++++++ tests/test_detectCDN.py | 74 ++++++----------------------------------- 2 files changed, 57 insertions(+), 63 deletions(-) diff --git a/tests/test_cdnengine.py b/tests/test_cdnengine.py index 4cb06d0..e8cb04a 100644 --- a/tests/test_cdnengine.py +++ b/tests/test_cdnengine.py @@ -9,6 +9,52 @@ TIMEOUT = 30 THREADS = 0 # If 0 then cdnEngine uses CPU count to set thread count +def test_domain_init(): + """Test domain initializer to ensure that values are not being inadvertently shared + between instances""" + + domain1 = findcdn.cdnEngine.detectCDN.Domain("foo.absolutely.fake.zzz1") + domain2 = findcdn.cdnEngine.detectCDN.Domain("bar.absolutely.fake.zzz1") + assert domain1.url == "foo.absolutely.fake.zzz1" + assert domain2.url == "bar.absolutely.fake.zzz1" + #ensure that both start blank + for d in [domain1,domain2]: + assert d.ip == [] + assert d.cnames == [] + assert d.cdns == [] + assert d.cdns_by_name == [] + assert d.namesrvs == [] + assert d.headers == [] + assert d.whois_data == [] + assert d.cdn_present == False + + #now, add some data to each field in domain1 + domain1.ip.append("d1_ip") + domain1.cnames.append("d1_cnames") + domain1.cdns.append("d1_cdns") + domain1.namesrvs.append("d1_namesrvs") + domain1.headers.append("d1_headers") + domain1.whois_data.append("d1_whois_data") + domain1.cdn_present = True + + #ensure that the domain1 has the values... + assert domain1.ip == ["d1_ip"] + assert domain1.cnames == ["d1_cnames"] + assert domain1.cdns == ["d1_cdns"] + assert domain1.namesrvs == ["d1_namesrvs"] + assert domain1.headers == ["d1_headers"] + assert domain1.whois_data == ["d1_whois_data"] + assert domain1.cdn_present == True + #and domain2 does not. + assert domain2.ip == [] + assert domain2.cnames == [] + assert domain2.cdns == [] + assert domain2.namesrvs == [] + assert domain2.headers == [] + assert domain2.whois_data == [] + assert domain2.cdn_present == False + + def test_domainpot_init(): """Test if DomainPot can be instantiated correctly.""" diff --git a/tests/test_detectCDN.py b/tests/test_detectCDN.py index f2c90b4..af57442 100644 --- a/tests/test_detectCDN.py +++ b/tests/test_detectCDN.py @@ -17,8 +17,7 @@ def test_ip(): dns.resolver.default_resolver = dns.resolver.Resolver() dns.resolver.default_resolver.nameservers = ["1.1.1.1", "8.8.8.8"] dom_in = Domain( - "dns.google.com", list(), list(), list(), list(), list(), list(), list() - ) + "dns.google.com") check = cdnCheck() check.ip(dom_in) @@ -29,16 +28,7 @@ def test_broken_ip(): """Test a non-working domain IP resolving feature.""" dns.resolver.default_resolver = dns.resolver.Resolver() dns.resolver.default_resolver.nameservers = ["1.1.1.1", "8.8.8.8"] - dom_in = Domain( - "notarealdomain.fakedomaindne.com", - list(), - list(), - list(), - list(), - list(), - list(), - list(), - ) + dom_in = Domain("notarealdomain.fakedomaindne.com") check = cdnCheck() return_code = check.ip(dom_in) assert return_code != 0, "This fake site should return a non 0 code." @@ -46,9 +36,7 @@ def test_broken_ip(): def test_cname(): """Test the CNAME resolving feature.""" - dom_in = Domain( - "www.asu.edu", list(), list(), list(), list(), list(), list(), list() - ) + dom_in = Domain("www.asu.edu") check = cdnCheck() check.cname(dom_in, timeout=TIMEOUT) @@ -59,16 +47,7 @@ def test_cname(): def test_broken_cname(): """Test a non-working domain CNAME resolving feature.""" - dom_in = Domain( - "notarealdomain.fakedomaindne.com", - list(), - list(), - list(), - list(), - list(), - list(), - list(), - ) + dom_in = Domain("notarealdomain.fakedomaindne.com") check = cdnCheck() return_code = check.cname(dom_in, timeout=TIMEOUT) assert return_code != 0, "This fake site should return a non 0 code." @@ -76,9 +55,7 @@ def test_broken_cname(): def test_https_lookup(): """Test the header resolving feature.""" - dom_in = Domain( - "google.com", list(), list(), list(), list(), list(), list(), list() - ) + dom_in = Domain("google.com") check = cdnCheck() check.https_lookup( dom_in, timeout=TIMEOUT, agent=USER_AGENT, interactive=False, verbose=False @@ -89,16 +66,7 @@ def test_https_lookup(): def test_broken_https_lookup(): """Test a non-working domain header resolving feature.""" - dom_in = Domain( - "notarealdomain.fakedomaindne.com", - list(), - list(), - list(), - list(), - list(), - list(), - list(), - ) + dom_in = Domain("notarealdomain.fakedomaindne.com") check = cdnCheck() check.https_lookup( dom_in, timeout=TIMEOUT, agent=USER_AGENT, interactive=False, verbose=False @@ -108,9 +76,7 @@ def test_broken_https_lookup(): def test_whois(): """Test the whois resolving feature.""" - dom_in = Domain( - "google.com", list(), list(), list(), list(), list(), list(), list() - ) + dom_in = Domain("google.com") check = cdnCheck() check.ip(dom_in) check.whois(dom_in, interactive=False, verbose=False) @@ -122,16 +88,7 @@ def test_whois(): def test_broken_whois(): """Test a non-working domain whois resolving feature.""" - dom_in = Domain( - "notarealdomain.fakedomaindne.com", - list(), - list(), - list(), - list(), - list(), - list(), - list(), - ) + dom_in = Domain("notarealdomain.fakedomaindne.com") check = cdnCheck() check.ip(dom_in) return_code = check.whois(dom_in, interactive=False, verbose=False) @@ -140,7 +97,7 @@ def test_broken_whois(): def test_all_checks(): """Run all checks.""" - dom_in = Domain("login.gov", list(), list(), list(), list(), list(), list(), list()) + dom_in = Domain("login.gov") check = cdnCheck() check.all_checks(dom_in, timeout=TIMEOUT, agent=USER_AGENT) @@ -151,7 +108,7 @@ def test_all_checks(): def test_all_checks_by_name(): """Run all checks and get CDN name.""" - dom_in = Domain("login.gov", list(), list(), list(), list(), list(), list(), list()) + dom_in = Domain("login.gov") check = cdnCheck() check.all_checks(dom_in, timeout=TIMEOUT, agent=USER_AGENT) @@ -164,16 +121,7 @@ def test_all_checks_bad(): """Test fake domain and ensure it dosen't break anything.""" dns.resolver.default_resolver = dns.resolver.Resolver() dns.resolver.default_resolver.nameservers = ["1.1.1.1", "8.8.8.8"] - dom = Domain( - "super.definitelynot.notarealdomain.fakedomaindne.com", - list(), - list(), - list(), - list(), - list(), - list(), - list(), - ) + dom = Domain("super.definitelynot.notarealdomain.fakedomaindne.com") print(dom.url, dom.cdns, dom.cnames, dom.headers, dom.whois_data, dom.ip) check = cdnCheck() return_code = check.all_checks(dom, timeout=TIMEOUT, agent=USER_AGENT)