Skip to content

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

feat: added support to send region to license server

=4416ed85924a
diff --git a/backend/src/services/license-client/license-client-backends.test.ts b/backend/src/services/license-client/license-client-backends.test.ts
new file mode 100644
index 0000000000..a25abd88e3
--- /dev/null
+++ b/backend/src/services/license-client/license-client-backends.test.ts
@@ -0,0 +1,75 @@
+import { afterEach, describe, expect, test, vi } from "vitest";
+
+import { licenseServerBackend } from "./license-client-backends";
+
+vi.mock("@app/lib/logger", () => ({
+ logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() }
+}));
+
+vi.mock("jsonwebtoken", () => ({
+ default: { sign: () => "service-token" }
+}));
+
+const SERVER_URL = "https://license.example.com";
+const ORG_ID = "org-1";
+
+const mockFetchReturning = (body: unknown) =>
+ vi.fn(async () => ({
+ ok: true,
+ status: 200,
+ headers: new Headers(),
+ json: async () => body
+ })) as unknown as typeof fetch;
+
+const readBody = (fetchMock: typeof fetch): Record<string, unknown> =>
+ JSON.parse(vi.mocked(fetchMock).mock.calls[0][1]?.body as string) as Record<string, unknown>;
+
+// Region is insert-only on the license server: it is read only by the call that creates the license,
+// so every license-creating call has to carry this deployment's region or the org is recorded as "us".
+describe("licenseServerBackend region on license-creating calls", () => {
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ });
+
+ test("buyProduct sends the deployment region alongside the payload", async () => {
+ const fetchMock = mockFetchReturning({ outcome: "subscription_updated" });
+ vi.stubGlobal("fetch", fetchMock);
+
+ await licenseServerBackend(SERVER_URL, "key", "eu").buyProduct(ORG_ID, { productId: "boost", plan: "pro" });
+
+ expect(readBody(fetchMock)).toMatchObject({ productId: "boost", plan: "pro", region: "eu" });
+ });
+
+ test("changeCommitments sends the deployment region alongside the payload", async () => {
+ const fetchMock = mockFetchReturning({ outcome: "subscription_updated" });
+ vi.stubGlobal("fetch", fetchMock);
+
+ await licenseServerBackend(SERVER_URL, "key", "eu").changeCommitments(ORG_ID, {
+ productId: "boost",
+ dimensions: []
+ });
+
+ expect(readBody(fetchMock)).toMatchObject({ productId: "boost", region: "eu" });
+ });
+
+ test("startTrial sends the deployment region alongside the payload", async () => {
+ const fetchMock = mockFetchReturning({ outcome: "trial_started" });
+ vi.stubGlobal("fetch", fetchMock);
+
+ await licenseServerBackend(SERVER_URL, "key", "eu").startTrial(ORG_ID, {
+ productKey: "boost",
+ planKey: "pro"
+ });
+
+ expect(readBody(fetchMock)).toMatchObject({ product_key: "boost", plan_key: "pro", region: "eu" });
+ });
+
+ test("omits region entirely when the deployment has none configured", async () => {
+ const fetchMock = mockFetchReturning({ outcome: "subscription_updated" });
+ vi.stubGlobal("fetch", fetchMock);
+
+ await licenseServerBackend(SERVER_URL, "key").buyProduct(ORG_ID, { productId: "boost", plan: "pro" });
+
+ expect(readBody(fetchMock)).not.toHaveProperty("region");
+ });
+});
diff --git a/backend/src/services/license-client/license-client-backends.ts b/backend/src/services/license-client/license-client-backends.ts
index 7a8345ec1f..42a3fff423 100644
--- a/backend/src/services/license-client/license-client-backends.ts
+++ b/backend/src/services/license-client/license-client-backends.ts
@@ -224,7 +224,7 @@ export const licenseServerBackend = (
const res = await fetch(url, {
method: "POST",
headers: { Authorization: `Bearer ${mintServiceToken(signingKey)}`, "Content-Type": "application/json" },
- body: JSON.stringify(payload),
+ body: JSON.stringify({ ...payload, region }),
redirect: "manual"
});
await throwIfResponseError(res);
@@ -281,7 +281,7 @@ export const licenseServerBackend = (
const res = await fetch(url, {
method: "PUT",
headers: { Authorization: `Bearer ${mintServiceToken(signingKey)}`, "Content-Type": "application/json" },
- body: JSON.stringify(payload),
+ body: JSON.stringify({ ...payload, region }),
redirect: "manual"
});
await throwIfResponseError(res);
@@ -300,7 +300,8 @@ export const licenseServerBackend = (
email: payload.email,
name: payload.name,
declaredUsage: payload.declaredUsage,
- returnUrl: payload.returnUrl
+ returnUrl: payload.returnUrl,
+ region
}),
redirect: "manual"
});