87 lines
2.9 KiB
TypeScript
87 lines
2.9 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import { signatureVerification } from "../../../../src/native/CodesignVerification.js";
|
|
import { NativeFixtureRunner } from "../../../fixtures/nativeCommands.js";
|
|
|
|
it.each(["permission denied", "I/O error", "EACCES"])(
|
|
"does not classify echoed pathname %s as an I/O failure",
|
|
async (text) => {
|
|
const path = `/Applications/${text}.app`;
|
|
const capture = await new NativeFixtureRunner().run("codesign", [
|
|
"--verify",
|
|
path,
|
|
]);
|
|
if (!capture.ok) throw capture.error;
|
|
const observed = signatureVerification(
|
|
{
|
|
...capture.value,
|
|
exitCode: 1,
|
|
stderr: `${path}: a sealed resource is missing or invalid\n`,
|
|
},
|
|
path,
|
|
false,
|
|
);
|
|
expect(observed.status).toBe("invalid");
|
|
expect(observed.diagnostics).toEqual([
|
|
`${path}: a sealed resource is missing or invalid`,
|
|
]);
|
|
},
|
|
);
|
|
|
|
it("keeps operational, unsigned, definite invalid and unrecognized failures distinct", async () => {
|
|
const path = "/Applications/Fixture.app";
|
|
const capture = await new NativeFixtureRunner().run("codesign", [
|
|
"--verify",
|
|
path,
|
|
]);
|
|
if (!capture.ok) throw capture.error;
|
|
const status = (reason: string, unsigned = false) =>
|
|
signatureVerification(
|
|
{ ...capture.value, exitCode: 1, stderr: `${path}: ${reason}\n` },
|
|
path,
|
|
unsigned,
|
|
).status;
|
|
expect(status("permission denied")).toBe("unknown");
|
|
expect(status("I/O error")).toBe("unknown");
|
|
expect(status("invalid signature")).toBe("invalid");
|
|
expect(status("code object is not signed at all", true)).toBe("unsigned");
|
|
expect(status("code object is not signed at all")).toBe("invalid");
|
|
expect(status("unrecognized failure")).toBe("unknown");
|
|
});
|
|
|
|
it("excludes complete selected paths with embedded newlines before classifying reasons", async () => {
|
|
const path =
|
|
"/Applications/permission denied\ncode object is not signed at all\nFixture.app";
|
|
const capture = await new NativeFixtureRunner().run("codesign", [
|
|
"--verify",
|
|
path,
|
|
]);
|
|
if (!capture.ok) throw capture.error;
|
|
const result = signatureVerification(
|
|
{ ...capture.value, exitCode: 1, stderr: `${path}: invalid signature\n` },
|
|
path,
|
|
false,
|
|
);
|
|
expect(result.status).toBe("invalid");
|
|
expect(result.diagnostics.join("\n")).toContain(path);
|
|
});
|
|
|
|
it("preserves definitive invalidity when other components have operational failures", async () => {
|
|
const path = "/Applications/Fixture.app";
|
|
const capture = await new NativeFixtureRunner().run("codesign", [
|
|
"--verify",
|
|
path,
|
|
]);
|
|
if (!capture.ok) throw capture.error;
|
|
const observed = signatureVerification(
|
|
{
|
|
...capture.value,
|
|
exitCode: 1,
|
|
stderr: `${path}/Contents/Helpers/one: permission denied\n${path}/Contents/Helpers/two: invalid signature\n`,
|
|
},
|
|
path,
|
|
false,
|
|
);
|
|
expect(observed.status).toBe("invalid");
|
|
expect(observed.diagnostics).toHaveLength(2);
|
|
});
|