|
@@ -23,10 +23,12 @@ class NSEC3HashTest(unittest.TestCase):
|
|
'''
|
|
'''
|
|
|
|
|
|
def setUp(self):
|
|
def setUp(self):
|
|
|
|
+ self.nsec3_common = "2T7B4G4VSA5SMI47K61MV5BV1A22BOJR A RRSIG"
|
|
self.test_hash = NSEC3Hash(Rdata(RRType.NSEC3PARAM(), RRClass.IN(),
|
|
self.test_hash = NSEC3Hash(Rdata(RRType.NSEC3PARAM(), RRClass.IN(),
|
|
"1 0 12 aabbccdd"))
|
|
"1 0 12 aabbccdd"))
|
|
- self.nsec3_common = "2T7B4G4VSA5SMI47K61MV5BV1A22BOJR A RRSIG"
|
|
|
|
-
|
|
|
|
|
|
+ self.test_hash_nsec3 = NSEC3Hash(Rdata(RRType.NSEC3(), RRClass.IN(),
|
|
|
|
+ "1 0 12 aabbccdd " +
|
|
|
|
+ self.nsec3_common))
|
|
def test_bad_construct(self):
|
|
def test_bad_construct(self):
|
|
# missing parameter
|
|
# missing parameter
|
|
self.assertRaises(TypeError, NSEC3Hash)
|
|
self.assertRaises(TypeError, NSEC3Hash)
|
|
@@ -39,28 +41,33 @@ class NSEC3HashTest(unittest.TestCase):
|
|
RRClass.IN(),
|
|
RRClass.IN(),
|
|
"1 0 12 aabbccdd"), 1)
|
|
"1 0 12 aabbccdd"), 1)
|
|
|
|
|
|
|
|
+ # Invaid type of RDATA
|
|
|
|
+ self.assertRaises(TypeError, NSEC3Hash, Rdata(RRType.A(), RRClass.IN(),
|
|
|
|
+ "192.0.2.1"))
|
|
|
|
+
|
|
def test_unknown_algorithm(self):
|
|
def test_unknown_algorithm(self):
|
|
self.assertRaises(UnknownNSEC3HashAlgorithm, NSEC3Hash,
|
|
self.assertRaises(UnknownNSEC3HashAlgorithm, NSEC3Hash,
|
|
Rdata(RRType.NSEC3PARAM(), RRClass.IN(),
|
|
Rdata(RRType.NSEC3PARAM(), RRClass.IN(),
|
|
"2 0 12 aabbccdd"))
|
|
"2 0 12 aabbccdd"))
|
|
|
|
+ self.assertRaises(UnknownNSEC3HashAlgorithm, NSEC3Hash,
|
|
|
|
+ Rdata(RRType.NSEC3(), RRClass.IN(),
|
|
|
|
+ "2 0 12 aabbccdd " + self.nsec3_common))
|
|
|
|
|
|
- def test_calculate(self):
|
|
|
|
|
|
+ def calculate_check(self, hash):
|
|
# A couple of normal cases from the RFC5155 example.
|
|
# A couple of normal cases from the RFC5155 example.
|
|
self.assertEqual("0P9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM",
|
|
self.assertEqual("0P9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM",
|
|
- self.test_hash.calculate(Name("example")))
|
|
|
|
|
|
+ hash.calculate(Name("example")))
|
|
self.assertEqual("35MTHGPGCU1QG68FAB165KLNSNK3DPVL",
|
|
self.assertEqual("35MTHGPGCU1QG68FAB165KLNSNK3DPVL",
|
|
- self.test_hash.calculate(Name("a.example")))
|
|
|
|
|
|
+ hash.calculate(Name("a.example")))
|
|
|
|
|
|
# Check case-insensitiveness
|
|
# Check case-insensitiveness
|
|
self.assertEqual("0P9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM",
|
|
self.assertEqual("0P9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM",
|
|
- self.test_hash.calculate(Name("EXAMPLE")))
|
|
|
|
|
|
+ hash.calculate(Name("EXAMPLE")))
|
|
|
|
|
|
- # Some boundary cases: 0-iteration and empty salt. Borrowed from the
|
|
|
|
- # .com zone data.
|
|
|
|
- self.test_hash = NSEC3Hash(Rdata(RRType.NSEC3PARAM(),
|
|
|
|
- RRClass.IN(),"1 0 0 -"))
|
|
|
|
- self.assertEqual("CK0POJMG874LJREF7EFN8430QVIT8BSM",
|
|
|
|
- self.test_hash.calculate(Name("com")))
|
|
|
|
|
|
+
|
|
|
|
+ def test_calculate(self):
|
|
|
|
+ self.calculate_check(self.test_hash)
|
|
|
|
+ self.calculate_check(self.test_hash_nsec3)
|
|
|
|
|
|
# Using unusually large iterations, something larger than the 8-bit
|
|
# Using unusually large iterations, something larger than the 8-bit
|
|
#range. (expected hash value generated by BIND 9's dnssec-signzone)
|
|
#range. (expected hash value generated by BIND 9's dnssec-signzone)
|
|
@@ -69,42 +76,46 @@ class NSEC3HashTest(unittest.TestCase):
|
|
self.assertEqual("COG6A52MJ96MNMV3QUCAGGCO0RHCC2Q3",
|
|
self.assertEqual("COG6A52MJ96MNMV3QUCAGGCO0RHCC2Q3",
|
|
self.test_hash.calculate(Name("example.org")))
|
|
self.test_hash.calculate(Name("example.org")))
|
|
|
|
|
|
|
|
+ # Some boundary cases: 0-iteration and empty salt. Borrowed from the
|
|
|
|
+ # .com zone data.
|
|
|
|
+ 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):
|
|
def test_calculate_badparam(self):
|
|
self.assertRaises(TypeError, self.test_hash.calculate, "example")
|
|
self.assertRaises(TypeError, self.test_hash.calculate, "example")
|
|
self.assertRaises(TypeError, self.test_hash.calculate)
|
|
self.assertRaises(TypeError, self.test_hash.calculate)
|
|
self.assertRaises(TypeError, self.test_hash.calculate, Name("."), 1)
|
|
self.assertRaises(TypeError, self.test_hash.calculate, Name("."), 1)
|
|
|
|
|
|
- def test_match_with_nsec3(self):
|
|
|
|
|
|
+ def check_match_with_nsec3(self, hash):
|
|
# If all parameters match, it's considered to be matched.
|
|
# If all parameters match, it's considered to be matched.
|
|
- self.assertTrue(self.test_hash.match(Rdata(RRType.NSEC3(),
|
|
|
|
- RRClass.IN(),
|
|
|
|
- "1 0 12 aabbccdd " +
|
|
|
|
- self.nsec3_common)))
|
|
|
|
|
|
+ self.assertTrue(hash.match(Rdata(RRType.NSEC3(), RRClass.IN(),
|
|
|
|
+ "1 0 12 aabbccdd " +
|
|
|
|
+ self.nsec3_common)))
|
|
# Algorithm doesn't match
|
|
# Algorithm doesn't match
|
|
- self.assertFalse(self.test_hash.match(Rdata(RRType.NSEC3(),
|
|
|
|
- RRClass.IN(),
|
|
|
|
- "2 0 12 aabbccdd " +
|
|
|
|
- self.nsec3_common)))
|
|
|
|
|
|
+ self.assertFalse(hash.match(Rdata(RRType.NSEC3(), RRClass.IN(),
|
|
|
|
+ "2 0 12 aabbccdd " +
|
|
|
|
+ self.nsec3_common)))
|
|
# Iterations doesn't match
|
|
# Iterations doesn't match
|
|
- self.assertFalse(self.test_hash.match(Rdata(RRType.NSEC3(),
|
|
|
|
- RRClass.IN(),
|
|
|
|
- "1 0 1 aabbccdd " +
|
|
|
|
- self.nsec3_common)))
|
|
|
|
|
|
+ self.assertFalse(hash.match(Rdata(RRType.NSEC3(), RRClass.IN(),
|
|
|
|
+ "1 0 1 aabbccdd " +
|
|
|
|
+ self.nsec3_common)))
|
|
# Salt doesn't match
|
|
# Salt doesn't match
|
|
- self.assertFalse(self.test_hash.match(Rdata(RRType.NSEC3(),
|
|
|
|
- RRClass.IN(),
|
|
|
|
- "1 0 12 aabbccde " +
|
|
|
|
- self.nsec3_common)))
|
|
|
|
|
|
+ self.assertFalse(hash.match(Rdata(RRType.NSEC3(), RRClass.IN(),
|
|
|
|
+ "1 0 12 aabbccde " +
|
|
|
|
+ self.nsec3_common)))
|
|
# Salt doesn't match: the other has an empty salt
|
|
# Salt doesn't match: the other has an empty salt
|
|
- self.assertFalse(self.test_hash.match(Rdata(RRType.NSEC3(),
|
|
|
|
- RRClass.IN(),
|
|
|
|
- "1 0 12 - " +
|
|
|
|
- self.nsec3_common)))
|
|
|
|
|
|
+ self.assertFalse(hash.match(Rdata(RRType.NSEC3(), RRClass.IN(),
|
|
|
|
+ "1 0 12 - " + self.nsec3_common)))
|
|
# Flags doesn't matter
|
|
# Flags doesn't matter
|
|
- self.assertTrue(self.test_hash.match(Rdata(RRType.NSEC3(),
|
|
|
|
- RRClass.IN(),
|
|
|
|
- "1 1 12 aabbccdd " +
|
|
|
|
- self.nsec3_common)))
|
|
|
|
|
|
+ self.assertTrue(hash.match(Rdata(RRType.NSEC3(), RRClass.IN(),
|
|
|
|
+ "1 1 12 aabbccdd " +
|
|
|
|
+ self.nsec3_common)))
|
|
|
|
+
|
|
|
|
+ def test_match_with_nsec3(self):
|
|
|
|
+ self.check_match_with_nsec3(self.test_hash)
|
|
|
|
+ self.check_match_with_nsec3(self.test_hash_nsec3)
|
|
|
|
|
|
# bad parameter checks
|
|
# bad parameter checks
|
|
self.assertRaises(TypeError, self.test_hash.match, 1)
|
|
self.assertRaises(TypeError, self.test_hash.match, 1)
|