pvl/hosts/tests.py
author Tero Marttila <tero.marttila@aalto.fi>
Wed, 25 Feb 2015 15:40:58 +0200
changeset 473 68fd85d850ab
parent 472 814cc88c531b
child 474 51983fcda6b1
permissions -rw-r--r--
pvl.hosts.zone: test host_reverse() more
440
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     1
import ipaddr
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     2
import unittest
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     3
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
     4
from pvl.hosts import config, host, zone
440
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     5
from StringIO import StringIO
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     6
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     7
class Options(object):
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     8
    hosts_charset   = 'utf-8'
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     9
    hosts_domain    = None
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    10
    hosts_include   = None
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    11
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    12
class ConfFile(StringIO):
440
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    13
    def __init__(self, name, buffer):
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    14
        StringIO.__init__(self, buffer)
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    15
        self.name = name
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    16
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    17
class TestConfig(unittest.TestCase):
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    18
    def setUp(self):
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    19
        self.options = Options()
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    20
461
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    21
    def assertHostEqual(self, host, host_str, attrs):
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    22
        self.assertEquals(str(host), host_str)
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    23
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    24
        for attr, value in attrs.iteritems():
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    25
            self.assertEquals(getattr(host, attr), value)
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    26
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    27
    def assertHostsEqual(self, hosts, expected):
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    28
        for host, expect in zip(hosts, expected):
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    29
            host_str, attrs = expect
441
f058fff1f272 pvl.hosts.hosts: fix sort_key()
Tero Marttila <tero.marttila@aalto.fi>
parents: 440
diff changeset
    30
461
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    31
            self.assertHostEqual(host, host_str, attrs)
441
f058fff1f272 pvl.hosts.hosts: fix sort_key()
Tero Marttila <tero.marttila@aalto.fi>
parents: 440
diff changeset
    32
 
451
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    33
    def testApplyHostsFileError(self):
440
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    34
        with self.assertRaises(config.HostConfigError):
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    35
            list(config.apply_hosts(self.options, ['nonexistant']))
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    36
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    37
    def testApplyHosts(self):
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    38
        conf_file = ConfFile('test', """
440
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    39
[foo]
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    40
    ip = 127.0.0.1
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    41
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    42
[bar]
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    43
    ip = 127.0.0.2
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    44
        """)
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    45
        expected = [
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    46
                ('foo@test', dict(ip=ipaddr.IPAddress('127.0.0.1'))),
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    47
                ('bar@test', dict(ip=ipaddr.IPAddress('127.0.0.2'))),
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    48
        ]
440
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    49
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    50
        self.assertHostsEqual(config.apply_hosts_file(self.options, conf_file), expected)
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    51
451
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    52
    def testApply(self):
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    53
        self.assertHostsEqual(config.apply(self.options, ['etc/hosts/test']), [
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    54
                ('foo@test', dict(
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    55
                    ip          = ipaddr.IPAddress('127.0.0.1'),
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    56
                    ethernet    = {None: '00:11:22:33:44:55'},
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    57
                )),
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    58
                ('bar@test', dict(
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    59
                    ip          = ipaddr.IPAddress('127.0.0.2'),
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    60
                    ethernet    = {None: '01:23:45:67:89:ab'},
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    61
                )),
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    62
        ])
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    63
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    64
    def testApplyHostsExpand(self):
449
a19438b781d5 pvl.hosts.config: cleanup apply_host_config
Tero Marttila <tero.marttila@aalto.fi>
parents: 447
diff changeset
    65
        self.assertHostsEqual(config.apply_host_config(self.options, 'asdf', 'asdf{1-3}', ip='10.100.100.$'), [
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    66
                ('asdf1@asdf', dict(ip=ipaddr.IPAddress('10.100.100.1'))),
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    67
                ('asdf2@asdf', dict(ip=ipaddr.IPAddress('10.100.100.2'))),
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    68
                ('asdf3@asdf', dict(ip=ipaddr.IPAddress('10.100.100.3'))),
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    69
        ])
461
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    70
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    71
    def testApplyHostConfigDict(self):
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    72
        host = config.apply_host(self.options, 'foo', 'test', {
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    73
            'ethernet.eth0': '00:11:22:33:44:55',
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    74
        })
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    75
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    76
        self.assertHostEqual(host, 'foo@test', dict(
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    77
                ethernet    = { 'eth0': '00:11:22:33:44:55' }
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    78
        ))
e3bddc5eeff5 pvl.hosts: test config.apply_host()
Tero Marttila <tero.marttila@aalto.fi>
parents: 451
diff changeset
    79
   
