Skip to content

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

feat(license): add tests and implementation for self-hosted license base functionality

Victor Hugo dos Santos2264911f40c9
diff --git a/backend/src/ee/services/license/self-hosted-license-base.test.ts b/backend/src/ee/services/license/self-hosted-license-base.test.ts
new file mode 100644
index 0000000000..4b970217f0
--- /dev/null
+++ b/backend/src/ee/services/license/self-hosted-license-base.test.ts
@@ -0,0 +1,33 @@
+import { projectV2ToFeatureSet } from "@app/services/license-client/entitlement-projection";
+import { TEntitlementsResponse } from "@app/services/license-client/license-client-types";
+
+import { getDefaultOnPremFeatures } from "./license-fns";
+import { withSelfHostedLicenseBase } from "./self-hosted-license-base";
+
+const entitlements = (features: TEntitlementsResponse["features"]) =>
+ ({ slug: "enterprise", features, products: [] }) as unknown as TEntitlementsResponse;
+
+describe("withSelfHostedLicenseBase", () => {
+ test("a v1 key without maxCas leaves CAs uncapped instead of the free tier's single CA", () => {
+ const features = { maxInternalCas: 10 } as Partial<ReturnType<typeof getDefaultOnPremFeatures>>;
+ const plan = { ...withSelfHostedLicenseBase(getDefaultOnPremFeatures()), ...features };
+ expect(plan.maxCas).toBeNull();
+ expect(plan.maxInternalCas).toBe(10);
+ });
+
+ test("a v1 key that sets maxCas keeps it", () => {
+ const plan = { ...withSelfHostedLicenseBase(getDefaultOnPremFeatures()), maxCas: 3 };
+ expect(plan.maxCas).toBe(3);
+ });
+
+ test("v2 entitlements without max_cas leave CAs uncapped; with it, the cap applies", () => {
+ const base = withSelfHostedLicenseBase(getDefaultOnPremFeatures());
+ expect(projectV2ToFeatureSet(base, entitlements({})).maxCas).toBeNull();
+ expect(projectV2ToFeatureSet(base, entitlements({ max_cas: { value: 4 } })).maxCas).toBe(4);
+ });
+
+ test("the defaults other paths use keep the free tier's single CA", () => {
+ expect(getDefaultOnPremFeatures().maxCas).toBe(1);
+ expect(projectV2ToFeatureSet(getDefaultOnPremFeatures(), entitlements({})).maxCas).toBe(1);
+ });
+});
diff --git a/backend/src/ee/services/license/self-hosted-license-base.ts b/backend/src/ee/services/license/self-hosted-license-base.ts
new file mode 100644
index 0000000000..49ab755b10
--- /dev/null
+++ b/backend/src/ee/services/license/self-hosted-license-base.ts
@@ -0,0 +1,6 @@
+import { TFeatureSet } from "./license-types";
+
+export const withSelfHostedLicenseBase = (defaults: TFeatureSet): TFeatureSet => ({
+ ...defaults,
+ maxCas: null
+});
diff --git a/backend/src/services/certificate-authority/certificate-authority-dal.ts b/backend/src/services/certificate-authority/certificate-authority-dal.ts
index 077c661b5b..b37d4e4372 100644
--- a/backend/src/services/certificate-authority/certificate-authority-dal.ts
+++ b/backend/src/services/certificate-authority/certificate-authority-dal.ts
@@ -397,9 +397,9 @@ export const certificateAuthorityDALFactory = (db: TDbClient) => {
}
};
- // Every CA type across the org tree (orgId null: the whole instance). Counting all types rather than
- // INTERNAL + ACME behaves identically, since tiers that set maxCas cannot create the others
- // (pkiEnterpriseCaIntegrations blocks them) and is simpler.
+ // Every CA type across the org tree (orgId null: the whole instance): maxCas caps internal, ACME and
+ // external CAs together. ACME CAs need no extra entitlement; external ones need
+ // pkiEnterpriseCaIntegrations.
const countCasByOrgId = async (orgId: string | null, tx?: Knex) => {
try {
const query = (tx || db.replicaNode())(TableName.CertificateAuthority)
diff --git a/frontend/src/pages/organization/BillingV2Page/billing-v2-offline-usage.test.ts b/frontend/src/pages/organization/BillingV2Page/billing-v2-offline-usage.test.ts
index 8baefdd8f2..f1eef5994e 100644
--- a/frontend/src/pages/organization/BillingV2Page/billing-v2-offline-usage.test.ts
+++ b/frontend/src/pages/organization/BillingV2Page/billing-v2-offline-usage.test.ts
@@ -13,7 +13,6 @@ import {
const plan = (overrides: Partial<OfflineUsagePlan> = {}): OfflineUsagePlan => ({
slug: SubscriptionPlanTypes.Enterprise,
identityLimit: null as unknown as number,
- maxCas: null,
maxInternalCas: null,
maxCertificates: null,
maxWildcardCertificates: null,
@@ -49,12 +48,11 @@ describe("resolveOfflineLimit", () => {
expect(resolveOfflineLimit(D.Identities, plan({ enforceIdentityLimit: true }))).toBeNull();
});
- it("uses maxInternalCas for internal CAs, falling back to maxCas only when it is tighter", () => {
+ it("pairs the internal-CA count with maxInternalCas only, never the all-types maxCas", () => {
expect(resolveOfflineLimit(D.InternalCas, plan({ maxInternalCas: 10 }))).toBe(10);
- expect(resolveOfflineLimit(D.InternalCas, plan({ maxCas: 1 }))).toBe(1);
- // Both set: the backend honours the larger as the all-types cap, so maxInternalCas binds.
- expect(resolveOfflineLimit(D.InternalCas, plan({ maxCas: 3, maxInternalCas: 10 }))).toBe(10);
- expect(resolveOfflineLimit(D.InternalCas, plan({ maxCas: 10, maxInternalCas: 3 }))).toBe(3);
+ expect(
+ resolveOfflineLimit(D.InternalCas, { ...plan(), maxCas: 1 } as OfflineUsagePlan)
+ ).toBeNull();
expect(resolveOfflineLimit(D.InternalCas, plan())).toBeNull();
});
@@ -74,7 +72,6 @@ describe("resolveOfflineLimit", () => {
const capped = plan({
identityLimit: 1,
enforceIdentityLimit: true,
- maxCas: 1,
maxInternalCas: 1,
maxCertificates: 1,
maxWildcardCertificates: 1
diff --git a/frontend/src/pages/organization/BillingV2Page/billing-v2-offline-usage.ts b/frontend/src/pages/organization/BillingV2Page/billing-v2-offline-usage.ts
index 4093a03e95..585ec0c593 100644
--- a/frontend/src/pages/organization/BillingV2Page/billing-v2-offline-usage.ts
+++ b/frontend/src/pages/organization/BillingV2Page/billing-v2-offline-usage.ts
@@ -62,7 +62,6 @@ export type OfflineUsagePlan = Pick<
| "slug"
| "identityLimit"
| "enforceIdentityLimit"
- | "maxCas"
| "maxInternalCas"
| "maxCertificates"
| "maxWildcardCertificates"
@@ -71,12 +70,6 @@ export type OfflineUsagePlan = Pick<
const asCap = (value: number | null | undefined) => (typeof value === "number" ? value : null);
-const effectiveMaxCas = (plan: OfflineUsagePlan) => {
- const maxCas = asCap(plan.maxCas);
- const maxInternalCas = asCap(plan.maxInternalCas);
- return maxCas !== null && maxInternalCas !== null ? Math.max(maxCas, maxInternalCas) : maxCas;
-};
-
export const resolveOfflineLimit = (
key: BillingV2BreakdownDimension,
plan: OfflineUsagePlan
@@ -85,12 +78,8 @@ export const resolveOfflineLimit = (
case BillingV2BreakdownDimension.Identities:
if (plan.slug === SubscriptionPlanTypes.Enterprise && !plan.enforceIdentityLimit) return null;
return plan.identityLimit || null;
- case BillingV2BreakdownDimension.InternalCas: {
- const caps = [asCap(plan.maxInternalCas), effectiveMaxCas(plan)].filter(
- (cap): cap is number => cap !== null
- );
- return caps.length > 0 ? Math.min(...caps) : null;
- }
+ case BillingV2BreakdownDimension.InternalCas:
+ return asCap(plan.maxInternalCas);
case BillingV2BreakdownDimension.ActiveCerts:
return asCap(plan.maxCertificates);
case BillingV2BreakdownDimension.WildcardCerts: