@centreon/js-config 25.10.16 → 25.10.18

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.
@@ -59,8 +59,14 @@ module.exports = ({
59
59
  }
60
60
 
61
61
  // Save the testRetries object to a file in the e2e/results directory
62
+ const projectRoot = path.resolve(process.cwd());
63
+ const resolvedFolder = path.resolve(mainCypressFolder);
64
+ if (resolvedFolder !== projectRoot && !resolvedFolder.startsWith(projectRoot + path.sep)) {
65
+ throw new Error('mainCypressFolder is outside of the project directory');
66
+ }
67
+
62
68
  const resultFilePath = path.join(
63
- mainCypressFolder,
69
+ resolvedFolder,
64
70
  'results',
65
71
  'retries.json'
66
72
  );
@@ -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;
@@ -378,13 +378,14 @@ Output:\n${displayedOutput}`);
378
378
 
379
379
  interface RequestOnDatabaseProps {
380
380
  database: string;
381
+ params?: Array<string | number>;
381
382
  query: string;
382
383
  }
383
384
 
384
385
  Cypress.Commands.add(
385
386
  'requestOnDatabase',
386
- ({ database, query }: RequestOnDatabaseProps): Cypress.Chainable => {
387
- return cy.task('requestOnDatabase', { database, query });
387
+ ({ database, query, params }: RequestOnDatabaseProps): Cypress.Chainable => {
388
+ return cy.task('requestOnDatabase', { database, query, params });
388
389
  }
389
390
  );
390
391
 
@@ -450,6 +451,8 @@ Cypress.Commands.add(
450
451
  interface StartContainersProps {
451
452
  composeFile?: string;
452
453
  databaseImage?: string;
454
+ dbConfiguration?: string;
455
+ dbStorage?: string;
453
456
  moduleName?: string;
454
457
  openidImage?: string;
455
458
  profiles?: Array<string>;
@@ -464,6 +467,8 @@ Cypress.Commands.add(
464
467
  ({
465
468
  composeFile,
466
469
  databaseImage = Cypress.env('DATABASE_IMAGE'),
470
+ dbConfiguration = Cypress.env('MYSQL_DB_CONFIGURATION'),
471
+ dbStorage = Cypress.env('MYSQL_DB_STORAGE'),
467
472
  moduleName = 'centreon-web',
468
473
  openidImage = `ghcr.io/centreon/centreon/keycloak:${Cypress.env(
469
474
  'OPENID_IMAGE_VERSION'
@@ -494,6 +499,8 @@ Cypress.Commands.add(
494
499
  {
495
500
  composeFile: composeFilePath,
496
501
  databaseImage,
502
+ dbConfiguration,
503
+ dbStorage,
497
504
  openidImage,
498
505
  profiles,
499
506
  samlImage,
@@ -958,7 +965,8 @@ declare global {
958
965
  }: NavigateToProps) => Cypress.Chainable;
959
966
  requestOnDatabase: ({
960
967
  database,
961
- query
968
+ query,
969
+ params
962
970
  }: RequestOnDatabaseProps) => Cypress.Chainable;
963
971
  setUserTokenApiV1: ({
964
972
  login,
@@ -173,7 +173,7 @@ export default (on: Cypress.PluginEvents): void => {
173
173
 
174
174
  return container.getMappedPort(containerPort);
175
175
  },
176
- requestOnDatabase: async ({ database, query }) => {
176
+ requestOnDatabase: async ({ database, query, params }) => {
177
177
  let container: StartedTestContainer | null = null;
178
178
 
179
179
  if (dockerEnvironment !== null) {
@@ -190,11 +190,15 @@ export default (on: Cypress.PluginEvents): void => {
190
190
  user: "centreon",
191
191
  });
192
192
 
193
- const [rows, fields] = await client.query(query);
194
-
195
- await client.end();
193
+ try {
194
+ const [rows, fields] = params
195
+ ? await client.execute(query, params)
196
+ : await client.query(query);
196
197
 
197
- return [rows, fields];
198
+ return [rows, fields];
199
+ } finally {
200
+ await client.end();
201
+ }
198
202
  },
199
203
  startContainer: async ({
200
204
  command,
@@ -224,6 +228,8 @@ export default (on: Cypress.PluginEvents): void => {
224
228
  startContainers: async ({
225
229
  composeFile,
226
230
  databaseImage,
231
+ dbConfiguration,
232
+ dbStorage,
227
233
  openidImage,
228
234
  profiles,
229
235
  samlImage,
@@ -233,16 +239,24 @@ export default (on: Cypress.PluginEvents): void => {
233
239
  const composeFileDir = path.dirname(composeFile);
234
240
  const composeFileName = path.basename(composeFile);
235
241
 
242
+ const environment: Record<string, string> = {
243
+ MYSQL_IMAGE: databaseImage,
244
+ OPENID_IMAGE: openidImage,
245
+ SAML_IMAGE: samlImage,
246
+ WEB_IMAGE: webImage,
247
+ };
248
+ if (dbConfiguration) {
249
+ environment.MYSQL_DB_CONFIGURATION = dbConfiguration;
250
+ }
251
+ if (dbStorage) {
252
+ environment.MYSQL_DB_STORAGE = dbStorage;
253
+ }
254
+
236
255
  dockerEnvironment = await new DockerComposeEnvironment(
237
256
  composeFileDir,
238
257
  composeFileName,
239
258
  )
240
- .withEnvironment({
241
- MYSQL_IMAGE: databaseImage,
242
- OPENID_IMAGE: openidImage,
243
- SAML_IMAGE: samlImage,
244
- WEB_IMAGE: webImage,
245
- })
259
+ .withEnvironment(environment)
246
260
  .withProfiles(...profiles)
247
261
  .withStartupTimeout(120000)
248
262
  .withWaitStrategy(
@@ -328,21 +342,36 @@ export default (on: Cypress.PluginEvents): void => {
328
342
  return path.join(downloadsFolder, files[0].name);
329
343
  },
330
344
  readCsvFile({ filePath }: { filePath: string }): Promise<string> {
345
+ const projectRoot = path.resolve(process.cwd());
346
+ const resolvedPath = path.resolve(filePath);
347
+ if (resolvedPath !== projectRoot && !resolvedPath.startsWith(projectRoot + path.sep)) {
348
+ return Promise.reject(new Error("Path is outside of the project directory"));
349
+ }
350
+
331
351
  return new Promise((resolve, reject) => {
332
- fs.readFile(filePath, "utf8", (err, data) => {
352
+ fs.readFile(resolvedPath, "utf8", (err, data) => {
333
353
  if (err) return reject(err);
334
354
  resolve(data);
335
355
  });
336
356
  });
337
357
  },
338
358
  clearDownloadsFolder({ downloadsFolder }: { downloadsFolder: string }): null {
339
- if (!fs.existsSync(downloadsFolder)) {
359
+ const projectRoot = path.resolve(process.cwd());
360
+ const resolvedFolder = path.resolve(downloadsFolder);
361
+ if (resolvedFolder !== projectRoot && !resolvedFolder.startsWith(projectRoot + path.sep)) {
362
+ throw new Error("Path is outside of the project directory");
363
+ }
364
+
365
+ if (!fs.existsSync(resolvedFolder)) {
340
366
  return null;
341
367
  }
342
368
 
343
- const files = fs.readdirSync(downloadsFolder);
369
+ const files = fs.readdirSync(resolvedFolder);
344
370
  for (const file of files) {
345
- const filePath = path.join(downloadsFolder, file);
371
+ const filePath = path.join(resolvedFolder, file);
372
+ if (!filePath.startsWith(resolvedFolder + path.sep)) {
373
+ continue;
374
+ }
346
375
  fs.unlinkSync(filePath);
347
376
  }
348
377
 
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": "25.10.16",
4
+ "version": "25.10.18",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/centreon/centreon.git"