@@ -47,13 +47,26 @@ module.exports = {
4747 "compareSync" : function ( test ) {
4848 var salt1 = bcrypt . genSaltSync ( ) ,
4949 hash1 = bcrypt . hashSync ( "hello" , salt1 ) ; // $2a$
50- var salt2 = bcrypt . genSaltSync ( ) ;
51- salt2 = salt2 . substring ( 0 , 2 ) + 'y' + salt2 . substring ( 3 ) ; // $2y$
52- var hash2 = bcrypt . hashSync ( "world" , salt2 ) ;
50+ var salt2 = bcrypt . genSaltSync ( ) . replace ( / \$ 2 a \$ / , "$2y$" ) ,
51+ hash2 = bcrypt . hashSync ( "world" , salt2 ) ;
52+ var salt3 = bcrypt . genSaltSync ( ) . replace ( / \$ 2 a \$ / , "$2b$" ) ,
53+ hash3 = bcrypt . hashSync ( "hello world" , salt3 ) ;
54+
55+ test . strictEqual ( hash1 . substring ( 0 , 4 ) , "$2a$" ) ;
5356 test . ok ( bcrypt . compareSync ( "hello" , hash1 ) ) ;
5457 test . notOk ( bcrypt . compareSync ( "hello" , hash2 ) ) ;
58+ test . notOk ( bcrypt . compareSync ( "hello" , hash3 ) ) ;
59+
60+ test . strictEqual ( hash2 . substring ( 0 , 4 ) , "$2y$" ) ;
5561 test . ok ( bcrypt . compareSync ( "world" , hash2 ) ) ;
5662 test . notOk ( bcrypt . compareSync ( "world" , hash1 ) ) ;
63+ test . notOk ( bcrypt . compareSync ( "world" , hash3 ) ) ;
64+
65+ test . strictEqual ( hash3 . substring ( 0 , 4 ) , "$2b$" ) ;
66+ test . ok ( bcrypt . compareSync ( "hello world" , hash3 ) ) ;
67+ test . notOk ( bcrypt . compareSync ( "hello world" , hash1 ) ) ;
68+ test . notOk ( bcrypt . compareSync ( "hello world" , hash2 ) ) ;
69+
5770 test . done ( ) ;
5871 } ,
5972
@@ -84,9 +97,7 @@ module.exports = {
8497
8598 "getSalt" : function ( test ) {
8699 var hash1 = bcrypt . hashSync ( "hello" , bcrypt . genSaltSync ( ) ) ;
87- test . log ( "Hash: " + hash1 ) ;
88100 var salt = bcrypt . getSalt ( hash1 ) ;
89- test . log ( "Salt: " + salt ) ;
90101 var hash2 = bcrypt . hashSync ( "hello" , salt ) ;
91102 test . equal ( hash1 , hash2 ) ;
92103 test . done ( ) ;
0 commit comments