Debian Codegraph @

tests/test_rdtypeanytkey.py

raw
1 # -*- coding: utf-8
2 # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
3
4 # Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
5 #
6 # Permission to use, copy, modify, and distribute this software and its
7 # documentation for any purpose with or without fee is hereby granted,
8 # provided that the above copyright notice and this permission notice
9 # appear in all copies.
10 #
11 # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
19 import unittest
20 import base64
21
22 import dns.name
23 import dns.zone
24 import dns.rdtypes.ANY.TKEY
25 from dns.rdataclass import RdataClass
26 from dns.rdatatype import RdataType
27
28
29 class RdtypeAnyTKeyTestCase(unittest.TestCase):
30 tkey_rdata_text = "gss-tsig. 1594203795 1594206664 3 0 KEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEY OTHEROTHEROTHEROTHEROTHEROTHEROT"
31 tkey_rdata_text_no_other = (
32 "gss-tsig. 1594203795 1594206664 3 0 KEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEY"
33 )
34
35 def testTextOptionalData(self):
36 # construct the rdata from text and extract the TKEY
37 tkey = dns.rdata.from_text(
38 RdataClass.ANY,
39 RdataType.TKEY,
40 RdtypeAnyTKeyTestCase.tkey_rdata_text,
41 origin=".",
42 )
43 self.assertEqual(type(tkey), dns.rdtypes.ANY.TKEY.TKEY)
44
45 # go to text and compare
46 tkey_out_text = tkey.to_text(relativize=False)
47 self.assertEqual(tkey_out_text, RdtypeAnyTKeyTestCase.tkey_rdata_text)
48
49 def testTextNoOptionalData(self):
50 # construct the rdata from text and extract the TKEY
51 tkey = dns.rdata.from_text(
52 RdataClass.ANY,
53 RdataType.TKEY,
54 RdtypeAnyTKeyTestCase.tkey_rdata_text_no_other,
55 origin=".",
56 )
57 self.assertEqual(type(tkey), dns.rdtypes.ANY.TKEY.TKEY)
58
59 # go to text and compare
60 tkey_out_text = tkey.to_text(relativize=False)
61 self.assertEqual(tkey_out_text, RdtypeAnyTKeyTestCase.tkey_rdata_text_no_other)
62
63 def testWireOptionalData(self):
64 key = base64.b64decode("KEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEY")
65 other = base64.b64decode("OTHEROTHEROTHEROTHEROTHEROTHEROT")
66
67 # construct the TKEY and compare the text output
68 tkey = dns.rdtypes.ANY.TKEY.TKEY(
69 dns.rdataclass.ANY,
70 dns.rdatatype.TKEY,
71 dns.name.from_text("gss-tsig."),
72 1594203795,
73 1594206664,
74 3,
75 0,
76 key,
77 other,
78 )
79 self.assertEqual(
80 tkey.to_text(relativize=False), RdtypeAnyTKeyTestCase.tkey_rdata_text
81 )
82
83 # go to/from wire and compare the text output
84 wire = tkey.to_wire()
85 tkey_out_wire = dns.rdata.from_wire(
86 dns.rdataclass.ANY, dns.rdatatype.TKEY, wire, 0, len(wire)
87 )
88 self.assertEqual(
89 tkey_out_wire.to_text(relativize=False),
90 RdtypeAnyTKeyTestCase.tkey_rdata_text,
91 )
92
93 def testWireNoOptionalData(self):
94 key = base64.b64decode("KEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEYKEY")
95
96 # construct the TKEY with no 'other' data and compare the text output
97 tkey = dns.rdtypes.ANY.TKEY.TKEY(
98 dns.rdataclass.ANY,
99 dns.rdatatype.TKEY,
100 dns.name.from_text("gss-tsig."),
101 1594203795,
102 1594206664,
103 3,
104 0,
105 key,
106 )
107 self.assertEqual(
108 tkey.to_text(relativize=False),
109 RdtypeAnyTKeyTestCase.tkey_rdata_text_no_other,
110 )
111
112 # go to/from wire and compare the text output
113 wire = tkey.to_wire()
114 tkey_out_wire = dns.rdata.from_wire(
115 dns.rdataclass.ANY, dns.rdatatype.TKEY, wire, 0, len(wire)
116 )
117 self.assertEqual(
118 tkey_out_wire.to_text(relativize=False),
119 RdtypeAnyTKeyTestCase.tkey_rdata_text_no_other,
120 )