feat: enhance password generation method; improve connection pooling logic in DatabasePlugin; update test cases with correct tokens
This commit is contained in:
@ -108,21 +108,24 @@ export class DatabaseManagerService extends DatabaseEncryptionService {
|
||||
const lowerCase = "abcdefghijklmnopqrstuvwxyz";
|
||||
const numbers = "0123456789";
|
||||
const symbols = "!@#$%^&*()_+[]{}|;:,.<>?";
|
||||
|
||||
|
||||
// Ensure at least one character from each required category
|
||||
let password = "";
|
||||
password += upperCase.charAt(Math.floor(Math.random() * upperCase.length));
|
||||
password += numbers.charAt(Math.floor(Math.random() * numbers.length));
|
||||
password += symbols.charAt(Math.floor(Math.random() * symbols.length));
|
||||
|
||||
|
||||
// Fill the rest with random characters from all categories
|
||||
const allChars = upperCase + lowerCase + numbers + symbols;
|
||||
for (let i = 3; i < length; i++) {
|
||||
password += allChars.charAt(Math.floor(Math.random() * allChars.length));
|
||||
}
|
||||
|
||||
|
||||
// Shuffle the password to randomize the position of required characters
|
||||
return password.split('').sort(() => Math.random() - 0.5).join('');
|
||||
return password
|
||||
.split("")
|
||||
.sort(() => Math.random() - 0.5)
|
||||
.join("");
|
||||
}
|
||||
|
||||
async createDatabase(projectId: string): Promise<Database> {
|
||||
@ -141,9 +144,7 @@ export class DatabaseManagerService extends DatabaseEncryptionService {
|
||||
const c_username = `c_user_${Math.random().toString(36).substring(2, 8)}`;
|
||||
const q_username = `q_user_${Math.random().toString(36).substring(2, 8)}`;
|
||||
const databaseName = `db_${Math.random().toString(36).substring(2, 8)}`;
|
||||
const password = this.encryptPassword(
|
||||
this.generatePassword()
|
||||
);
|
||||
const password = this.encryptPassword(this.generatePassword());
|
||||
|
||||
await this.databaseNodeService.initDatabase(
|
||||
{
|
||||
|
||||
@ -31,7 +31,12 @@ export class DatabasePlugin extends Plugin {
|
||||
if (DatabasePlugin.connectionPool.has(connectionKey)) {
|
||||
const existingConnection =
|
||||
DatabasePlugin.connectionPool.get(connectionKey);
|
||||
return new DatabasePlugin(name, existingConnection);
|
||||
|
||||
if (!(await existingConnection.ping())) {
|
||||
DatabasePlugin.connectionPool.delete(connectionKey);
|
||||
} else {
|
||||
return new DatabasePlugin(name, existingConnection);
|
||||
}
|
||||
}
|
||||
|
||||
const dbConnection = await mysql.createConnection({
|
||||
@ -40,13 +45,13 @@ export class DatabasePlugin extends Plugin {
|
||||
port: config.port,
|
||||
password: config.password,
|
||||
database: config.database,
|
||||
idleTimeout: config.idleTimeout,
|
||||
connectTimeout: config.connectTimeout,
|
||||
enableKeepAlive: true,
|
||||
idleTimeout: config.idleTimeout,
|
||||
maxIdle: 10,
|
||||
connectionLimit: 15,
|
||||
});
|
||||
|
||||
// await dbConnection.query("SET SESSION MAX_EXECUTION_TIME=2000;");
|
||||
|
||||
DatabasePlugin.connectionPool.set(connectionKey, dbConnection);
|
||||
return new DatabasePlugin(name, dbConnection);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user