Example #1
0
 def testFromFile2(self):
     z = dns.zone.from_file(here('example'), 'example', relativize=False)
     ok = False
     try:
         z.to_file(here('example2.out'), relativize=False, nl=b'\x0a')
         ok = compare_files('testFromFile2', here('example2.out'),
                            here('example2.good'))
     finally:
         if not _keep_output:
             os.unlink(here('example2.out'))
     self.assertTrue(ok)
Example #2
0
 def testToFileFilename(self):
     z = dns.zone.from_file(here('example'), 'example')
     try:
         z.to_file(here('example3-filename.out'))
         ok = compare_files('testToFileFilename',
                            here('example3-filename.out'),
                            here('example3.good'))
     finally:
         if not _keep_output:
             os.unlink(here('example3-filename.out'))
     self.assertTrue(ok)
Example #3
0
 def testToFileBinary(self):
     z = dns.zone.from_file(here("example"), "example")
     try:
         f = open(here("example3-binary.out"), "wb")
         z.to_file(f)
         f.close()
         ok = compare_files("testToFileBinary", here("example3-binary.out"),
                            here("example3.good"))
     finally:
         if not _keep_output:
             os.unlink(here("example3-binary.out"))
     self.assertTrue(ok)
Example #4
0
 def testToFileBinary(self):  # type: () -> None
     z = dns.zone.from_file(here('example'), 'example')
     try:
         f = open(here('example3-binary.out'), 'wb')
         z.to_file(f)
         f.close()
         ok = compare_files('testToFileBinary', here('example3-binary.out'),
                            here('example3.good'))
     finally:
         if not _keep_output:
             os.unlink(here('example3-binary.out'))
     self.assertTrue(ok)
Example #5
0
 def testToFileTextual(self):
     z = dns.zone.from_file(here('example'), 'example')
     try:
         f = open(here('example3-textual.out'), 'w')
         z.to_file(f)
         f.close()
         ok = compare_files('testToFileTextual',
                            here('example3-textual.out'),
                            here('example3.good'))
     finally:
         if not _keep_output:
             os.unlink(here('example3-textual.out'))
     self.assertTrue(ok)
Example #6
0
 def testToFileFilename(self):
     z = dns.zone.from_file(here("example"), "example")
     try:
         z.to_file(here("example3-filename.out"))
         ok = compare_files(
             "testToFileFilename",
             here("example3-filename.out"),
             here("example3.good"),
         )
     finally:
         if not _keep_output:
             os.unlink(here("example3-filename.out"))
     self.assertTrue(ok)
Example #7
0
 def testToFileBinaryWithOrigin(self):
     z = dns.zone.from_file(here('example'), 'example')
     try:
         f = open(here('example4-binary.out'), 'wb')
         z.to_file(f, want_origin=True)
         f.close()
         ok = compare_files('testToFileBinaryWithOrigin',
                            here('example4-binary.out'),
                            here('example4.good'))
     finally:
         if not _keep_output:
             os.unlink(here('example4-binary.out'))
     self.assertTrue(ok)
Example #8
0
 def testToText(self):  # type: () -> None
     z = dns.zone.from_file(here('example'), 'example')
     ok = False
     try:
         text_zone = z.to_text(nl='\x0a')
         f = open(here('example3.out'), 'w')
         f.write(text_zone)
         f.close()
         ok = compare_files('testToText', here('example3.out'),
                            here('example3.good'))
     finally:
         if not _keep_output:
             os.unlink(here('example3.out'))
     self.assertTrue(ok)
Example #9
0
 def testToText(self):
     z = dns.zone.from_file(here("example"), "example")
     ok = False
     try:
         text_zone = z.to_text(nl="\x0a")
         f = open(here("example3.out"), "w")
         f.write(text_zone)
         f.close()
         ok = compare_files("testToText", here("example3.out"),
                            here("example3.good"))
     finally:
         if not _keep_output:
             os.unlink(here("example3.out"))
     self.assertTrue(ok)
Example #10
0
 def testToFileBinaryWithOrigin(self):
     z = dns.zone.from_file(here("example"), "example")
     try:
         f = open(here("example4-binary.out"), "wb")
         z.to_file(f, want_origin=True)
         f.close()
         ok = compare_files(
             "testToFileBinaryWithOrigin",
             here("example4-binary.out"),
             here("example4.good"),
         )
     finally:
         if not _keep_output:
             os.unlink(here("example4-binary.out"))
     self.assertTrue(ok)
Example #11
0
 def testInclude(self):  # type: () -> None
     z1 = dns.zone.from_text(include_text,
                             'example.',
                             relativize=True,
                             allow_include=True)
     z2 = dns.zone.from_file(here('example'), 'example.', relativize=True)
     self.assertEqual(z1, z2)
Example #12
0
 def testInclude(self):
     z1 = dns.zone.from_text(include_text,
                             "example.",
                             relativize=True,
                             allow_include=True)
     z2 = dns.zone.from_file(here("example"), "example.", relativize=True)
     self.assertEqual(z1, z2)
Example #13
0
 def testTorture1(self):
     #
     # Read a zone containing all our supported RR types, and
     # for each RR in the zone, convert the rdata into wire format
     # and then back out, and see if we get equal rdatas.
     #
     f = BytesIO()
     o = dns.name.from_text('example.')
     z = dns.zone.from_file(here('example'), o)
     for node in z.values():
         for rds in node:
             for rd in rds:
                 f.seek(0)
                 f.truncate()
                 rd.to_wire(f, origin=o)
                 wire = f.getvalue()
                 rd2 = dns.rdata.from_wire(rds.rdclass, rds.rdtype,
                                           wire, 0, len(wire),
                                           origin=o)
                 self.assertEqual(rd, rd2)
Example #14
0
 def test_unpickle(self):
     expected_mx = dns.rdata.from_text('in', 'mx', '10 mx.example.')
     with open(here('mx-2-0.pickle'), 'rb') as f:
         mx = pickle.load(f)
     self.assertEqual(mx, expected_mx)
     self.assertIsNone(mx.rdcomment)
Example #15
0
 def test_from_file(self):
     m = dns.message.from_file(here('query'))
     expected = dns.message.from_text(query_text)
     self.assertEqual(m, expected)
Example #16
0
no_soa_text = """$TTL 1h
$ORIGIN example.
@ ns ns1
@ ns ns2
ns1 1d1s a 10.0.0.1
ns2 1w1D1h1m1S a 10.0.0.2
"""

no_ns_text = """$TTL 1h
$ORIGIN example.
@ soa foo bar 1 2 3 4 5
"""

include_text = """$INCLUDE "%s"
""" % here("example")

bad_directive_text = """$FOO bar
$ORIGIN example.
@ soa foo bar 1 2 3 4 5
@ ns ns1
@ ns ns2
ns1 1d1s a 10.0.0.1
ns2 1w1D1h1m1S a 10.0.0.2
"""

codec_text = """
@ soa foo bar 1 2 3 4 5
@ ns ns1
@ ns ns2
Königsgäßchen 300 NS Königsgäßchen
Example #17
0
 def test_unpickle(self):
     expected_mx = dns.rdata.from_text("in", "mx", "10 mx.example.")
     with open(here("mx-2-0.pickle"), "rb") as f:
         mx = pickle.load(f)
     self.assertEqual(mx, expected_mx)
     self.assertIsNone(mx.rdcomment)