123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- import unittest
- from pydnspp import *
- class NSEC3HashTest(unittest.TestCase):
- '''These tests are mostly straightforward conversion of C++ tests
- except for python specific type checks.
- '''
- def setUp(self):
- self.nsec3_common = "2T7B4G4VSA5SMI47K61MV5BV1A22BOJR A RRSIG"
- self.test_hash = NSEC3Hash(Rdata(RRType.NSEC3PARAM(), RRClass.IN(),
- "1 0 12 aabbccdd"))
- self.test_hash_nsec3 = NSEC3Hash(Rdata(RRType.NSEC3(), RRClass.IN(),
- "1 0 12 aabbccdd " +
- self.nsec3_common))
- def test_bad_construct(self):
-
- self.assertRaises(TypeError, NSEC3Hash)
-
- self.assertRaises(TypeError, NSEC3Hash, "1 0 12 aabbccdd")
-
- self.assertRaises(TypeError, NSEC3Hash, Rdata(RRType.NSEC3PARAM(),
- RRClass.IN(),
- "1 0 12 aabbccdd"), 1)
-
- self.assertRaises(TypeError, NSEC3Hash, Rdata(RRType.A(), RRClass.IN(),
- "192.0.2.1"))
- def test_unknown_algorithm(self):
- self.assertRaises(UnknownNSEC3HashAlgorithm, NSEC3Hash,
- Rdata(RRType.NSEC3PARAM(), RRClass.IN(),
- "2 0 12 aabbccdd"))
- self.assertRaises(UnknownNSEC3HashAlgorithm, NSEC3Hash,
- Rdata(RRType.NSEC3(), RRClass.IN(),
- "2 0 12 aabbccdd " + self.nsec3_common))
- def calculate_check(self, hash):
-
- self.assertEqual("0P9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM",
- hash.calculate(Name("example")))
- self.assertEqual("35MTHGPGCU1QG68FAB165KLNSNK3DPVL",
- hash.calculate(Name("a.example")))
-
- self.assertEqual("0P9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM",
- hash.calculate(Name("EXAMPLE")))
- def test_calculate(self):
- self.calculate_check(self.test_hash)
- self.calculate_check(self.test_hash_nsec3)
-
-
- self.test_hash = NSEC3Hash(Rdata(RRType.NSEC3PARAM(),
- RRClass.IN(), "1 0 256 AABBCCDD"))
- self.assertEqual("COG6A52MJ96MNMV3QUCAGGCO0RHCC2Q3",
- self.test_hash.calculate(Name("example.org")))
-
-
- self.test_hash = NSEC3Hash(Rdata(RRType.NSEC3PARAM(),
- RRClass.IN(),"1 0 0 -"))
- self.assertEqual("CK0POJMG874LJREF7EFN8430QVIT8BSM",
- self.test_hash.calculate(Name("com")))
- def test_calculate_badparam(self):
- self.assertRaises(TypeError, self.test_hash.calculate, "example")
- self.assertRaises(TypeError, self.test_hash.calculate)
- self.assertRaises(TypeError, self.test_hash.calculate, Name("."), 1)
- def check_match(self, hash, rrtype, postfix):
-
- self.assertTrue(hash.match(Rdata(rrtype, RRClass.IN(),
- "1 0 12 aabbccdd" + postfix)))
-
- self.assertFalse(hash.match(Rdata(rrtype, RRClass.IN(),
- "2 0 12 aabbccdd" + postfix)))
-
- self.assertFalse(hash.match(Rdata(rrtype, RRClass.IN(),
- "1 0 1 aabbccdd" + postfix)))
-
- self.assertFalse(hash.match(Rdata(rrtype, RRClass.IN(),
- "1 0 12 aabbccde" + postfix)))
-
- self.assertFalse(hash.match(Rdata(rrtype, RRClass.IN(),
- "1 0 12 -" + postfix)))
-
- self.assertTrue(hash.match(Rdata(rrtype, RRClass.IN(),
- "1 1 12 aabbccdd" + postfix)))
- def test_match(self):
- self.check_match(self.test_hash, RRType.NSEC3(),
- " " + self.nsec3_common)
- self.check_match(self.test_hash_nsec3, RRType.NSEC3(),
- " " + self.nsec3_common)
- self.check_match(self.test_hash, RRType.NSEC3PARAM(), "")
- self.check_match(self.test_hash_nsec3, RRType.NSEC3PARAM(), "")
-
- self.assertRaises(TypeError, self.test_hash.match, 1)
- self.assertRaises(TypeError, self.test_hash.match,
- Rdata(RRType.NSEC3(), RRClass.IN(),
- "1 0 12 aabbccdd " + self.nsec3_common), 1)
- self.assertRaises(TypeError, self.test_hash.match,
- Rdata(RRType.A(), RRClass.IN(), "192.0.2.1"))
- if __name__ == '__main__':
- unittest.main()
|