mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 14:05:49 +00:00
test(browser): sharpen HAR malformed input and producer guard checks (#12805)
* test(har): sharpen producer admission checks * test(browser): construct empty HAR failure markers explicitly
This commit is contained in:
1 parent
c94f275667
commit
9ab18ba1da
2 files changed
+29
-33
No files matched your search
@@ -70,7 +70,7 @@ it.each([
|
||||
it.each([
|
||||
"other-producer",
|
||||
"other-version",
|
||||
"successful-response",
|
||||
"empty-failure",
|
||||
"missing-failure",
|
||||
"invalid-duration",
|
||||
])("keeps timing validation for %s", (variant) => {
|
||||
@@ -78,12 +78,15 @@ it.each([
|
||||
const failed = fixture.log.entries[1]!;
|
||||
if (variant === "other-producer") fixture.log.creator.name = "unknown";
|
||||
if (variant === "other-version") fixture.log.creator.version = "unknown";
|
||||
if (variant === "successful-response") {
|
||||
failed.response.status = 200;
|
||||
Reflect.deleteProperty(failed.response, "_failureText");
|
||||
}
|
||||
if (variant === "empty-failure")
|
||||
Object.assign(failed.response, { _failureText: "" });
|
||||
if (variant === "missing-failure")
|
||||
Reflect.deleteProperty(failed.response, "_failureText");
|
||||
if (variant === "invalid-duration") failed.timings.send = -2;
|
||||
expect(() => decodeHarCapture(JSON.stringify(fixture), [])).toThrow();
|
||||
expect(() => decodeHarCapture(JSON.stringify(fixture), [])).toThrow(
|
||||
expect.objectContaining({
|
||||
failure: expect.objectContaining({ kind: "malformed" }),
|
||||
pointer: "/log/entries/1/timings/send",
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -49,13 +49,7 @@ it("validates malformed timings before excluding an explicitly sensitive propert
|
||||
expect(() => decodeHarCapture(text, ["timings"])).toThrow(CaptureFormatError);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ cache: null },
|
||||
{ cache: false },
|
||||
{ cache: 0 },
|
||||
{ cache: "cache" },
|
||||
{ cache: [] },
|
||||
])("rejects a non-object HAR cache: $cache", ({ cache }) => {
|
||||
it.each([null, false, []])("rejects a non-object HAR cache: %j", (cache) => {
|
||||
const fixture = historicalHar();
|
||||
const entry = fixture.log.entries[0]!;
|
||||
expect(() =>
|
||||
@@ -287,7 +281,6 @@ it("does not decode container lookalikes when excluding explicitly sensitive bod
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ values: [] },
|
||||
{ values: ["response"] },
|
||||
{ values: ["content"] },
|
||||
{ values: ["log"] },
|
||||
@@ -444,18 +437,26 @@ it("rejects identical duplicate core fields before schema validation", () => {
|
||||
expect(() => decodeHarCapture(text, [])).toThrow("duplicate");
|
||||
});
|
||||
|
||||
it("names the violated HAR schema constraint without restating capture values", () => {
|
||||
expect(() =>
|
||||
decodeHarCapture(
|
||||
JSON.stringify({
|
||||
log: { creator: { name: "x", version: "1" }, entries: [] },
|
||||
it.each([
|
||||
{
|
||||
log: { creator: { name: "x", version: "1" }, entries: [] },
|
||||
missing: "version",
|
||||
},
|
||||
{ log: { version: "1.2", entries: [] }, missing: "creator" },
|
||||
])(
|
||||
"names a required HAR property $missing without disclosing producer values",
|
||||
({ log, missing }) => {
|
||||
expect(() => decodeHarCapture(JSON.stringify({ log }), [])).toThrow(
|
||||
expect.objectContaining({
|
||||
failure: expect.objectContaining({
|
||||
kind: "malformed",
|
||||
field: "/log",
|
||||
detail: `HAR schema validation failed: required (must have required property '${missing}').`,
|
||||
}),
|
||||
}),
|
||||
[],
|
||||
),
|
||||
).toThrow(
|
||||
"HAR schema validation failed: required (must have required property 'version').",
|
||||
);
|
||||
});
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("preserves prototype-named producer members through the capture boundary", () => {
|
||||
const text = JSON.stringify(historicalHar()).replace(
|
||||
@@ -729,14 +730,6 @@ it("redacts actual authentication fields and explicit binary values while preser
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
"{",
|
||||
'{"log":{},"log":{}}',
|
||||
JSON.stringify({ log: { version: "1.2", entries: [] } }),
|
||||
])("rejects malformed producer data %s", (text) => {
|
||||
expect(() => decodeHarCapture(text, [])).toThrow();
|
||||
});
|
||||
|
||||
it("preserves observed SaveHar null post-data without broadening arbitrary HAR producers", () => {
|
||||
const fixture = historicalHar();
|
||||
const first = fixture.log.entries[0];
|
||||
|
||||
Reference in new issue
Block a user