def test_11_load_rollback(self): cc = CryptContext(['des_crypt', 'sha256_crypt'], sha256_crypt__default_rounds=5000, all__vary_rounds=0.1) result = cc.to_string() self.assertRaises(TypeError, cc.update, too__many__key__parts=True) self.assertEqual(cc.to_string(), result) self.assertRaises(KeyError, cc.update, fake_context_option=True) self.assertEqual(cc.to_string(), result) self.assertRaises(ValueError, cc.update, sha256_crypt__min_rounds=10000) self.assertEqual(cc.to_string(), result)
def test_35_to_string(self): ctx = CryptContext(**self.sample_1_dict) dump = ctx.to_string() if not PY26: self.assertEqual(dump, self.sample_1_unicode) ctx2 = CryptContext.from_string(dump) self.assertEqual(ctx2.to_dict(), self.sample_1_dict) other = ctx.to_string(section='password-security') self.assertEqual(other, dump.replace('[passlib]', '[password-security]')) from otp.ai.passlib.tests.test_utils_handlers import UnsaltedHash ctx3 = CryptContext([UnsaltedHash, 'md5_crypt']) dump = ctx3.to_string() self.assertRegex(dump, "# NOTE: the 'unsalted_test_hash' handler\\(s\\) are not registered with Passlib")