test(oci): share descriptor budget refusal assertions (#15159)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-11-30 06:13:02 +00:00
1 parent 40014da6e8
commit 39fa51184d
1 file changed
+22 -129
+22 -129
View File
@@ -67,6 +67,19 @@ const inspectLayout = async (
}
};
const expectDescriptorBytesLimit = async (root: string) => {
const result = inspectLayout(root, { max_descriptor_bytes: 1024 });
await expect(result).rejects.toBeInstanceOf(ParseFailureError);
await expect(result).rejects.toMatchObject({
failure: {
kind: "limit",
detail:
"OCI image layout retained descriptor text exceeds the 1024-byte budget.",
limit: { name: "max_descriptor_bytes", maximum: 1024 },
},
});
};
it("inventories a single-platform layout and keeps Env values by default", async () => {
const root = await createTestTempDirectory("rea-oci-valid-");
const written = await writeOciImageLayoutFixture(root);
@@ -536,28 +549,7 @@ it("charges each retained annotation record against max_descriptor_bytes", async
annotations[position.toString(36).padStart(2, "0")] = "";
entry.annotations = annotations;
await writeFile(indexPath, `${JSON.stringify(index)}\n`);
const reader = new DirectoryArtifactReader(root);
try {
await expect(
parseOciImageLayout(
reader,
inspectOciImageLayoutInputSchema.parse({
path: root,
max_descriptor_bytes: 1024,
}),
),
).rejects.toSatisfy((cause: unknown) => {
expect(cause).toBeInstanceOf(ParseFailureError);
if (!(cause instanceof ParseFailureError)) return false;
expect(cause.failure).toMatchObject({
kind: "limit",
limit: { name: "max_descriptor_bytes", maximum: 1024 },
});
return true;
});
} finally {
await reader.close();
}
await expectDescriptorBytesLimit(root);
const report = await inspectLayout(root);
expect(report.indexes[0]?.entries[0]?.annotations).toHaveLength(400);
});
@@ -2897,30 +2889,7 @@ it("refuses index entry text that accumulates past max_descriptor_bytes", async
join(root, "index.json"),
`${JSON.stringify({ schemaVersion: 2, mediaType: OCI_INDEX, manifests: nested })}\n`,
);
const reader = new DirectoryArtifactReader(root);
try {
await expect(
parseOciImageLayout(
reader,
inspectOciImageLayoutInputSchema.parse({
path: root,
max_descriptor_bytes: 1024,
}),
),
).rejects.toSatisfy((cause: unknown) => {
expect(cause).toBeInstanceOf(ParseFailureError);
if (!(cause instanceof ParseFailureError)) return false;
expect(cause.failure).toMatchObject({
kind: "limit",
detail:
"OCI image layout retained descriptor text exceeds the 1024-byte budget.",
limit: { name: "max_descriptor_bytes", maximum: 1024 },
});
return true;
});
} finally {
await reader.close();
}
await expectDescriptorBytesLimit(root);
const report = await inspectLayout(root);
expect(report.indexes).toHaveLength(4);
});
@@ -2933,32 +2902,6 @@ it("refuses accepted layer and config text that accumulates past max_descriptor_
const OCI_INDEX = "application/vnd.oci.image.index.v1+json";
const OCI_MANIFEST = "application/vnd.oci.image.manifest.v1+json";
const OCI_LAYER = "application/vnd.oci.image.layer.v1.tar";
const expectDescriptorBytesLimit = async () => {
const reader = new DirectoryArtifactReader(root);
try {
await expect(
parseOciImageLayout(
reader,
inspectOciImageLayoutInputSchema.parse({
path: root,
max_descriptor_bytes: 1024,
}),
),
).rejects.toSatisfy((cause: unknown) => {
expect(cause).toBeInstanceOf(ParseFailureError);
if (!(cause instanceof ParseFailureError)) return false;
expect(cause.failure).toMatchObject({
kind: "limit",
detail:
"OCI image layout retained descriptor text exceeds the 1024-byte budget.",
limit: { name: "max_descriptor_bytes", maximum: 1024 },
});
return true;
});
} finally {
await reader.close();
}
};
const writeManifests = async (bodies: string[]) => {
const manifests = [];
for (const body of bodies)
@@ -2993,7 +2936,7 @@ it("refuses accepted layer and config text that accumulates past max_descriptor_
}),
);
await writeManifests(layerManifests);
await expectDescriptorBytesLimit();
await expectDescriptorBytesLimit(root);
// An accepted config descriptor with a long digest spends it too.
await writeManifests([
@@ -3008,7 +2951,7 @@ it("refuses accepted layer and config text that accumulates past max_descriptor_
layers: [],
}),
]);
await expectDescriptorBytesLimit();
await expectDescriptorBytesLimit(root);
});
it("refuses rejected descriptor text that accumulates past max_descriptor_bytes", async () => {
@@ -3018,32 +2961,6 @@ it("refuses rejected descriptor text that accumulates past max_descriptor_bytes"
const written = await writeOciImageLayoutFixture(root);
const OCI_INDEX = "application/vnd.oci.image.index.v1+json";
const OCI_MANIFEST = "application/vnd.oci.image.manifest.v1+json";
const expectDescriptorBytesLimit = async () => {
const reader = new DirectoryArtifactReader(root);
try {
await expect(
parseOciImageLayout(
reader,
inspectOciImageLayoutInputSchema.parse({
path: root,
max_descriptor_bytes: 1024,
}),
),
).rejects.toSatisfy((cause: unknown) => {
expect(cause).toBeInstanceOf(ParseFailureError);
if (!(cause instanceof ParseFailureError)) return false;
expect(cause.failure).toMatchObject({
kind: "limit",
detail:
"OCI image layout retained descriptor text exceeds the 1024-byte budget.",
limit: { name: "max_descriptor_bytes", maximum: 1024 },
});
return true;
});
} finally {
await reader.close();
}
};
// Rejected manifests[] entries (digest present, mediaType missing) across
// entries and nested indexes accumulate past max_descriptor_bytes.
@@ -3067,7 +2984,7 @@ it("refuses rejected descriptor text that accumulates past max_descriptor_bytes"
join(root, "index.json"),
`${JSON.stringify({ schemaVersion: 2, mediaType: OCI_INDEX, manifests: nested })}\n`,
);
await expectDescriptorBytesLimit();
await expectDescriptorBytesLimit(root);
// Rejected subject, manifest config, and manifest layers[] descriptors with
// large digests also spend max_descriptor_bytes.
@@ -3080,7 +2997,7 @@ it("refuses rejected descriptor text that accumulates past max_descriptor_bytes"
subject: { digest: `sha256:${"s".repeat(1024)}`, size: 1 },
})}\n`,
);
await expectDescriptorBytesLimit();
await expectDescriptorBytesLimit(root);
const emptyConfig = await putOciBlob(root, "{}");
for (const manifestBody of [
@@ -3112,7 +3029,7 @@ it("refuses rejected descriptor text that accumulates past max_descriptor_bytes"
],
})}\n`,
);
await expectDescriptorBytesLimit();
await expectDescriptorBytesLimit(root);
}
// A small rejected entry within max_descriptor_bytes still yields the
@@ -3971,30 +3888,6 @@ it("refuses unknown declared media types that accumulate past max_descriptor_byt
const manifest = JSON.parse(
await readFile(join(root, "blobs", "sha256", hex ?? ""), "utf8"),
) as Record<string, unknown>;
const expectDescriptorBytesLimit = async () => {
const reader = new DirectoryArtifactReader(root);
try {
await expect(
parseOciImageLayout(
reader,
inspectOciImageLayoutInputSchema.parse({
path: root,
max_descriptor_bytes: 1024,
}),
),
).rejects.toSatisfy((cause: unknown) => {
expect(cause).toBeInstanceOf(ParseFailureError);
if (!(cause instanceof ParseFailureError)) return false;
expect(cause.failure).toMatchObject({
kind: "limit",
limit: { name: "max_descriptor_bytes", maximum: 1024 },
});
return true;
});
} finally {
await reader.close();
}
};
// Hash-valid manifests whose own mediaType is a long unknown string are
// quoted in findings, so their declarations spend the budget.
@@ -4014,7 +3907,7 @@ it("refuses unknown declared media types that accumulate past max_descriptor_byt
join(root, "index.json"),
`${JSON.stringify({ schemaVersion: 2, mediaType: OCI_INDEX, manifests })}\n`,
);
await expectDescriptorBytesLimit();
await expectDescriptorBytesLimit(root);
// Nested indexes are charged the same way.
const nested = [];
@@ -4034,7 +3927,7 @@ it("refuses unknown declared media types that accumulate past max_descriptor_byt
join(root, "index.json"),
`${JSON.stringify({ schemaVersion: 2, mediaType: OCI_INDEX, manifests: nested })}\n`,
);
await expectDescriptorBytesLimit();
await expectDescriptorBytesLimit(root);
});
it("accepts a referenced manifest that omits its optional mediaType", async () => {