Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backend] Fix orga sharing tests (#4538) #8404

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand Down