Skip to content

Commit

Permalink
Address issue cisagov#1 and cisagov#3 by altering Domain() initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Yablargo committed Oct 26, 2022
1 parent ad96d7c commit f7f84a5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 63 deletions.
46 changes: 46 additions & 0 deletions tests/test_cdnengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
74 changes: 11 additions & 63 deletions tests/test_detectCDN.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -29,26 +28,15 @@ 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."


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)

Expand All @@ -59,26 +47,15 @@ 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."


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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)
Expand Down

0 comments on commit f7f84a5

Please sign in to comment.