Beispiel #1
0
 def xx_test_dnssec_qmin(self):
     """DNSSEC + QName Minimization tests"""
     print('\nDNSSEC + QMIN tests:')
     count = 0
     for vector in TEST_VECTORS:
         count += 1
         with self.subTest(vector=vector):
             Prefs.DNSSEC = True
             reset_all()
             components, expect = vector
             qname, qtype = components
             print("subtest: {} {} ...".format(qname, qtype))
             query = Query(qname, qtype, 'IN', minimize=True)
             if expect['exc'] is not None:
                 with self.assertRaises(expect['exc']):
                     resolve_name(query, RootZone, addResults=query)
                 continue
             resolve_name(query, RootZone, addResults=query)
             self.assertEqual(query.response.rcode(), expect['rcode'])
             self.assertEqual(query.is_secure(),
                              expect['secure'],
                              msg="DNSSEC secured?")
             if expect['wildcard']:
                 self.assertTrue(query.wildcard, msg="Wildcard")
             if expect['ent']:
                 self.assertTrue(query.ent, msg="Empty Non-Terminal")
     print("Total subtests: {}".format(count))
Beispiel #2
0
def main():
    """
    resolve.py main() function
    """

    random.seed(os.urandom(64))
    qname, qtype, qclass = process_args(sys.argv[1:])

    if Prefs.DNSSEC:
        initialize_dnssec()

    if Prefs.BATCHFILE:
        time_start = time.time()
        batchmode(cache, Prefs.BATCHFILE,
                  info="Command: {}".format(" ".join(sys.argv)))
        stats.elapsed = time.time() - time_start
        if Prefs.STATS:
            stats.print()
        if Prefs.DUMPCACHE:
            print('')
            cache.dump()
            key_cache.dump()
        return 0

    query = Query(qname, qtype, qclass, minimize=Prefs.MINIMIZE)

    time_start = time.time()
    if Prefs.VERBOSE:
        print_root_zone()

    try:
        resolve_name(query, RootZone, addResults=query)
    except ResError as e:
        print("\nERROR:", e)
        return 255

    stats.elapsed = time.time() - time_start

    if Prefs.VERBOSE and not query.quiet:
        print('')
    query.print_full_answer()

    if Prefs.STATS:
        stats.print()

    if Prefs.DUMPCACHE:
        print('')
        cache.dump()
        key_cache.dump()

    return exit_status(query)
Beispiel #3
0
 def xx_test_plain(self):
     """Plain DNS tests"""
     print('\nPlain DNS tests:')
     count = 0
     for vector in TEST_VECTORS:
         count += 1
         with self.subTest(vector=vector):
             Prefs.DNSSEC = False
             reset_all()
             components, expect = vector
             qname, qtype = components
             print("subtest: {} {} ...".format(qname, qtype))
             query = Query(qname, qtype, 'IN')
             if not expect['secure'] and expect['exc'] is not None:
                 with self.assertRaises(expect['exc']):
                     resolve_name(query, RootZone, addResults=query)
                 continue
             resolve_name(query, RootZone, addResults=query)
             self.assertEqual(query.response.rcode(), expect['rcode'])
     print("Total subtests: {}".format(count))
Beispiel #4
0
def batchmode(cache, infile, info):
    """Execute batch mode on specified input file"""

    print("### resolve.py Batch Mode. File: {}".format(infile))
    print("### {}".format(info))

    linenum = 0
    for line in open(infile):
        linenum += 1
        line = line.rstrip('\n')
        parts = line.split()
        if len(parts) == 1:
            qname, = parts
            qtype = 'A'
            qclass = 'IN'
        elif len(parts) == 2:
            qname, qtype = parts
            qclass = 'IN'
        elif len(parts) == 3:
            qname, qtype, qclass = parts
        else:
            print("\nERROR input line {}: {}".format(linenum, line))
            continue

        print("\n###\n### Query: {}, {}, {}".format(qname, qtype, qclass))
        stats.reset()
        query = Query(qname, qtype, qclass, minimize=Prefs.MINIMIZE)
        starting_zone = cache.closest_zone(query.qname)
        key_cache.SecureSoFar = starting_zone.secure
        print("### Starting at zone: {}\n###".format(starting_zone.name))
        if Prefs.VERBOSE and starting_zone == RootZone:
            print_root_zone()
        resolve_name(query, starting_zone, addResults=query)
        if Prefs.VERBOSE:
            print('')
        query.print_full_answer()

    print("\n### End Batch Mode.")
    return
Beispiel #5
0
#!/usr/bin/env python3
#
"""
Simple test of main name resolution function.
"""

import sys

from reslib.prefs import Prefs
from reslib.cache import RootZone
from reslib.query import Query
from reslib.lookup import initialize_dnssec, resolve_name

if __name__ == '__main__':

    qname = sys.argv[1]
    qtype = sys.argv[2]
    qclass = 'IN'

    Prefs.DNSSEC = True
    initialize_dnssec()
    query = Query(qname, qtype, qclass)
    resolve_name(query, RootZone, addResults=query)
    query.print_full_answer()