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 lowerCase = "abcdefghijklmnopqrstuvwxyz";
|
||||||
const numbers = "0123456789";
|
const numbers = "0123456789";
|
||||||
const symbols = "!@#$%^&*()_+[]{}|;:,.<>?";
|
const symbols = "!@#$%^&*()_+[]{}|;:,.<>?";
|
||||||
|
|
||||||
// Ensure at least one character from each required category
|
// Ensure at least one character from each required category
|
||||||
let password = "";
|
let password = "";
|
||||||
password += upperCase.charAt(Math.floor(Math.random() * upperCase.length));
|
password += upperCase.charAt(Math.floor(Math.random() * upperCase.length));
|
||||||
password += numbers.charAt(Math.floor(Math.random() * numbers.length));
|
password += numbers.charAt(Math.floor(Math.random() * numbers.length));
|
||||||
password += symbols.charAt(Math.floor(Math.random() * symbols.length));
|
password += symbols.charAt(Math.floor(Math.random() * symbols.length));
|
||||||
|
|
||||||
// Fill the rest with random characters from all categories
|
// Fill the rest with random characters from all categories
|
||||||
const allChars = upperCase + lowerCase + numbers + symbols;
|
const allChars = upperCase + lowerCase + numbers + symbols;
|
||||||
for (let i = 3; i < length; i++) {
|
for (let i = 3; i < length; i++) {
|
||||||
password += allChars.charAt(Math.floor(Math.random() * allChars.length));
|
password += allChars.charAt(Math.floor(Math.random() * allChars.length));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shuffle the password to randomize the position of required characters
|
// 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> {
|
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 c_username = `c_user_${Math.random().toString(36).substring(2, 8)}`;
|
||||||
const q_username = `q_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 databaseName = `db_${Math.random().toString(36).substring(2, 8)}`;
|
||||||
const password = this.encryptPassword(
|
const password = this.encryptPassword(this.generatePassword());
|
||||||
this.generatePassword()
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.databaseNodeService.initDatabase(
|
await this.databaseNodeService.initDatabase(
|
||||||
{
|
{
|
||||||
|
|||||||
@ -31,7 +31,12 @@ export class DatabasePlugin extends Plugin {
|
|||||||
if (DatabasePlugin.connectionPool.has(connectionKey)) {
|
if (DatabasePlugin.connectionPool.has(connectionKey)) {
|
||||||
const existingConnection =
|
const existingConnection =
|
||||||
DatabasePlugin.connectionPool.get(connectionKey);
|
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({
|
const dbConnection = await mysql.createConnection({
|
||||||
@ -40,13 +45,13 @@ export class DatabasePlugin extends Plugin {
|
|||||||
port: config.port,
|
port: config.port,
|
||||||
password: config.password,
|
password: config.password,
|
||||||
database: config.database,
|
database: config.database,
|
||||||
idleTimeout: config.idleTimeout,
|
|
||||||
connectTimeout: config.connectTimeout,
|
connectTimeout: config.connectTimeout,
|
||||||
enableKeepAlive: true,
|
enableKeepAlive: true,
|
||||||
|
idleTimeout: config.idleTimeout,
|
||||||
|
maxIdle: 10,
|
||||||
|
connectionLimit: 15,
|
||||||
});
|
});
|
||||||
|
|
||||||
// await dbConnection.query("SET SESSION MAX_EXECUTION_TIME=2000;");
|
|
||||||
|
|
||||||
DatabasePlugin.connectionPool.set(connectionKey, dbConnection);
|
DatabasePlugin.connectionPool.set(connectionKey, dbConnection);
|
||||||
return new DatabasePlugin(name, dbConnection);
|
return new DatabasePlugin(name, dbConnection);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,13 +36,13 @@ import runQuery from "../functions/runQuery";
|
|||||||
|
|
||||||
// const payloadPath = path.join(__dirname, "case1-payload.js");
|
// const payloadPath = path.join(__dirname, "case1-payload.js");
|
||||||
// const query = await createQuery(
|
// const query = await createQuery(
|
||||||
// { token: "c69c2c75-9b30-4aa5-9641-0a931f5aad40" },
|
// { token: "04c38f93-f2fb-4d2c-a8e2-791effa35239" },
|
||||||
// fs.readFileSync(payloadPath, { encoding: "utf-8" })
|
// fs.readFileSync(payloadPath, { encoding: "utf-8" })
|
||||||
// );
|
// );
|
||||||
|
|
||||||
// console.log(query);
|
// console.log(query);
|
||||||
|
|
||||||
const result = await runQuery("66e651f0-261b-4ebd-9749-077abffaddc2", {
|
const result = await runQuery("9468cf88-24f6-436a-bf42-27827329111e", {
|
||||||
id: 1,
|
id: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ export default async (project: { token: string }, source: string) => {
|
|||||||
source,
|
source,
|
||||||
projectToken: project.token,
|
projectToken: project.token,
|
||||||
},
|
},
|
||||||
{ headers: { "x-api-token": "43c2e96e-af25-4467-9103-1479daa6288d" } }
|
{ headers: { "x-api-token": "efbeccd6-dde1-47dc-b3aa-4fbd773d5429" } }
|
||||||
);
|
);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -8,7 +8,7 @@ export default async (token: string, queryData: Record<string, any>) => {
|
|||||||
queryData,
|
queryData,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"x-api-token": "43c2e96e-af25-4467-9103-1479daa6288d",
|
"x-api-token": "efbeccd6-dde1-47dc-b3aa-4fbd773d5429",
|
||||||
Cookie: `x-session-id=gTEd90aRJFmLzJKu_1760193754588`,
|
Cookie: `x-session-id=gTEd90aRJFmLzJKu_1760193754588`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user