68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import { randomBytes } from "node:crypto";
|
|
import { eq } from "drizzle-orm";
|
|
import { drizzle } from "drizzle-orm/mysql2";
|
|
import { bcrypt, bcryptVerify } from "hash-wasm";
|
|
import mysql from "mysql2/promise";
|
|
import * as schema from "@/db/schema";
|
|
|
|
const url = new URL(
|
|
"mysql://cms:HeelM%3Coeikgsdgsccusygcsugy@localhost:3306/habbo",
|
|
);
|
|
const pool = mysql.createPool({
|
|
host: url.hostname,
|
|
port: Number(url.port) || 3306,
|
|
user: decodeURIComponent(url.username),
|
|
password: decodeURIComponent(url.password),
|
|
database: "habbo",
|
|
charset: "utf8mb4",
|
|
});
|
|
|
|
const db = drizzle(pool, { schema, mode: "default" });
|
|
|
|
async function main() {
|
|
const hash = await bcrypt({
|
|
password: "Test1234",
|
|
salt: randomBytes(16),
|
|
costFactor: 12,
|
|
outputType: "encoded",
|
|
});
|
|
const uname = "__e2e_test_" + Date.now();
|
|
try {
|
|
await db.insert(schema.User).values({
|
|
username: uname,
|
|
password: hash,
|
|
mail: null,
|
|
accountCreated: Math.floor(Date.now() / 1000),
|
|
ipRegister: "127.0.0.1",
|
|
ipCurrent: "127.0.0.1",
|
|
look: "hr-100-.hd-180-1.ch-255-66.lg-280-110.sh-305-62",
|
|
});
|
|
console.log("INSERT OK");
|
|
|
|
// Simuleer login-verificatie
|
|
const [user] = await db
|
|
.select()
|
|
.from(schema.User)
|
|
.where(eq(schema.User.username, uname))
|
|
.limit(1);
|
|
if (!user) throw new Error("User not found after insert");
|
|
const ok = await bcryptVerify({
|
|
password: "Test1234",
|
|
hash: user.password,
|
|
});
|
|
console.log("LOGIN VERIFY:", ok ? "OK" : "FAILED");
|
|
} catch (err) {
|
|
console.error("FAILED:", (err as Error).message);
|
|
if ((err as { cause?: Error }).cause)
|
|
console.error("CAUSE:", (err as { cause?: Error }).cause?.message);
|
|
process.exitCode = 1;
|
|
} finally {
|
|
await pool.execute(
|
|
"DELETE FROM users WHERE username LIKE '\\_\\_e2e\\_test\\_%'",
|
|
);
|
|
await pool.end();
|
|
}
|
|
}
|
|
|
|
main();
|