summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2012-08-01 17:00:46 -0400
committerEli Collins <elic@assurancetechnologies.com>2012-08-01 17:00:46 -0400
commit4c50517503da531df315bb04d171464fab65eb0d (patch)
treedfd83bb0d6ed147cf37889d5901913789207c0b0
parent0c1086c6a41884352356f0d4822c95080e0caad6 (diff)
downloadpasslib-4c50517503da531df315bb04d171464fab65eb0d.tar.gz
border case: CryptContext now accepts keys with mixed '.' and '__' separators
-rw-r--r--passlib/context.py2
-rw-r--r--passlib/tests/test_context.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/passlib/context.py b/passlib/context.py
index 2b091f1..940954d 100644
--- a/passlib/context.py
+++ b/passlib/context.py
@@ -1901,7 +1901,7 @@ class CryptContext(object):
"""helper used to parse ``cat__scheme__option`` keys into a tuple"""
# split string into 1-3 parts
assert isinstance(ckey, str)
- parts = ckey.split("." if "." in ckey else "__")
+ parts = ckey.replace(".","__").split("__")
count = len(parts)
if count == 1:
cat, scheme, key = None, None, parts[0]
diff --git a/passlib/tests/test_context.py b/passlib/tests/test_context.py
index 85dc7d0..cdd8746 100644
--- a/passlib/tests/test_context.py
+++ b/passlib/tests/test_context.py
@@ -423,6 +423,14 @@ sha512_crypt__min_rounds = 45000
self.assertRaises(TypeError, CryptContext,
category__scheme__option__invalid = 30000)
+ # keys with mixed separators should be handled correctly.
+ # (testing actual data, not to_dict(), since re-render hid original bug)
+ self.assertRaises(KeyError, parse,
+ **{"admin.context__schemes":"md5_crypt"})
+ ctx = CryptContext(**{"schemes":"md5_crypt,des_crypt",
+ "admin.context__default":"des_crypt"})
+ self.assertEqual(ctx.default_scheme("admin"), "des_crypt")
+
#
# context option -specific tests
#