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
feat: added testing for auth setups
=e078075171b6
diff --git a/backend/e2e-test/mocks/smtp.ts b/backend/e2e-test/mocks/smtp.tsindex 4ba42e8389..dee38fae3e 100644--- a/backend/e2e-test/mocks/smtp.ts+++ b/backend/e2e-test/mocks/smtp.ts@@ -1,6 +1,12 @@import { TSmtpSendMail, TSmtpService } from "@app/services/smtp/smtp-service";-export const mockSmtpServer = (): TSmtpService => {+export type TTestSmtpService = TSmtpService & {+ getEmails: () => TSmtpSendMail[];+ getLastEmail: () => TSmtpSendMail | undefined;+ clear: () => void;+};++export const mockSmtpServer = (): TTestSmtpService => {const storage: TSmtpSendMail[] = [];return {sendMail: async (data) => {@@ -8,6 +14,11 @@ export const mockSmtpServer = (): TSmtpService => {},verify: async () => {return true;+ },+ getEmails: () => storage,+ getLastEmail: () => storage[storage.length - 1],+ clear: () => {+ storage.length = 0;}};};diff --git a/backend/e2e-test/routes/v1/auth-invite.spec.ts b/backend/e2e-test/routes/v1/auth-invite.spec.tsnew file mode 100644index 0000000000..37efc769ca--- /dev/null+++ b/backend/e2e-test/routes/v1/auth-invite.spec.ts@@ -0,0 +1,50 @@+import { seedData1 } from "@app/db/seed-data";++describe("Auth Org Invite V1", () => {+ test("Verify invite with valid token for existing accepted user returns user without token", async () => {+ // Create a membership invite for the seed user in the seed org+ // The seed user is already accepted, so verifyUserToOrg should return { user } without a token+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v1/invite-org/verify",+ body: {+ email: seedData1.email,+ organizationId: seedData1.organization.id,+ code: "invalid-code-to-test-flow"+ }+ });++ // Should fail because the seed user is already an accepted member+ expect(res.statusCode).toBe(400);+ const payload = res.json();+ expect(payload.message).toMatch(/already a member/i);+ });++ test("Verify invite with wrong code returns 400", async () => {+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v1/invite-org/verify",+ body: {+ email: "[email protected]",+ organizationId: seedData1.organization.id,+ code: "wrong-code-123"+ }+ });++ expect(res.statusCode).toBeGreaterThanOrEqual(400);+ });++ test("Verify invite with non-existent email returns 404", async () => {+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v1/invite-org/verify",+ body: {+ email: "[email protected]",+ organizationId: seedData1.organization.id,+ code: "some-code"+ }+ });++ expect(res.statusCode).toBe(404);+ });+});diff --git a/backend/e2e-test/routes/v1/auth-token.spec.ts b/backend/e2e-test/routes/v1/auth-token.spec.tsnew file mode 100644index 0000000000..9ac664adbf--- /dev/null+++ b/backend/e2e-test/routes/v1/auth-token.spec.ts@@ -0,0 +1,105 @@+import { seedData1 } from "@app/db/seed-data";++import { extractCookie } from "../../testUtils/cookies";++describe("Auth Token V1", () => {+ test("checkAuth with valid JWT returns 200", async () => {+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v1/auth/checkAuth",+ headers: {+ authorization: `Bearer ${jwtAuthToken}`+ }+ });++ expect(res.statusCode).toBe(200);+ });++ test("checkAuth without JWT returns 401", async () => {+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v1/auth/checkAuth"+ });++ expect(res.statusCode).toBe(401);+ });++ test("Token refresh with valid jid cookie returns new token", async () => {+ // First login to get a refresh cookie+ const loginRes = await testServer.inject({+ method: "POST",+ url: "/api/v3/auth/login",+ body: {+ email: seedData1.email,+ password: seedData1.password+ }+ });+ expect(loginRes.statusCode).toBe(200);++ const refreshCookie = extractCookie(loginRes, "jid");+ expect(refreshCookie).toBeDefined();++ // Use the refresh cookie to get a new token+ const refreshRes = await testServer.inject({+ method: "POST",+ url: "/api/v1/auth/token",+ cookies: {+ jid: refreshCookie!+ }+ });++ expect(refreshRes.statusCode).toBe(200);+ const payload = refreshRes.json();+ expect(payload).toHaveProperty("token");+ });++ test("Token refresh without cookie returns error", async () => {+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v1/auth/token"+ });++ expect(res.statusCode).toBeGreaterThanOrEqual(400);+ });++ test("Logout invalidates session, subsequent refresh fails", async () => {+ // Login to get tokens+ const loginRes = await testServer.inject({+ method: "POST",+ url: "/api/v3/auth/login",+ body: {+ email: seedData1.email,+ password: seedData1.password+ }+ });+ expect(loginRes.statusCode).toBe(200);++ const { accessToken } = loginRes.json();+ const refreshCookie = extractCookie(loginRes, "jid");+ expect(refreshCookie).toBeDefined();++ // Logout+ const logoutRes = await testServer.inject({+ method: "POST",+ url: "/api/v1/auth/logout",+ headers: {+ authorization: `Bearer ${accessToken}`+ },+ cookies: {+ jid: refreshCookie!+ }+ });+ expect(logoutRes.statusCode).toBe(200);++ // Subsequent refresh should fail+ const refreshRes = await testServer.inject({+ method: "POST",+ url: "/api/v1/auth/token",+ cookies: {+ jid: refreshCookie!+ }+ });++ expect(refreshRes.statusCode).toBeGreaterThanOrEqual(400);+ });+});diff --git a/backend/e2e-test/routes/v3/auth-email-login.spec.ts b/backend/e2e-test/routes/v3/auth-email-login.spec.tsnew file mode 100644index 0000000000..63f9cce061--- /dev/null+++ b/backend/e2e-test/routes/v3/auth-email-login.spec.ts@@ -0,0 +1,72 @@+import { decode } from "jsonwebtoken";++import { seedData1 } from "@app/db/seed-data";+import { AuthMethod, AuthTokenType } from "@app/services/auth/auth-type";++import { extractCookie } from "../../testUtils/cookies";++describe("Auth Email Login V3", () => {+ test("Login with valid email + password returns accessToken and sets jid cookie", async () => {+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v3/auth/login",+ body: {+ email: seedData1.email,+ password: seedData1.password+ }+ });++ expect(res.statusCode).toBe(200);+ const payload = res.json();+ expect(payload).toHaveProperty("accessToken");+ expect(typeof payload.accessToken).toBe("string");++ const refreshCookie = extractCookie(res, "jid");+ expect(refreshCookie).toBeDefined();+ });++ test("Login with wrong password returns 400", async () => {+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v3/auth/login",+ body: {+ email: seedData1.email,+ password: "wrongPassword123!"+ }+ });++ expect(res.statusCode).toBe(400);+ });++ test("Login with non-existent email returns 400", async () => {+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v3/auth/login",+ body: {+ email: "[email protected]",+ password: seedData1.password+ }+ });++ expect(res.statusCode).toBe(400);+ });++ test("Returned token has correct JWT claims", async () => {+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v3/auth/login",+ body: {+ email: seedData1.email,+ password: seedData1.password+ }+ });++ expect(res.statusCode).toBe(200);+ const { accessToken } = res.json();++ const decoded = decode(accessToken) as Record<string, unknown>;+ expect(decoded.userId).toBe(seedData1.id);+ expect(decoded.authMethod).toBe(AuthMethod.EMAIL);+ expect(decoded.authTokenType).toBe(AuthTokenType.ACCESS_TOKEN);+ });+});diff --git a/backend/e2e-test/routes/v3/auth-email-signup.spec.ts b/backend/e2e-test/routes/v3/auth-email-signup.spec.tsnew file mode 100644index 0000000000..50a746adfa--- /dev/null+++ b/backend/e2e-test/routes/v3/auth-email-signup.spec.ts@@ -0,0 +1,140 @@+import { decode } from "jsonwebtoken";++import { AuthTokenType } from "@app/services/auth/auth-type";++import { TTestSmtpService } from "../../mocks/smtp";++const smtp = () => (globalThis as unknown as { testSmtp: TTestSmtpService }).testSmtp;++describe("Auth Email Signup V3", () => {+ const testEmail = "[email protected]";++ beforeEach(() => {+ smtp().clear();+ });++ test("Begin email signup sends verification code", async () => {+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v3/signup/email/signup",+ body: { email: testEmail }+ });++ expect(res.statusCode).toBe(200);+ const payload = res.json();+ expect(payload.message).toContain(testEmail);++ // Verify email was sent via SMTP mock+ const lastEmail = smtp().getLastEmail();+ expect(lastEmail).toBeDefined();+ expect(lastEmail?.recipients).toContain(testEmail);+ });++ test("Verify email signup with correct code returns signup token", async () => {+ // Step 1: Begin signup+ await testServer.inject({+ method: "POST",+ url: "/api/v3/signup/email/signup",+ body: { email: testEmail }+ });++ // Extract code from SMTP mock+ const lastEmail = smtp().getLastEmail();+ const code = (lastEmail?.substitutions as Record<string, string>)?.code;+ expect(code).toBeDefined();++ // Step 2: Verify+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v3/signup/email/verify",+ body: { email: testEmail, code }+ });++ expect(res.statusCode).toBe(200);+ const payload = res.json();+ expect(payload).toHaveProperty("token");+ expect(payload).toHaveProperty("user");++ // Token should be a signup token+ const decoded = decode(payload.token) as Record<string, unknown>;+ expect(decoded.authTokenType).toBe(AuthTokenType.SIGNUP_TOKEN);+ });++ test("Verify email signup with wrong code fails", async () => {+ // Begin signup first+ await testServer.inject({+ method: "POST",+ url: "/api/v3/signup/email/signup",+ body: { email: testEmail }+ });++ const res = await testServer.inject({+ method: "POST",+ url: "/api/v3/signup/email/verify",+ body: { email: testEmail, code: "000000" }+ });++ expect(res.statusCode).toBeGreaterThanOrEqual(400);+ });++ test("Complete account with valid signup token creates user", async () => {+ const newEmail = "[email protected]";++ // Step 1: Begin signup+ await testServer.inject({+ method: "POST",+ url: "/api/v3/signup/email/signup",+ body: { email: newEmail }+ });++ const signupEmail = smtp().getLastEmail();+ const code = (signupEmail?.substitutions as Record<string, string>)?.code;++ // Step 2: Verify email+ const verifyRes = await testServer.inject({+ method: "POST",+ url: "/api/v3/signup/email/verify",+ body: { email: newEmail, code }+ });+ const { token: signupToken } = verifyRes.json();++ // Step 3: Complete account+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v3/signup/complete-account/signup",+ headers: {+ authorization: `Bearer ${signupToken}`+ },+ body: {+ type: "email",+ email: newEmail,+ firstName: "Test",+ lastName: "Signup",+ password: "testPassword123!",+ organizationName: "Test Org"+ }+ });++ expect(res.statusCode).toBe(200);+ const payload = res.json();+ expect(payload).toHaveProperty("token");+ expect(payload).toHaveProperty("user");+ expect(payload.user.username).toBe(newEmail);+ });++ test("Complete account without signup token fails", async () => {+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v3/signup/complete-account/signup",+ body: {+ type: "email",+ email: "[email protected]",+ firstName: "No",+ lastName: "Token",+ password: "testPassword123!"+ }+ });++ expect(res.statusCode).toBeGreaterThanOrEqual(400);+ });+});diff --git a/backend/e2e-test/routes/v3/auth-idp-attacks.spec.ts b/backend/e2e-test/routes/v3/auth-idp-attacks.spec.tsnew file mode 100644index 0000000000..0b88dc471d--- /dev/null+++ b/backend/e2e-test/routes/v3/auth-idp-attacks.spec.ts@@ -0,0 +1,207 @@+import crypto from "node:crypto";++import { Knex } from "knex";++import { AccessScope, TableName } from "@app/db/schemas";+import { seedData1 } from "@app/db/seed-data";++import { cleanupEmailDomains, seedVerifiedEmailDomain } from "../../testUtils/email-domains";++const ORG_A_ID = seedData1.organization.id;+const ORG_A_DOMAIN = "org-a-domain.local";++const getDb = () => (globalThis as unknown as { testDb: Knex }).testDb;+// eslint-disable-next-line @typescript-eslint/no-explicit-any+const getServices = () => (globalThis as any).testServices;++describe("Auth IdP Attack Vector Tests", () => {+ let orgBId: string;+ const ORG_B_DOMAIN = "org-b-domain.local";+ const createdUserIds: string[] = [];++ beforeAll(async () => {+ const db = getDb();++ await seedVerifiedEmailDomain(ORG_A_ID, ORG_A_DOMAIN, db);++ // Create Org B+ const [orgB] = await db(TableName.Organization)+ .insert({+ name: "Attack Test Org B",+ slug: `attack-test-org-b-${crypto.randomUUID().slice(0, 8)}`+ })+ .returning("*");+ orgBId = orgB.id;++ await seedVerifiedEmailDomain(orgBId, ORG_B_DOMAIN, db);+ });++ afterAll(async () => {+ const db = getDb();++ if (createdUserIds.length > 0) {+ await db(TableName.UserAliases).whereIn("userId", createdUserIds).del();+ await db(TableName.Membership).whereIn("actorUserId", createdUserIds).del();+ await db(TableName.Users).whereIn("id", createdUserIds).where("id", "!=", seedData1.id).del();+ }++ await cleanupEmailDomains(ORG_A_ID, db);+ await cleanupEmailDomains(orgBId, db);+ await db(TableName.Organization).where({ id: orgBId }).del();+ });++ describe("Cross-Org Domain Attacks", () => {+ test("SAML login to Org-A with Org-B's verified domain email throws", async () => {+ await expect(+ getServices().saml.samlLogin({+ externalId: `cross-org-${crypto.randomUUID()}`,+ email: `attacker@${ORG_B_DOMAIN}`,+ firstName: "Attacker",+ lastName: "User",+ authProvider: "okta-saml",+ orgId: ORG_A_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ })+ ).rejects.toThrow(/domain/i);+ });++ test("SAML login with completely unverified domain email throws", async () => {+ await expect(+ getServices().saml.samlLogin({+ externalId: `unverified-${crypto.randomUUID()}`,+ email: "[email protected]",+ firstName: "Unverified",+ lastName: "User",+ authProvider: "okta-saml",+ orgId: ORG_A_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ })+ ).rejects.toThrow(/domain/i);+ });++ test("OIDC login to Org-A with Org-B's verified domain email throws", async () => {+ await expect(+ getServices().oidc.oidcLogin({+ externalId: `oidc-cross-org-${crypto.randomUUID()}`,+ email: `oidcattacker@${ORG_B_DOMAIN}`,+ firstName: "OIDC",+ lastName: "Attacker",+ orgId: ORG_A_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ })+ ).rejects.toThrow(/domain/i);+ });++ test("LDAP login to Org-A with Org-B's verified domain email throws", async () => {+ await expect(+ getServices().ldap.ldapLogin({+ ldapConfigId: "00000000-0000-0000-0000-000000000000",+ externalId: `ldap-cross-org-${crypto.randomUUID()}`,+ username: `ldapattacker@${ORG_B_DOMAIN}`,+ email: `ldapattacker@${ORG_B_DOMAIN}`,+ firstName: "LDAP",+ lastName: "Attacker",+ orgId: ORG_A_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ })+ ).rejects.toThrow(/domain/i);+ });+ });++ describe("Membership Promotion Security", () => {+ test("New SAML login creates membership as Invited, not Accepted", async () => {+ const externalId = `invite-check-${crypto.randomUUID()}`;+ const email = `invitecheck-${crypto.randomUUID()}@${ORG_A_DOMAIN}`;++ const result = await getServices().saml.samlLogin({+ externalId,+ email,+ firstName: "Invite",+ lastName: "Check",+ authProvider: "okta-saml",+ orgId: ORG_A_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ createdUserIds.push(result.user.id);++ const db = getDb();+ const [membership] = await db(TableName.Membership).where({+ actorUserId: result.user.id,+ scopeOrgId: ORG_A_ID,+ scope: AccessScope.Organization+ });++ expect(membership).toBeDefined();+ expect(membership.status).toBe("invited");+ });++ test("SCIM createScimUser with cross-org domain email throws", async () => {+ const db = getDb();+ // SCIM requires an SSO config to exist (orgAuthMethod is derived from saml_configs/oidc_configs join)+ await db(TableName.SamlConfig)+ .insert({+ orgId: ORG_A_ID,+ authProvider: "okta-saml",+ isActive: true,+ encryptedSamlEntryPoint: Buffer.from("test"),+ encryptedSamlIssuer: Buffer.from("test"),+ encryptedSamlCertificate: Buffer.from("test")+ })+ .onConflict()+ .ignore();+ await db(TableName.Organization).where({ id: ORG_A_ID }).update({ scimEnabled: true });++ try {+ await expect(+ getServices().scim.createScimUser({+ externalId: `scim-cross-${crypto.randomUUID()}`,+ email: `scimattacker@${ORG_B_DOMAIN}`,+ firstName: "SCIM",+ lastName: "Attacker",+ orgId: ORG_A_ID+ })+ ).rejects.toThrow(/domain/i);+ } finally {+ await db(TableName.Organization).where({ id: ORG_A_ID }).update({ scimEnabled: false });+ await db(TableName.SamlConfig).where({ orgId: ORG_A_ID }).del();+ }+ });++ test("SCIM createScimUser with unverified domain email throws", async () => {+ const db = getDb();+ await db(TableName.SamlConfig)+ .insert({+ orgId: ORG_A_ID,+ authProvider: "okta-saml",+ isActive: true,+ encryptedSamlEntryPoint: Buffer.from("test"),+ encryptedSamlIssuer: Buffer.from("test"),+ encryptedSamlCertificate: Buffer.from("test")+ })+ .onConflict()+ .ignore();+ await db(TableName.Organization).where({ id: ORG_A_ID }).update({ scimEnabled: true });++ try {+ await expect(+ getServices().scim.createScimUser({+ externalId: `scim-unverified-${crypto.randomUUID()}`,+ email: "[email protected]",+ firstName: "SCIM",+ lastName: "Unverified",+ orgId: ORG_A_ID+ })+ ).rejects.toThrow(/domain/i);+ } finally {+ await db(TableName.Organization).where({ id: ORG_A_ID }).update({ scimEnabled: false });+ await db(TableName.SamlConfig).where({ orgId: ORG_A_ID }).del();+ }+ });+ });+});diff --git a/backend/e2e-test/routes/v3/auth-idp.spec.ts b/backend/e2e-test/routes/v3/auth-idp.spec.tsnew file mode 100644index 0000000000..a0ea12481a--- /dev/null+++ b/backend/e2e-test/routes/v3/auth-idp.spec.ts@@ -0,0 +1,345 @@+import crypto from "node:crypto";++import { Knex } from "knex";++import { AccessScope, TableName } from "@app/db/schemas";+import { seedData1 } from "@app/db/seed-data";+import { ProviderAuthResult } from "@app/services/auth/auth-type";++import { cleanupEmailDomains, seedVerifiedEmailDomain } from "../../testUtils/email-domains";++const TEST_ORG_ID = seedData1.organization.id;+const TEST_DOMAIN = "testdomain.local";++const getDb = () => (globalThis as unknown as { testDb: Knex }).testDb;+// eslint-disable-next-line @typescript-eslint/no-explicit-any+const getServices = () => (globalThis as any).testServices;++describe("Auth IdP Service-Level Tests", () => {+ const createdUserIds: string[] = [];+ // Use a dummy LDAP config ID — ldapLogin only uses it for group mapping, which we don't test here+ const ldapConfigId = "00000000-0000-0000-0000-000000000000";++ beforeAll(async () => {+ const db = getDb();+ await seedVerifiedEmailDomain(TEST_ORG_ID, TEST_DOMAIN, db);+ });++ afterAll(async () => {+ const db = getDb();++ if (createdUserIds.length > 0) {+ await db(TableName.UserAliases).whereIn("userId", createdUserIds).del();+ await db(TableName.Membership).whereIn("actorUserId", createdUserIds).del();+ await db(TableName.Users).whereIn("id", createdUserIds).where("id", "!=", seedData1.id).del();+ }++ await cleanupEmailDomains(TEST_ORG_ID, db);+ });++ describe("SAML Login", () => {+ test("Creates new user + alias + membership as Invited", async () => {+ const externalId = `saml-ext-${crypto.randomUUID()}`;+ const email = `samluser-${crypto.randomUUID()}@${TEST_DOMAIN}`;++ const result = await getServices().saml.samlLogin({+ externalId,+ email,+ firstName: "SAML",+ lastName: "User",+ authProvider: "okta-saml",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ expect(result.user).toBeDefined();+ createdUserIds.push(result.user.id);++ const db = getDb();+ const [membership] = await db(TableName.Membership).where({+ actorUserId: result.user.id,+ scopeOrgId: TEST_ORG_ID,+ scope: AccessScope.Organization+ });+ expect(membership).toBeDefined();+ expect(membership.status).toBe("invited");+ });++ test("Returns SIGNUP_REQUIRED for new unverified user", async () => {+ const externalId = `saml-ext-${crypto.randomUUID()}`;+ const email = `newuser-${crypto.randomUUID()}@${TEST_DOMAIN}`;++ const result = await getServices().saml.samlLogin({+ externalId,+ email,+ firstName: "New",+ lastName: "User",+ authProvider: "okta-saml",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ expect(result.result).toBe(ProviderAuthResult.SIGNUP_REQUIRED);+ expect(result).toHaveProperty("signupToken");+ createdUserIds.push(result.user.id);+ });++ test("Same externalId reuses existing user", async () => {+ const externalId = `saml-reuse-${crypto.randomUUID()}`;+ const email = `reuse-${crypto.randomUUID()}@${TEST_DOMAIN}`;++ const result1 = await getServices().saml.samlLogin({+ externalId,+ email,+ firstName: "Reuse",+ lastName: "User",+ authProvider: "okta-saml",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });+ createdUserIds.push(result1.user.id);++ const result2 = await getServices().saml.samlLogin({+ externalId,+ email,+ firstName: "Reuse",+ lastName: "User",+ authProvider: "okta-saml",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ expect(result2.user.id).toBe(result1.user.id);+ });++ test("Login without verified domain throws", async () => {+ await expect(+ getServices().saml.samlLogin({+ externalId: `saml-no-domain-${crypto.randomUUID()}`,+ email: "[email protected]",+ firstName: "No",+ lastName: "Domain",+ authProvider: "okta-saml",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ })+ ).rejects.toThrow();+ });+ });++ describe("LDAP Login", () => {+ test("Creates new user + alias", async () => {+ const externalId = `ldap-ext-${crypto.randomUUID()}`;+ const email = `ldapuser-${crypto.randomUUID()}@${TEST_DOMAIN}`;++ const result = await getServices().ldap.ldapLogin({+ ldapConfigId,+ externalId,+ username: email,+ email,+ firstName: "LDAP",+ lastName: "User",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ expect(result).toBeDefined();++ const db = getDb();+ const alias = await db(TableName.UserAliases).where({ externalId, orgId: TEST_ORG_ID }).first();+ expect(alias).toBeDefined();+ if (alias) createdUserIds.push(alias.userId);+ });++ test("Same externalId reuses existing user", async () => {+ const externalId = `ldap-reuse-${crypto.randomUUID()}`;+ const email = `ldapreuse-${crypto.randomUUID()}@${TEST_DOMAIN}`;++ await getServices().ldap.ldapLogin({+ ldapConfigId,+ externalId,+ username: email,+ email,+ firstName: "LDAP",+ lastName: "Reuse",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ const db = getDb();+ const alias1 = await db(TableName.UserAliases).where({ externalId, orgId: TEST_ORG_ID }).first();+ expect(alias1).toBeDefined();+ if (alias1) createdUserIds.push(alias1.userId);++ await getServices().ldap.ldapLogin({+ ldapConfigId,+ externalId,+ username: email,+ email,+ firstName: "LDAP",+ lastName: "Reuse",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ const alias2 = await db(TableName.UserAliases).where({ externalId, orgId: TEST_ORG_ID }).first();+ expect(alias2?.userId).toBe(alias1?.userId);+ });++ test("Login without verified domain throws", async () => {+ await expect(+ getServices().ldap.ldapLogin({+ ldapConfigId,+ externalId: `ldap-no-domain-${crypto.randomUUID()}`,+ username: "[email protected]",+ email: "[email protected]",+ firstName: "No",+ lastName: "Domain",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ })+ ).rejects.toThrow();+ });+ });++ describe("OIDC Login", () => {+ test("Creates new user + alias", async () => {+ const externalId = `oidc-ext-${crypto.randomUUID()}`;+ const email = `oidcuser-${crypto.randomUUID()}@${TEST_DOMAIN}`;++ const result = await getServices().oidc.oidcLogin({+ externalId,+ email,+ firstName: "OIDC",+ lastName: "User",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ expect(result.user).toBeDefined();+ createdUserIds.push(result.user.id);++ const db = getDb();+ const alias = await db(TableName.UserAliases).where({ externalId, orgId: TEST_ORG_ID }).first();+ expect(alias).toBeDefined();+ });++ test("Returns SIGNUP_REQUIRED for new user", async () => {+ const externalId = `oidc-signup-${crypto.randomUUID()}`;+ const email = `oidcsignup-${crypto.randomUUID()}@${TEST_DOMAIN}`;++ const result = await getServices().oidc.oidcLogin({+ externalId,+ email,+ firstName: "OIDC",+ lastName: "Signup",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ expect(result.result).toBe(ProviderAuthResult.SIGNUP_REQUIRED);+ createdUserIds.push(result.user.id);+ });++ test("Same externalId reuses existing user", async () => {+ const externalId = `oidc-reuse-${crypto.randomUUID()}`;+ const email = `oidcreuse-${crypto.randomUUID()}@${TEST_DOMAIN}`;++ const result1 = await getServices().oidc.oidcLogin({+ externalId,+ email,+ firstName: "OIDC",+ lastName: "Reuse",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });+ createdUserIds.push(result1.user.id);++ const result2 = await getServices().oidc.oidcLogin({+ externalId,+ email,+ firstName: "OIDC",+ lastName: "Reuse",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ expect(result2.user.id).toBe(result1.user.id);+ });++ test("Login without verified domain throws", async () => {+ await expect(+ getServices().oidc.oidcLogin({+ externalId: `oidc-no-domain-${crypto.randomUUID()}`,+ email: "[email protected]",+ firstName: "No",+ lastName: "Domain",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ })+ ).rejects.toThrow();+ });+ });++ describe("OAuth Login", () => {+ test("GitHub OAuth creates new user + alias", async () => {+ const providerUserId = `github-${crypto.randomUUID()}`;+ const email = `githubuser-${crypto.randomUUID()}@${TEST_DOMAIN}`;++ const result = await getServices().login.oauth2Login({+ email,+ firstName: "GitHub",+ lastName: "User",+ authMethod: "github",+ providerUserId,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ expect(result.user).toBeDefined();+ createdUserIds.push(result.user.id);+ });++ test("Same providerUserId reuses existing user", async () => {+ const providerUserId = `github-reuse-${crypto.randomUUID()}`;+ const email = `githubreuse-${crypto.randomUUID()}@${TEST_DOMAIN}`;++ const result1 = await getServices().login.oauth2Login({+ email,+ firstName: "GitHub",+ lastName: "Reuse",+ authMethod: "github",+ providerUserId,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });+ createdUserIds.push(result1.user.id);++ const result2 = await getServices().login.oauth2Login({+ email,+ firstName: "GitHub",+ lastName: "Reuse",+ authMethod: "github",+ providerUserId,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ expect(result2.user.id).toBe(result1.user.id);+ });+ });+});diff --git a/backend/e2e-test/routes/v3/auth-mfa.spec.ts b/backend/e2e-test/routes/v3/auth-mfa.spec.tsnew file mode 100644index 0000000000..69c0afe366--- /dev/null+++ b/backend/e2e-test/routes/v3/auth-mfa.spec.ts@@ -0,0 +1,100 @@+import { decode } from "jsonwebtoken";++import { TableName } from "@app/db/schemas";+import { seedData1 } from "@app/db/seed-data";+import { MfaMethod } from "@app/services/auth/auth-type";++import { TTestSmtpService } from "../../mocks/smtp";+import { loginUser, selectOrg } from "../../testUtils/auth";++describe("Auth MFA V3", () => {+ const smtp = () => (globalThis as unknown as { testSmtp: TTestSmtpService }).testSmtp;+ const db = () => (globalThis as unknown as { testDb: import("knex").Knex }).testDb;++ beforeAll(async () => {+ await db()(TableName.Organization).where({ id: seedData1.organization.id }).update({+ enforceMfa: true+ });+ });++ afterAll(async () => {+ await db()(TableName.Organization).where({ id: seedData1.organization.id }).update({+ enforceMfa: false+ });+ });++ beforeEach(() => {+ smtp().clear();+ });++ test("Select-org with MFA enforced returns MFA token", async () => {+ const { accessToken } = await loginUser(seedData1.email, seedData1.password);++ const { statusCode, payload } = await selectOrg(accessToken, seedData1.organization.id);++ expect(statusCode).toBe(200);+ expect(payload.isMfaEnabled).toBe(true);+ expect(payload.mfaMethod).toBe(MfaMethod.EMAIL);+ expect(payload).toHaveProperty("token");+ });++ test("MFA token contains email claim", async () => {+ const { accessToken } = await loginUser(seedData1.email, seedData1.password);++ const { payload } = await selectOrg(accessToken, seedData1.organization.id);+ const decoded = decode(payload.token) as Record<string, unknown>;++ expect(decoded.email).toBe(seedData1.email);+ });++ test("Verify MFA with correct code succeeds", async () => {+ const { accessToken } = await loginUser(seedData1.email, seedData1.password);++ const { payload: mfaPayload } = await selectOrg(accessToken, seedData1.organization.id);+ expect(mfaPayload.isMfaEnabled).toBe(true);++ // Extract the MFA code from the emailed message+ const lastEmail = smtp().getLastEmail();+ expect(lastEmail).toBeDefined();+ const mfaCode = (lastEmail?.substitutions as Record<string, string>)?.code;+ expect(mfaCode).toBeDefined();++ // Verify MFA+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v2/auth/mfa/verify",+ headers: {+ authorization: `Bearer ${mfaPayload.token}`+ },+ body: {+ mfaToken: mfaCode,+ mfaMethod: MfaMethod.EMAIL+ }+ });++ expect(res.statusCode).toBe(200);+ const verifyPayload = res.json();+ expect(verifyPayload).toHaveProperty("token");+ });++ test("Verify MFA with wrong code fails", async () => {+ const { accessToken } = await loginUser(seedData1.email, seedData1.password);++ const { payload: mfaPayload } = await selectOrg(accessToken, seedData1.organization.id);+ expect(mfaPayload.isMfaEnabled).toBe(true);++ const res = await testServer.inject({+ method: "POST",+ url: "/api/v2/auth/mfa/verify",+ headers: {+ authorization: `Bearer ${mfaPayload.token}`+ },+ body: {+ mfaToken: "000000",+ mfaMethod: MfaMethod.EMAIL+ }+ });++ expect(res.statusCode).toBeGreaterThanOrEqual(400);+ });+});diff --git a/backend/e2e-test/routes/v3/auth-select-org.spec.ts b/backend/e2e-test/routes/v3/auth-select-org.spec.tsnew file mode 100644index 0000000000..2705fc83cb--- /dev/null+++ b/backend/e2e-test/routes/v3/auth-select-org.spec.ts@@ -0,0 +1,44 @@+import { decode } from "jsonwebtoken";++import { seedData1 } from "@app/db/seed-data";++import { loginUser, selectOrg } from "../../testUtils/auth";++describe("Auth Select Organization V3", () => {+ test("Select org with valid token + org membership returns token", async () => {+ const { accessToken } = await loginUser(seedData1.email, seedData1.password);++ const { statusCode, payload } = await selectOrg(accessToken, seedData1.organization.id);++ expect(statusCode).toBe(200);+ expect(payload).toHaveProperty("token");+ expect(payload.isMfaEnabled).toBe(false);+ });++ test("Returned token is org-scoped", async () => {+ const { accessToken } = await loginUser(seedData1.email, seedData1.password);++ const { payload } = await selectOrg(accessToken, seedData1.organization.id);+ const decoded = decode(payload.token) as Record<string, unknown>;++ expect(decoded.organizationId).toBe(seedData1.organization.id);+ });++ test("Select org with non-member org ID returns 403", async () => {+ const { accessToken } = await loginUser(seedData1.email, seedData1.password);++ const { statusCode } = await selectOrg(accessToken, "00000000-0000-0000-0000-000000000099");++ expect(statusCode).toBe(403);+ });++ test("Select org without Authorization header returns 401", async () => {+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v3/auth/select-organization",+ body: { organizationId: seedData1.organization.id }+ });++ expect(res.statusCode).toBe(401);+ });+});diff --git a/backend/e2e-test/routes/v3/auth-signup-sso.spec.ts b/backend/e2e-test/routes/v3/auth-signup-sso.spec.tsnew file mode 100644index 0000000000..e26f303213--- /dev/null+++ b/backend/e2e-test/routes/v3/auth-signup-sso.spec.ts@@ -0,0 +1,165 @@+import crypto from "node:crypto";++import { decode } from "jsonwebtoken";+import { Knex } from "knex";++import { TableName } from "@app/db/schemas";+import { seedData1 } from "@app/db/seed-data";+import { AuthTokenType, ProviderAuthResult } from "@app/services/auth/auth-type";++import { TTestSmtpService } from "../../mocks/smtp";+import { cleanupEmailDomains, seedVerifiedEmailDomain } from "../../testUtils/email-domains";++const getDb = () => (globalThis as unknown as { testDb: Knex }).testDb;+const smtp = () => (globalThis as unknown as { testSmtp: TTestSmtpService }).testSmtp;+// eslint-disable-next-line @typescript-eslint/no-explicit-any+const getServices = () => (globalThis as any).testServices;++const TEST_ORG_ID = seedData1.organization.id;+const TEST_DOMAIN = "sso-signup-test.local";++describe("Auth SSO Signup V3", () => {+ const createdUserIds: string[] = [];++ beforeAll(async () => {+ await seedVerifiedEmailDomain(TEST_ORG_ID, TEST_DOMAIN, getDb());+ });++ afterAll(async () => {+ const db = getDb();+ if (createdUserIds.length > 0) {+ await db(TableName.UserAliases).whereIn("userId", createdUserIds).del();+ await db(TableName.Membership).whereIn("actorUserId", createdUserIds).del();+ await db(TableName.Users).whereIn("id", createdUserIds).where("id", "!=", seedData1.id).del();+ }+ await cleanupEmailDomains(TEST_ORG_ID, db);+ });++ beforeEach(() => {+ smtp().clear();+ });++ test("SAML login for new user returns SIGNUP_REQUIRED with signup token", async () => {+ const email = `sso-new-${crypto.randomUUID()}@${TEST_DOMAIN}`;++ const result = await getServices().saml.samlLogin({+ externalId: `sso-signup-${crypto.randomUUID()}`,+ email,+ firstName: "SSO",+ lastName: "Signup",+ authProvider: "okta-saml",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ expect(result.result).toBe(ProviderAuthResult.SIGNUP_REQUIRED);+ expect(result.signupToken).toBeDefined();+ createdUserIds.push(result.user.id);++ // Verify the signup token is a valid SIGNUP_TOKEN JWT+ const decoded = decode(result.signupToken) as Record<string, unknown>;+ expect(decoded.authTokenType).toBe(AuthTokenType.SIGNUP_TOKEN);+ expect(decoded.userId).toBe(result.user.id);+ });++ test("Email verification code is sent for new SSO user", async () => {+ const email = `sso-verify-${crypto.randomUUID()}@${TEST_DOMAIN}`;++ await getServices().saml.samlLogin({+ externalId: `sso-email-${crypto.randomUUID()}`,+ email,+ firstName: "SSO",+ lastName: "Verify",+ authProvider: "okta-saml",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ // Check that a verification email was sent+ const emails = smtp().getEmails();+ const verificationEmail = emails.find((e) => e.recipients?.includes(email));+ expect(verificationEmail).toBeDefined();+ expect((verificationEmail?.substitutions as Record<string, string>)?.code).toBeDefined();+ });++ test("Complete SSO account with valid alias verification code succeeds", async () => {+ const email = `sso-complete-${crypto.randomUUID()}@${TEST_DOMAIN}`;++ const result = await getServices().saml.samlLogin({+ externalId: `sso-complete-${crypto.randomUUID()}`,+ email,+ firstName: "SSO",+ lastName: "Complete",+ authProvider: "okta-saml",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ expect(result.result).toBe(ProviderAuthResult.SIGNUP_REQUIRED);+ createdUserIds.push(result.user.id);++ // Extract verification code from email+ const emails = smtp().getEmails();+ const verificationEmail = emails.find((e) => e.recipients?.includes(email));+ const code = (verificationEmail?.substitutions as Record<string, string>)?.code;+ expect(code).toBeDefined();++ // Complete account with alias type+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v3/signup/complete-account/signup",+ headers: {+ authorization: `Bearer ${result.signupToken}`+ },+ body: {+ type: "alias",+ code+ }+ });++ expect(res.statusCode).toBe(200);+ const payload = res.json();+ expect(payload).toHaveProperty("token");+ expect(payload).toHaveProperty("user");++ // Verify user is now accepted+ const db = getDb();+ const user = await db(TableName.Users).where({ id: result.user.id }).first();+ expect(user?.isAccepted).toBe(true);+ expect(user?.isEmailVerified).toBe(true);+ });++ test("Complete SSO account with wrong code fails", async () => {+ const email = `sso-wrongcode-${crypto.randomUUID()}@${TEST_DOMAIN}`;++ const result = await getServices().saml.samlLogin({+ externalId: `sso-wrongcode-${crypto.randomUUID()}`,+ email,+ firstName: "SSO",+ lastName: "WrongCode",+ authProvider: "okta-saml",+ orgId: TEST_ORG_ID,+ ip: "127.0.0.1",+ userAgent: "test-agent"+ });++ createdUserIds.push(result.user.id);++ const res = await testServer.inject({+ method: "POST",+ url: "/api/v3/signup/complete-account/signup",+ headers: {+ authorization: `Bearer ${result.signupToken}`+ },+ body: {+ type: "alias",+ code: "000000"+ }+ });++ expect(res.statusCode).toBeGreaterThanOrEqual(400);+ });+});diff --git a/backend/e2e-test/testUtils/auth.ts b/backend/e2e-test/testUtils/auth.tsnew file mode 100644index 0000000000..2591109ca2--- /dev/null+++ b/backend/e2e-test/testUtils/auth.ts@@ -0,0 +1,23 @@+import { extractCookie } from "./cookies";++export const loginUser = async (email: string, password: string) => {+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v3/auth/login",+ body: { email, password }+ });+ expect(res.statusCode).toBe(200);+ const payload = res.json();+ const refreshCookie = extractCookie(res, "jid");+ return { accessToken: payload.accessToken as string, refreshCookie };+};++export const selectOrg = async (accessToken: string, organizationId: string) => {+ const res = await testServer.inject({+ method: "POST",+ url: "/api/v3/auth/select-organization",+ headers: { authorization: `Bearer ${accessToken}` },+ body: { organizationId }+ });+ return { statusCode: res.statusCode, payload: res.json(), res };+};diff --git a/backend/e2e-test/testUtils/cookies.ts b/backend/e2e-test/testUtils/cookies.tsnew file mode 100644index 0000000000..801c417d5a--- /dev/null+++ b/backend/e2e-test/testUtils/cookies.ts@@ -0,0 +1,13 @@+import { type LightMyRequestResponse } from "fastify";++export const extractCookie = (res: LightMyRequestResponse, name: string): string | undefined => {+ const cookies = res.headers["set-cookie"];+ if (!cookies) return undefined;++ const cookieArray = Array.isArray(cookies) ? cookies : [cookies];+ for (const cookie of cookieArray) {+ const match = cookie.match(new RegExp(`^${name}=([^;]+)`));+ if (match) return match[1];+ }+ return undefined;+};diff --git a/backend/e2e-test/testUtils/email-domains.ts b/backend/e2e-test/testUtils/email-domains.tsnew file mode 100644index 0000000000..0c20263b5d--- /dev/null+++ b/backend/e2e-test/testUtils/email-domains.ts@@ -0,0 +1,25 @@+import crypto from "node:crypto";++import { Knex } from "knex";++import { TableName } from "@app/db/schemas";++export const seedVerifiedEmailDomain = async (orgId: string, domain: string, knex: Knex) => {+ const [record] = await knex(TableName.EmailDomains)+ .insert({+ orgId,+ domain: domain.toLowerCase(),+ verificationMethod: "dns-txt",+ verificationCode: crypto.randomBytes(16).toString("hex"),+ verificationRecordName: `_infisical-verification.${domain}`,+ status: "verified",+ verifiedAt: new Date(),+ codeExpiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)+ })+ .returning("*");+ return record;+};++export const cleanupEmailDomains = async (orgId: string, knex: Knex) => {+ await knex(TableName.EmailDomains).where({ orgId }).del();+};diff --git a/backend/e2e-test/vitest-environment-knex.ts b/backend/e2e-test/vitest-environment-knex.tsindex b0d13b8bfb..a1d3b7d49d 100644--- a/backend/e2e-test/vitest-environment-knex.ts+++ b/backend/e2e-test/vitest-environment-knex.ts@@ -98,6 +98,10 @@ export default {// @ts-expect-error typeglobalThis.testServer = server;// @ts-expect-error type+ globalThis.testSmtp = smtp;+ // @ts-expect-error type+ globalThis.testDb = db;+ // @ts-expect-error typeglobalThis.testQueue = queue;// @ts-expect-error typeglobalThis.testSuperAdminDAL = superAdminDAL;diff --git a/backend/src/db/seeds/1-user.ts b/backend/src/db/seeds/1-user.tsindex 9f42ef12b6..ec7e4bab9d 100644--- a/backend/src/db/seeds/1-user.ts+++ b/backend/src/db/seeds/1-user.ts@@ -1,3 +1,4 @@+import bcrypt from "bcrypt";import { Knex } from "knex";import { initializeHsmModule } from "@app/ee/services/hsm/hsm-fns";@@ -56,6 +57,7 @@ export async function seed(knex: Knex): Promise<void> {lastName: "",authMethods: [AuthMethod.EMAIL],isAccepted: true,+ isEmailVerified: true,isMfaEnabled: false,mfaMethods: null,devices: null@@ -63,6 +65,10 @@ export async function seed(knex: Knex): Promise<void> {]).returning("*");+ // Hash password for modern login support (POST /api/v3/auth/login)+ const hashedPassword = await bcrypt.hash(seedData1.password, 10);+ await knex(TableName.Users).where({ id: user.id }).update({ hashedPassword });+const encKeys = await generateUserSrpKeys(seedData1.password);// password: testInfisical@1await knex(TableName.UserEncryptionKey).insert([diff --git a/backend/src/db/seeds/3-project.ts b/backend/src/db/seeds/3-project.tsindex 303ee5bad3..e18d774c88 100644--- a/backend/src/db/seeds/3-project.ts+++ b/backend/src/db/seeds/3-project.ts@@ -141,16 +141,18 @@ const createUserWithGhostUser = async (const user = await userDAL.findUserEncKeyByUserId(userId, knex);- if (!user) {+ if (!user || !user.id) {throw new Error("User not found");}+ const userEnc = await knex(TableName.UserEncryptionKey).where({ userId: user.id }).first();+const [projectAdmin] = assignWorkspaceKeysToMembers({decryptKey: latestKey,userPrivateKey: encKeys.plainPrivateKey,members: [{- userPublicKey: "",+ userPublicKey: userEnc?.publicKey || "",orgMembershipId: userOrgMembershipId}]diff --git a/backend/src/ee/services/license/__mocks__/license-fns.ts b/backend/src/ee/services/license/__mocks__/license-fns.tsindex 2f29e4812a..7ea2ab6c1b 100644--- a/backend/src/ee/services/license/__mocks__/license-fns.ts+++ b/backend/src/ee/services/license/__mocks__/license-fns.ts@@ -19,9 +19,10 @@ export const getDefaultOnPremFeatures = () => {customAlerts: false,auditLogs: false,auditLogsRetentionDays: 0,- samlSSO: false,- scim: false,- ldap: false,+ samlSSO: true,+ oidcSSO: true,+ scim: true,+ ldap: true,groups: false,status: null,trial_end: null,@@ -34,7 +35,8 @@ export const getDefaultOnPremFeatures = () => {enterpriseCertificateSyncs: false,enterpriseAppConnections: true,machineIdentityAuthTemplates: false,- pkiLegacyTemplates: false+ pkiLegacyTemplates: false,+ emailDomainVerification: true};};diff --git a/backend/src/ee/services/license/license-fns.ts b/backend/src/ee/services/license/license-fns.tsindex 19e3ad6f23..66a0bbb0a4 100644--- a/backend/src/ee/services/license/license-fns.ts+++ b/backend/src/ee/services/license/license-fns.ts@@ -78,7 +78,7 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({auditLogsRetentionDays: 0,auditLogStreams: false,auditLogStreamLimit: 3,- samlSSO: true,+ samlSSO: false,enforceGoogleSSO: false,hsm: false,oidcSSO: false,@@ -115,7 +115,7 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({machineIdentityAuthTemplates: false,pkiLegacyTemplates: false,secretShareExternalBranding: false,- emailDomainVerification: true+ emailDomainVerification: false});export const setupLicenseRequestWithStore = (diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex d2b8c8abc8..4f83827f3b 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -3198,6 +3198,12 @@ export const registerRoutes = async (caAutoRenewalQueue});+ // Expose services globally for e2e tests (only available inside the encapsulated plugin context)+ if (process.env.NODE_ENV === "test") {+ // @ts-expect-error type - expose for e2e test access+ globalThis.testServices = server.services;+ }+const cronJobs: CronJob[] = [];if (appCfg.isProductionMode) {const rateLimitSyncJob = await rateLimitService.initializeBackgroundSync();diff --git a/backend/src/server/routes/v2/user-router.ts b/backend/src/server/routes/v2/user-router.tsindex 56e04b113e..5ca8d9578b 100644--- a/backend/src/server/routes/v2/user-router.ts+++ b/backend/src/server/routes/v2/user-router.ts@@ -386,7 +386,14 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {selectedMfaMethod: z.string().nullable().optional(),isGitHubVerified: z.boolean().nullable().optional(),isGitLabVerified: z.boolean().nullable().optional(),- isGoogleVerified: z.boolean().nullable().optional()+ isGoogleVerified: z.boolean().nullable().optional(),+ encryptedPrivateKey: z.string().nullable().optional(),+ iv: z.string().nullable().optional(),+ tag: z.string().nullable().optional(),+ salt: z.string().nullable().optional(),+ protectedKey: z.string().nullable().optional(),+ protectedKeyIV: z.string().nullable().optional(),+ protectedKeyTag: z.string().nullable().optional()})})}diff --git a/backend/src/services/user/user-dal.ts b/backend/src/services/user/user-dal.tsindex f703b0963e..f9be787027 100644--- a/backend/src/services/user/user-dal.ts+++ b/backend/src/services/user/user-dal.ts@@ -111,8 +111,23 @@ export const userDALFactory = (db: TDbClient) => {const findUserEncKeyByUserId = async (userId: string, tx?: Knex) => {try {- const user = await (tx || db.replicaNode())(TableName.Users).where(`${TableName.Users}.id`, userId).first();- return { ...user, publicKey: "" };+ const user = await (tx || db.replicaNode())(TableName.Users)+ .leftJoin(TableName.UserEncryptionKey, `${TableName.Users}.id`, `${TableName.UserEncryptionKey}.userId`)+ .where(`${TableName.Users}.id`, userId)+ .select(selectAllTableCols(TableName.Users))+ .select(+ db.ref("publicKey").withSchema(TableName.UserEncryptionKey),+ db.ref("iv").withSchema(TableName.UserEncryptionKey),+ db.ref("salt").withSchema(TableName.UserEncryptionKey),+ db.ref("tag").withSchema(TableName.UserEncryptionKey),+ db.ref("protectedKey").withSchema(TableName.UserEncryptionKey),+ db.ref("protectedKeyIV").withSchema(TableName.UserEncryptionKey),+ db.ref("protectedKeyTag").withSchema(TableName.UserEncryptionKey),+ db.ref("encryptedPrivateKey").withSchema(TableName.UserEncryptionKey)+ )+ .first();++ return user;} catch (error) {throw new DatabaseError({ error, name: "Find user enc by user id" });}diff --git a/backend/src/services/user/user-service.ts b/backend/src/services/user/user-service.tsindex c0603b33de..bb1906b1d4 100644--- a/backend/src/services/user/user-service.ts+++ b/backend/src/services/user/user-service.ts@@ -340,7 +340,7 @@ export const userServiceFactory = ({};const getMe = async (userId: string) => {- const user = await userDAL.findById(userId);+ const user = await userDAL.findUserEncKeyByUserId(userId);if (!user) throw new NotFoundError({ message: `User with ID '${userId}' not found`, name: "GetMe" });return {diff --git a/docker-compose.dev.yml b/docker-compose.dev.ymlindex 4a689a497e..d5da211312 100644--- a/docker-compose.dev.yml+++ b/docker-compose.dev.yml@@ -74,6 +74,7 @@ services:POSTGRES_PASSWORD: infisicalPOSTGRES_USER: infisicalPOSTGRES_DB: infisical-test+ command: postgres -c max_locks_per_transaction=512backend:container_name: infisical-dev-api