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
improvement: add tests and handle error in check
Scott Wilsonfdaf71602abb
diff --git a/backend/src/services/update-check/update-check-fns.test.ts b/backend/src/services/update-check/update-check-fns.test.tsindex 8706ce74c6..7d9272bb63 100644--- a/backend/src/services/update-check/update-check-fns.test.ts+++ b/backend/src/services/update-check/update-check-fns.test.ts@@ -1,4 +1,10 @@-import { isVersionNewer, parseSemanticVersion, TSemanticVersion } from "./update-check-fns";+import {+ isUpdateCheckEnabled,+ isVersionNewer,+ parseSemanticVersion,+ TSemanticVersion,+ TUpdateCheckGateInput+} from "./update-check-fns";const version = (value: string): TSemanticVersion => {const parsed = parseSemanticVersion(value);@@ -56,3 +62,36 @@ describe("isVersionNewer", () => {expect(isVersionNewer(version("0.100.0"), version("0.99.0"))).toBe(true);});});++describe("isUpdateCheckEnabled", () => {+ const connectedSelfHosted: TUpdateCheckGateInput = {+ isInfisicalCloud: false,+ isCloud: false,+ isUpdateCheckDisabled: false,+ hasOfflineLicense: false,+ platformVersion: "0.162.10"+ };++ test("enabled for a standard self-hosted instance with a semver version", () => {+ expect(isUpdateCheckEnabled(connectedSelfHosted)).toBe(true);+ });++ test("disabled on cloud instances", () => {+ expect(isUpdateCheckEnabled({ ...connectedSelfHosted, isInfisicalCloud: true })).toBe(false);+ expect(isUpdateCheckEnabled({ ...connectedSelfHosted, isCloud: true })).toBe(false);+ });++ test("disabled by the DISABLE_UPDATE_CHECK flag", () => {+ expect(isUpdateCheckEnabled({ ...connectedSelfHosted, isUpdateCheckDisabled: true })).toBe(false);+ });++ test("disabled when an offline license is configured", () => {+ expect(isUpdateCheckEnabled({ ...connectedSelfHosted, hasOfflineLicense: true })).toBe(false);+ });++ test("disabled without a comparable platform version", () => {+ expect(isUpdateCheckEnabled({ ...connectedSelfHosted, platformVersion: undefined })).toBe(false);+ // dedicated instances use commit hash versions+ expect(isUpdateCheckEnabled({ ...connectedSelfHosted, platformVersion: "a1b2c3d" })).toBe(false);+ });+});diff --git a/backend/src/services/update-check/update-check-fns.ts b/backend/src/services/update-check/update-check-fns.tsindex 4aa4da7edb..bd2985c724 100644--- a/backend/src/services/update-check/update-check-fns.ts+++ b/backend/src/services/update-check/update-check-fns.ts@@ -17,3 +17,21 @@ export const isVersionNewer = (candidate: TSemanticVersion, current: TSemanticVeif (candidate.minor !== current.minor) return candidate.minor > current.minor;return candidate.patch > current.patch;};++export type TUpdateCheckGateInput = {+ isInfisicalCloud: boolean;+ isCloud: boolean;+ isUpdateCheckDisabled: boolean;+ hasOfflineLicense: boolean;+ platformVersion?: string;+};++// The update check only applies to standard self-hosted instances: cloud deploys+// continuously, dedicated instances use hash versions that cannot be compared, and+// an offline license explicitly signals an intentionally air-gapped instance.+export const isUpdateCheckEnabled = (input: TUpdateCheckGateInput) =>+ !input.isInfisicalCloud &&+ !input.isCloud &&+ !input.isUpdateCheckDisabled &&+ !input.hasOfflineLicense &&+ Boolean(parseSemanticVersion(input.platformVersion));diff --git a/backend/src/services/update-check/update-check-queue.ts b/backend/src/services/update-check/update-check-queue.tsindex 1791af34da..5ef66dc384 100644--- a/backend/src/services/update-check/update-check-queue.ts+++ b/backend/src/services/update-check/update-check-queue.ts@@ -6,7 +6,7 @@ import { request } from "@app/lib/config/request";import { CronJobName, TCronJobFactory } from "@app/lib/cron/cron-job";import { logger } from "@app/lib/logger";-import { isVersionNewer, parseSemanticVersion } from "./update-check-fns";+import { isUpdateCheckEnabled, isVersionNewer, parseSemanticVersion } from "./update-check-fns";const GITHUB_LATEST_RELEASE_URL = "https://api.github.com/repos/Infisical/infisical/releases/latest";@@ -21,17 +21,14 @@ export const updateCheckServiceFactory = ({ cronJob, keyStore }: TUpdateCheckSerconst appCfg = getConfig();const licenseKeyConfig = getLicenseKeyConfig();- const hasOfflineLicense = licenseKeyConfig.isValid && licenseKeyConfig.type === LicenseType.Offline;-- // The update check only applies to standard self-hosted instances: cloud deploys- // continuously, dedicated instances use hash versions that cannot be compared, and- // an offline license explicitly signals an intentionally air-gapped instance.- const isEnabled =- !appCfg.INFISICAL_CLOUD &&- !appCfg.isCloud &&- !appCfg.DISABLE_UPDATE_CHECK &&- !hasOfflineLicense &&- Boolean(parseSemanticVersion(appCfg.INFISICAL_PLATFORM_VERSION));++ const isEnabled = isUpdateCheckEnabled({+ isInfisicalCloud: appCfg.INFISICAL_CLOUD,+ isCloud: appCfg.isCloud,+ isUpdateCheckDisabled: appCfg.DISABLE_UPDATE_CHECK,+ hasOfflineLicense: Boolean(licenseKeyConfig.isValid && licenseKeyConfig.type === LicenseType.Offline),+ platformVersion: appCfg.INFISICAL_PLATFORM_VERSION+ });const refreshLatestVersion = async () => {try {@@ -78,12 +75,19 @@ export const updateCheckServiceFactory = ({ cronJob, keyStore }: TUpdateCheckSer.catch((err) => logger.debug(err, "update-check: failed to refresh latest platform version at boot"));};- // Returns the latest release version when it is newer than the running instance,- // null otherwise (up to date, check disabled, or no data fetched yet).+ // Returns the latest release version when it is newer than the running instance, null+ // otherwise (up to date, check disabled, no data fetched yet, or keystore unavailable).+ // Never throws: the optional indicator must not be able to fail admin config reads.const getAvailableUpdateVersion = async () => {if (!isEnabled) return null;- const latestVersion = await keyStore.getItem(KeyStorePrefixes.UpdateCheckLatestVersion);+ let latestVersion: string | null;+ try {+ latestVersion = await keyStore.getItem(KeyStorePrefixes.UpdateCheckLatestVersion);+ } catch (err) {+ logger.debug(err, "update-check: failed to read latest platform version from the keystore");+ return null;+ }if (!latestVersion) return null;const latest = parseSemanticVersion(latestVersion);