451
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    80
    def testApplyHostsConfigError(self):
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    81
        with self.assertRaises(config.HostConfigError):
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    82
            config.apply_host(self.options, 'foo', 'test', {
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    83
                'ethernet': 'foo',
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    84
                'ethernet.eth0': 'bar',
d302b4957b07 pvl.hosts.config: fix apply_host override error handling
Tero Marttila <tero.marttila@aalto.fi>
parents: 449
diff changeset
    85
            })
447
6f0357759e9b pvl.hosts: fixup and document host expansion
Tero Marttila <tero.marttila@aalto.fi>
parents: 441
diff changeset
    86
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
    87
class TestZoneMixin(object):
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    88
    def assertZoneEquals(self, rrs, expected):
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    89
        gather = { }
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    90
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    91
        for rr in rrs:
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    92
            key = (rr.name.lower(), rr.type.upper())
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    93
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    94
            self.assertNotIn(key, gather)
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    95
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    96
            gather[key] = rr.data
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    97
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    98
        self.assertDictEqual(gather, expected)
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    99
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   100
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   101
class TestForwardZone(TestZoneMixin, unittest.TestCase):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   102
    def setUp(self):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   103
        self.options = Options()
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   104
        self.options.add_origin = False
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   105
462
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   106
    def testResolve(self):
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   107
        self.assertEquals(zone.resolve(None, None, 'host'), 'host.')
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   108
        self.assertEquals(zone.resolve(None, 'domain', 'host'), 'host.domain.')
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   109
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   110
        with self.assertRaises(zone.HostZoneError):
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   111
            zone.resolve('origin', 'domain', 'host')
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   112
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   113
        self.assertEquals(zone.resolve('domain', 'domain', 'host'), 'host')
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   114
        self.assertEquals(zone.resolve('origin', 'domain.origin', 'host'), 'host.domain')
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   115
        
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   116
        with self.assertRaises(zone.HostZoneError):
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   117
            zone.resolve('origin', 'domainorigin', 'host')
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   118
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   119
        with self.assertRaises(zone.HostZoneError):
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   120
            zone.resolve('origin', None, 'host.domain')
6d699c76d75d pvl.hosts.zone: test resolve() and handle FQDN's strictly
Tero Marttila <tero.marttila@aalto.fi>
parents: 461
diff changeset
   121
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   122
    def testHostOutOfOrigin(self):
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   123
        h = host.Host('host', 'domain', ip=ipaddr.IPAddress('10.0.0.1'))
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   124
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   125
        self.assertZoneEquals(zone.host_forward(h, 'test'), { })
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   126
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   127
    def testHostIP(self):
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   128
        h = host.Host.build('host', 'domain',
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   129
                ip  = '192.0.2.1',
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   130
                ip6 = '2001:db8::192.0.2.1',
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   131
        )
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   132
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   133
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   134
            ('host', 'A'): ['192.0.2.1'],
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   135
            ('host', 'AAAA'): ['2001:db8::c000:201'],
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   136
        })
465
133f14810eb5 pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents: 464
diff changeset
   137
    
466
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   138
    def testHostAlias(self):
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   139
        h = host.Host.build('host', 'domain',
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   140
                ip      = '192.0.2.1',
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   141
                alias   = 'test *.test',
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   142
        )
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   143
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   144
        self.assertEquals(h.alias, ['test', '*.test'])
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   145
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   146
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   147
            ('host', 'A'): ['192.0.2.1'],
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   148
            ('test', 'CNAME'): ['host'],
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   149
            ('*.test', 'CNAME'): ['host'],
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   150
        })
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   151
468
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   152
    def testHostAlias46(self):
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   153
        h = host.Host.build('host', 'domain',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   154
                ip      = '192.0.2.1',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   155
                ip6     = '2001:db8::192.0.2.1',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   156
                alias4  = 'test4',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   157
                alias6  = 'test6',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   158
        )
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   159
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   160
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   161
            ('host', 'A'): ['192.0.2.1'],
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   162
            ('host', 'AAAA'): ['2001:db8::c000:201'],
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   163
            ('test4', 'A'): ['192.0.2.1'],
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   164
            ('test6', 'AAAA'): ['2001:db8::c000:201'],
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   165
        })
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   166
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   167
    def testHostAlias4Missing(self):
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   168
        h = host.Host.build('host', 'domain',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   169
                ip6     = '2001:db8::192.0.2.1',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   170
                alias4  = 'test4',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   171
                alias6  = 'test6',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   172
        )
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   173
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   174
        with self.assertRaises(zone.HostZoneError):
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   175
            self.assertZoneEquals(zone.host_forward(h, 'domain'), { })
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   176
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   177
    def testHostAlias6Missing(self):
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   178
        h = host.Host.build('host', 'domain',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   179
                ip      = '192.0.2.1',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   180
                alias4  = 'test4',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   181
                alias6  = 'test6',
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   182
        )
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   183
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   184
        with self.assertRaises(zone.HostZoneError):
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   185
            self.assertZoneEquals(zone.host_forward(h, 'domain'), { })
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
   186
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   187
    def testHostDelegate(self):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   188
        h = host.Host.build('host', 'example.com',
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   189
                forward = 'host.example.net',
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   190
        )
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   191
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   192
        self.assertZoneEquals(zone.host_forward(h, 'example.com'), {
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   193
            ('host', 'CNAME'): ['host.example.net.'],
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   194
        })
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   195
467
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   196
    def testHostForwardAlias(self):
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   197
        h = host.Host.build('host', 'domain',
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   198
                forward = 'host.example.net',
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   199
                alias   = 'test',
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   200
        )
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   201
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   202
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   203
            ('host', 'CNAME'): ['host.example.net.'],
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   204
            ('test', 'CNAME'): ['host'],
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
   205
        })
