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
test(secret-sync): pin getAncestorPaths against malformed paths
Calvinaf3391893fea
diff --git a/backend/src/services/secret-sync/secret-sync-recursive-fns.test.ts b/backend/src/services/secret-sync/secret-sync-recursive-fns.test.tsindex 9f492f19b8..3d9f0cfe5b 100644--- a/backend/src/services/secret-sync/secret-sync-recursive-fns.test.ts+++ b/backend/src/services/secret-sync/secret-sync-recursive-fns.test.ts@@ -54,6 +54,47 @@ describe("getAncestorPaths", () => {expect(getAncestorPaths("/backend/api/v2")).toEqual(["/", "/backend", "/backend/api"]);});+ test("never includes the path itself", () => {+ for (const path of ["/", "/backend", "/backend/api", "/backend/api/v2"]) {+ expect(getAncestorPaths(path)).not.toContain(path);+ }+ });++ test("returns one fewer entry than the path has segments", () => {+ expect(getAncestorPaths("/a")).toHaveLength(1);+ expect(getAncestorPaths("/a/b")).toHaveLength(2);+ expect(getAncestorPaths("/a/b/c")).toHaveLength(3);+ expect(getAncestorPaths("/a/b/c/d")).toHaveLength(4);+ });++ test("treats a trailing slash as the same path", () => {+ expect(getAncestorPaths("/backend/api/")).toEqual(getAncestorPaths("/backend/api"));+ });++ test("tolerates repeated separators", () => {+ expect(getAncestorPaths("/backend//api")).toEqual(getAncestorPaths("/backend/api"));+ });++ test("returns an empty list for inputs that name no folder", () => {+ // The queue passes whatever path the write carried. An empty result must mean+ // "no ancestors to consider", never a lookup for a folder that cannot exist.+ expect(getAncestorPaths("")).toEqual([]);+ expect(getAncestorPaths("//")).toEqual([]);+ });++ test("every returned path is absolute and free of a trailing slash", () => {+ for (const ancestor of getAncestorPaths("/a/b/c/d")) {+ expect(ancestor.startsWith("/")).toBe(true);+ if (ancestor !== "/") expect(ancestor.endsWith("/")).toBe(false);+ }+ });++ test("returns the root exactly once, and only as the first entry", () => {+ const ancestors = getAncestorPaths("/a/b/c");+ expect(ancestors.filter((entry) => entry === "/")).toHaveLength(1);+ expect(ancestors[0]).toBe("/");+ });+test("returns the root for a single-segment path", () => {expect(getAncestorPaths("/backend")).toEqual(["/"]);});