Back to index

python-bcrypt  0.2
test.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Copyright (c) 2006 Damien Miller <djm@mindrot.org>
00004 #
00005 # Permission to use, copy, modify, and distribute this software for any
00006 # purpose with or without fee is hereby granted, provided that the above
00007 # copyright notice and this permission notice appear in all copies.
00008 #
00009 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00010 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00011 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00012 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00013 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00014 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00015 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00016 
00017 # $Id: test.py,v 1.1.1.1 2006/05/22 11:53:27 djm Exp $
00018 
00019 import bcrypt
00020 import unittest
00021 
00022 test_vectors = [
00023        [ '', '$2a$06$DCq7YPn5Rq63x1Lad4cll.',
00024          '$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s.' ],
00025        [ '', '$2a$08$HqWuK6/Ng6sg9gQzbLrgb.',
00026          '$2a$08$HqWuK6/Ng6sg9gQzbLrgb.Tl.ZHfXLhvt/SgVyWhQqgqcZ7ZuUtye' ],
00027        [ '', '$2a$10$k1wbIrmNyFAPwPVPSVa/ze',
00028          '$2a$10$k1wbIrmNyFAPwPVPSVa/zecw2BCEnBwVS2GbrmgzxFUOqW9dk4TCW' ],
00029        [ '', '$2a$12$k42ZFHFWqBp3vWli.nIn8u',
00030          '$2a$12$k42ZFHFWqBp3vWli.nIn8uYyIkbvYRvodzbfbK18SSsY.CsIQPlxO' ],
00031        [ 'a', '$2a$06$m0CrhHm10qJ3lXRY.5zDGO',
00032          '$2a$06$m0CrhHm10qJ3lXRY.5zDGO3rS2KdeeWLuGmsfGlMfOxih58VYVfxe' ],
00033        [ 'a', '$2a$08$cfcvVd2aQ8CMvoMpP2EBfe',
00034          '$2a$08$cfcvVd2aQ8CMvoMpP2EBfeodLEkkFJ9umNEfPD18.hUF62qqlC/V.' ],
00035        [ 'a', '$2a$10$k87L/MF28Q673VKh8/cPi.',
00036          '$2a$10$k87L/MF28Q673VKh8/cPi.SUl7MU/rWuSiIDDFayrKk/1tBsSQu4u' ],
00037        [ 'a', '$2a$12$8NJH3LsPrANStV6XtBakCe',
00038          '$2a$12$8NJH3LsPrANStV6XtBakCez0cKHXVxmvxIlcz785vxAIZrihHZpeS' ],
00039        [ 'abc', '$2a$06$If6bvum7DFjUnE9p2uDeDu',
00040          '$2a$06$If6bvum7DFjUnE9p2uDeDu0YHzrHM6tf.iqN8.yx.jNN1ILEf7h0i' ],
00041        [ 'abc', '$2a$08$Ro0CUfOqk6cXEKf3dyaM7O',
00042          '$2a$08$Ro0CUfOqk6cXEKf3dyaM7OhSCvnwM9s4wIX9JeLapehKK5YdLxKcm' ],
00043        [ 'abc', '$2a$10$WvvTPHKwdBJ3uk0Z37EMR.',
00044          '$2a$10$WvvTPHKwdBJ3uk0Z37EMR.hLA2W6N9AEBhEgrAOljy2Ae5MtaSIUi' ],
00045        [ 'abc', '$2a$12$EXRkfkdmXn2gzds2SSitu.',
00046          '$2a$12$EXRkfkdmXn2gzds2SSitu.MW9.gAVqa9eLS1//RYtYCmB1eLHg.9q' ],
00047        [ 'abcdefghijklmnopqrstuvwxyz', '$2a$06$.rCVZVOThsIa97pEDOxvGu',
00048          '$2a$06$.rCVZVOThsIa97pEDOxvGuRRgzG64bvtJ0938xuqzv18d3ZpQhstC' ],
00049        [ 'abcdefghijklmnopqrstuvwxyz', '$2a$08$aTsUwsyowQuzRrDqFflhge',
00050          '$2a$08$aTsUwsyowQuzRrDqFflhgekJ8d9/7Z3GV3UcgvzQW3J5zMyrTvlz.' ],
00051        [ 'abcdefghijklmnopqrstuvwxyz', '$2a$10$fVH8e28OQRj9tqiDXs1e1u',
00052          '$2a$10$fVH8e28OQRj9tqiDXs1e1uxpsjN0c7II7YPKXua2NAKYvM6iQk7dq' ],
00053        [ 'abcdefghijklmnopqrstuvwxyz', '$2a$12$D4G5f18o7aMMfwasBL7Gpu',
00054          '$2a$12$D4G5f18o7aMMfwasBL7GpuQWuP3pkrZrOAnqP.bmezbMng.QwJ/pG' ],
00055        [ '~!@#$%^&*()      ~!@#$%^&*()PNBFRD', '$2a$06$fPIsBO8qRqkjj273rfaOI.',
00056          '$2a$06$fPIsBO8qRqkjj273rfaOI.HtSV9jLDpTbZn782DC6/t7qT67P6FfO' ],
00057        [ '~!@#$%^&*()      ~!@#$%^&*()PNBFRD', '$2a$08$Eq2r4G/76Wv39MzSX262hu',
00058          '$2a$08$Eq2r4G/76Wv39MzSX262huzPz612MZiYHVUJe/OcOql2jo4.9UxTW' ],
00059        [ '~!@#$%^&*()      ~!@#$%^&*()PNBFRD', '$2a$10$LgfYWkbzEvQ4JakH7rOvHe',
00060          '$2a$10$LgfYWkbzEvQ4JakH7rOvHe0y8pHKF9OaFgwUZ2q7W2FFZmZzJYlfS' ],
00061        [ '~!@#$%^&*()      ~!@#$%^&*()PNBFRD', '$2a$12$WApznUOJfkEGSmYRfnkrPO',
00062          '$2a$12$WApznUOJfkEGSmYRfnkrPOr466oFDCaj4b6HY3EXGvfxm43seyhgC' ],
00063 ]
00064 
00065 class TestRadix(unittest.TestCase):
00066        def test_00__test_vectors(self):
00067               for plain, salt, expected in test_vectors:
00068                      self.assertEqual(bcrypt.hashpw(plain, salt), expected)
00069 
00070        def test_01__gensalt(self):
00071               for plain, salt, expected in test_vectors:
00072                      for i in range(4,14,2):
00073                             salt = bcrypt.gensalt(i)
00074                             crypted = bcrypt.hashpw(plain, salt)
00075                             crypted2 = bcrypt.hashpw(plain, crypted)
00076                             self.assertEqual(crypted, crypted2)
00077 
00078 def main():
00079        unittest.main()
00080 
00081 if __name__ == '__main__':
00082        main()
00083