39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import bcrypt from "bcryptjs";
|
|
|
|
// Test the actual bcrypt functionality without importing our modules
|
|
describe("Authentication Integration", () => {
|
|
describe("Password Hashing Integration", () => {
|
|
it("should hash and verify passwords using bcrypt", async () => {
|
|
const password = "testpassword123";
|
|
|
|
// Hash the password
|
|
const hashedPassword = await bcrypt.hash(password, 12);
|
|
|
|
expect(hashedPassword).toBeDefined();
|
|
expect(hashedPassword).not.toBe(password);
|
|
expect(hashedPassword.length).toBeGreaterThan(0);
|
|
|
|
// Verify correct password
|
|
const isValidPassword = await bcrypt.compare(password, hashedPassword);
|
|
expect(isValidPassword).toBe(true);
|
|
|
|
// Verify incorrect password
|
|
const isInvalidPassword = await bcrypt.compare("wrongpassword", hashedPassword);
|
|
expect(isInvalidPassword).toBe(false);
|
|
});
|
|
|
|
it("should generate different hashes for the same password", async () => {
|
|
const password = "testpassword123";
|
|
|
|
const hash1 = await bcrypt.hash(password, 12);
|
|
const hash2 = await bcrypt.hash(password, 12);
|
|
|
|
expect(hash1).not.toBe(hash2);
|
|
|
|
// But both should verify correctly
|
|
expect(await bcrypt.compare(password, hash1)).toBe(true);
|
|
expect(await bcrypt.compare(password, hash2)).toBe(true);
|
|
});
|
|
});
|
|
}); |