Harden proxy segment integrity verification
This commit is contained in:
+20
-7
@@ -25,10 +25,22 @@ describe("integrity", () => {
|
||||
tempDirs.push(dir);
|
||||
const filePath = path.join(dir, "movie.bin");
|
||||
fs.writeFileSync(filePath, Buffer.from("hello"));
|
||||
fs.writeFileSync(path.join(dir, "hash.md5"), "5d41402abc4b2a76b9719d911017c592 movie.bin\n");
|
||||
const result = await validateFileAgainstManifest(filePath, dir);
|
||||
expect(result.ok).toBe(true);
|
||||
});
|
||||
fs.writeFileSync(path.join(dir, "hash.md5"), "5d41402abc4b2a76b9719d911017c592 movie.bin\n");
|
||||
const result = await validateFileAgainstManifest(filePath, dir);
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.checked).toBe(true);
|
||||
});
|
||||
|
||||
it("reports when no checksum was actually available", async () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "rd-int-"));
|
||||
tempDirs.push(dir);
|
||||
const filePath = path.join(dir, "movie.bin");
|
||||
fs.writeFileSync(filePath, Buffer.from("hello"));
|
||||
|
||||
const result = await validateFileAgainstManifest(filePath, dir);
|
||||
|
||||
expect(result).toEqual({ ok: true, checked: false, message: "Kein Hash verfügbar" });
|
||||
});
|
||||
|
||||
it("skips manifest files larger than 5MB", () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "rd-int-"));
|
||||
@@ -76,9 +88,10 @@ describe("integrity", () => {
|
||||
const manifest = readHashManifest(dir);
|
||||
expect(manifest.get("movie.bin")?.algorithm).toBe("md5");
|
||||
|
||||
const result = await validateFileAgainstManifest(filePath, dir);
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.message).toContain("MD5");
|
||||
const result = await validateFileAgainstManifest(filePath, dir);
|
||||
expect(result.ok).toBe(true);
|
||||
expect(result.checked).toBe(true);
|
||||
expect(result.message).toContain("MD5");
|
||||
});
|
||||
|
||||
it("keeps first hash entry when duplicate filename appears across manifests", () => {
|
||||
|
||||
Reference in New Issue
Block a user