feat: enhance password generation method; improve connection pooling logic in DatabasePlugin; update test cases with correct tokens
This commit is contained in:
@ -122,7 +122,10 @@ export class DatabaseManagerService extends DatabaseEncryptionService {
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@ -36,13 +36,13 @@ import runQuery from "../functions/runQuery";
|
||||
|
||||
// const payloadPath = path.join(__dirname, "case1-payload.js");
|
||||
// const query = await createQuery(
|
||||
// { token: "c69c2c75-9b30-4aa5-9641-0a931f5aad40" },
|
||||
// { token: "04c38f93-f2fb-4d2c-a8e2-791effa35239" },
|
||||
// fs.readFileSync(payloadPath, { encoding: "utf-8" })
|
||||
// );
|
||||
|
||||
// console.log(query);
|
||||
|
||||
const result = await runQuery("66e651f0-261b-4ebd-9749-077abffaddc2", {
|
||||
const result = await runQuery("9468cf88-24f6-436a-bf42-27827329111e", {
|
||||
id: 1,
|
||||
});
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ export default async (project: { token: string }, source: string) => {
|
||||
source,
|
||||
projectToken: project.token,
|
||||
},
|
||||
{ headers: { "x-api-token": "43c2e96e-af25-4467-9103-1479daa6288d" } }
|
||||
{ headers: { "x-api-token": "efbeccd6-dde1-47dc-b3aa-4fbd773d5429" } }
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
|
||||
@ -8,7 +8,7 @@ export default async (token: string, queryData: Record<string, any>) => {
|
||||
queryData,
|
||||
{
|
||||
headers: {
|
||||
"x-api-token": "43c2e96e-af25-4467-9103-1479daa6288d",
|
||||
"x-api-token": "efbeccd6-dde1-47dc-b3aa-4fbd773d5429",
|
||||
Cookie: `x-session-id=gTEd90aRJFmLzJKu_1760193754588`,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user