Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_decode_with_timeout(self):
secret_key = "predictable-key"
value = u"hello"
s = self.make_serializer(secret_key)
ts = s.dumps(value)
self.assertNotEqual(ts, itsdangerous.Serializer(secret_key).dumps(value))
self.assertEqual(s.loads(ts), value)
time.time = lambda: 10
self.assertEqual(s.loads(ts, max_age=11), value)
self.assertEqual(s.loads(ts, max_age=10), value)
self.assertRaises(itsdangerous.SignatureExpired, s.loads, ts, max_age=9)
def build_local_part(name, uid):
"""Build local part as 'name-uid-digest', ensuring length < 64."""
key = current_app.config["SECRET_KEY"]
serializer = Serializer(key)
signature = serializer.dumps(uid)
digest = md5(signature)
local_part = name + "+" + uid + "-" + digest
if len(local_part) > 64:
if (len(local_part) - len(digest) - 1) > 64:
# even without digest, it's too long
raise ValueError(
"Cannot build reply address: local part exceeds 64 characters"
)
local_part = local_part[:64]
return local_part
def get_serializer(secret_key='secret_key'):
return Serializer(secret_key)
def get_serializer(secret_key=None):
return Serializer('secret_key')
def get_serializer(secret_key='secret_key'):
return Serializer(secret_key)