@centreon/js-config 26.7.9 → 26.7.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,8 +63,14 @@ module.exports = ({
63
63
  }
64
64
 
65
65
  // Save the testRetries object to a file in the e2e/results directory
66
+ const projectRoot = path.resolve(process.cwd());
67
+ const resolvedFolder = path.resolve(mainCypressFolder);
68
+ if (resolvedFolder !== projectRoot && !resolvedFolder.startsWith(projectRoot + path.sep)) {
69
+ throw new Error('mainCypressFolder is outside of the project directory');
70
+ }
71
+
66
72
  const resultFilePath = path.join(
67
- mainCypressFolder,
73
+ resolvedFolder,
68
74
  'results',
69
75
  'retries.json'
70
76
  );
@@ -32,12 +32,11 @@ Cypress.Commands.add(
32
32
  host,
33
33
  isForced = true
34
34
  }: ServiceCheck): Cypress.Chainable => {
35
- let query = `SELECT id FROM resources WHERE name = '${host}' AND type = 1`;
36
-
37
35
  return cy
38
36
  .requestOnDatabase({
39
37
  database: 'centreon_storage',
40
- query
38
+ query: 'SELECT id FROM resources WHERE name = ? AND type = 1',
39
+ params: [host]
41
40
  })
42
41
  .then(([rows]) => {
43
42
  if (rows.length === 0) {
@@ -84,12 +83,11 @@ Cypress.Commands.add(
84
83
  isForced = true,
85
84
  service
86
85
  }: ServiceCheck): Cypress.Chainable => {
87
- let query = `SELECT parent_id, id FROM resources WHERE parent_name = '${host}' AND name = '${service}'`;
88
-
89
86
  return cy
90
87
  .requestOnDatabase({
91
88
  database: 'centreon_storage',
92
- query
89
+ query: 'SELECT parent_id, id FROM resources WHERE parent_name = ? AND name = ?',
90
+ params: [host, service]
93
91
  })
94
92
  .then(([rows]) => {
95
93
  if (rows.length === 0) {
@@ -181,22 +179,23 @@ Cypress.Commands.add(
181
179
  cy.log('Checking hosts in database');
182
180
 
183
181
  let query = `SELECT COUNT(d.downtime_id) AS count_downtimes FROM downtimes as d
184
- INNER JOIN hosts as h ON h.host_id = d.host_id AND h.name = '${downtime.host}'`;
182
+ INNER JOIN hosts as h ON h.host_id = d.host_id AND h.name = ?`;
183
+ const params: Array<string> = [downtime.host];
185
184
  if (downtime.service) {
186
- query += ` INNER JOIN services as s ON s.service_id = d.service_id AND s.description = '${downtime.service}'`;
185
+ query += ` INNER JOIN services as s ON s.service_id = d.service_id AND s.description = ?`;
186
+ params.push(downtime.service);
187
187
  }
188
188
  query += ` WHERE d.started=1`;
189
189
  if (!downtime.service) {
190
190
  query += ` AND d.service_id = 0`;
191
191
  }
192
192
 
193
- cy.log(query);
194
-
195
193
  cy.waitUntil(() => {
196
194
  return cy
197
195
  .requestOnDatabase({
198
196
  database: 'centreon_storage',
199
- query
197
+ query,
198
+ params
200
199
  })
201
200
  .then(([rows]) => {
202
201
  const foundDowntimesCount = rows.length ? rows[0].count_downtimes : 0;
@@ -459,13 +459,14 @@ Output:\n${displayedOutput}`);
459
459
 
460
460
  interface RequestOnDatabaseProps {
461
461
  database: string;
462
+ params?: Array<string | number>;
462
463
  query: string;
463
464
  }
464
465
 
465
466
  Cypress.Commands.add(
466
467
  'requestOnDatabase',
467
- ({ database, query }: RequestOnDatabaseProps): Cypress.Chainable => {
468
- return cy.task('requestOnDatabase', { database, query });
468
+ ({ database, query, params }: RequestOnDatabaseProps): Cypress.Chainable => {
469
+ return cy.task('requestOnDatabase', { database, query, params });
469
470
  }
470
471
  );
471
472
 
@@ -1046,7 +1047,8 @@ declare global {
1046
1047
  }: NavigateToProps) => Cypress.Chainable;
1047
1048
  requestOnDatabase: ({
1048
1049
  database,
1049
- query
1050
+ query,
1051
+ params
1050
1052
  }: RequestOnDatabaseProps) => Cypress.Chainable;
1051
1053
  setUserTokenApiV1: ({
1052
1054
  login,
@@ -155,7 +155,7 @@ export default (on: Cypress.PluginEvents): void => {
155
155
 
156
156
  return container.getMappedPort(containerPort);
157
157
  },
158
- requestOnDatabase: async ({ database, query }) => {
158
+ requestOnDatabase: async ({ database, query, params }) => {
159
159
  let container: StartedTestContainer | null = null;
160
160
 
161
161
  if (dockerEnvironment !== null) {
@@ -172,11 +172,15 @@ export default (on: Cypress.PluginEvents): void => {
172
172
  user: "centreon",
173
173
  });
174
174
 
175
- const [rows, fields] = await client.query(query);
176
-
177
- await client.end();
175
+ try {
176
+ const [rows, fields] = params
177
+ ? await client.execute(query, params)
178
+ : await client.query(query);
178
179
 
179
- return [rows, fields];
180
+ return [rows, fields];
181
+ } finally {
182
+ await client.end();
183
+ }
180
184
  },
181
185
  startContainer: async ({
182
186
  command,
@@ -308,21 +312,36 @@ export default (on: Cypress.PluginEvents): void => {
308
312
  return path.join(downloadsFolder, files[0].name);
309
313
  },
310
314
  readCsvFile({ filePath }: { filePath: string }): Promise<string> {
315
+ const projectRoot = path.resolve(process.cwd());
316
+ const resolvedPath = path.resolve(filePath);
317
+ if (resolvedPath !== projectRoot && !resolvedPath.startsWith(projectRoot + path.sep)) {
318
+ return Promise.reject(new Error("Path is outside of the project directory"));
319
+ }
320
+
311
321
  return new Promise((resolve, reject) => {
312
- fs.readFile(filePath, "utf8", (err, data) => {
322
+ fs.readFile(resolvedPath, "utf8", (err, data) => {
313
323
  if (err) return reject(err);
314
324
  resolve(data);
315
325
  });
316
326
  });
317
327
  },
318
328
  clearDownloadsFolder({ downloadsFolder }: { downloadsFolder: string }): null {
319
- if (!fs.existsSync(downloadsFolder)) {
329
+ const projectRoot = path.resolve(process.cwd());
330
+ const resolvedFolder = path.resolve(downloadsFolder);
331
+ if (resolvedFolder !== projectRoot && !resolvedFolder.startsWith(projectRoot + path.sep)) {
332
+ throw new Error("Path is outside of the project directory");
333
+ }
334
+
335
+ if (!fs.existsSync(resolvedFolder)) {
320
336
  return null;
321
337
  }
322
338
 
323
- const files = fs.readdirSync(downloadsFolder);
339
+ const files = fs.readdirSync(resolvedFolder);
324
340
  for (const file of files) {
325
- const filePath = path.join(downloadsFolder, file);
341
+ const filePath = path.join(resolvedFolder, file);
342
+ if (!filePath.startsWith(resolvedFolder + path.sep)) {
343
+ continue;
344
+ }
326
345
  fs.unlinkSync(filePath);
327
346
  }
328
347
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@centreon/js-config",
3
3
  "description": "Centreon Frontend shared build configuration",
4
- "version": "26.7.9",
4
+ "version": "26.7.10",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/centreon/centreon.git"