@centreon/js-config 25.10.16 → 25.10.17
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
|
-
|
|
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 =
|
|
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 =
|
|
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;
|
package/cypress/e2e/commands.ts
CHANGED
|
@@ -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
|
|
|
@@ -958,7 +959,8 @@ declare global {
|
|
|
958
959
|
}: NavigateToProps) => Cypress.Chainable;
|
|
959
960
|
requestOnDatabase: ({
|
|
960
961
|
database,
|
|
961
|
-
query
|
|
962
|
+
query,
|
|
963
|
+
params
|
|
962
964
|
}: RequestOnDatabaseProps) => Cypress.Chainable;
|
|
963
965
|
setUserTokenApiV1: ({
|
|
964
966
|
login,
|
package/cypress/e2e/tasks.ts
CHANGED
|
@@ -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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
try {
|
|
194
|
+
const [rows, fields] = params
|
|
195
|
+
? await client.execute(query, params)
|
|
196
|
+
: await client.query(query);
|
|
196
197
|
|
|
197
|
-
|
|
198
|
+
return [rows, fields];
|
|
199
|
+
} finally {
|
|
200
|
+
await client.end();
|
|
201
|
+
}
|
|
198
202
|
},
|
|
199
203
|
startContainer: async ({
|
|
200
204
|
command,
|
|
@@ -328,21 +332,36 @@ export default (on: Cypress.PluginEvents): void => {
|
|
|
328
332
|
return path.join(downloadsFolder, files[0].name);
|
|
329
333
|
},
|
|
330
334
|
readCsvFile({ filePath }: { filePath: string }): Promise<string> {
|
|
335
|
+
const projectRoot = path.resolve(process.cwd());
|
|
336
|
+
const resolvedPath = path.resolve(filePath);
|
|
337
|
+
if (resolvedPath !== projectRoot && !resolvedPath.startsWith(projectRoot + path.sep)) {
|
|
338
|
+
return Promise.reject(new Error("Path is outside of the project directory"));
|
|
339
|
+
}
|
|
340
|
+
|
|
331
341
|
return new Promise((resolve, reject) => {
|
|
332
|
-
fs.readFile(
|
|
342
|
+
fs.readFile(resolvedPath, "utf8", (err, data) => {
|
|
333
343
|
if (err) return reject(err);
|
|
334
344
|
resolve(data);
|
|
335
345
|
});
|
|
336
346
|
});
|
|
337
347
|
},
|
|
338
348
|
clearDownloadsFolder({ downloadsFolder }: { downloadsFolder: string }): null {
|
|
339
|
-
|
|
349
|
+
const projectRoot = path.resolve(process.cwd());
|
|
350
|
+
const resolvedFolder = path.resolve(downloadsFolder);
|
|
351
|
+
if (resolvedFolder !== projectRoot && !resolvedFolder.startsWith(projectRoot + path.sep)) {
|
|
352
|
+
throw new Error("Path is outside of the project directory");
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (!fs.existsSync(resolvedFolder)) {
|
|
340
356
|
return null;
|
|
341
357
|
}
|
|
342
358
|
|
|
343
|
-
const files = fs.readdirSync(
|
|
359
|
+
const files = fs.readdirSync(resolvedFolder);
|
|
344
360
|
for (const file of files) {
|
|
345
|
-
const filePath = path.join(
|
|
361
|
+
const filePath = path.join(resolvedFolder, file);
|
|
362
|
+
if (!filePath.startsWith(resolvedFolder + path.sep)) {
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
346
365
|
fs.unlinkSync(filePath);
|
|
347
366
|
}
|
|
348
367
|
|
package/package.json
CHANGED