-
Notifications
You must be signed in to change notification settings - Fork 961
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
713a2ab
commit 47d48f2
Showing
3 changed files
with
371 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
.../opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import gql from 'graphql-tag'; | ||
import { ADMIN_API_TOKEN, ADMIN_USER, adminQuery, API_URI, FIVE_MINUTES, getOrganizationIdByName, PLATFORM_ORGANIZATION, PYTHON_PATH, testContext } from '../../utils/testQuery'; | ||
import { queryAsAdminWithSuccess } from '../../utils/testQueryHelper'; | ||
import { execChildPython } from '../../../src/python/pythonBridge'; | ||
import { findById } from '../../../src/domain/report'; | ||
|
||
const READ_QUERY = gql` | ||
query caseIncident($id: String!) { | ||
caseIncident(id: $id) { | ||
id | ||
standard_id | ||
name | ||
authorized_members { | ||
id | ||
access_right | ||
} | ||
currentUserAccessRight | ||
} | ||
} | ||
`; | ||
|
||
const DELETE_QUERY = gql` | ||
mutation CaseIncidentDelete($id: ID!) { | ||
caseIncidentDelete(id: $id) | ||
} | ||
`; | ||
|
||
const PLATFORM_ORGANIZATION_QUERY = gql` | ||
mutation PoliciesFieldPatchMutation($id: ID!, $input: [EditInput]!) { | ||
settingsEdit(id: $id) { | ||
fieldPatch(input: $input) { | ||
platform_organization { | ||
id | ||
name | ||
} | ||
enterprise_edition | ||
id | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const ORGANIZATION_SHARING_QUERY = gql` | ||
mutation StixCoreObjectSharingGroupAddMutation( | ||
$id: ID! | ||
$organizationId: ID! | ||
) { | ||
stixCoreObjectEdit(id: $id) { | ||
restrictionOrganizationAdd(organizationId: $organizationId) { | ||
id | ||
objectOrganization { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const importOpts: string[] = [API_URI, ADMIN_API_TOKEN, './tests/data/DATA-TEST-STIX2_v2.json']; | ||
|
||
describe('Database provision', () => { | ||
it('Should import creation succeed', async () => { | ||
// Inject data | ||
const execution = await execChildPython(testContext, ADMIN_USER, PYTHON_PATH, 'local_importer.py', importOpts); | ||
expect(execution).not.toBeNull(); | ||
expect(execution.status).toEqual('success'); | ||
}, FIVE_MINUTES); | ||
// Python lib is fixed but we need to wait for a new release | ||
it('Should import update succeed', async () => { | ||
const execution = await execChildPython(testContext, ADMIN_USER, PYTHON_PATH, 'local_importer.py', importOpts); | ||
expect(execution).not.toBeNull(); | ||
expect(execution.status).toEqual('success'); | ||
}, FIVE_MINUTES); | ||
}); | ||
|
||
describe('Organization sharing standard behavior for container', () => { | ||
let reportInternalId: string; | ||
let organizationId: string; | ||
let settingsInternalId: string; | ||
let platformOrganizationId: string; | ||
it('should load Report', async () => { | ||
const report = await findById(testContext, ADMIN_USER, 'report--57162a65-2a58-560b-9a65-47c3f040f3d4'); // Report is in DATA-TEST-STIX_v2.json | ||
console.log('report', JSON.stringify((report))); | ||
reportInternalId = report.internal_id; | ||
}); | ||
it('should plateform organization sharing and EE activated', async () => { | ||
// Get organization id | ||
platformOrganizationId = await getOrganizationIdByName(PLATFORM_ORGANIZATION.name); | ||
|
||
// Get settings ID | ||
const SETTINGS_READ_QUERY = gql` | ||
query settings { | ||
settings { | ||
id | ||
platform_organization { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
`; | ||
const queryResult = await adminQuery({ query: SETTINGS_READ_QUERY, variables: {} }); | ||
settingsInternalId = queryResult.data?.settings?.id; | ||
|
||
// Set plateform organization | ||
const platformOrganization = await queryAsAdminWithSuccess({ | ||
query: PLATFORM_ORGANIZATION_QUERY, | ||
variables: { | ||
id: settingsInternalId, | ||
input: [ | ||
{ key: 'platform_organization', value: platformOrganizationId }, | ||
{ key: 'enterprise_edition', value: new Date().getTime() }, | ||
] | ||
} | ||
}); | ||
expect(platformOrganization?.data?.settingsEdit.fieldPatch.platform_organization).not.toBeUndefined(); | ||
expect(platformOrganization?.data?.settingsEdit.fieldPatch.enterprise_edition).not.toBeUndefined(); | ||
expect(platformOrganization?.data?.settingsEdit.fieldPatch.platform_organization.name).toEqual(PLATFORM_ORGANIZATION.name); | ||
}); | ||
it('should share Report with Organization', async () => { | ||
// Get organization id | ||
organizationId = await getOrganizationIdByName(PLATFORM_ORGANIZATION.name); | ||
const organizationSharingQueryResult = await queryAsAdminWithSuccess({ | ||
query: ORGANIZATION_SHARING_QUERY, | ||
variables: { id: reportInternalId, organizationId } | ||
}); | ||
expect(organizationSharingQueryResult?.data?.stixCoreObjectEdit.restrictionOrganizationAdd).not.toBeNull(); | ||
expect(organizationSharingQueryResult?.data?.stixCoreObjectEdit.restrictionOrganizationAdd.objectOrganization[0].name).toEqual(PLATFORM_ORGANIZATION.name); | ||
}); | ||
it('should Report deleted', async () => { | ||
// Delete the case | ||
await adminQuery({ | ||
query: DELETE_QUERY, | ||
variables: { id: reportInternalId }, | ||
}); | ||
// Verify is no longer found | ||
const queryResult = await queryAsAdminWithSuccess({ query: READ_QUERY, variables: { id: reportInternalId } }); | ||
expect(queryResult?.data?.caseIncident).toBeNull(); | ||
}); | ||
it('should plateform organization sharing and EE deactivated', async () => { | ||
// Remove plateform organization | ||
const platformOrganization = await queryAsAdminWithSuccess({ | ||
query: PLATFORM_ORGANIZATION_QUERY, | ||
variables: { | ||
id: settingsInternalId, | ||
input: [ | ||
{ key: 'platform_organization', value: [] }, | ||
{ key: 'enterprise_edition', value: [] }, | ||
] | ||
} | ||
}); | ||
expect(platformOrganization?.data?.settingsEdit.fieldPatch.platform_organization).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters