Skip to content

Commit 448083d

Browse files
committed
[backend] tests (#13901)
1 parent 63dc2e2 commit 448083d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

opencti-platform/opencti-graphql/src/domain/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ const loadUserToUpdateWithAccessCheck = async (context, user, userId) => {
534534
// Check in an organization admin edits a user that's not in its administrated organizations
535535
if (isOnlyOrgaAdmin(user)) {
536536
const myAdministratedOrganizationsIds = user.administrated_organizations.map((orga) => orga.id);
537-
if (!userToUpdate[RELATION_PARTICIPATE_TO].find((orga) => myAdministratedOrganizationsIds.includes(orga))) {
537+
if (!userToUpdate[RELATION_PARTICIPATE_TO]?.find((orga) => myAdministratedOrganizationsIds.includes(orga))) {
538538
throw ForbiddenAccess();
539539
}
540540
} else {

opencti-platform/opencti-graphql/tests/03-integration/02-resolvers/user-test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
USER_CONNECTOR,
2121
USER_DISINFORMATION_ANALYST,
2222
USER_EDITOR,
23+
USER_SECURITY,
24+
USER_EDITOR,
2325
} from '../../utils/testQuery';
2426
import { ENTITY_TYPE_IDENTITY_ORGANIZATION } from '../../../src/modules/organization/organization-types';
2527
import { VIRTUAL_ORGANIZATION_ADMIN } from '../../../src/utils/access';
@@ -749,6 +751,7 @@ describe('User list members query behavior', () => {
749751
it('Should user lists all members', async () => {
750752
const queryResult = await editorQuery({ query: LIST_MEMBERS_QUERY });
751753
const usersEdges = queryResult.data.members.edges as { node: Member }[];
754+
expect(usersEdges.map((n) => n.node)).toEqual('test');
752755
expect(usersEdges.length).toEqual(25);
753756
expect(usersEdges.filter(({ node: { entity_type } }) => entity_type === ENTITY_TYPE_USER).length).toEqual(TESTING_USERS.length + 1); // +1 = Plus admin user
754757
expect(usersEdges.filter(({ node: { entity_type } }) => entity_type === ENTITY_TYPE_GROUP).length).toEqual(entitiesCounter.Group);
@@ -980,6 +983,18 @@ describe('User has no settings capability and is organization admin query behavi
980983
});
981984
expect(queryResult.data.userEdit.fieldPatch.account_status).toEqual('Inactive');
982985
});
986+
it('should not update user with no organization', async () => {
987+
await queryAsUserIsExpectedForbidden(USER_EDITOR.client, {
988+
query: UPDATE_QUERY,
989+
variables: { id: ADMIN_USER.id, input: { key: 'account_status', value: ['Inactive'] } },
990+
});
991+
});
992+
it('should not update user from an other organization', async () => {
993+
await queryAsUserIsExpectedForbidden(USER_EDITOR.client, {
994+
query: UPDATE_QUERY,
995+
variables: { id: USER_SECURITY.id, input: { key: 'account_status', value: ['Inactive'] } },
996+
});
997+
});
983998
it('should not add organization to user if not admin', async () => {
984999
platformOrganizationId = await getOrganizationIdByName(PLATFORM_ORGANIZATION.name);
9851000
await queryAsUserIsExpectedForbidden(USER_EDITOR.client, {
@@ -990,6 +1005,15 @@ describe('User has no settings capability and is organization admin query behavi
9901005
},
9911006
});
9921007
});
1008+
it('should not add organization to user if user is not in its own organization', async () => {
1009+
await queryAsUserIsExpectedForbidden(USER_EDITOR.client, {
1010+
query: ORGANIZATION_ADD_QUERY,
1011+
variables: {
1012+
id: ADMIN_USER.id,
1013+
organizationId: testOrganizationId,
1014+
},
1015+
});
1016+
});
9931017
it('should administrate more than 1 organization', async () => {
9941018
// Need to add granted_groups to PLATFORM_ORGANIZATION because of line 533 in domain/user.js
9951019
const grantableGroupQueryResult = await adminQuery({

0 commit comments

Comments
 (0)