Skip to content

Commit 44fee74

Browse files
[backend] WIP: improve container orga sharing tests (#4538)
1 parent 9b4f282 commit 44fee74

File tree

1 file changed

+92
-45
lines changed

1 file changed

+92
-45
lines changed

opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-authorized-members-test.ts

+92-45
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
editorQuery,
88
getOrganizationIdByName,
99
getUserIdByEmail,
10-
participantQuery,
1110
PLATFORM_ORGANIZATION,
1211
queryAsAdmin,
1312
securityQuery,
@@ -73,7 +72,22 @@ const EDIT_AUTHORIZED_MEMBERS_QUERY = gql`
7372
}
7473
`;
7574

76-
/* describe('Case Incident Response standard behavior with authorized_members activation from entity', () => {
75+
const PLATFORM_ORGANIZATION_QUERY = gql`
76+
mutation PoliciesFieldPatchMutation($id: ID!, $input: [EditInput]!) {
77+
settingsEdit(id: $id) {
78+
fieldPatch(input: $input) {
79+
platform_organization {
80+
id
81+
name
82+
}
83+
enterprise_edition
84+
id
85+
}
86+
}
87+
}
88+
`;
89+
90+
describe('Case Incident Response standard behavior with authorized_members activation from entity', () => {
7791
let caseIncident: CaseIncident;
7892
let userEditorId: string;
7993
// 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
@@ -420,6 +434,9 @@ describe('Case Incident Response standard behavior with authorized_members activ
420434

421435
describe('Case Incident Response and organization sharing standard behavior without platform organization', () => {
422436
let caseIrId: string;
437+
let organizationId: string;
438+
let settingsInternalId: string;
439+
// 1. On créé un case incident et on le partage à une orga différente de l'orga de editor
423440
it('should Case Incident Response created', async () => {
424441
// Create Case Incident Response
425442
const caseIRCreateQueryResult = await adminQuery({
@@ -436,45 +453,78 @@ describe('Case Incident Response and organization sharing standard behavior with
436453
expect(caseIRCreateQueryResult?.data?.caseIncidentAdd.authorized_members).toEqual([]); // authorized members not activated
437454
caseIrId = caseIRCreateQueryResult?.data?.caseIncidentAdd.id;
438455
});
439-
it('should access Case Incident Response', async () => {
440-
const caseIRQueryResult = await securityQuery({ query: READ_QUERY, variables: { id: caseIrId } });
441-
expect(caseIRQueryResult).not.toBeNull();
442-
expect(caseIRQueryResult?.data?.caseIncident).not.toBeUndefined();
443-
expect(caseIRQueryResult?.data?.caseIncident.id).toEqual(caseIrId);
444-
});
445-
it('should Authorized Members activated', async () => {
446-
await queryAsAdmin({
447-
query: EDIT_AUTHORIZED_MEMBERS_QUERY,
456+
it('should EE activated', async () => {
457+
// Get settings ID
458+
const SETTINGS_READ_QUERY = gql`
459+
query settings {
460+
settings {
461+
id
462+
platform_organization {
463+
id
464+
name
465+
}
466+
}
467+
}
468+
`;
469+
const queryResult = await adminQuery({ query: SETTINGS_READ_QUERY, variables: {} });
470+
settingsInternalId = queryResult.data?.settings?.id;
471+
472+
// Set plateform organization
473+
const EEqueryResult = await adminQuery({
474+
query: PLATFORM_ORGANIZATION_QUERY,
448475
variables: {
449-
id: caseIrId,
476+
id: settingsInternalId,
450477
input: [
451-
{
452-
id: ADMIN_USER.id,
453-
access_right: 'admin'
454-
}
478+
{ key: 'enterprise_edition', value: new Date().getTime() },
455479
]
456480
}
457481
});
458-
// Verify if authorized members have been edited
459-
const caseIRUpdatedQueryResult = await adminQuery({
460-
query: READ_QUERY,
461-
variables: { id: caseIrId }
462-
});
463-
expect(caseIRUpdatedQueryResult).not.toBeNull();
464-
expect(caseIRUpdatedQueryResult?.data?.caseIncident.authorized_members).not.toBeUndefined();
465-
expect(caseIRUpdatedQueryResult?.data?.caseIncident.authorized_members).toEqual([
466-
{
467-
id: ADMIN_USER.id,
468-
access_right: 'admin'
482+
expect(EEqueryResult).not.toBeNull();
483+
expect(EEqueryResult?.data?.settingsEdit.fieldPatch.enterprise_edition).not.toBeUndefined();
484+
});
485+
it('should share Case Incident Response with Organization', async () => {
486+
// Get organization id
487+
organizationId = await getOrganizationIdByName(PLATFORM_ORGANIZATION.name);
488+
const ORGANIZATION_SHARING_QUERY = gql`
489+
mutation StixCoreObjectSharingGroupAddMutation(
490+
$id: ID!
491+
$organizationId: ID!
492+
) {
493+
stixCoreObjectEdit(id: $id) {
494+
restrictionOrganizationAdd(organizationId: $organizationId) {
495+
id
496+
objectOrganization {
497+
id
498+
name
499+
}
500+
}
501+
}
469502
}
470-
]);
503+
`;
504+
505+
const organizationSharingQueryResult = await adminQuery({
506+
query: ORGANIZATION_SHARING_QUERY,
507+
variables: { id: caseIrId, organizationId: PLATFORM_ORGANIZATION.id }
508+
});
509+
expect(organizationSharingQueryResult).not.toBeNull();
510+
expect(organizationSharingQueryResult?.data?.stixCoreObjectEdit.restrictionOrganizationAdd).not.toBeNull();
511+
expect(organizationSharingQueryResult?.data?.stixCoreObjectEdit.restrictionOrganizationAdd.objectOrganization[0].name).toEqual(PLATFORM_ORGANIZATION.name);
471512
});
472-
it('should not access Case Incident Response if not in authorized members', async () => {
513+
// 2. On vérifie qu'editor a bien accès au case incident
514+
it('should Editor user from different organization access Case Incident Response', async () => {
515+
const caseIRQueryResult = await editorQuery({ query: READ_QUERY, variables: { id: caseIrId } });
516+
expect(caseIRQueryResult).not.toBeNull();
517+
expect(caseIRQueryResult?.data?.caseIncident).not.toBeUndefined();
518+
expect(caseIRQueryResult?.data?.caseIncident.id).toEqual(caseIrId);
519+
});
520+
// 3. On vérifie qu'un user faisant partie de l'orga a bien accès au case aussi
521+
it('should Security user from shared organization access Case Incident Response', async () => {
473522
const caseIRQueryResult = await securityQuery({ query: READ_QUERY, variables: { id: caseIrId } });
474523
expect(caseIRQueryResult).not.toBeNull();
475524
expect(caseIRQueryResult?.data?.caseIncident).not.toBeUndefined();
476-
expect(caseIRQueryResult?.data?.caseIncident).toBeNull();
525+
expect(caseIRQueryResult?.data?.caseIncident.id).toEqual(caseIrId);
477526
});
527+
// 4. On delete le case avec l'admin
478528
it('should Case Incident Response deleted', async () => {
479529
// Delete the case
480530
await adminQuery({
@@ -486,28 +536,25 @@ describe('Case Incident Response and organization sharing standard behavior with
486536
expect(queryResult).not.toBeNull();
487537
expect(queryResult?.data?.caseIncident).toBeNull();
488538
});
489-
}); */
539+
it('should EE deactivated', async () => {
540+
const platformOrganization = await adminQuery({
541+
query: PLATFORM_ORGANIZATION_QUERY,
542+
variables: { id: settingsInternalId,
543+
input: [
544+
{ key: 'enterprise_edition', value: [] },
545+
] }
546+
});
547+
expect(platformOrganization).not.toBeNull();
548+
expect(platformOrganization?.data?.settingsEdit.fieldPatch.enterprise_edition).toBeNull();
549+
});
550+
});
490551

491552
describe('Case Incident Response and organization sharing standard behavior with platform organization', () => {
492553
let platformOrganizationId: string;
493554
let testOrganizationId: string;
494555
let caseIrId: string;
495556
let userEditorId: string;
496557
let settingsInternalId: string;
497-
const PLATFORM_ORGANIZATION_QUERY = gql`
498-
mutation PoliciesFieldPatchMutation($id: ID!, $input: [EditInput]!) {
499-
settingsEdit(id: $id) {
500-
fieldPatch(input: $input) {
501-
platform_organization {
502-
id
503-
name
504-
}
505-
enterprise_edition
506-
id
507-
}
508-
}
509-
}
510-
`;
511558
// 1. 'should plateform organization sharing and EE activated' => OK avec PlaformOrganization
512559
it('should plateform organization sharing and EE activated', async () => {
513560
// Get organization id

0 commit comments

Comments
 (0)