466
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 465
diff changeset
   206
470
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   207
    def testHostLocation(self):
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   208
        h = host.Host.build('host', 'domain',
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   209
                ip          = '192.0.2.1',
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   210
                location    = 'test',
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   211
        )
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   212
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   213
        self.assertEquals(h.location, ('test', 'domain'))
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   214
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   215
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   216
            ('host', 'A'): ['192.0.2.1'],
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   217
            ('test', 'CNAME'): ['host'],
ac334a55eebc pvl.hosts: fix location= and test forward records
Tero Marttila <tero.marttila@aalto.fi>
parents: 469
diff changeset
   218
        })
471
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   219
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   220
    def testHostLocationDomain(self):
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   221
        h = host.Host.build('host', 'foo.domain',
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   222
                ip          = '192.0.2.1',
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   223
                location    = 'test@bar.domain',
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   224
        )
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   225
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   226
        self.assertEquals(h.location, ('test', 'bar.domain'))
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   227
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   228
        self.assertZoneEquals(zone.host_forward(h, 'domain'), {
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   229
            ('host.foo', 'A'): ['192.0.2.1'],
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   230
            ('test.bar', 'CNAME'): ['host.foo'],
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   231
        })
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   232
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   233
    def testHostLocationDomainOutOfOrigin(self):
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   234
        h = host.Host.build('host', 'foo.domain',
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   235
                ip          = '192.0.2.1',
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   236
                location    = 'test@bar.domain',
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   237
        )
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   238
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   239
        self.assertEquals(h.location, ('test', 'bar.domain'))
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   240
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   241
        with self.assertRaises(zone.HostZoneError):
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   242
            self.assertZoneEquals(zone.host_forward(h, 'foo.domain'), {
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   243
                ('host', 'A'): ['192.0.2.1'],
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   244
            })
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   245
        
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   246
        # TODO
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   247
        #self.assertZoneEquals(zone.host_forward(h, 'bar.domain'), {
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   248
        #    ('test', 'CNAME'): ['host.foo'],
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
   249
        #})
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   250
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   251
    def testHostsForward(self):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   252
        hosts = [
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   253
                host.Host.build('foo', 'domain',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   254
                    ip      = '192.0.2.1',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   255
                    ip6     = '2001:db8::192.0.2.1',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   256
                    alias   = 'test',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   257
                ),
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   258
                host.Host.build('bar', 'domain',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   259
                    ip      = '192.0.2.2',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   260
                )
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   261
        ]
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   262
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   263
        self.assertZoneEquals(zone.apply_hosts_forward(self.options, hosts, 'domain'), {
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   264
            ('foo', 'A'): ['192.0.2.1'],
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   265
            ('foo', 'AAAA'): ['2001:db8::c000:201'],
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   266
            ('test', 'CNAME'): ['foo'],
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   267
            ('bar', 'A'): ['192.0.2.2'],
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   268
        })
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   269
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   270
    def testHostsConflict(self):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   271
        hosts = [
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   272
                host.Host.build('foo', 'domain',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   273
                    ip      = '192.0.2.1',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   274
                ),
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   275
                host.Host.build('foo', 'domain',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   276
                    ip      = '192.0.2.2',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   277
                )
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   278
        ]
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   279
        
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   280
        with self.assertRaises(zone.HostZoneError):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   281
            self.assertZoneEquals(zone.apply_hosts_forward(self.options, hosts, 'domain'), { })
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   282
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   283
    def testHostsAliasConflict(self):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   284
        hosts = [
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   285
                host.Host.build('foo', 'domain',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   286
                    ip          = '192.0.2.1',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   287
                ),
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   288
                host.Host.build('bar', 'domain',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   289
                    ip          = '192.0.2.2',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   290
                    alias       = 'foo',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   291
                )
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   292
        ]
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   293
        
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   294
        # with A first
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   295
        with self.assertRaises(zone.HostZoneError):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   296
            self.assertZoneEquals(zone.apply_hosts_forward(self.options, hosts, 'domain'), { })
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   297
    
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   298
        # also with CNAME first
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   299
        with self.assertRaises(zone.HostZoneError):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   300
            self.assertZoneEquals(zone.apply_hosts_forward(self.options, reversed(hosts), 'domain'), { })
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   301
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   302
    def testHostsAlias4Conflict(self):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   303
        hosts = [
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   304
                host.Host.build('foo', 'domain',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   305
                    ip          = '192.0.2.1',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   306
                ),
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   307
                host.Host.build('bar', 'domain',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   308
                    ip          = '192.0.2.2',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   309
                    alias4      = 'foo',
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   310
                )
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   311
        ]
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   312
        
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   313
        with self.assertRaises(zone.HostZoneError):
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   314
            self.assertZoneEquals(zone.apply_hosts_forward(self.options, hosts, 'domain'), { })
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   315
    
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   316
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   317
class TestReverseZone(TestZoneMixin, unittest.TestCase):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   318
    def setUp(self):
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   319
        self.options = Options()
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   320
        self.options.unknown_host = False
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   321
473
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   322
    def testHostIP(self):
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   323
        h = host.Host.build('host', 'domain',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   324
                ip  = '192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   325
                ip6 = '2001:db8::192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   326
        )
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   327
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   328
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   329
            ('1', 'PTR'): ['host.domain.'],
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   330
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   331
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   332
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   333
            ('1.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): ['host.domain.'],
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   334
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   335
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   336
    def testHostIP4(self):
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   337
        h = host.Host.build('host', 'domain',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   338
                ip  = '192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   339
        )
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   340
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   341
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   342
            ('1', 'PTR'): ['host.domain.'],
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   343
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   344
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   345
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   346
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   347
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   348
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   349
    def testHostIP6(self):
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   350
        h = host.Host.build('host', 'domain',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   351
                ip6 = '2001:db8::192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   352
        )
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   353
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   354
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   355
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   356
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   357
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   358
            ('1.0.2.0.0.0.0.c.0.0.0.0.0.0.0.0', 'PTR'): ['host.domain.'],
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   359
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   360
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   361
    def testHostIPOutOfPrefix(self):
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   362
        h = host.Host.build('host', 'domain',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   363
                ip  = '192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   364
                ip6 = '2001:db8::192.0.2.1',
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   365
        )
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   366
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   367
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.1.0/24'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   368
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   369
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   370
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   371
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8:1::/64'))), {
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   372
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   373
        })
