Skip to content

Commit 080858e

Browse files
[backend] Fix orga sharing tests (#4538)
1 parent 7ed3504 commit 080858e

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

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

+13-14
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import {
88
getOrganizationIdByName,
99
getUserIdByEmail,
1010
PLATFORM_ORGANIZATION,
11-
queryAsAdmin,
1211
securityQuery,
1312
TEST_ORGANIZATION,
1413
USER_EDITOR
1514
} from '../../utils/testQuery';
16-
import { queryAsAdminWithSuccess, queryAsUserIsExpectedForbidden } from '../../utils/testQueryHelper';
15+
import { adminQueryWithSuccess, queryAsUserIsExpectedForbidden } from '../../utils/testQueryHelper';
1716
import { ENTITY_TYPE_CONTAINER_CASE_INCIDENT } from '../../../src/modules/case/case-incident/case-incident-types';
1817

1918
const CREATE_QUERY = gql`
@@ -122,7 +121,7 @@ describe('Case Incident Response standard behavior with authorized_members activ
122121
let userEditorId: string;
123122
it('should Case Incident Response created', async () => {
124123
// Create Case Incident Response
125-
const caseIncidentResponseCreateQueryResult = await queryAsAdmin({
124+
const caseIncidentResponseCreateQueryResult = await adminQuery({
126125
query: CREATE_QUERY,
127126
variables: {
128127
input: {
@@ -162,7 +161,7 @@ describe('Case Incident Response standard behavior with authorized_members activ
162161
});
163162
it('should Admin user edit authorized members', async () => {
164163
// Activate Authorized members
165-
const caseIncidentResponseUpdatedQueryResult = await queryAsAdmin({
164+
const caseIncidentResponseUpdatedQueryResult = await adminQuery({
166165
query: EDIT_AUTHORIZED_MEMBERS_QUERY,
167166
variables: {
168167
id: caseIncident?.id,
@@ -191,7 +190,7 @@ describe('Case Incident Response standard behavior with authorized_members activ
191190
});
192191
it('should Admin user edit authorized members: Editor has view access right', async () => {
193192
// Add Editor user in authorized members
194-
const caseIncidentResponseUpdatedQueryResult = await queryAsAdmin({
193+
const caseIncidentResponseUpdatedQueryResult = await adminQuery({
195194
query: EDIT_AUTHORIZED_MEMBERS_QUERY,
196195
variables: {
197196
id: caseIncident.id,
@@ -236,7 +235,7 @@ describe('Case Incident Response standard behavior with authorized_members activ
236235
});
237236
});
238237
it('should Admin user edit authorized members: Editor has edit access right', async () => {
239-
const caseIncidentResponseUpdatedQueryResult = await queryAsAdmin({
238+
const caseIncidentResponseUpdatedQueryResult = await adminQuery({
240239
query: EDIT_AUTHORIZED_MEMBERS_QUERY,
241240
variables: {
242241
id: caseIncident.id,
@@ -277,7 +276,7 @@ describe('Case Incident Response standard behavior with authorized_members activ
277276
});
278277
});
279278
it('should Admin user edit authorized members: Editor has admin access right', async () => {
280-
const caseIncidentResponseUpdatedQueryResult = await queryAsAdmin({
279+
const caseIncidentResponseUpdatedQueryResult = await adminQuery({
281280
query: EDIT_AUTHORIZED_MEMBERS_QUERY,
282281
variables: {
283282
id: caseIncident.id,
@@ -314,7 +313,7 @@ describe('Case Incident Response standard behavior with authorized_members activ
314313
variables: { id: caseIncident.id },
315314
});
316315
// Verify is no longer found
317-
const queryResult = await queryAsAdmin({ query: READ_QUERY, variables: { id: caseIncident.id } });
316+
const queryResult = await adminQuery({ query: READ_QUERY, variables: { id: caseIncident.id } });
318317
expect(queryResult).not.toBeNull();
319318
expect(queryResult?.data?.caseIncident).toBeNull();
320319
});
@@ -450,7 +449,7 @@ describe('Case Incident Response and organization sharing standard behavior with
450449
settingsInternalId = queryResult.data?.settings?.id;
451450

452451
// Set EE
453-
const EEqueryResult = await queryAsAdminWithSuccess({
452+
const EEqueryResult = await adminQueryWithSuccess({
454453
query: PLATFORM_ORGANIZATION_QUERY,
455454
variables: {
456455
id: settingsInternalId,
@@ -496,7 +495,7 @@ describe('Case Incident Response and organization sharing standard behavior with
496495
expect(queryResult?.data?.caseIncident).toBeNull();
497496
});
498497
it('should EE deactivated', async () => {
499-
const EEDeactivationQuery = await queryAsAdminWithSuccess({
498+
const EEDeactivationQuery = await adminQueryWithSuccess({
500499
query: PLATFORM_ORGANIZATION_QUERY,
501500
variables: {
502501
id: settingsInternalId,
@@ -532,7 +531,7 @@ describe('Case Incident Response and organization sharing standard behavior with
532531
settingsInternalId = queryResult.data?.settings?.id;
533532

534533
// Set plateform organization
535-
const platformOrganization = await queryAsAdminWithSuccess({
534+
const platformOrganization = await adminQueryWithSuccess({
536535
query: PLATFORM_ORGANIZATION_QUERY,
537536
variables: {
538537
id: settingsInternalId,
@@ -568,7 +567,7 @@ describe('Case Incident Response and organization sharing standard behavior with
568567
});
569568
it('should Admin user activate Authorized Members', async () => {
570569
userEditorId = await getUserIdByEmail(USER_EDITOR.email);
571-
const caseIRUpdatedQueryResult = await queryAsAdmin({
570+
const caseIRUpdatedQueryResult = await adminQuery({
572571
query: EDIT_AUTHORIZED_MEMBERS_QUERY,
573572
variables: {
574573
id: caseIrId,
@@ -605,7 +604,7 @@ describe('Case Incident Response and organization sharing standard behavior with
605604
expect(caseIRQueryResult?.data?.caseIncident.currentUserAccessRight).toEqual('view');
606605
});
607606
it('should Admin user deactivate authorized members', async () => {
608-
await queryAsAdmin({
607+
await adminQuery({
609608
query: EDIT_AUTHORIZED_MEMBERS_QUERY,
610609
variables: {
611610
id: caseIrId,
@@ -636,7 +635,7 @@ describe('Case Incident Response and organization sharing standard behavior with
636635
});
637636
it('should plateform organization sharing and EE deactivated', async () => {
638637
// Remove plateform organization
639-
const platformOrganization = await queryAsAdminWithSuccess({
638+
const platformOrganization = await adminQueryWithSuccess({
640639
query: PLATFORM_ORGANIZATION_QUERY,
641640
variables: {
642641
id: settingsInternalId,

opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'vitest';
22
import { print } from 'graphql/index';
33
import type { AxiosInstance } from 'axios';
4-
import { createUnauthenticatedClient, executeInternalQuery, queryAsAdmin } from './testQuery';
4+
import { adminQuery, createUnauthenticatedClient, executeInternalQuery, queryAsAdmin } from './testQuery';
55
import { downloadFile, streamConverter } from '../../src/database/file-storage';
66
import { logApp } from '../../src/config/conf';
77
import { AUTH_REQUIRED, FORBIDDEN_ACCESS } from '../../src/config/errors';
@@ -24,6 +24,16 @@ export const queryAsAdminWithSuccess = async (request: { query: any, variables:
2424
return requestResult;
2525
};
2626

27+
export const adminQueryWithSuccess = async (request: { query: any, variables: any }) => {
28+
const requestResult = await adminQuery({
29+
query: request.query,
30+
variables: request.variables,
31+
});
32+
expect(requestResult, `Something is wrong with this query: ${request.query}`).toBeDefined();
33+
expect(requestResult.errors, `This errors should not be there: ${requestResult.errors}`).toBeUndefined();
34+
return requestResult;
35+
};
36+
2737
/**
2838
* Execute the query as some User, and verify success and return query result.
2939
* @param client

0 commit comments

Comments
 (0)