summaryrefslogtreecommitdiff
path: root/tests/test_nsec3.py
blob: bf7d1151b83737be214b23c987d9a50338fe7d2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license

# Copyright (C) 2006-2017 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose with or without fee is hereby granted,
# provided that the above copyright notice and this permission notice
# appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

import unittest

import dns.exception
import dns.rdata
import dns.rdataclass
import dns.rdatatype
import dns.rdtypes.ANY.TXT
import dns.ttl

class NSEC3TestCase(unittest.TestCase):
    def test_NSEC3_bitmap(self):
        rdata = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NSEC3,
                u"1 0 100 ABCD SCBCQHKU35969L2A68P3AD59LHF30715 A CAA TYPE65534")
        bitmap = bytearray(b'\0' * 32)
        bitmap[31] = bitmap[31] | 2
        self.assertEqual(rdata.windows, ((0, b'@'),
                                         (1, b'@'), # CAA = 257
                                         (255, bitmap)
                                         ))

    def test_NSEC3_bad_bitmaps(self):
        rdata = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NSEC3,
                u"1 0 100 ABCD SCBCQHKU35969L2A68P3AD59LHF30715 A CAA")

        with self.assertRaises(dns.exception.FormError):
            copy = bytearray(rdata.to_wire())
            copy[-3] = 0
            dns.rdata.from_wire('IN', 'NSEC3', copy, 0, len(copy))

if __name__ == '__main__':
    unittest.main()