68fd85d850ab pvl.hosts.zone: test host_reverse() more
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   374
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   375
    def testHostDelegate(self):
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   376
        h = host.Host.build('host', 'example.com',
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   377
                ip      = '192.0.2.1',
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   378
                ip6     = '2001:db8::192.0.2.1',
465
133f14810eb5 pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents: 464
diff changeset
   379
                forward = '',
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   380
                reverse = '1.0/28.2.0.192.in-addr.arpa',
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   381
        )
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   382
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   383
        self.assertZoneEquals(zone.host_forward(h, 'example.com'), {
465
133f14810eb5 pvl.hosts.zone: test forward= omit
Tero Marttila <tero.marttila@aalto.fi>
parents: 464
diff changeset
   384
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   385
        })
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   386
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   387
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('192.0.2.1/24'))), {
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   388
            ('1', 'CNAME'): ['1.0/28.2.0.192.in-addr.arpa.'],
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   389
        })
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   390
        
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   391
        self.assertZoneEquals((rr for ip, rr in zone.host_reverse(h, ipaddr.IPNetwork('2001:db8::/64'))), {
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   392
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   393
        })
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
   394
469
cd1f1b51f3a0 pvl.hosts.tests: split TestForwardZone/TestReverseZone using TestZoneMixin
Tero Marttila <tero.marttila@aalto.fi>
parents: 468
diff changeset
   395
440
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   396
if __name__ == '__main__':
1d755df7bf97 pvl.hosts: refactor as a package; cleanup pvl.hosts.config with some basic tests
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   397
    unittest.main()