This commit is contained in:
2021-08-30 12:58:04 +02:00
parent e892152b0c
commit e64ce32d92
3 changed files with 35 additions and 35 deletions

View File

@@ -15,21 +15,21 @@ from dns import resolver
# list of puzzle authoritative name servers # list of puzzle authoritative name servers
pitc_nameservers = [ pitc_nameservers = [
'ns1.dnsimple.com.', 'ns1.dnsimple.com.',
'ns2.dnsimple.com.', 'ns2.dnsimple.com.',
'ns3.dnsimple.com.', 'ns3.dnsimple.com.',
'ns4.dnsimple.com.', 'ns4.dnsimple.com.',
'ns5.dnsmadeeasy.com.', 'ns5.dnsmadeeasy.com.',
'ns6.dnsmadeeasy.com.', 'ns6.dnsmadeeasy.com.',
'ns7.dnsmadeeasy.com.' 'ns7.dnsmadeeasy.com.'
] ]
# list of puzzle managed zone files # list of puzzle managed zone files
pitc_domains = [ pitc_domains = [
'puzzle.ch.yaml', 'puzzle.ch.yaml',
'puzzle.yaml', 'puzzle.yaml',
'nonpuzzle.yaml' 'nonpuzzle.yaml'
] ]
# configure opendns resolver # configure opendns resolver
resolver = resolver.Resolver() resolver = resolver.Resolver()
@@ -37,13 +37,13 @@ resolver.nameservers = ['208.67.222.222','208.67.220.220']
def do_check(domains, nameservers, verbose=False): def do_check(domains, nameservers, verbose=False):
''' '''
dsc: Implementatin of the check loop which writes output if verbose is set. dsc: Implementatin of the check loop which writes output if verbose is set.
Checks if the authoritative ns returned for domain x is in the list Checks if the authoritative ns returned for domain x is in the list
of nameservers provided as argument. of nameservers provided as argument.
arg: [list], domains to check arg: [list], domains to check
arg: [list], verified nameservers arg: [list], verified nameservers
arg: [boolean], verbose printing or not arg: [boolean], verbose printing or not
ret: [boolean], true if all checked nameservers are ok, false otherwise ret: [boolean], true if all checked nameservers are ok, false otherwise
''' '''
for domain in domains: for domain in domains:
returned_nameservers = get_authoritative_ns(domain) returned_nameservers = get_authoritative_ns(domain)
@@ -63,9 +63,9 @@ def do_check(domains, nameservers, verbose=False):
def get_authoritative_ns(domain): def get_authoritative_ns(domain):
''' '''
dsc: Query the domain and return the authoritative name servers. dsc: Query the domain and return the authoritative name servers.
arg: [str], domain to query arg: [str], domain to query
ret: [list], list of nameservers or empty list on error. ret: [list], list of nameservers or empty list on error.
''' '''
try: try:
answer = resolver.resolve(domain,'NS') answer = resolver.resolve(domain,'NS')
@@ -78,9 +78,9 @@ def get_authoritative_ns(domain):
def get_domains_from_yaml(filenames): def get_domains_from_yaml(filenames):
''' '''
dsc: Loads domain names from a list of yaml files. dsc: Loads domain names from a list of yaml files.
arg: [list], filenames arg: [list], filenames
ret: [list], arbitrary list of domain names, emptylist on err ret: [list], arbitrary list of domain names, emptylist on err
''' '''
domains = [] domains = []
try: try:
@@ -97,10 +97,10 @@ def get_domains_from_yaml(filenames):
def verify_authoritative_ns(nameserver, verified_nameservers): def verify_authoritative_ns(nameserver, verified_nameservers):
''' '''
dsc: Verifies if the authoritative NS belongs to the puzzle managed NS. dsc: Verifies if the authoritative NS belongs to the puzzle managed NS.
arg: [str], nameserver to test arg: [str], nameserver to test
arg: [list], a list of verified nameservers arg: [list], a list of verified nameservers
ret: [boolean], true if ok; false if nok. ret: [boolean], true if ok; false if nok.
''' '''
if not isinstance(nameserver, str): if not isinstance(nameserver, str):
print("Type of nameserver must be string!") print("Type of nameserver must be string!")

View File

@@ -16,23 +16,23 @@ from pylint.reporters import CollectingReporter
class TestDnsVerify(unittest.TestCase): class TestDnsVerify(unittest.TestCase):
def test_do_check(self): def test_do_check(self):
''' '''
... Test if checks acutally fail when an error occures. ... Test whether checks acutally fail when an error occures.
''' '''
self.assertEqual(do_check(['puzzle.ch'], ['ns1.google.com'], verbose=False), self.assertEqual(do_check(['puzzle.ch'], ['ns1.google.com'], verbose=False),
False) False)
def test_get_authoritative_ns(self): def test_get_authoritative_ns(self):
''' '''
... Test if garbage queries trigger a stack trace. ... Test whether garbage queries trigger a stack trace.
''' '''
self.assertEqual(get_authoritative_ns('dinimer.lolwas'), []) self.assertEqual(get_authoritative_ns('dinimer.lolwas'), [])
def test_get_domains_from_yaml(self): def test_get_domains_from_yaml(self):
''' '''
... Test wheter missing files generate an empty list. ... Test whether missing files generate an empty list.
''' '''
self.assertEqual(get_domains_from_yaml(["notexist.yaml"]), []) self.assertEqual(get_domains_from_yaml(["notexist.yaml"]), [])
def test_verify_authoritative_ns(self): def test_verify_authoritative_ns(self):
''' '''
... Test wheter false is returned when the ns does not match the list. And test if type errors are handeled correctly. ... Test whether false if check fails and test if type errors are handeled correctly.
''' '''
self.assertEqual(verify_authoritative_ns('ns1.google.com', ['ns2.google.com']), False) self.assertEqual(verify_authoritative_ns('ns1.google.com', ['ns2.google.com']), False)
self.assertRaises(TypeError, verify_authoritative_ns, 123, ['123']) self.assertRaises(TypeError, verify_authoritative_ns, 123, ['123'])
@@ -40,7 +40,7 @@ class TestDnsVerify(unittest.TestCase):
def test_pylint(self): def test_pylint(self):
''' '''
... Test wheter the coding style is acceptable. ... Test whether the coding style is acceptable.
''' '''
rep = CollectingReporter() rep = CollectingReporter()
results = Run(['dnsverify.py', '-sn'], reporter=rep, exit=False) results = Run(['dnsverify.py', '-sn'], reporter=rep, exit=False)

View File

@@ -1,3 +1,3 @@
#!/bin/env bash #!/bin/env bash
pipenv run python -m unittest -bv test_dnsverify pipenv run python -m unittest -bv dnsverify_tests.py