mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 11:33:10 +00:00
fix(oci): recognize Docker foreign layers (#15676)
This commit is contained in:
1 parent
3f4e24bced
commit
abada9bc76
2 files changed
+57
No files matched your search
@@ -104,6 +104,7 @@ export const OCI_KNOWN_MEDIA_TYPES = [
|
||||
"application/vnd.docker.container.image.v1+json",
|
||||
"application/vnd.docker.image.rootfs.diff.tar",
|
||||
"application/vnd.docker.image.rootfs.diff.tar.gzip",
|
||||
"application/vnd.docker.image.rootfs.foreign.diff.tar.gzip",
|
||||
] as const;
|
||||
|
||||
const INDEX_MEDIA_TYPES = new Set([
|
||||
|
||||
@@ -273,6 +273,62 @@ it("records a missing blob as a finding", async () => {
|
||||
expect(report.coverage.status).toBe("partial");
|
||||
});
|
||||
|
||||
it("recognizes a Docker foreign layer whose blob is absent", async () => {
|
||||
const root = await createTestTempDirectory("rea-oci-foreign-layer-");
|
||||
const written = await writeOciImageLayoutFixture(root);
|
||||
const parsedManifest = parseOciDigest(written.manifestDigest);
|
||||
const parsedLayer = parseOciDigest(written.layerDigest);
|
||||
if (parsedManifest === undefined || parsedLayer === undefined)
|
||||
throw new Error("expected sha256 fixture digests");
|
||||
const manifestPath = join(
|
||||
root,
|
||||
"blobs",
|
||||
parsedManifest.algorithm,
|
||||
parsedManifest.hex,
|
||||
);
|
||||
const manifest = JSON.parse(await readFile(manifestPath, "utf8")) as {
|
||||
layers: Record<string, unknown>[];
|
||||
};
|
||||
manifest.layers[0] = {
|
||||
...manifest.layers[0],
|
||||
mediaType: "application/vnd.docker.image.rootfs.foreign.diff.tar.gzip",
|
||||
urls: ["https://example.invalid/foreign-layer"],
|
||||
};
|
||||
const manifestJson = `${JSON.stringify(manifest)}\n`;
|
||||
const manifestDigest = await putOciBlob(root, manifestJson);
|
||||
const indexPath = join(root, "index.json");
|
||||
const index = JSON.parse(await readFile(indexPath, "utf8")) as {
|
||||
manifests: Record<string, unknown>[];
|
||||
};
|
||||
index.manifests[0] = {
|
||||
...index.manifests[0],
|
||||
digest: manifestDigest,
|
||||
size: Buffer.byteLength(manifestJson),
|
||||
};
|
||||
await writeFile(indexPath, `${JSON.stringify(index)}\n`);
|
||||
await unlink(join(root, "blobs", parsedLayer.algorithm, parsedLayer.hex));
|
||||
const report = await inspectLayout(root);
|
||||
expect(report.images[0]?.layers[0]).toMatchObject({
|
||||
media_type: "application/vnd.docker.image.rootfs.foreign.diff.tar.gzip",
|
||||
present: false,
|
||||
});
|
||||
expect(report.findings).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
kind: "missing_blob",
|
||||
digest: written.layerDigest,
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(
|
||||
report.findings.some(
|
||||
(finding) =>
|
||||
finding.kind === "unknown_media_type" &&
|
||||
finding.digest === written.layerDigest,
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("records a digest mismatch as a finding", async () => {
|
||||
const root = await createTestTempDirectory("rea-oci-mismatch-");
|
||||
const written = await writeOciImageLayoutFixture(root);
|
||||
|
||||
Reference in new issue
Block a user