def test_create_trunc_salt(self): msg = 'message' digest_size = hashlib.sha1().digest_size salt = b'x' * (digest_size + 10) val = DigestValue.create(msg, hashlib.sha1, salt=salt) assert len(val.salt) == digest_size assert val.salt == (b'x' * digest_size)
def test_valid_default(self): val = ChallengeField('md5', default=DigestValue.create('digest', hashlib.md5))
def test_create_salt_exact(self): msg = 'message' digest_size = hashlib.sha256().digest_size salt = b'x' * digest_size val = DigestValue.create(msg, hashlib.sha256, salt=salt) assert val.salt == salt
def test_create_short_salt(self): msg = b'message' digest_size = hashlib.sha256().digest_size salt = b'x' * (digest_size - 1) with pytest.raises(TypeError): DigestValue.create(msg, hashlib.sha256, salt=salt)
def test_create_no_salt(self): msg = 'message' val = DigestValue.create(msg, hashlib.md5) assert len(val.salt) == hashlib.md5().digest_size
def test_set_default_tuple(self): sdt = DigestValue.create('hello', hashlib.md5) field = ChallengeField('md5', key='test', default=sdt) cfg = BaseConfig(BaseSchema()) field.__setdefault__(cfg) assert cfg._data['test'] is sdt