|
9 | 9 | getBinaryCurrentPath, |
10 | 10 | getBinaryShareRoot, |
11 | 11 | getBinaryVersionsDir, |
| 12 | + isValidUpdateTargetVersion, |
12 | 13 | normalizeBinaryVersion, |
13 | 14 | pruneBinaryVersions, |
14 | 15 | readCurrentVersionDir, |
@@ -83,6 +84,27 @@ test("normalizeBinaryVersion strips release-style v prefix", () => { |
83 | 84 | expect(normalizeBinaryVersion(" 0.1.14-channel.1 ")).toBe("0.1.14-channel.1"); |
84 | 85 | }); |
85 | 86 |
|
| 87 | +test("isValidUpdateTargetVersion accepts semver and channel betas", () => { |
| 88 | + expect(isValidUpdateTargetVersion("1.13.0")).toBe(true); |
| 89 | + expect(isValidUpdateTargetVersion("v1.13.0")).toBe(true); |
| 90 | + expect(isValidUpdateTargetVersion("1.4.2-beta.1")).toBe(true); |
| 91 | + expect(isValidUpdateTargetVersion("0.0.0-beta-be3033b-202607311142")).toBe(true); |
| 92 | + expect(isValidUpdateTargetVersion("v0.0.0-beta-be3033b-202607311142")).toBe(true); |
| 93 | + expect(isValidUpdateTargetVersion("latest")).toBe(false); |
| 94 | + expect(isValidUpdateTargetVersion("1.2")).toBe(false); |
| 95 | + expect(isValidUpdateTargetVersion("foo")).toBe(false); |
| 96 | + expect(isValidUpdateTargetVersion("")).toBe(false); |
| 97 | + // Path-traversal / path-separator inputs must never reach versions/<ver>/ |
| 98 | + expect(isValidUpdateTargetVersion("../../../..")).toBe(false); |
| 99 | + expect(isValidUpdateTargetVersion("..\\..\\..")).toBe(false); |
| 100 | + expect(isValidUpdateTargetVersion("1.2.3/../x")).toBe(false); |
| 101 | + expect(isValidUpdateTargetVersion("1.2.3\\..\\x")).toBe(false); |
| 102 | + expect(isValidUpdateTargetVersion("/etc/passwd")).toBe(false); |
| 103 | + expect(isValidUpdateTargetVersion("versions/../../tmp")).toBe(false); |
| 104 | + expect(isValidUpdateTargetVersion("1.2.3/")).toBe(false); |
| 105 | + expect(isValidUpdateTargetVersion("..")).toBe(false); |
| 106 | +}); |
| 107 | + |
86 | 108 | test("resolveBinaryDownloadSpec targets version assets, not latest manifest url", async () => { |
87 | 109 | const version = "0.1.14-channel.1"; |
88 | 110 | const { detectBinaryPlatform } = await import("bailian-cli-core"); |
|
0 commit comments