Skip to content

Commit

Permalink
[backend] WIP: test (#8333)
Browse files Browse the repository at this point in the history
  • Loading branch information
marieflorescontact committed Sep 19, 2024
1 parent c7a5a0a commit 8096959
Showing 1 changed file with 46 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
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 {
ADMIN_API_TOKEN,
ADMIN_USER,
adminQuery,
API_URI,
FIVE_MINUTES,
getOrganizationIdByName,
PLATFORM_ORGANIZATION,
PYTHON_PATH,
testContext,
USER_SECURITY
} from '../../utils/testQuery';
import { adminQueryWithSuccess, queryAsUserWithSuccess } from '../../utils/testQueryHelper';
import { execChildPython } from '../../../src/python/pythonBridge';
import { findById } from '../../../src/domain/report';

Expand Down Expand Up @@ -58,31 +69,13 @@ const ORGANIZATION_SHARING_QUERY = gql`
}
`;

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 () => {
Expand All @@ -105,7 +98,7 @@ describe('Organization sharing standard behavior for container', () => {
settingsInternalId = queryResult.data?.settings?.id;

// Set plateform organization
const platformOrganization = await queryAsAdminWithSuccess({
const platformOrganization = await adminQueryWithSuccess({
query: PLATFORM_ORGANIZATION_QUERY,
variables: {
id: settingsInternalId,
Expand All @@ -122,26 +115,55 @@ describe('Organization sharing standard behavior for container', () => {
it('should share Report with Organization', async () => {
// Get organization id
organizationId = await getOrganizationIdByName(PLATFORM_ORGANIZATION.name);
const organizationSharingQueryResult = await queryAsAdminWithSuccess({
const organizationSharingQueryResult = await adminQueryWithSuccess({
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 Security user access all objects', async () => {
const REPORT_STIX_DOMAIN_ENTITIES = gql`
query report($id: String!) {
report(id: $id) {
id
standard_id
objects(first: 30) {
edges {
node {
... on BasicObject {
id
standard_id
}
... on BasicRelationship {
id
standard_id
}
}
}
}
}
}
`;
const queryResult = await queryAsUserWithSuccess(USER_SECURITY.client, {
query: REPORT_STIX_DOMAIN_ENTITIES,
variables: { id: reportInternalId },
});
expect(queryResult.data.report.objects.edges.length).toEqual(10);
});
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 } });
const queryResult = await adminQueryWithSuccess({ 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({
const platformOrganization = await adminQueryWithSuccess({
query: PLATFORM_ORGANIZATION_QUERY,
variables: {
id: settingsInternalId,
Expand Down

0 comments on commit 8096959

Please sign in to comment.