def test_02_from_string(self): ctx = CryptContext.from_string(self.sample_1_unicode) self.assertEqual(ctx.to_dict(), self.sample_1_dict) ctx = CryptContext.from_string(self.sample_1_unnormalized) self.assertEqual(ctx.to_dict(), self.sample_1_dict) ctx = CryptContext.from_string(self.sample_1_unicode.encode('utf-8')) self.assertEqual(ctx.to_dict(), self.sample_1_dict) ctx = CryptContext.from_string(self.sample_1b_unicode) self.assertEqual(ctx.to_dict(), self.sample_1_dict) ctx = CryptContext.from_string(self.sample_1c_bytes, section='mypolicy', encoding='utf-16') self.assertEqual(ctx.to_dict(), self.sample_1_dict) self.assertRaises(TypeError, CryptContext.from_string, None) self.assertRaises(NoSectionError, CryptContext.from_string, self.sample_1_unicode, section='fakesection') return
def test_13_config_defaults(self): from otp.ai.passlib.ext.django.utils import PASSLIB_DEFAULT default = CryptContext.from_string(PASSLIB_DEFAULT) self.load_extension() self.assert_patched(PASSLIB_DEFAULT) self.load_extension(PASSLIB_CONTEXT='passlib-default', check=False) self.assert_patched(PASSLIB_DEFAULT) self.load_extension(PASSLIB_CONTEXT=PASSLIB_DEFAULT, check=False) self.assert_patched(PASSLIB_DEFAULT)
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")