File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ export type SlipAuthEmailVerificationCode = ReturnType<typeof getEmailVerificati
4949
5050export interface IPasswordHashingMethods {
5151 hash : ( rawPassword : string ) => Promise < string >
52- verify : ( sourceHashedPassword : string , rawPassword : string ) => Promise < string >
52+ verify : ( sourceHashedPassword : string , rawPassword : string ) => Promise < boolean >
5353}
5454
5555export interface ISlipAuthCoreOptions {
Original file line number Diff line number Diff line change @@ -24,13 +24,14 @@ beforeEach(async () => {
2424
2525const defaultInsert = {
2626 email : "email@test.com" ,
27- password : "password " ,
27+ password : "pa$$word " ,
2828} ;
2929
3030const mocks = vi . hoisted ( ( ) => {
3131 return {
3232 userCreatedCount : 0 ,
3333 sessionCreatedCount : 0 ,
34+ passwordCount : 0 ,
3435 } ;
3536} ) ;
3637
@@ -71,6 +72,21 @@ describe("SlipAuthCore", () => {
7172 mocks . sessionCreatedCount ++ ;
7273 return `session-id-${ mocks . sessionCreatedCount } ` ;
7374 } ) ;
75+
76+ function sanitizePassword ( str : string ) {
77+ return str . replaceAll ( "$" , "" ) + "$" ;
78+ }
79+ auth . setPasswordHashingMethods ( ( ) => ( {
80+ hash : async ( password : string ) => sanitizePassword ( password ) + mocks . passwordCount ,
81+ verify : async ( sourceHashedPassword , rawPassword ) => {
82+ const salt = sourceHashedPassword . split ( "$" ) . at ( - 1 ) ;
83+ if ( ! salt ) {
84+ return false ;
85+ }
86+ return sourceHashedPassword === sanitizePassword ( rawPassword ) + salt ;
87+ } ,
88+ } ) ,
89+ ) ;
7490 } ) ;
7591
7692 describe ( "register" , ( ) => {
You can’t perform that action at this time.
0 commit comments