mirror of
https://github.com/morluto/rea.git
synced 2026-11-30 02:17:09 +00:00
test(diagnostics): share invalid inspection input assertions (#14501)
* test(diagnostics): share invalid inspection input assertions * test(diagnostics): keep the PE import fixture independently mergeable
This commit is contained in:
1 parent
d0c51d1fa0
commit
4bcd0af58c
9 files changed
+87
-183
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { expectInvalidInspectionInputs } from "../../../tests/support/expectInvalidInspectionInputs.js";
|
||||
import { lateCancellationEvidence } from "../../../tests/support/lateCancellationEvidence.js";
|
||||
import { createHash } from "node:crypto";
|
||||
import { parseAppleIps } from "../../native/apple/AppleIpsParser.js";
|
||||
@@ -7,7 +8,6 @@ import { AppleIpsService } from "./AppleIpsService.js";
|
||||
import { APPLE_IPS_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import type { AppleIps } from "../../domain/native/appleIps.js";
|
||||
import { ok } from "../../domain/result.js";
|
||||
import { AnalysisInputError } from "../../domain/analysisErrorCore.js";
|
||||
|
||||
const identity = APPLE_IPS_PROVIDER;
|
||||
const bytes = Buffer.from(
|
||||
@@ -117,26 +117,12 @@ it.each([null, { caller: "selected IPS request" }])(
|
||||
},
|
||||
);
|
||||
|
||||
it("rejects a relative path and extra arguments before reading", async () => {
|
||||
let calls = 0;
|
||||
const service = new AppleIpsService({
|
||||
identity,
|
||||
inspect: () => {
|
||||
calls += 1;
|
||||
return Promise.resolve(ok(report));
|
||||
},
|
||||
});
|
||||
const relative = await service.inspect({ path: "report.ips" });
|
||||
const extra = await service.inspect({
|
||||
path: report.artifact.path,
|
||||
extra: true,
|
||||
});
|
||||
expect(relative.ok).toBe(false);
|
||||
expect(extra.ok).toBe(false);
|
||||
if (!relative.ok) expect(relative.error).toBeInstanceOf(AnalysisInputError);
|
||||
if (!extra.ok) expect(extra.error).toBeInstanceOf(AnalysisInputError);
|
||||
expect(calls).toBe(0);
|
||||
});
|
||||
it("rejects a relative path and extra arguments before reading", () =>
|
||||
expectInvalidInspectionInputs(
|
||||
report,
|
||||
"report.ips",
|
||||
(inspect) => new AppleIpsService({ identity, inspect }),
|
||||
));
|
||||
|
||||
it("records the selected report as a file subject", async () => {
|
||||
const result = await new AppleIpsService({
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { expectInvalidInspectionInputs } from "../../../tests/support/expectInvalidInspectionInputs.js";
|
||||
import { parseEvidence } from "../../domain/evidence.js";
|
||||
import { expect, it } from "vitest";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisInputError,
|
||||
AnalysisOutputError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { DWARF_UNITS_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
@@ -40,26 +40,12 @@ const report: DwarfUnitsReport = {
|
||||
],
|
||||
};
|
||||
|
||||
it("rejects a relative path and extra arguments before reading", async () => {
|
||||
let calls = 0;
|
||||
const service = new DwarfUnitsService({
|
||||
identity,
|
||||
inspect: () => {
|
||||
calls += 1;
|
||||
return Promise.resolve(ok(report));
|
||||
},
|
||||
});
|
||||
const relative = await service.inspect({ path: "program" });
|
||||
const extra = await service.inspect({
|
||||
path: report.artifact.path,
|
||||
extra: true,
|
||||
});
|
||||
expect(relative.ok).toBe(false);
|
||||
expect(extra.ok).toBe(false);
|
||||
if (!relative.ok) expect(relative.error).toBeInstanceOf(AnalysisInputError);
|
||||
if (!extra.ok) expect(extra.error).toBeInstanceOf(AnalysisInputError);
|
||||
expect(calls).toBe(0);
|
||||
});
|
||||
it("rejects a relative path and extra arguments before reading", () =>
|
||||
expectInvalidInspectionInputs(
|
||||
report,
|
||||
"program",
|
||||
(inspect) => new DwarfUnitsService({ identity, inspect }),
|
||||
));
|
||||
|
||||
it("records absent debug info for this file", async () => {
|
||||
const result = await new DwarfUnitsService({
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import { expectInvalidInspectionInputs } from "../../../tests/support/expectInvalidInspectionInputs.js";
|
||||
import { lateCancellationEvidence } from "../../../tests/support/lateCancellationEvidence.js";
|
||||
import { expect, it } from "vitest";
|
||||
import { ElfDependenciesService } from "./ElfDependenciesService.js";
|
||||
import { ELF_DEPENDENCIES_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import type { ElfDependencies } from "../../domain/native/elfDependencies.js";
|
||||
import { ok } from "../../domain/result.js";
|
||||
import {
|
||||
AnalysisInputError,
|
||||
AnalysisOutputError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
|
||||
|
||||
const identity = ELF_DEPENDENCIES_PROVIDER;
|
||||
const digest = "a".repeat(64);
|
||||
@@ -47,26 +45,12 @@ const report: ElfDependencies = {
|
||||
],
|
||||
};
|
||||
|
||||
it("rejects a relative path and extra arguments before reading", async () => {
|
||||
let calls = 0;
|
||||
const service = new ElfDependenciesService({
|
||||
identity,
|
||||
inspect: () => {
|
||||
calls += 1;
|
||||
return Promise.resolve(ok(report));
|
||||
},
|
||||
});
|
||||
const relative = await service.inspect({ path: "program" });
|
||||
const extra = await service.inspect({
|
||||
path: report.artifact.path,
|
||||
extra: true,
|
||||
});
|
||||
expect(relative.ok).toBe(false);
|
||||
expect(extra.ok).toBe(false);
|
||||
if (!relative.ok) expect(relative.error).toBeInstanceOf(AnalysisInputError);
|
||||
if (!extra.ok) expect(extra.error).toBeInstanceOf(AnalysisInputError);
|
||||
expect(calls).toBe(0);
|
||||
});
|
||||
it("rejects a relative path and extra arguments before reading", () =>
|
||||
expectInvalidInspectionInputs(
|
||||
report,
|
||||
"program",
|
||||
(inspect) => new ElfDependenciesService({ identity, inspect }),
|
||||
));
|
||||
|
||||
it("records an empty PT_DYNAMIC inventory and its x86_64 architecture", async () => {
|
||||
const result = await new ElfDependenciesService({
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { expectInvalidInspectionInputs } from "../../../tests/support/expectInvalidInspectionInputs.js";
|
||||
import { lateCancellationEvidence } from "../../../tests/support/lateCancellationEvidence.js";
|
||||
import { expect, it } from "vitest";
|
||||
import { ElfNotesService } from "./ElfNotesService.js";
|
||||
@@ -9,7 +10,6 @@ import { parseElfNotesFromHandle } from "../../native/elf/ElfNoteParser.js";
|
||||
import { ok } from "../../domain/result.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisInputError,
|
||||
AnalysisOutputError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { bufferByteSource } from "../../domain/byteSource.js";
|
||||
@@ -28,26 +28,12 @@ const report = await parseElfNotesFromHandle(
|
||||
async () => {},
|
||||
);
|
||||
|
||||
it("rejects a relative path and extra arguments before reading", async () => {
|
||||
let calls = 0;
|
||||
const service = new ElfNotesService({
|
||||
identity,
|
||||
inspect: () => {
|
||||
calls += 1;
|
||||
return Promise.resolve(ok(report));
|
||||
},
|
||||
});
|
||||
const relative = await service.inspect({ path: "app" });
|
||||
const extra = await service.inspect({
|
||||
path: report.artifact.path,
|
||||
extra: true,
|
||||
});
|
||||
expect(relative.ok).toBe(false);
|
||||
expect(extra.ok).toBe(false);
|
||||
if (!relative.ok) expect(relative.error).toBeInstanceOf(AnalysisInputError);
|
||||
if (!extra.ok) expect(extra.error).toBeInstanceOf(AnalysisInputError);
|
||||
expect(calls).toBe(0);
|
||||
});
|
||||
it("rejects a relative path and extra arguments before reading", () =>
|
||||
expectInvalidInspectionInputs(
|
||||
report,
|
||||
"app",
|
||||
(inspect) => new ElfNotesService({ identity, inspect }),
|
||||
));
|
||||
|
||||
it("records the selected ELF and an absent note table", async () => {
|
||||
const result = await new ElfNotesService({
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { expectInvalidInspectionInputs } from "../../../tests/support/expectInvalidInspectionInputs.js";
|
||||
import { lateCancellationEvidence } from "../../../tests/support/lateCancellationEvidence.js";
|
||||
import { expect, it } from "vitest";
|
||||
import { ElfUnwindRangesService } from "./ElfUnwindRangesService.js";
|
||||
@@ -14,10 +15,7 @@ import {
|
||||
elfUnwindSectionlessFixture,
|
||||
} from "../../native/elf/ElfUnwindTables.fixture.js";
|
||||
import { ok } from "../../domain/result.js";
|
||||
import {
|
||||
AnalysisInputError,
|
||||
AnalysisOutputError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
|
||||
import { bufferByteSource } from "../../domain/byteSource.js";
|
||||
|
||||
const identity = ELF_UNWIND_RANGES_PROVIDER;
|
||||
@@ -62,26 +60,12 @@ const accept = async (
|
||||
}).inspect(input);
|
||||
};
|
||||
|
||||
it("rejects a relative path and extra arguments before reading", async () => {
|
||||
let calls = 0;
|
||||
const service = new ElfUnwindRangesService({
|
||||
identity,
|
||||
inspect: () => {
|
||||
calls += 1;
|
||||
return Promise.resolve(ok(report));
|
||||
},
|
||||
});
|
||||
const relative = await service.inspect({ path: "app" });
|
||||
const extra = await service.inspect({
|
||||
path: report.artifact.path,
|
||||
extra: true,
|
||||
});
|
||||
expect(relative.ok).toBe(false);
|
||||
expect(extra.ok).toBe(false);
|
||||
if (!relative.ok) expect(relative.error).toBeInstanceOf(AnalysisInputError);
|
||||
if (!extra.ok) expect(extra.error).toBeInstanceOf(AnalysisInputError);
|
||||
expect(calls).toBe(0);
|
||||
});
|
||||
it("rejects a relative path and extra arguments before reading", () =>
|
||||
expectInvalidInspectionInputs(
|
||||
report,
|
||||
"app",
|
||||
(inspect) => new ElfUnwindRangesService({ identity, inspect }),
|
||||
));
|
||||
|
||||
it("records an absent unwind table for the selected ELF", async () => {
|
||||
const result = await accept(report);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { expectInvalidInspectionInputs } from "../../../tests/support/expectInvalidInspectionInputs.js";
|
||||
import { lateCancellationEvidence } from "../../../tests/support/lateCancellationEvidence.js";
|
||||
import { inspectPeCertificatesInputSchema } from "../../domain/native/peCertificates.js";
|
||||
import {
|
||||
@@ -10,10 +11,7 @@ import { PeCertificatesService } from "./PeCertificatesService.js";
|
||||
import { PE_CERTIFICATES_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import type { PeCertificates } from "../../domain/native/peCertificates.js";
|
||||
import { ok } from "../../domain/result.js";
|
||||
import {
|
||||
AnalysisInputError,
|
||||
AnalysisOutputError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
|
||||
|
||||
const identity = PE_CERTIFICATES_PROVIDER;
|
||||
const input = inspectPeCertificatesInputSchema.parse({
|
||||
@@ -24,26 +22,12 @@ const report = await parsePeCertificateFixture(
|
||||
input,
|
||||
);
|
||||
|
||||
it("rejects a relative path and extra arguments before reading", async () => {
|
||||
let calls = 0;
|
||||
const service = new PeCertificatesService({
|
||||
identity,
|
||||
inspect: () => {
|
||||
calls += 1;
|
||||
return Promise.resolve(ok(report));
|
||||
},
|
||||
});
|
||||
const relative = await service.inspect({ path: "app.exe" });
|
||||
const extra = await service.inspect({
|
||||
path: report.artifact.path,
|
||||
extra: true,
|
||||
});
|
||||
expect(relative.ok).toBe(false);
|
||||
expect(extra.ok).toBe(false);
|
||||
if (!relative.ok) expect(relative.error).toBeInstanceOf(AnalysisInputError);
|
||||
if (!extra.ok) expect(extra.error).toBeInstanceOf(AnalysisInputError);
|
||||
expect(calls).toBe(0);
|
||||
});
|
||||
it("rejects a relative path and extra arguments before reading", () =>
|
||||
expectInvalidInspectionInputs(
|
||||
report,
|
||||
"app.exe",
|
||||
(inspect) => new PeCertificatesService({ identity, inspect }),
|
||||
));
|
||||
|
||||
it("retains a completed observation when the caller cancels as the provider completes", async () => {
|
||||
const evidence = await lateCancellationEvidence(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { bufferByteSource } from "../../domain/byteSource.js";
|
||||
import { lateCancellationEvidence } from "../../../tests/support/lateCancellationEvidence.js";
|
||||
import { expectInvalidInspectionInputs } from "../../../tests/support/expectInvalidInspectionInputs.js";
|
||||
import { createHash } from "node:crypto";
|
||||
import {
|
||||
peImportImage,
|
||||
@@ -15,10 +16,7 @@ import { expect, it } from "vitest";
|
||||
import { PeImportsService } from "./PeImportsService.js";
|
||||
import { PE_IMPORTS_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import { ok } from "../../domain/result.js";
|
||||
import {
|
||||
AnalysisInputError,
|
||||
AnalysisOutputError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
|
||||
|
||||
const identity = PE_IMPORTS_PROVIDER;
|
||||
const path = "/artifacts/app.exe";
|
||||
@@ -33,26 +31,12 @@ const report = await parsePeImportsFromHandle(
|
||||
inspectPeImportsInputSchema.parse({ path }),
|
||||
);
|
||||
|
||||
it("rejects a relative path and extra arguments before reading", async () => {
|
||||
let calls = 0;
|
||||
const service = new PeImportsService({
|
||||
identity,
|
||||
inspect: () => {
|
||||
calls += 1;
|
||||
return Promise.resolve(ok(report));
|
||||
},
|
||||
});
|
||||
const relative = await service.inspect({ path: "app.exe" });
|
||||
const extra = await service.inspect({
|
||||
path: report.artifact.path,
|
||||
extra: true,
|
||||
});
|
||||
expect(relative.ok).toBe(false);
|
||||
expect(extra.ok).toBe(false);
|
||||
if (!relative.ok) expect(relative.error).toBeInstanceOf(AnalysisInputError);
|
||||
if (!extra.ok) expect(extra.error).toBeInstanceOf(AnalysisInputError);
|
||||
expect(calls).toBe(0);
|
||||
});
|
||||
it("rejects a relative path and extra arguments before reading", () =>
|
||||
expectInvalidInspectionInputs(
|
||||
report,
|
||||
"app.exe",
|
||||
(inspect) => new PeImportsService({ identity, inspect }),
|
||||
));
|
||||
|
||||
it.each(["imports", "delay_imports", "examined_dlls"] as const)(
|
||||
"rejects contradictory complete %s coverage",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { expectInvalidInspectionInputs } from "../../../tests/support/expectInvalidInspectionInputs.js";
|
||||
import { lateCancellationEvidence } from "../../../tests/support/lateCancellationEvidence.js";
|
||||
import { expect, it } from "vitest";
|
||||
import { WindowsShortcutService } from "./WindowsShortcutService.js";
|
||||
@@ -6,10 +7,7 @@ import { createHash } from "node:crypto";
|
||||
import { inspectWindowsShortcutInputSchema } from "../../domain/native/windowsShortcut.js";
|
||||
import { parseWindowsShortcut } from "../../native/windows/WindowsShortcutParser.js";
|
||||
import { ok } from "../../domain/result.js";
|
||||
import {
|
||||
AnalysisInputError,
|
||||
AnalysisOutputError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
|
||||
|
||||
const identity = WINDOWS_SHORTCUT_PROVIDER;
|
||||
|
||||
@@ -28,26 +26,12 @@ const report = await parseWindowsShortcut(
|
||||
inspectWindowsShortcutInputSchema.parse({ path }),
|
||||
);
|
||||
|
||||
it("rejects a relative path and extra arguments before reading", async () => {
|
||||
let calls = 0;
|
||||
const service = new WindowsShortcutService({
|
||||
identity,
|
||||
inspect: () => {
|
||||
calls += 1;
|
||||
return Promise.resolve(ok(report));
|
||||
},
|
||||
});
|
||||
const relative = await service.inspect({ path: "shortcut.lnk" });
|
||||
const extra = await service.inspect({
|
||||
path: report.artifact.path,
|
||||
extra: true,
|
||||
});
|
||||
expect(relative.ok).toBe(false);
|
||||
expect(extra.ok).toBe(false);
|
||||
if (!relative.ok) expect(relative.error).toBeInstanceOf(AnalysisInputError);
|
||||
if (!extra.ok) expect(extra.error).toBeInstanceOf(AnalysisInputError);
|
||||
expect(calls).toBe(0);
|
||||
});
|
||||
it("rejects a relative path and extra arguments before reading", () =>
|
||||
expectInvalidInspectionInputs(
|
||||
report,
|
||||
"shortcut.lnk",
|
||||
(inspect) => new WindowsShortcutService({ identity, inspect }),
|
||||
));
|
||||
|
||||
it("records the selected shortcut as a file subject", async () => {
|
||||
const result = await new WindowsShortcutService({
|
||||
|
||||
Reference in new issue
Block a user