Sorcerer's IsleCode cfPassphrase / files

  1<cfcomponent extends="TestBase">
  2<cfscript>
  3
  4	function init( IncludeSlowTests )
  5	{
  6		super.init( argumentcollection=arguments );
  7
  8		this.Name = 'bcrypt';
  9
 10		var TestData =
 11			[ [ "", "$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s." ]
 12			, [ "", "$2a$08$HqWuK6/Ng6sg9gQzbLrgb.Tl.ZHfXLhvt/SgVyWhQqgqcZ7ZuUtye" ]
 13			, [ "", "$2a$10$k1wbIrmNyFAPwPVPSVa/zecw2BCEnBwVS2GbrmgzxFUOqW9dk4TCW" ]
 14			, [ "", "$2a$12$k42ZFHFWqBp3vWli.nIn8uYyIkbvYRvodzbfbK18SSsY.CsIQPlxO" ]
 15			, [ "a", "$2a$06$m0CrhHm10qJ3lXRY.5zDGO3rS2KdeeWLuGmsfGlMfOxih58VYVfxe" ]
 16			, [ "a", "$2a$08$cfcvVd2aQ8CMvoMpP2EBfeodLEkkFJ9umNEfPD18.hUF62qqlC/V." ]
 17			, [ "a", "$2a$10$k87L/MF28Q673VKh8/cPi.SUl7MU/rWuSiIDDFayrKk/1tBsSQu4u" ]
 18			, [ "a", "$2a$12$8NJH3LsPrANStV6XtBakCez0cKHXVxmvxIlcz785vxAIZrihHZpeS" ]
 19			, [ "abc", "$2a$06$If6bvum7DFjUnE9p2uDeDu0YHzrHM6tf.iqN8.yx.jNN1ILEf7h0i" ]
 20			, [ "abc", "$2a$08$Ro0CUfOqk6cXEKf3dyaM7OhSCvnwM9s4wIX9JeLapehKK5YdLxKcm" ]
 21			, [ "abc", "$2a$10$WvvTPHKwdBJ3uk0Z37EMR.hLA2W6N9AEBhEgrAOljy2Ae5MtaSIUi" ]
 22			, [ "abc", "$2a$12$EXRkfkdmXn2gzds2SSitu.MW9.gAVqa9eLS1//RYtYCmB1eLHg.9q" ]
 23			, [ "abcdefghijklmnopqrstuvwxyz", "$2a$06$.rCVZVOThsIa97pEDOxvGuRRgzG64bvtJ0938xuqzv18d3ZpQhstC" ]
 24			, [ "abcdefghijklmnopqrstuvwxyz", "$2a$08$aTsUwsyowQuzRrDqFflhgekJ8d9/7Z3GV3UcgvzQW3J5zMyrTvlz." ]
 25			, [ "abcdefghijklmnopqrstuvwxyz", "$2a$10$fVH8e28OQRj9tqiDXs1e1uxpsjN0c7II7YPKXua2NAKYvM6iQk7dq" ]
 26			, [ "abcdefghijklmnopqrstuvwxyz", "$2a$12$D4G5f18o7aMMfwasBL7GpuQWuP3pkrZrOAnqP.bmezbMng.QwJ/pG" ]
 27			, [ "~!@##$%^&*()      ~!@##$%^&*()PNBFRD", "$2a$06$fPIsBO8qRqkjj273rfaOI.HtSV9jLDpTbZn782DC6/t7qT67P6FfO" ]
 28			, [ "~!@##$%^&*()      ~!@##$%^&*()PNBFRD", "$2a$08$Eq2r4G/76Wv39MzSX262huzPz612MZiYHVUJe/OcOql2jo4.9UxTW" ]
 29			, [ "~!@##$%^&*()      ~!@##$%^&*()PNBFRD", "$2a$10$LgfYWkbzEvQ4JakH7rOvHe0y8pHKF9OaFgwUZ2q7W2FFZmZzJYlfS" ]
 30			, [ "~!@##$%^&*()      ~!@##$%^&*()PNBFRD", "$2a$12$WApznUOJfkEGSmYRfnkrPOr466oFDCaj4b6HY3EXGvfxm43seyhgC" ]
 31			];
 32
 33		super.start();
 34
 35		this.test_info( TestData );
 36
 37		if ( IncludeSlowTests )
 38			this.test_basic( TestData );
 39		else
 40			skip( ArrayLen(TestData)*2 );
 41
 42		this.test_nonascii();
 43
 44		return super.end();
 45	}
 46
 47
 48	function test_info( TestData )
 49	{
 50		var info1 = PassphraseInfo('$2a$10$9zXu55aPNya8ek17DwCXZ.X6kExa5cK5bpGmyTBrqD1dg76rkWz4y');
 51		assertEqual(info1.Algorithm,'BCrypt');
 52		assertEqual(info1.Status,'Supported');
 53		assertEqual(info1.Version,'2a');
 54		assertEqual(info1.Rounds,10);
 55		assertEqual(info1.Salt,'9zXu55aPNya8ek17');
 56		assertEqual(info1.Hash,'DwCXZ.X6kExa5cK5bpGmyTBrqD1dg76rkWz4y');
 57		assertEqual(StructCount(info1),6);
 58
 59		var info = PassphraseInfo(Arguments.TestData[1][2]);
 60		assertEqual(info.Algorithm,'BCrypt');
 61		assertEqual(info.Status,'Supported');
 62		assertEqual(info.Version,'2a');
 63		assertEqual(info.Rounds,6);
 64		assertEqual(info.Salt,'DCq7YPn5Rq63x1La');
 65		assertEqual(info.Hash,'d4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s.');
 66
 67		info = PassphraseInfo(Arguments.TestData[20][2]);
 68		assertEqual(info.Algorithm,'BCrypt');
 69		assertEqual(info.Status,'Supported');
 70		assertEqual(info.Version,'2a');
 71		assertEqual(info.Rounds,12);
 72		assertEqual(info.Salt,'WApznUOJfkEGSmYR');
 73		assertEqual(info.Hash,'fnkrPOr466oFDCaj4b6HY3EXGvfxm43seyhgC');
 74	}
 75
 76
 77	function test_basic( TestData )
 78	{
 79		for ( var i=1 ; i<=ArrayLen(Arguments.TestData) ; ++i )
 80		{
 81			assertTrue( PassphraseCheck(Arguments.TestData[i][1],Arguments.TestData[i][2]) );
 82			assertFalse( PassphraseCheck(Arguments.TestData[i][1],Arguments.TestData[((i + 4) % ArrayLen(Arguments.TestData))+1][2]) );
 83		}
 84	}
 85
 86
 87	function test_nonascii()
 88	{
 89		var TestData =
 90			[ RepeatString(chr(2605),8)
 91			, "????????"
 92			];
 93
 94		var h1 = PassphraseHash(TestData[1],'bcrypt',{rounds:6});
 95		var h2 = PassphraseHash(TestData[2],'bcrypt',{rounds:6});
 96		assertTrue(PassphraseCheck(TestData[1],h1));
 97		assertFalse(PassphraseCheck(TestData[1],h2));
 98		assertTrue(PassphraseCheck(TestData[2],h2));
 99		assertFalse(PassphraseCheck(TestData[2],h1));
100	}
101
102
103</cfscript>
104</cfcomponent>