@centreon/e2e-config 0.0.0-stage → 1.0.0-MON-212077-web-e2e-config-package.0

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.
@@ -0,0 +1,693 @@
1
+ /* eslint-disable @typescript-eslint/no-namespace */
2
+
3
+ import { Action } from 'e2e/features/ACLs/commands';
4
+
5
+ const apiBase = '/centreon/api';
6
+ const apiActionV1 = `${apiBase}/index.php`;
7
+
8
+ interface ActionClapi {
9
+ action: string;
10
+ object?: string;
11
+ values: string;
12
+ }
13
+
14
+ interface ExecuteActionViaClapiProps {
15
+ bodyContent: ActionClapi;
16
+ method?: string;
17
+ failOnError?: boolean;
18
+ }
19
+
20
+ Cypress.Commands.add(
21
+ 'executeActionViaClapi',
22
+ ({
23
+ bodyContent,
24
+ method = 'POST',
25
+ failOnError = true
26
+ }: ExecuteActionViaClapiProps): Cypress.Chainable => {
27
+ return cy.ensureUserTokenApiV1().then(() =>
28
+ cy.request({
29
+ body: bodyContent,
30
+ failOnStatusCode: failOnError,
31
+ headers: {
32
+ 'Content-Type': 'application/json',
33
+ 'centreon-auth-token': window.localStorage.getItem('userTokenApiV1')
34
+ },
35
+ method,
36
+ url: `${apiActionV1}?action=action&object=centreon_clapi`
37
+ })
38
+ );
39
+ }
40
+ );
41
+
42
+ Cypress.Commands.add(
43
+ 'executeCommandsViaClapi',
44
+ (fixtureFile: string): Cypress.Chainable => {
45
+ return cy.fixture(fixtureFile).then((listRequestConfig) => {
46
+ cy.wrap(
47
+ Promise.all(
48
+ listRequestConfig.map((request: ActionClapi) =>
49
+ cy.executeActionViaClapi({ bodyContent: request })
50
+ )
51
+ )
52
+ );
53
+ });
54
+ }
55
+ );
56
+
57
+ interface TimePeriod {
58
+ alias?: string | null;
59
+ friday?: string;
60
+ monday?: string;
61
+ name: string;
62
+ saturday?: string;
63
+ sunday?: string;
64
+ thursday?: string;
65
+ tuesday?: string;
66
+ wednesday?: string;
67
+ }
68
+
69
+ const defaultDayPeriod = '00:00-24:00';
70
+
71
+ Cypress.Commands.add(
72
+ 'addTimePeriod',
73
+ ({
74
+ alias = null,
75
+ friday = defaultDayPeriod,
76
+ monday = defaultDayPeriod,
77
+ name,
78
+ saturday = defaultDayPeriod,
79
+ sunday = defaultDayPeriod,
80
+ thursday = defaultDayPeriod,
81
+ tuesday = defaultDayPeriod,
82
+ wednesday = defaultDayPeriod
83
+ }: TimePeriod): Cypress.Chainable => {
84
+ const timePeriodAlias = alias === null ? name : alias;
85
+
86
+ return cy
87
+ .executeActionViaClapi({
88
+ bodyContent: {
89
+ action: 'ADD',
90
+ object: 'TP',
91
+ values: `${name};${timePeriodAlias}`
92
+ }
93
+ })
94
+ .then(() => {
95
+ const weekDays = {
96
+ friday,
97
+ monday,
98
+ saturday,
99
+ sunday,
100
+ thursday,
101
+ tuesday,
102
+ wednesday
103
+ };
104
+ Object.entries(weekDays).map(([dayName, dayValue]) => {
105
+ return cy.executeActionViaClapi({
106
+ bodyContent: {
107
+ action: 'SETPARAM',
108
+ object: 'TP',
109
+ values: `${name};${dayName};${dayValue}`
110
+ }
111
+ });
112
+ });
113
+
114
+ return cy.wrap(null);
115
+ });
116
+ }
117
+ );
118
+
119
+ interface CheckCommand {
120
+ command: string;
121
+ enableShell?: boolean;
122
+ name: string;
123
+ }
124
+
125
+ Cypress.Commands.add(
126
+ 'addCheckCommand',
127
+ ({ name, enableShell = true, command }: CheckCommand): Cypress.Chainable => {
128
+ const commandEnableShell = enableShell ? 1 : 0;
129
+
130
+ return cy
131
+ .executeActionViaClapi({
132
+ bodyContent: {
133
+ action: 'ADD',
134
+ object: 'CMD',
135
+ values: `${name};check;${command}`
136
+ }
137
+ })
138
+ .executeActionViaClapi({
139
+ bodyContent: {
140
+ action: 'SETPARAM',
141
+ object: 'CMD',
142
+ values: `${name};enable_shell;${commandEnableShell}`
143
+ }
144
+ });
145
+ }
146
+ );
147
+
148
+ interface Contact {
149
+ GUIAccess?: boolean;
150
+ admin?: boolean;
151
+ alias?: string | null;
152
+ authenticationType?: 'local' | 'ldap';
153
+ email: string;
154
+ enableNotifications?: boolean;
155
+ language?: string;
156
+ name: string;
157
+ password: string;
158
+ }
159
+
160
+ Cypress.Commands.add(
161
+ 'addContact',
162
+ ({
163
+ admin = true,
164
+ alias = null,
165
+ authenticationType = 'local',
166
+ email,
167
+ enableNotifications = true,
168
+ GUIAccess = true,
169
+ language = 'en_US',
170
+ name,
171
+ password
172
+ }: Contact): Cypress.Chainable => {
173
+ const contactAdmin = admin ? 1 : 0;
174
+ const contactAlias = alias === null ? name : alias;
175
+ const contactEnableNotifications = enableNotifications ? 1 : 0;
176
+ const contactGUIAccess = GUIAccess ? 1 : 0;
177
+
178
+ return cy
179
+ .executeActionViaClapi({
180
+ bodyContent: {
181
+ action: 'ADD',
182
+ object: 'CONTACT',
183
+ values: `${name};${contactAlias};${email};${password};${contactAdmin};${contactGUIAccess};${language};${authenticationType}`
184
+ }
185
+ })
186
+ .then(() => {
187
+ const contactParams = {
188
+ enable_notifications: contactEnableNotifications
189
+ };
190
+ Object.entries(contactParams).map(([paramName, paramValue]) => {
191
+ if (paramValue === null) {
192
+ return null;
193
+ }
194
+
195
+ return cy.executeActionViaClapi({
196
+ bodyContent: {
197
+ action: 'SETPARAM',
198
+ object: 'CONTACT',
199
+ values: `${name};${paramName};${paramValue}`
200
+ }
201
+ });
202
+ });
203
+
204
+ return cy.wrap(null);
205
+ });
206
+ }
207
+ );
208
+
209
+ interface ContactGroup {
210
+ alias?: string | null;
211
+ contacts: Array<string>;
212
+ name: string;
213
+ }
214
+
215
+ Cypress.Commands.add(
216
+ 'addContactGroup',
217
+ ({ alias = null, contacts, name }: ContactGroup): Cypress.Chainable => {
218
+ const contactGroupAlias = alias === null ? name : alias;
219
+
220
+ return cy
221
+ .executeActionViaClapi({
222
+ bodyContent: {
223
+ action: 'ADD',
224
+ object: 'CG',
225
+ values: `${name};${contactGroupAlias}`
226
+ }
227
+ })
228
+ .then(() => {
229
+ contacts.map((contact) => {
230
+ return cy.executeActionViaClapi({
231
+ bodyContent: {
232
+ action: 'ADDCONTACT',
233
+ object: 'CG',
234
+ values: `${name};${contact}`
235
+ }
236
+ });
237
+ });
238
+
239
+ return cy.wrap(null);
240
+ });
241
+ }
242
+ );
243
+
244
+ interface Host {
245
+ activeCheckEnabled?: boolean;
246
+ address?: string;
247
+ alias?: string | null;
248
+ checkCommand?: string | null;
249
+ checkPeriod?: string | null;
250
+ hostGroup?: string;
251
+ maxCheckAttempts?: number | null;
252
+ name: string;
253
+ passiveCheckEnabled?: boolean;
254
+ poller?: string;
255
+ template?: string;
256
+ }
257
+
258
+ Cypress.Commands.add(
259
+ 'addHost',
260
+ ({
261
+ activeCheckEnabled = true,
262
+ address = '127.0.0.1',
263
+ alias = null,
264
+ checkCommand = null,
265
+ checkPeriod = null,
266
+ hostGroup = '',
267
+ maxCheckAttempts = 1,
268
+ name,
269
+ passiveCheckEnabled = true,
270
+ poller = 'Central',
271
+ template = ''
272
+ }: Host): Cypress.Chainable => {
273
+ const hostAlias = alias === null ? name : alias;
274
+ const hostMaxCheckAttempts =
275
+ maxCheckAttempts === null ? '' : maxCheckAttempts;
276
+ const hostActiveCheckEnabled = activeCheckEnabled ? 1 : 0;
277
+ const hostPassiveCheckEnabled = passiveCheckEnabled ? 1 : 0;
278
+
279
+ return cy
280
+ .executeActionViaClapi({
281
+ bodyContent: {
282
+ action: 'ADD',
283
+ object: 'HOST',
284
+ values: `${name};${hostAlias};${address};${template};${poller};${hostGroup}`
285
+ }
286
+ })
287
+ .then(() => {
288
+ const hostParams = {
289
+ active_checks_enabled: hostActiveCheckEnabled,
290
+ check_command: checkCommand,
291
+ check_period: checkPeriod,
292
+ max_check_attempts: hostMaxCheckAttempts,
293
+ passive_checks_enabled: hostPassiveCheckEnabled
294
+ };
295
+ Object.entries(hostParams).map(([paramName, paramValue]) => {
296
+ if (paramValue === null) {
297
+ return null;
298
+ }
299
+
300
+ return cy.executeActionViaClapi({
301
+ bodyContent: {
302
+ action: 'SETPARAM',
303
+ object: 'HOST',
304
+ values: `${name};${paramName};${paramValue}`
305
+ }
306
+ });
307
+ });
308
+
309
+ return cy.wrap(null);
310
+ });
311
+ }
312
+ );
313
+
314
+ interface HostGroup {
315
+ alias?: string | null;
316
+ name: string;
317
+ }
318
+
319
+ Cypress.Commands.add(
320
+ 'addHostGroup',
321
+ ({ alias = null, name }: HostGroup): Cypress.Chainable => {
322
+ const hostGroupAlias = alias === null ? name : alias;
323
+
324
+ return cy.executeActionViaClapi({
325
+ bodyContent: {
326
+ action: 'ADD',
327
+ object: 'HG',
328
+ values: `${name};${hostGroupAlias}`
329
+ }
330
+ });
331
+ }
332
+ );
333
+
334
+ interface ServiceTemplate {
335
+ activeCheckEnabled?: boolean;
336
+ checkCommand?: string | null;
337
+ checkPeriod?: string | null;
338
+ description?: string | null;
339
+ maxCheckAttempts?: number | null;
340
+ name: string;
341
+ passiveCheckEnabled?: boolean;
342
+ template?: string;
343
+ }
344
+
345
+ Cypress.Commands.add(
346
+ 'addServiceTemplate',
347
+ ({
348
+ activeCheckEnabled = true,
349
+ checkCommand = null,
350
+ checkPeriod = null,
351
+ description = null,
352
+ maxCheckAttempts = 1,
353
+ name,
354
+ passiveCheckEnabled = true,
355
+ template = ''
356
+ }: ServiceTemplate): Cypress.Chainable => {
357
+ const serviceDescription = description === null ? name : description;
358
+ const serviceMaxCheckAttempts =
359
+ maxCheckAttempts === null ? '' : maxCheckAttempts;
360
+ const serviceActiveCheckEnabled = activeCheckEnabled ? 1 : 0;
361
+ const servicePassiveCheckEnabled = passiveCheckEnabled ? 1 : 0;
362
+
363
+ return cy
364
+ .executeActionViaClapi({
365
+ bodyContent: {
366
+ action: 'ADD',
367
+ object: 'STPL',
368
+ values: `${name};${description};${template}`
369
+ }
370
+ })
371
+ .then(() => {
372
+ const serviceParams = {
373
+ active_checks_enabled: serviceActiveCheckEnabled,
374
+ check_command: checkCommand,
375
+ check_period: checkPeriod,
376
+ description: serviceDescription,
377
+ max_check_attempts: serviceMaxCheckAttempts,
378
+ passive_checks_enabled: servicePassiveCheckEnabled
379
+ };
380
+ Object.entries(serviceParams).map(([paramName, paramValue]) => {
381
+ if (paramValue === null) {
382
+ return null;
383
+ }
384
+
385
+ return cy.executeActionViaClapi({
386
+ bodyContent: {
387
+ action: 'SETPARAM',
388
+ object: 'STPL',
389
+ values: `${name};${paramName};${paramValue}`
390
+ }
391
+ });
392
+ });
393
+
394
+ return cy.wrap(null);
395
+ });
396
+ }
397
+ );
398
+
399
+ interface Service extends ServiceTemplate {
400
+ host: string;
401
+ }
402
+
403
+ Cypress.Commands.add(
404
+ 'addService',
405
+ ({
406
+ activeCheckEnabled = true,
407
+ checkCommand = null,
408
+ checkPeriod = null,
409
+ host,
410
+ maxCheckAttempts = 1,
411
+ name,
412
+ passiveCheckEnabled = true,
413
+ template = ''
414
+ }: Service): Cypress.Chainable => {
415
+ const serviceMaxCheckAttempts =
416
+ maxCheckAttempts === null ? '' : maxCheckAttempts;
417
+ const serviceActiveCheckEnabled = activeCheckEnabled ? 1 : 0;
418
+ const servicePassiveCheckEnabled = passiveCheckEnabled ? 1 : 0;
419
+
420
+ return cy
421
+ .executeActionViaClapi({
422
+ bodyContent: {
423
+ action: 'ADD',
424
+ object: 'SERVICE',
425
+ values: `${host};${name};${template}`
426
+ }
427
+ })
428
+ .then(() => {
429
+ const serviceParams = {
430
+ active_checks_enabled: serviceActiveCheckEnabled,
431
+ check_command: checkCommand,
432
+ check_period: checkPeriod,
433
+ max_check_attempts: serviceMaxCheckAttempts,
434
+ passive_checks_enabled: servicePassiveCheckEnabled
435
+ };
436
+ Object.entries(serviceParams).map(([paramName, paramValue]) => {
437
+ if (paramValue === null) {
438
+ return null;
439
+ }
440
+
441
+ return cy.executeActionViaClapi({
442
+ bodyContent: {
443
+ action: 'SETPARAM',
444
+ object: 'SERVICE',
445
+ values: `${host};${name};${paramName};${paramValue}`
446
+ }
447
+ });
448
+ });
449
+
450
+ return cy.wrap(null);
451
+ });
452
+ }
453
+ );
454
+
455
+ interface ServiceGroup {
456
+ alias?: string | null;
457
+ hostsAndServices: Array<Array<string>>;
458
+ name: string;
459
+ }
460
+
461
+ Cypress.Commands.add(
462
+ 'addServiceGroup',
463
+ ({
464
+ alias = null,
465
+ hostsAndServices,
466
+ name
467
+ }: ServiceGroup): Cypress.Chainable => {
468
+ const serviceGroupAlias = alias === null ? name : alias;
469
+
470
+ return cy
471
+ .executeActionViaClapi({
472
+ bodyContent: {
473
+ action: 'ADD',
474
+ object: 'SG',
475
+ values: `${name};${serviceGroupAlias}`
476
+ }
477
+ })
478
+ .then(() => {
479
+ hostsAndServices.map((hostAndService) => {
480
+ return cy.executeActionViaClapi({
481
+ bodyContent: {
482
+ action: 'ADDSERVICE',
483
+ object: 'SG',
484
+ values: `${name};${hostAndService[0]},${hostAndService[1]}`
485
+ }
486
+ });
487
+ });
488
+
489
+ return cy.wrap(null);
490
+ });
491
+ }
492
+ );
493
+
494
+ Cypress.Commands.add(
495
+ 'applyPollerConfiguration',
496
+ (pollerName = 'Central'): Cypress.Chainable => {
497
+ return cy.executeActionViaClapi({
498
+ bodyContent: {
499
+ action: 'APPLYCFG',
500
+ values: pollerName
501
+ }
502
+ });
503
+ }
504
+ );
505
+
506
+ interface ACLGroup {
507
+ alias?: string | null;
508
+ contactGroups?: Array<string>;
509
+ contacts?: Array<string>;
510
+ name: string;
511
+ }
512
+
513
+ Cypress.Commands.add(
514
+ 'addACLGroup',
515
+ ({
516
+ alias = null,
517
+ contacts = [],
518
+ contactGroups = [],
519
+ name
520
+ }: ACLGroup): Cypress.Chainable => {
521
+ const ACLGroupALias = alias === null ? name : alias;
522
+
523
+ return cy
524
+ .executeActionViaClapi({
525
+ bodyContent: {
526
+ action: 'ADD',
527
+ object: 'ACLGROUP',
528
+ values: `${name};${ACLGroupALias}`
529
+ }
530
+ })
531
+ .then(() => {
532
+ if (contacts) {
533
+ contacts.forEach((contact) => {
534
+ cy.executeActionViaClapi({
535
+ bodyContent: {
536
+ action: 'ADDCONTACT',
537
+ object: 'ACLGROUP',
538
+ values: `${name};${contact}`
539
+ }
540
+ });
541
+ });
542
+ }
543
+ if (contactGroups) {
544
+ contactGroups.forEach((contactGroup) => {
545
+ cy.executeActionViaClapi({
546
+ bodyContent: {
547
+ action: 'ADDCONTACTGROUP',
548
+ object: 'ACLGROUP',
549
+ values: `${name};${contactGroup}`
550
+ }
551
+ });
552
+ });
553
+ }
554
+ });
555
+ }
556
+ );
557
+
558
+ interface ACLMenu {
559
+ alias?: string | null;
560
+ includeChildren?: boolean;
561
+ name: string;
562
+ readOnly?: boolean;
563
+ rule?: Array<string>;
564
+ }
565
+
566
+ Cypress.Commands.add(
567
+ 'addACLMenu',
568
+ ({
569
+ name,
570
+ rule = [],
571
+ alias = null,
572
+ includeChildren = true,
573
+ readOnly = false
574
+ }: ACLMenu): Cypress.Chainable => {
575
+ const ACLMenuAlias = alias === null ? name : alias;
576
+ const action = readOnly ? 'GRANTRO' : 'GRANTRW';
577
+ const children = includeChildren ? '1' : '0';
578
+
579
+ return cy
580
+ .executeActionViaClapi({
581
+ bodyContent: {
582
+ action: 'ADD',
583
+ object: 'ACLMENU',
584
+ values: `${name};${ACLMenuAlias}`
585
+ }
586
+ })
587
+ .then(() => {
588
+ if (rule.length === 0) {
589
+ return cy.wrap(null);
590
+ }
591
+
592
+ let ruleCommand = '';
593
+ rule.forEach((rulePage, index) => {
594
+ ruleCommand += rulePage + (index == rule.length - 1 ? '' : ';');
595
+ });
596
+ cy.executeActionViaClapi({
597
+ bodyContent: {
598
+ action,
599
+ object: 'ACLMENU',
600
+ values: `${name};${children};${ruleCommand}`
601
+ }
602
+ });
603
+
604
+ return cy.wrap(null);
605
+ });
606
+ }
607
+ );
608
+
609
+ interface ACLAction {
610
+ actions?: Array<Action>;
611
+ description: string;
612
+ name: string;
613
+ }
614
+
615
+ Cypress.Commands.add(
616
+ 'addACLAction',
617
+ ({ name, description, actions = [] }: ACLAction): Cypress.Chainable => {
618
+ return cy
619
+ .executeActionViaClapi({
620
+ bodyContent: {
621
+ action: 'ADD',
622
+ object: 'ACLACTION',
623
+ values: `${name};${description}`
624
+ }
625
+ })
626
+ .then(() => {
627
+ if (actions.length === 0) {
628
+ return cy.wrap(null);
629
+ }
630
+
631
+ let actionCommand = '';
632
+ actions.forEach((action, index) => {
633
+ actionCommand += action + (index == actions.length - 1 ? '' : '|');
634
+ });
635
+ cy.executeActionViaClapi({
636
+ bodyContent: {
637
+ action: 'GRANT',
638
+ object: 'ACLACTION',
639
+ values: `${name};${actionCommand}`
640
+ }
641
+ });
642
+
643
+ return cy.wrap(null);
644
+ });
645
+ }
646
+ );
647
+
648
+ interface ACLResource {
649
+ alias?: string | null;
650
+ name: string;
651
+ }
652
+
653
+ Cypress.Commands.add(
654
+ 'addACLResource',
655
+ ({ name, alias = null }: ACLResource): Cypress.Chainable => {
656
+ const ACLResourcesAlias = alias === null ? name : alias;
657
+
658
+ return cy.executeActionViaClapi({
659
+ bodyContent: {
660
+ action: 'ADD',
661
+ object: 'ACLRESOURCE',
662
+ values: `${name};${ACLResourcesAlias}`
663
+ }
664
+ });
665
+ }
666
+ );
667
+
668
+ declare global {
669
+ namespace Cypress {
670
+ interface Chainable {
671
+ addACLAction: (props: ACLAction) => Cypress.Chainable;
672
+ addACLGroup: (props: ACLGroup) => Cypress.Chainable;
673
+ addACLMenu: (props: ACLMenu) => Cypress.Chainable;
674
+ addACLResource: (props: ACLResource) => Cypress.Chainable;
675
+ addCheckCommand: (props: CheckCommand) => Cypress.Chainable;
676
+ addContact: (props: Contact) => Cypress.Chainable;
677
+ addContactGroup: (props: ContactGroup) => Cypress.Chainable;
678
+ addHost: (props: Host) => Cypress.Chainable;
679
+ addHostGroup: (props: HostGroup) => Cypress.Chainable;
680
+ addService: (props: Service) => Cypress.Chainable;
681
+ addServiceGroup: (props: ServiceGroup) => Cypress.Chainable;
682
+ addServiceTemplate: (props: ServiceTemplate) => Cypress.Chainable;
683
+ addTimePeriod: (props: TimePeriod) => Cypress.Chainable;
684
+ applyPollerConfiguration: (props?: string) => Cypress.Chainable;
685
+ executeActionViaClapi: (
686
+ props: ExecuteActionViaClapiProps
687
+ ) => Cypress.Chainable;
688
+ executeCommandsViaClapi: (fixtureFile: string) => Cypress.Chainable;
689
+ }
690
+ }
691
+ }
692
+
693
+ export {};