def test_dumps_loads(self): "dumps and loads should work reversibly for any picklable object" objects = ( ['a', 'list'], 'a string', u'a unicode string \u2019', {'a': 'dictionary'}, ) for o in objects: self.assert_(o != signed.dumps(o)) self.assertEqual(o, signed.loads(signed.dumps(o)))
def test_dumps_loads(self): "dumps and loads should work reversibly for any picklable object" objects = ( ['a', 'list'], 'a string', u'a unicode string \u2019', { 'a': 'dictionary' }, ) for o in objects: self.assert_(o != signed.dumps(o)) self.assertEqual(o, signed.loads(signed.dumps(o)))
def test_decode_detects_tampering(self): "loads should raise exception for tampered objects" transforms = ( lambda s: s.upper(), lambda s: s + 'a', lambda s: 'a' + s[1:], lambda s: s.replace('.', ''), ) value = {'foo': 'bar', 'baz': 1} encoded = signed.dumps(value) self.assertEqual(value, signed.loads(encoded)) for transform in transforms: self.assertRaises(signed.BadSignature, signed.loads, transform(encoded))
def test_decode_detects_tampering(self): "loads should raise exception for tampered objects" transforms = ( lambda s: s.upper(), lambda s: s + 'a', lambda s: 'a' + s[1:], lambda s: s.replace('.', ''), ) value = {'foo': 'bar', 'baz': 1} encoded = signed.dumps(value) self.assertEqual(value, signed.loads(encoded)) for transform in transforms: self.assertRaises( signed.BadSignature, signed.loads, transform(encoded) )