Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

PATCH selection like PUT

Thiago Araujo da Silvac4f2dc2c9772
diff --git a/backend/e2e-test/routes/v1/scim.spec.ts b/backend/e2e-test/routes/v1/scim.spec.ts
index 9df1e82895..9bb9bb4d7b 100644
--- a/backend/e2e-test/routes/v1/scim.spec.ts
+++ b/backend/e2e-test/routes/v1/scim.spec.ts
@@ -850,5 +850,41 @@ describe("SCIM v1 Router", () => {
const [row] = await db(TableName.Users).where({ id: user.id }).select("username");
expect(row.username).toBe(user.username);
});
+
+ test("should take the primary address when the assertion carries several", async () => {
+ const db = getDb();
+ const label = `multi-${crypto.randomUUID().slice(0, 8)}`;
+ const { user, membership } = await seedUser(db, label);
+ const primaryEmail = `renamed-${label}@${TEST_DOMAIN}`;
+ const secondaryEmail = `alias-${label}@${TEST_DOMAIN}`;
+
+ await db(TableName.Organization).where({ id: ORG_ID }).update({ authEnforced: true });
+
+ const res = await testServer.inject({
+ method: "PATCH",
+ url: `/api/v1/scim/Users/${membership.id}`,
+ headers: { authorization: `Bearer ${scimToken}`, "content-type": "application/scim+json" },
+ payload: JSON.stringify({
+ schemas: ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
+ Operations: [
+ {
+ op: "replace",
+ path: "emails",
+ // The mailbox we key on is not first, which is what the PUT handler already accounts for.
+ value: [
+ { primary: false, value: secondaryEmail, type: "home" },
+ { primary: true, value: primaryEmail, type: "work" }
+ ]
+ }
+ ]
+ })
+ });
+
+ expect(res.statusCode).toBe(200);
+
+ const [row] = await db(TableName.Users).where({ id: user.id }).select("username", "email");
+ expect(row.username).toBe(primaryEmail);
+ expect(row.email).toBe(primaryEmail);
+ });
});
});
diff --git a/backend/src/ee/services/scim/scim-service.ts b/backend/src/ee/services/scim/scim-service.ts
index 3b89a81cf6..afd5a815c9 100644
--- a/backend/src/ee/services/scim/scim-service.ts
+++ b/backend/src/ee/services/scim/scim-service.ts
@@ -781,7 +781,7 @@ export const scimServiceFactory = ({
const newEmail = await $resolveScimEmailChange({
org,
user,
- assertedEmail: scimUser.emails?.[0]?.value
+ assertedEmail: (scimUser.emails?.find((email) => email.primary) ?? scimUser.emails?.[0])?.value
});
await verifyEmailDomainOwnership({