summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJustin Santa Barbara <justin@fathomdb.com>2012-02-08 12:53:44 -0800
committerJustin Santa Barbara <justin@fathomdb.com>2012-02-08 13:19:15 -0800
commit95280608fc82f7ae51f8c42678d6a7f0ac2ecff0 (patch)
treecda05b01bf691eeec0b943002d08284160bc3878 /tests
parent3364905041dd133cef3512a0a3ee4a3aa161b798 (diff)
downloadkeystone-95280608fc82f7ae51f8c42678d6a7f0ac2ecff0.tar.gz
keystone-95280608fc82f7ae51f8c42678d6a7f0ac2ecff0.tar.xz
keystone-95280608fc82f7ae51f8c42678d6a7f0ac2ecff0.zip
Cope with unicode passwords or None
If the password has a unicode character in it, bcrypt breaks. So encode it using utf-8. utf-8 should mean that existing hashes still work. Change-Id: I4f9f3b636c8728234ada87de62d22bed2ff8eb60
Diffstat (limited to 'tests')
-rw-r--r--tests/test_utils.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py
new file mode 100644
index 00000000..81cec7c9
--- /dev/null
+++ b/tests/test_utils.py
@@ -0,0 +1,40 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012 Justin Santa Barbara
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from keystone import test
+from keystone.common import utils
+
+
+class UtilsTestCase(test.TestCase):
+ def test_hash(self):
+ password = 'right'
+ wrong = 'wrongwrong' # Two wrongs don't make a right
+ hashed = utils.hash_password(password)
+ self.assertTrue(utils.check_password(password, hashed))
+ self.assertFalse(utils.check_password(wrong, hashed))
+
+ def test_hash_edge_cases(self):
+ hashed = utils.hash_password('secret')
+ self.assertFalse(utils.check_password('', hashed))
+ self.assertFalse(utils.check_password(None, hashed))
+
+ def test_hash_unicode(self):
+ password = u'Comment \xe7a va'
+ wrong = 'Comment ?a va'
+ hashed = utils.hash_password(password)
+ self.assertTrue(utils.check_password(password, hashed))
+ self.assertFalse(utils.check_password(wrong, hashed))