Skip to content

Commit cdacb8e

Browse files
committed
add tests #31
1 parent bd8561a commit cdacb8e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/runtime/core/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export type SlipAuthEmailVerificationCode = ReturnType<typeof getEmailVerificati
4949

5050
export 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

5555
export interface ISlipAuthCoreOptions {

tests/core-email-password.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ beforeEach(async () => {
2424

2525
const defaultInsert = {
2626
email: "email@test.com",
27-
password: "password",
27+
password: "pa$$word",
2828
};
2929

3030
const 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", () => {

0 commit comments

Comments
 (0)