refactor(native): isolate signature workflow and evidence classification
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
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");
|
||||
});
|
||||
@@ -388,14 +388,28 @@ describe("native signature posture slice-aware cases", () => {
|
||||
const result = inspectSignatureSchema.parse(signature.value.result);
|
||||
expect(result.verification?.status).toBe("unknown");
|
||||
expect(result.limitations).toContainEqual(
|
||||
expect.stringContaining(
|
||||
"operational failure, not a proven broken signature",
|
||||
),
|
||||
expect.stringContaining("not a proven broken signature"),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("signature architecture coverage", () => {
|
||||
it("does not let uncertain display probes hide definitive verification failure", async () => {
|
||||
const { app, executable } = await fixtureApp(undefined);
|
||||
const signature = await new NativeMacOSProvider(
|
||||
new DefiniteInvalidWithUncertainSlicesRunner(),
|
||||
"darwin",
|
||||
)
|
||||
.createClient(machoTarget(executable, app))
|
||||
.execute("inspect_signature", {});
|
||||
if (!signature.ok) throw signature.error;
|
||||
const result = inspectSignatureSchema.parse(signature.value.result);
|
||||
expect(result.signed).toBe(true);
|
||||
expect(result.verification?.status).toBe("invalid");
|
||||
expect(result.limitations).toContainEqual(
|
||||
expect.stringContaining("could not be classified"),
|
||||
);
|
||||
});
|
||||
it("does not turn inconclusive slice probes into an unsigned claim", async () => {
|
||||
const { app, executable } = await fixtureApp(undefined);
|
||||
const signature = await new NativeMacOSProvider(
|
||||
@@ -606,6 +620,20 @@ class InconclusiveSlicesRunner extends FixtureRunner {
|
||||
}
|
||||
}
|
||||
|
||||
/** Slice display uncertainty and an independently established invalid signature. */
|
||||
class DefiniteInvalidWithUncertainSlicesRunner extends InconclusiveSlicesRunner {
|
||||
override async run(tool: string, arguments_: readonly string[]) {
|
||||
const result = await super.run(tool, arguments_);
|
||||
if (!result.ok || arguments_[0] !== "--verify") return result;
|
||||
const stderr = `${arguments_.at(-1)}: invalid signature\n`;
|
||||
return ok({
|
||||
...result.value,
|
||||
stderr,
|
||||
stderrBytes: Buffer.byteLength(stderr),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** A nested helper whose file name ends in a carriage return. */
|
||||
class CarriageReturnPathRunner extends FixtureRunner {
|
||||
override async run(tool: string, arguments_: readonly string[]) {
|
||||
|
||||
Reference in New Issue
Block a user