feat(auth): change default admin password to admin and default agent password to 123 using TDD

This commit is contained in:
Rafif-Riqullah-Siregar committed 2026-07-02 14:48:14 +07:00
1 parent 14a4b7bce5
commit bb89e6ad2a
4 files changed
+45 -5

No files matched your search

+3 -3
View File
@@ -103,9 +103,9 @@ function initSchema() {
const adminExists = d.prepare("SELECT count(*) as count FROM users WHERE username = 'admin'").get();
if (adminExists.count === 0) {
const hash = bcrypt.hashSync('admin123', 10);
const hash = bcrypt.hashSync('admin', 10);
d.prepare("INSERT INTO users (username, password_hash, role) VALUES (?, ?, ?)").run('admin', hash, 'SUPER_ADMIN');
console.log('[DB] Created default admin user (admin / admin123)');
console.log('[DB] Created default admin user (admin / admin)');
}
d.exec(`CREATE TABLE IF NOT EXISTS tls_versions (
@@ -1972,7 +1972,7 @@ function updateUserProfilePicture(userId, filename) {
function syncAgentUsers(agents) {
const d = getDB();
const bcrypt = require('bcryptjs');
const hash = bcrypt.hashSync('agent123', 10);
const hash = bcrypt.hashSync('123', 10);
const siteUuid = process.env.NETIFY_SITE_UUID || '6681452d_9cae_4ff4_8ae8_0d504774265e';
// Hardcoded labels map for friendly user mapping
Binary file not shown.
@@ -0,0 +1,40 @@
const Database = require('better-sqlite3');
const path = require('path');
const bcrypt = require('bcryptjs');
const dbPath = path.join(__dirname, '../netify_data.db');
const dbModule = require('../database');
console.log("=== RUNNING TDD TEST: DEFAULT PASSWORDS VERIFICATION ===");
// 1. Verify admin password
const adminUser = dbModule.getUserByUsername('admin');
if (!adminUser) {
throw new Error("❌ TEST FAILED: Admin user not found!");
}
const adminPwOk = bcrypt.compareSync('admin', adminUser.password_hash);
if (!adminPwOk) {
throw new Error("❌ TEST FAILED: Admin default password is NOT 'admin'!");
}
console.log("✅ Admin default password is correctly 'admin'.");
// 2. Verify agent default password
const mockAgents = [
{ id: 999999999, uuid: "TDD-TEST-AGENT", label: "TDD-TEST-AGENT" }
];
dbModule.syncAgentUsers(mockAgents);
const agentUser = dbModule.getUserByUsername('tdd-test-agent');
if (!agentUser) {
throw new Error("❌ TEST FAILED: Test agent user not created!");
}
const agentPwOk = bcrypt.compareSync('123', agentUser.password_hash);
if (!agentPwOk) {
throw new Error("❌ TEST FAILED: Agent default password is NOT '123'!");
}
console.log("✅ Agent default password is correctly '123'.");
console.log("=== TDD TEST PASSED SUCCESSFULLY! ===");
process.exit(0);
+2 -2
View File
@@ -37,8 +37,8 @@ for (const u of expectedUsernames) {
}
console.log(`✅ User verified: '${u}' (Role: ${user.role}, Agent UUID: ${user.agent_uuid})`);
// Verify password matches agent123
const pwOk = bcrypt.compareSync('agent123', user.password_hash);
// Verify password matches 123
const pwOk = bcrypt.compareSync('123', user.password_hash);
if (!pwOk) {
throw new Error(`❌ TEST FAILED: Password for user '${u}' is incorrect!`);
}