17 lines
1.7 KiB
JavaScript
17 lines
1.7 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import crypto from "node:crypto";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
const report = JSON.parse(fs.readFileSync(path.join(root, "tests/golden/M13-01F/malicious-report.json"), "utf8"));
|
|
const manifest = JSON.parse(fs.readFileSync(path.join(root, "tests/golden/M13-01F/manifest.json"), "utf8"));
|
|
assert.deepEqual({ schemaVersion: manifest.schemaVersion, task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask }, { schemaVersion: 1, task: "M13-01F", parentTask: "M13-01E", nextTask: "M13-02A" });
|
|
const fixturePath = path.join(root, "tests/files/web/m13_malicious_script_v1", report.fixture.name);
|
|
assert.deepEqual({ schemaVersion: report.schemaVersion, task: report.task, operation: report.operation, nextTask: report.nextTask }, { schemaVersion: 1, task: "M13-01F", operation: "MALICIOUS_SCRIPT_FIXTURE", nextTask: "M13-02A" });
|
|
assert.equal(report.sources.length, 4); assert.equal(report.sources.filter((source) => source.useModule).length, 1); assert.ok(report.sources.every((source) => source.expectedExecution === "BLOCKED"));
|
|
assert.equal(crypto.createHash("sha256").update(fs.readFileSync(fixturePath)).digest("hex"), report.fixture.sha256);
|
|
for (const artifact of Object.values(manifest.artifacts)) assert.equal(crypto.createHash("sha256").update(fs.readFileSync(path.join(root, artifact.path))).digest("hex"), artifact.sha256, `artifact hash mismatch ${artifact.path}`);
|
|
process.stdout.write(`malicious-script-fixture-ok sources=${report.sources.length} module=1 execution=BLOCKED fixtureSha256=${report.fixture.sha256} next=${report.nextTask}\n`);
|