Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
make status code consistent
Thiago Araujo da Silva2e297cf610ea
diff --git a/backend/e2e-test/routes/v1/sub-org-group-link-identity.spec.ts b/backend/e2e-test/routes/v1/sub-org-group-link-identity.spec.tsindex d0319498da..24b8d5e23d 100644--- a/backend/e2e-test/routes/v1/sub-org-group-link-identity.spec.ts+++ b/backend/e2e-test/routes/v1/sub-org-group-link-identity.spec.ts@@ -181,6 +181,16 @@ describe("Linking root groups to a sub-organization with a machine identity", ()const headers = { authorization: `Bearer ${adminSubOrgToken}` };for (const id of [otherGroup.id, crypto.randomUUID()]) {const url = `/api/v1/organizations/memberships/groups/${id}`;+ // eslint-disable-next-line no-await-in-loop+ const createRes = await testServer.inject({+ method: "POST",+ url,+ headers,+ body: { roles: [{ role: OrgMembershipRole.NoAccess }] }+ });+ expect(createRes.statusCode).toBe(404);+ expect(createRes.json().message).toBe(`Group with ID '${id}' not found`);+// eslint-disable-next-line no-await-in-loopconst updateRes = await testServer.inject({method: "PATCH",@@ -204,7 +214,7 @@ describe("Linking root groups to a sub-organization with a machine identity", ()}});- test("refuses to unlink a group owned by the sub-organization", async () => {+ test("refuses to link or unlink a group owned by the sub-organization", async () => {const suffix = alphaNumericNanoId(8).toLowerCase();const [ownedGroup] = await testDb(TableName.Groups).insert({ orgId: subOrgId, name: `owned-grp-${suffix}`, slug: `owned-grp-${suffix}` })@@ -218,11 +228,18 @@ describe("Linking root groups to a sub-organization with a machine identity", ()});try {- const deleteRes = await testServer.inject({- method: "DELETE",- url: `/api/v1/organizations/memberships/groups/${ownedGroup.id}`,- headers: { authorization: `Bearer ${adminSubOrgToken}` }+ const url = `/api/v1/organizations/memberships/groups/${ownedGroup.id}`;+ const headers = { authorization: `Bearer ${adminSubOrgToken}` };++ const createRes = await testServer.inject({+ method: "POST",+ url,+ headers,+ body: { roles: [{ role: OrgMembershipRole.NoAccess }] }});+ expect(createRes.statusCode).toBe(400);++ const deleteRes = await testServer.inject({ method: "DELETE", url, headers });expect(deleteRes.statusCode).toBe(400);expect(await testDb(TableName.Membership).where({ id: homeMembership.id })).toHaveLength(1);} finally {diff --git a/backend/src/services/membership-group/org/org-membership-group-factory.ts b/backend/src/services/membership-group/org/org-membership-group-factory.tsindex 6323d14d35..7d7bd3b706 100644--- a/backend/src/services/membership-group/org/org-membership-group-factory.ts+++ b/backend/src/services/membership-group/org/org-membership-group-factory.ts@@ -101,10 +101,10 @@ export const newOrgMembershipGroupFactory = ({});ForbiddenError.from(permission).throwUnlessCan(OrgPermissionGroupActions.Create, OrgPermissionSubjects.Groups);- const group = await groupDAL.findById(dto.data.groupId);- if (!group || group.orgId !== dto.permission.rootOrgId) {+ const group = await $getGroupInActorScope(dto.permission, dto.data.groupId);+ if (group.orgId === dto.permission.orgId) {throw new BadRequestError({- message: "Only groups from parent organization can be linked to this sub-organization"+ message: `Group '${group.name}' belongs to this organization. Only groups from the parent organization can be linked to it.`});}