fix(security): 清理测试脚本硬编码数据库密码与后台默认演示凭证预填
这个提交包含在:
@@ -1,13 +1,14 @@
|
||||
import 'dotenv/config';
|
||||
import mysql from 'mysql2/promise';
|
||||
|
||||
async function testConnection() {
|
||||
const host = '118.184.172.94';
|
||||
const port = 3306;
|
||||
const user = 'peiwan';
|
||||
const password = 'XxW7Xe5rRSckKmXm';
|
||||
const database = 'peiwan';
|
||||
const host = process.env.MYSQL_HOST || '127.0.0.1';
|
||||
const port = Number(process.env.MYSQL_PORT) || 3306;
|
||||
const user = process.env.MYSQL_USER || 'peiwan';
|
||||
const password = process.env.MYSQL_PASSWORD || '';
|
||||
const database = process.env.MYSQL_DATABASE || 'peiwan';
|
||||
|
||||
console.log(`[Remote Test] 尝试连接远程 MySQL: ${host}:${port}, 用户: ${user}, 库: ${database}`);
|
||||
console.log(`[Remote Test] 尝试连接 MySQL: ${host}:${port}, 用户: ${user}, 库: ${database}`);
|
||||
|
||||
try {
|
||||
const connection = await mysql.createConnection({
|
||||
@@ -19,10 +20,9 @@ async function testConnection() {
|
||||
connectTimeout: 5000,
|
||||
});
|
||||
|
||||
console.log('[Remote Test] 恭喜,成功连接到线上远程数据库!');
|
||||
console.log('[Remote Test] 成功连接数据库');
|
||||
const [rows]: any = await connection.query('SHOW TABLES;');
|
||||
console.log('[Remote Test] 线上已存在的表数量:', rows.length);
|
||||
console.log('[Remote Test] 表列表:', rows.map((r: any) => Object.values(r)[0]).join(', '));
|
||||
console.log('[Remote Test] 表数量:', rows.length);
|
||||
await connection.end();
|
||||
return true;
|
||||
} catch (err: any) {
|
||||
@@ -31,4 +31,6 @@ async function testConnection() {
|
||||
}
|
||||
}
|
||||
|
||||
testConnection();
|
||||
if (process.env.RUN_DB_TEST === 'true') {
|
||||
void testConnection();
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户