def test_33_genconfig_saltchars(self): "test genconfig() honors salt_chars" handler = self.handler if not has_salt_info(handler): raise self.skipTest("handler doesn't provide salt info") mx = handler.max_salt_size mn = handler.min_salt_size cs = handler.salt_chars raw = isinstance(cs, bytes) #make sure all listed chars are accepted chunk = 32 if mx is None else mx for i in xrange(0,len(cs),chunk): salt = cs[i:i+chunk] if len(salt) < mn: salt = (salt*(mn//len(salt)+1))[:chunk] self.do_genconfig(salt=salt) #check some invalid salt chars, make sure they're rejected source = u'\x00\xff' if raw: source = source.encode("latin-1") chunk = max(mn, 1) for c in source: if c not in cs: self.assertRaises(ValueError, self.do_genconfig, salt=c*chunk, __msg__="invalid salt char %r:" % (c,))
def test_32_genconfig_maxsalt(self): "test genconfig() honors max salt chars" handler = self.handler if not has_salt_info(handler): raise self.skipTest("handler doesn't provide salt info") cs = handler.salt_chars cc = cs[0:1] mx = handler.max_salt_size if mx is None: #make sure salt is NOT truncated, #use a really large salt for testing salt = cc * 1024 c1 = self.do_genconfig(salt=salt) c2 = self.do_genconfig(salt=salt + cc) self.assertNotEqual(c1,c2) else: #make sure salt is truncated exactly where it should be. salt = cc * mx c1 = self.do_genconfig(salt=salt) c2 = self.do_genconfig(salt=salt + cc) self.assertEqual(c1,c2) #if min_salt supports it, check smaller than mx is NOT truncated if handler.min_salt_size < mx: c3 = self.do_genconfig(salt=salt[:-1]) self.assertNotEqual(c1,c3)
def test_31_genconfig_minsalt(self): "test genconfig() honors min salt chars" handler = self.handler if not has_salt_info(handler): raise self.skipTest("handler doesn't provide salt info") cs = handler.salt_chars cc = cs[0:1] mn = handler.min_salt_size c1 = self.do_genconfig(salt=cc * mn) if mn > 0: self.assertRaises(ValueError, self.do_genconfig, salt=cc*(mn-1))
def test_01_optional_salt_attributes(self): "validate optional salt attributes" cls = self.handler if not has_salt_info(cls): raise self.skipTest("handler doesn't provide salt info") AssertionError = self.failureException #check max_salt_size mx_set = (cls.max_salt_size is not None) if mx_set and cls.max_salt_size < 1: raise AssertionError("max_salt_chars must be >= 1") #check min_salt_size if cls.min_salt_size < 0: raise AssertionError("min_salt_chars must be >= 0") if mx_set and cls.min_salt_size > cls.max_salt_size: raise AssertionError("min_salt_chars must be <= max_salt_chars") #check default_salt_size if cls.default_salt_size < cls.min_salt_size: raise AssertionError("default_salt_size must be >= min_salt_size") if mx_set and cls.default_salt_size > cls.max_salt_size: raise AssertionError("default_salt_size must be <= max_salt_size") #check for 'salt_size' keyword if 'salt_size' not in cls.setting_kwds and \ (not mx_set or cls.min_salt_size < cls.max_salt_size): #NOTE: for now, only bothering to issue warning if default_salt_size isn't maxed out if (not mx_set or cls.default_salt_size < cls.max_salt_size): warn("%s: hash handler supports range of salt sizes, but doesn't offer 'salt_size' setting" % (cls.name,)) #check salt_chars & default_salt_chars if cls.salt_chars: if not cls.default_salt_chars: raise AssertionError("default_salt_chars must not be empty") if any(c not in cls.salt_chars for c in cls.default_salt_chars): raise AssertionError("default_salt_chars must be subset of salt_chars: %r not in salt_chars" % (c,)) else: if not cls.default_salt_chars: raise AssertionError("default_salt_chars MUST be specified if salt_chars is empty")