"Fossies" - the Fresh Open Source Software Archive

Member "rbldnsd-0.998/test_ip4trie.py" (7 Apr 2013, 1233 Bytes) of package /linux/misc/dns/rbldnsd-0.998.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 """ (Very) basic ip4trie dataset tests
    2 """
    3 import unittest
    4 
    5 from rbldnsd import Rbldnsd, ZoneFile
    6 
    7 __all__ = [
    8     'TestIp4TrieDataset',
    9     ]
   10 
   11 def ip4trie(zone_data):
   12     """ Run rbldnsd with an ip6trie dataset
   13     """
   14     dnsd = Rbldnsd()
   15     dnsd.add_dataset('ip4trie', ZoneFile(zone_data))
   16     return dnsd
   17 
   18 def reversed_ip(ip4addr, domain='example.com'):
   19     revip = '.'.join(reversed(ip4addr.split('.')))
   20     return "%s.%s" % (revip, domain)
   21 
   22 class TestIp4TrieDataset(unittest.TestCase):
   23     def test_exclusion(self):
   24         with ip4trie(["1.2.3.0/24 listed",
   25                       "!1.2.3.4"]) as dnsd:
   26             self.assertEqual(dnsd.query(reversed_ip("1.2.3.4")), None)
   27             self.assertEqual(dnsd.query(reversed_ip("1.2.3.3")), "listed")
   28             self.assertEqual(dnsd.query(reversed_ip("1.2.3.5")), "listed")
   29 
   30     def test_wildcard_prefix(self):
   31         with ip4trie(["0/0 wild",
   32                       "127.0.0.1 localhost"]) as dnsd:
   33             self.assertEqual(dnsd.query(reversed_ip("127.0.0.1")), "localhost")
   34             self.assertEqual(dnsd.query(reversed_ip("0.0.0.0")), "wild")
   35             self.assertEqual(dnsd.query(reversed_ip("127.0.0.2")), "wild")
   36 
   37 if __name__ == '__main__':
   38     unittest.main()