From b9f2423c2aab8452193b4648ad292c375a81acbb Mon Sep 17 00:00:00 2001 From: marie flores Date: Wed, 18 Sep 2024 16:25:59 +0200 Subject: [PATCH] [backend] use adminQuery for cache --- .../container-authorized-members-test.ts | 27 +++++++++---------- .../tests/utils/testQueryHelper.ts | 12 ++++++++- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-authorized-members-test.ts b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-authorized-members-test.ts index f67f5f3c7d34..35a1ab1cfbca 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-authorized-members-test.ts +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-authorized-members-test.ts @@ -8,12 +8,11 @@ import { getOrganizationIdByName, getUserIdByEmail, PLATFORM_ORGANIZATION, - queryAsAdmin, securityQuery, TEST_ORGANIZATION, USER_EDITOR } from '../../utils/testQuery'; -import { queryAsAdminWithSuccess, queryAsUserIsExpectedForbidden } from '../../utils/testQueryHelper'; +import { adminQueryWithSuccess, queryAsUserIsExpectedForbidden } from '../../utils/testQueryHelper'; import { ENTITY_TYPE_CONTAINER_CASE_INCIDENT } from '../../../src/modules/case/case-incident/case-incident-types'; const CREATE_QUERY = gql` @@ -122,7 +121,7 @@ describe('Case Incident Response standard behavior with authorized_members activ let userEditorId: string; it('should Case Incident Response created', async () => { // Create Case Incident Response - const caseIncidentResponseCreateQueryResult = await queryAsAdmin({ + const caseIncidentResponseCreateQueryResult = await adminQuery({ query: CREATE_QUERY, variables: { input: { @@ -162,7 +161,7 @@ describe('Case Incident Response standard behavior with authorized_members activ }); it('should Admin user edit authorized members', async () => { // Activate Authorized members - const caseIncidentResponseUpdatedQueryResult = await queryAsAdmin({ + const caseIncidentResponseUpdatedQueryResult = await adminQuery({ query: EDIT_AUTHORIZED_MEMBERS_QUERY, variables: { id: caseIncident?.id, @@ -191,7 +190,7 @@ describe('Case Incident Response standard behavior with authorized_members activ }); it('should Admin user edit authorized members: Editor has view access right', async () => { // Add Editor user in authorized members - const caseIncidentResponseUpdatedQueryResult = await queryAsAdmin({ + const caseIncidentResponseUpdatedQueryResult = await adminQuery({ query: EDIT_AUTHORIZED_MEMBERS_QUERY, variables: { id: caseIncident.id, @@ -236,7 +235,7 @@ describe('Case Incident Response standard behavior with authorized_members activ }); }); it('should Admin user edit authorized members: Editor has edit access right', async () => { - const caseIncidentResponseUpdatedQueryResult = await queryAsAdmin({ + const caseIncidentResponseUpdatedQueryResult = await adminQuery({ query: EDIT_AUTHORIZED_MEMBERS_QUERY, variables: { id: caseIncident.id, @@ -277,7 +276,7 @@ describe('Case Incident Response standard behavior with authorized_members activ }); }); it('should Admin user edit authorized members: Editor has admin access right', async () => { - const caseIncidentResponseUpdatedQueryResult = await queryAsAdmin({ + const caseIncidentResponseUpdatedQueryResult = await adminQuery({ query: EDIT_AUTHORIZED_MEMBERS_QUERY, variables: { id: caseIncident.id, @@ -314,7 +313,7 @@ describe('Case Incident Response standard behavior with authorized_members activ variables: { id: caseIncident.id }, }); // Verify is no longer found - const queryResult = await queryAsAdmin({ query: READ_QUERY, variables: { id: caseIncident.id } }); + const queryResult = await adminQuery({ query: READ_QUERY, variables: { id: caseIncident.id } }); expect(queryResult).not.toBeNull(); expect(queryResult?.data?.caseIncident).toBeNull(); }); @@ -450,7 +449,7 @@ describe('Case Incident Response and organization sharing standard behavior with settingsInternalId = queryResult.data?.settings?.id; // Set EE - const EEqueryResult = await queryAsAdminWithSuccess({ + const EEqueryResult = await adminQueryWithSuccess({ query: PLATFORM_ORGANIZATION_QUERY, variables: { id: settingsInternalId, @@ -496,7 +495,7 @@ describe('Case Incident Response and organization sharing standard behavior with expect(queryResult?.data?.caseIncident).toBeNull(); }); it('should EE deactivated', async () => { - const EEDeactivationQuery = await queryAsAdminWithSuccess({ + const EEDeactivationQuery = await adminQueryWithSuccess({ query: PLATFORM_ORGANIZATION_QUERY, variables: { id: settingsInternalId, @@ -532,7 +531,7 @@ describe('Case Incident Response and organization sharing standard behavior with settingsInternalId = queryResult.data?.settings?.id; // Set plateform organization - const platformOrganization = await queryAsAdminWithSuccess({ + const platformOrganization = await adminQueryWithSuccess({ query: PLATFORM_ORGANIZATION_QUERY, variables: { id: settingsInternalId, @@ -568,7 +567,7 @@ describe('Case Incident Response and organization sharing standard behavior with }); it('should Admin user activate Authorized Members', async () => { userEditorId = await getUserIdByEmail(USER_EDITOR.email); - const caseIRUpdatedQueryResult = await queryAsAdmin({ + const caseIRUpdatedQueryResult = await adminQuery({ query: EDIT_AUTHORIZED_MEMBERS_QUERY, variables: { id: caseIrId, @@ -605,7 +604,7 @@ describe('Case Incident Response and organization sharing standard behavior with expect(caseIRQueryResult?.data?.caseIncident.currentUserAccessRight).toEqual('view'); }); it('should Admin user deactivate authorized members', async () => { - await queryAsAdmin({ + await adminQuery({ query: EDIT_AUTHORIZED_MEMBERS_QUERY, variables: { id: caseIrId, @@ -636,7 +635,7 @@ describe('Case Incident Response and organization sharing standard behavior with }); 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, diff --git a/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts b/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts index 01e20183c3a5..2553d4018188 100644 --- a/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts +++ b/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts @@ -1,7 +1,7 @@ import { expect } from 'vitest'; import { print } from 'graphql/index'; import type { AxiosInstance } from 'axios'; -import { createUnauthenticatedClient, executeInternalQuery, queryAsAdmin } from './testQuery'; +import { adminQuery, createUnauthenticatedClient, executeInternalQuery, queryAsAdmin } from './testQuery'; import { downloadFile, streamConverter } from '../../src/database/file-storage'; import { logApp } from '../../src/config/conf'; import { AUTH_REQUIRED, FORBIDDEN_ACCESS } from '../../src/config/errors'; @@ -24,6 +24,16 @@ export const queryAsAdminWithSuccess = async (request: { query: any, variables: return requestResult; }; +export const adminQueryWithSuccess = async (request: { query: any, variables: any }) => { + const requestResult = await adminQuery({ + query: request.query, + variables: request.variables, + }); + expect(requestResult, `Something is wrong with this query: ${request.query}`).toBeDefined(); + expect(requestResult.errors, `This errors should not be there: ${requestResult.errors}`).toBeUndefined(); + return requestResult; +}; + /** * Execute the query as some User, and verify success and return query result. * @param client