summaryrefslogtreecommitdiff
path: root/passlib/tests
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2011-08-12 18:21:09 -0400
committerEli Collins <elic@assurancetechnologies.com>2011-08-12 18:21:09 -0400
commit7b2a8080cb9ed66ed6205c9bbf253c92ad5a8134 (patch)
treeea5d9907852e78486ebe767e9d4e6ca9774e237c /passlib/tests
parentf02b0e6c69930c893daba2df59df6e3dc5fc7c62 (diff)
downloadpasslib-7b2a8080cb9ed66ed6205c9bbf253c92ad5a8134.tar.gz
additional linesep & encoded tests for CryptPolicy.from_string / from_path
Diffstat (limited to 'passlib/tests')
-rw-r--r--passlib/tests/test_context.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/passlib/tests/test_context.py b/passlib/tests/test_context.py
index efdbd45..d0285e1 100644
--- a/passlib/tests/test_context.py
+++ b/passlib/tests/test_context.py
@@ -14,7 +14,7 @@ import sys
#pkg
from passlib import hash
from passlib.context import CryptContext, CryptPolicy, LazyCryptContext
-from passlib.utils import to_bytes
+from passlib.utils import to_bytes, to_unicode
import passlib.utils.handlers as uh
from passlib.tests.utils import TestCase, mktemp, catch_warnings, gae_env
from passlib.registry import register_crypt_handler_path, has_crypt_handler, \
@@ -205,11 +205,19 @@ admin.sha512_crypt.max_rounds = 40000
return self.skipTest("GAE doesn't offer read/write filesystem access")
path = mktemp()
- with open(path, "w") as fh:
+
+ #test "\n" linesep
+ with open(path, "wb") as fh:
fh.write(self.sample_config_1s)
policy = CryptPolicy.from_path(path)
self.assertEqual(policy.to_dict(), self.sample_config_1pd)
+ #test "\r\n" linesep
+ with open(path, "wb") as fh:
+ fh.write(self.sample_config_1s.replace("\n","\r\n"))
+ policy = CryptPolicy.from_path(path)
+ self.assertEqual(policy.to_dict(), self.sample_config_1pd)
+
#test with custom encoding
uc2 = to_bytes(self.sample_config_1s, "utf-16", source_encoding="utf-8")
with open(path, "wb") as fh:
@@ -219,17 +227,29 @@ admin.sha512_crypt.max_rounds = 40000
def test_02_from_string(self):
"test CryptPolicy.from_string() constructor"
+ #test "\n" linesep
policy = CryptPolicy.from_string(self.sample_config_1s)
self.assertEqual(policy.to_dict(), self.sample_config_1pd)
- policy = CryptPolicy.from_string(self.sample_config_4s)
- self.assertEqual(policy.to_dict(), self.sample_config_4pd)
+ #test "\r\n" linesep
+ policy = CryptPolicy.from_string(
+ self.sample_config_1s.replace("\n","\r\n"))
+ self.assertEqual(policy.to_dict(), self.sample_config_1pd)
- #test with custom encoding
+ #test with unicode
+ data = to_unicode(self.sample_config_1s)
+ policy = CryptPolicy.from_string(data)
+ self.assertEqual(policy.to_dict(), self.sample_config_1pd)
+
+ #test with non-ascii-compatible encoding
uc2 = to_bytes(self.sample_config_1s, "utf-16", source_encoding="utf-8")
policy = CryptPolicy.from_string(uc2, encoding="utf-16")
self.assertEqual(policy.to_dict(), self.sample_config_1pd)
+ #test category specific options
+ policy = CryptPolicy.from_string(self.sample_config_4s)
+ self.assertEqual(policy.to_dict(), self.sample_config_4pd)
+
def test_03_from_source(self):
"test CryptPolicy.from_source() constructor"
#pass it a path