@@ -11,7 +11,8 @@ import {
11
11
PLATFORM_ORGANIZATION ,
12
12
queryAsAdmin ,
13
13
securityQuery ,
14
- USER_EDITOR ,
14
+ TEST_ORGANIZATION ,
15
+ USER_EDITOR
15
16
} from '../../utils/testQuery' ;
16
17
import { queryAsUserIsExpectedForbidden } from '../../utils/testQueryHelper' ;
17
18
import { executionContext , SYSTEM_USER } from '../../../src/utils/access' ;
@@ -72,7 +73,7 @@ const EDIT_AUTHORIZED_MEMBERS_QUERY = gql`
72
73
}
73
74
` ;
74
75
75
- describe ( 'Case Incident Response standard behavior with authorized_members activation from entity' , ( ) => {
76
+ /* describe('Case Incident Response standard behavior with authorized_members activation from entity', () => {
76
77
let caseIncident: CaseIncident;
77
78
let userEditorId: string;
78
79
// 1. On créé un case incident => on vérifie que l'editor y a accès, que les authorized members sont vide, que le user access right est admin
@@ -93,14 +94,14 @@ describe('Case Incident Response standard behavior with authorized_members activ
93
94
expect(caseIncidentResponseCreateQueryResult?.data?.caseIncidentAdd.currentUserAccessRight).toEqual('admin'); // CurrentUser should be admin if authorized members not activated
94
95
caseIncident = caseIncidentResponseCreateQueryResult?.data?.caseIncidentAdd;
95
96
});
96
- it ( 'should Editor User access Case Incident Response' , async ( ) => {
97
+ it('should Editor user access Case Incident Response', async () => {
97
98
const caseIRQueryResult = await editorQuery({ query: READ_QUERY, variables: { id: caseIncident.id } });
98
99
expect(caseIRQueryResult).not.toBeNull();
99
100
expect(caseIRQueryResult?.data?.caseIncident).not.toBeUndefined();
100
101
expect(caseIRQueryResult?.data?.caseIncident.id).toEqual(caseIncident.id);
101
102
});
102
103
// On essaye de modifier les authorized members avec le user editor => on vérifie qu'il n'a pas les droits et qu'il se prend une erreur forbidden
103
- it ( 'should Editor User not edit authorized members if not in authorized members' , async ( ) => {
104
+ it('should Editor user not edit authorized members if not in authorized members', async () => {
104
105
userEditorId = await getUserIdByEmail(USER_EDITOR.email);
105
106
const authorizedMembers = {
106
107
id: caseIncident.id,
@@ -117,7 +118,7 @@ describe('Case Incident Response standard behavior with authorized_members activ
117
118
});
118
119
});
119
120
// On essaye de modifier les authorized members avec l'admin (seulement admin) => on vérifie que ça a bien fonctionné avec l'admin, et on vérifie que l'editor n'a pas accès au case incident
120
- it ( 'should Admin User edit authorized members' , async ( ) => {
121
+ it('should Admin user edit authorized members', async () => {
121
122
// Activate Authorized members
122
123
await queryAsAdmin({
123
124
query: EDIT_AUTHORIZED_MEMBERS_QUERY,
@@ -145,15 +146,15 @@ describe('Case Incident Response standard behavior with authorized_members activ
145
146
}
146
147
]);
147
148
});
148
- it ( 'should Editor User not access Case Incident Response' , async ( ) => {
149
+ it('should Editor user not access Case Incident Response', async () => {
149
150
const caseIRQueryResult = await editorQuery({ query: READ_QUERY, variables: { id: caseIncident.id } });
150
151
expect(caseIRQueryResult).not.toBeNull();
151
152
expect(caseIRQueryResult?.data?.caseIncident).not.toBeUndefined();
152
153
expect(caseIRQueryResult?.data?.caseIncident).toBeNull();
153
154
});
154
155
// On modifie les authorized members avec l'admin en ajoutant l'editor en view => on vérifie que l'editor a bien accès au case incident
155
- it ( 'should Admin User edit authorized members: Editor has view access right' , async ( ) => {
156
- // Add Editor User in authorized members
156
+ it('should Admin user edit authorized members: Editor has view access right', async () => {
157
+ // Add Editor user in authorized members
157
158
await queryAsAdmin({
158
159
query: EDIT_AUTHORIZED_MEMBERS_QUERY,
159
160
variables: {
@@ -188,14 +189,14 @@ describe('Case Incident Response standard behavior with authorized_members activ
188
189
}
189
190
]);
190
191
});
191
- it ( 'should Editor User access Case Incident Response' , async ( ) => {
192
+ it('should Editor user access Case Incident Response', async () => {
192
193
const caseIRQueryResult = await editorQuery({ query: READ_QUERY, variables: { id: caseIncident.id } });
193
194
expect(caseIRQueryResult).not.toBeNull();
194
195
expect(caseIRQueryResult?.data?.caseIncident).not.toBeUndefined();
195
196
expect(caseIRQueryResult?.data?.caseIncident.id).toEqual(caseIncident.id);
196
197
});
197
198
// On essaye d'editer le case avec l'editor => forbidden parce qu'il a seulement l'accès en view
198
- it ( 'should Editor User not edit case incident with view access right' , async ( ) => {
199
+ it('should Editor user not edit case incident with view access right', async () => {
199
200
const authorizedMembers = {
200
201
id: caseIncident.id,
201
202
input: [
@@ -211,7 +212,7 @@ describe('Case Incident Response standard behavior with authorized_members activ
211
212
});
212
213
});
213
214
// On modifie les authorized members avec l'admin en mettant l'editor en 'edit', et on vérifie qu'il peut bien éditer un case incident (description)
214
- it ( 'should Admin User edit authorized members: Editor has edit access right' , async ( ) => {
215
+ it('should Admin user edit authorized members: Editor has edit access right', async () => {
215
216
await queryAsAdmin({
216
217
query: EDIT_AUTHORIZED_MEMBERS_QUERY,
217
218
variables: {
@@ -246,7 +247,7 @@ describe('Case Incident Response standard behavior with authorized_members activ
246
247
}
247
248
]);
248
249
});
249
- it ( 'should Editor User edit case incident' , async ( ) => {
250
+ it('should Editor user edit case incident', async () => {
250
251
const UPDATE_QUERY = gql`
251
252
mutation CaseIncident($id: ID!, $input: [EditInput]!) {
252
253
stixDomainObjectEdit(id: $id) {
@@ -266,14 +267,14 @@ describe('Case Incident Response standard behavior with authorized_members activ
266
267
expect(queryResult?.data?.stixDomainObjectEdit.fieldPatch.name).toEqual('Case Incident Response - updated');
267
268
});
268
269
// l'editor essaye de delete le case incident => forbidden parce qu'il a seulement l'accès en edit
269
- it ( 'should Editor User not delete case incident with edit access right' , async ( ) => {
270
+ it('should Editor user not delete case incident with edit access right', async () => {
270
271
await queryAsUserIsExpectedForbidden(USER_EDITOR.client, {
271
272
query: DELETE_QUERY,
272
273
variables: { id: caseIncident.id },
273
274
});
274
275
});
275
276
// On modifie les authorized members avec l'admin en mettant l'editor en 'admin', et on delete le case avec l'editor
276
- it ( 'should Admin User edit authorized members: Editor has admin access right' , async ( ) => {
277
+ it('should Admin user edit authorized members: Editor has admin access right', async () => {
277
278
await queryAsAdmin({
278
279
query: EDIT_AUTHORIZED_MEMBERS_QUERY,
279
280
variables: {
@@ -308,7 +309,7 @@ describe('Case Incident Response standard behavior with authorized_members activ
308
309
}
309
310
]);
310
311
});
311
- it ( 'should Editor User Case Incident Response deleted' , async ( ) => {
312
+ it('should Editor user Case Incident Response deleted', async () => {
312
313
// Delete the case
313
314
await editorQuery({
314
315
query: DELETE_QUERY,
@@ -485,9 +486,10 @@ describe('Case Incident Response and organization sharing standard behavior with
485
486
expect(queryResult).not.toBeNull();
486
487
expect(queryResult?.data?.caseIncident).toBeNull();
487
488
});
488
- } ) ;
489
+ }); */
489
490
490
491
describe ( 'Case Incident Response and organization sharing standard behavior with platform organization' , ( ) => {
492
+ let platformOrganizationId : string ;
491
493
let testOrganizationId : string ;
492
494
let caseIrId : string ;
493
495
let userEditorId : string ;
@@ -506,9 +508,10 @@ describe('Case Incident Response and organization sharing standard behavior with
506
508
}
507
509
}
508
510
` ;
511
+ // 1. 'should plateform organization sharing and EE activated' => OK avec PlaformOrganization
509
512
it ( 'should plateform organization sharing and EE activated' , async ( ) => {
510
513
// Get organization id
511
- testOrganizationId = await getOrganizationIdByName ( PLATFORM_ORGANIZATION . name ) ;
514
+ platformOrganizationId = await getOrganizationIdByName ( PLATFORM_ORGANIZATION . name ) ;
512
515
513
516
// Get settings ID
514
517
const SETTINGS_READ_QUERY = gql `
@@ -531,7 +534,7 @@ describe('Case Incident Response and organization sharing standard behavior with
531
534
variables : {
532
535
id : settingsInternalId ,
533
536
input : [
534
- { key : 'platform_organization' , value : testOrganizationId } ,
537
+ { key : 'platform_organization' , value : platformOrganizationId } ,
535
538
{ key : 'enterprise_edition' , value : new Date ( ) . getTime ( ) } ,
536
539
]
537
540
}
@@ -542,6 +545,7 @@ describe('Case Incident Response and organization sharing standard behavior with
542
545
expect ( platformOrganization ?. data ?. settingsEdit . fieldPatch . enterprise_edition ) . not . toBeUndefined ( ) ;
543
546
expect ( platformOrganization ?. data ?. settingsEdit . fieldPatch . platform_organization . name ) . toEqual ( PLATFORM_ORGANIZATION . name ) ;
544
547
} ) ;
548
+ // 2. 'should Case Incident Response created' => OK
545
549
it ( 'should Case Incident Response created' , async ( ) => {
546
550
// Create Case Incident Response
547
551
const caseIRCreateQueryResult = await adminQuery ( {
@@ -554,21 +558,17 @@ describe('Case Incident Response and organization sharing standard behavior with
554
558
} ) ;
555
559
556
560
expect ( caseIRCreateQueryResult ) . not . toBeNull ( ) ;
557
- expect ( caseIRCreateQueryResult ?. data ?. caseIncidentAdd . authorized_members ) . not . toBeUndefined ( ) ;
558
- expect ( caseIRCreateQueryResult ?. data ?. caseIncidentAdd . authorized_members ) . toEqual ( [ ] ) ; // authorized members not activated
561
+ expect ( caseIRCreateQueryResult ?. data ?. caseIncidentAdd ) . not . toBeUndefined ( ) ;
559
562
caseIrId = caseIRCreateQueryResult ?. data ?. caseIncidentAdd . id ;
560
563
} ) ;
561
- it ( 'should not access Case Incident Response if no organization' , async ( ) => {
562
- const caseIRQueryResult = await participantQuery ( { query : READ_QUERY , variables : { id : caseIrId } } ) ;
563
- expect ( caseIRQueryResult ) . not . toBeNull ( ) ;
564
- expect ( caseIRQueryResult . data ?. caseIncident ) . toBeNull ( ) ;
565
- } ) ;
566
- it ( 'should not access Case Incident Response from different organization' , async ( ) => {
564
+ // 3. On vérifie que editor n'a pas accès au case incident parce que editor fait partie de l'orga TestOrganization ('should not access Case Incident Response out of his organization')
565
+ it ( 'should Editor user not access Case Incident Response' , async ( ) => {
567
566
const caseIRQueryResult = await editorQuery ( { query : READ_QUERY , variables : { id : caseIrId } } ) ;
568
567
expect ( caseIRQueryResult ) . not . toBeNull ( ) ;
569
568
expect ( caseIRQueryResult . data ?. caseIncident ) . toBeNull ( ) ;
570
569
} ) ;
571
- it ( 'should Authorized Members activated' , async ( ) => {
570
+ // 4. 'should Authorized Members activated' avec editor en view => OK
571
+ it ( 'should Admin user Authorized Members activated' , async ( ) => {
572
572
userEditorId = await getUserIdByEmail ( USER_EDITOR . email ) ;
573
573
await queryAsAdmin ( {
574
574
query : EDIT_AUTHORIZED_MEMBERS_QUERY ,
@@ -604,12 +604,69 @@ describe('Case Incident Response and organization sharing standard behavior with
604
604
}
605
605
] ) ;
606
606
} ) ;
607
- it ( 'should access Case Incident Response out of her organization if authorized members activated' , async ( ) => {
607
+ // 5. 'should access Case Incident Response out of her organization if authorized members activated' => OK
608
+ it ( 'should Editor user access Case Incident Response out of her organization if authorized members activated' , async ( ) => {
609
+ const caseIRQueryResult = await editorQuery ( { query : READ_QUERY , variables : { id : caseIrId } } ) ;
610
+ expect ( caseIRQueryResult ) . not . toBeNull ( ) ;
611
+ expect ( caseIRQueryResult ?. data ?. caseIncident ) . not . toBeUndefined ( ) ;
612
+ expect ( caseIRQueryResult ?. data ?. caseIncident . id ) . toEqual ( caseIrId ) ;
613
+ } ) ;
614
+ // 6. On enlève les authorized members, et on vérifie que l'editor n'as plus accès au case
615
+ it ( 'should Admin user removes Editor user from authorized members' , async ( ) => {
616
+ await queryAsAdmin ( {
617
+ query : EDIT_AUTHORIZED_MEMBERS_QUERY ,
618
+ variables : {
619
+ id : caseIrId ,
620
+ input : [
621
+ {
622
+ id : ADMIN_USER . id ,
623
+ access_right : 'admin'
624
+ }
625
+ ]
626
+ }
627
+ } ) ;
628
+ // Verify Editor user has no more access to Case incident
629
+ const caseIRQueryResult = await editorQuery ( { query : READ_QUERY , variables : { id : caseIrId } } ) ;
630
+ expect ( caseIRQueryResult ) . not . toBeNull ( ) ;
631
+ expect ( caseIRQueryResult . data ?. caseIncident ) . toBeNull ( ) ;
632
+ } ) ;
633
+ // 7. On share le case à la platform orga "Test" dont fait partie l'editor, et on vérifie que l'editor y a accès maintenant
634
+ it ( 'should share Case Incident Response with Organization' , async ( ) => {
635
+ // Get organization id
636
+ testOrganizationId = await getOrganizationIdByName ( TEST_ORGANIZATION . name ) ;
637
+ const ORGANIZATION_SHARING_QUERY = gql `
638
+ mutation StixCoreObjectSharingGroupAddMutation(
639
+ $id: ID!
640
+ $organizationId: ID!
641
+ ) {
642
+ stixCoreObjectEdit(id: $id) {
643
+ restrictionOrganizationAdd(organizationId: $organizationId) {
644
+ id
645
+ objectOrganization {
646
+ id
647
+ name
648
+ }
649
+ }
650
+ }
651
+ }
652
+ ` ;
653
+
654
+ const organizationSharingQueryResult = await adminQuery ( {
655
+ query : ORGANIZATION_SHARING_QUERY ,
656
+ variables : { id : caseIrId , organizationId : testOrganizationId }
657
+ } ) ;
658
+ expect ( organizationSharingQueryResult ) . not . toBeNull ( ) ;
659
+ expect ( organizationSharingQueryResult ?. data ?. stixCoreObjectEdit . restrictionOrganizationAdd ) . not . toBeNull ( ) ;
660
+ expect ( organizationSharingQueryResult ?. data ?. stixCoreObjectEdit . restrictionOrganizationAdd . objectOrganization [ 0 ] . name ) . toEqual ( TEST_ORGANIZATION . name ) ;
661
+
662
+ // Verify Editor user has access to Case incident
608
663
const caseIRQueryResult = await editorQuery ( { query : READ_QUERY , variables : { id : caseIrId } } ) ;
664
+ console . log ( JSON . stringify ( caseIRQueryResult ) ) ;
609
665
expect ( caseIRQueryResult ) . not . toBeNull ( ) ;
610
666
expect ( caseIRQueryResult ?. data ?. caseIncident ) . not . toBeUndefined ( ) ;
611
667
expect ( caseIRQueryResult ?. data ?. caseIncident . id ) . toEqual ( caseIrId ) ;
612
668
} ) ;
669
+ // 'should plateform organization sharing and EE deactivated' => OK
613
670
it ( 'should plateform organization sharing and EE deactivated' , async ( ) => {
614
671
// Remove plateform organization
615
672
const platformOrganization = await adminQuery ( {
@@ -623,6 +680,7 @@ describe('Case Incident Response and organization sharing standard behavior with
623
680
expect ( platformOrganization ) . not . toBeNull ( ) ;
624
681
expect ( platformOrganization ?. data ?. settingsEdit . fieldPatch . platform_organization ) . toBeNull ( ) ;
625
682
} ) ;
683
+ // 'should Case Incident Response deleted' => OK
626
684
it ( 'should Case Incident Response deleted' , async ( ) => {
627
685
// Delete the case
628
686
await adminQuery ( {
0 commit comments