|
1 | 1 | import { DepGraph } from "@snyk/dep-graph"; |
2 | 2 | import * as plugin from "../../lib"; |
| 3 | +import { getFixture } from "../util"; |
3 | 4 |
|
4 | 5 | describe("plugin", () => { |
| 6 | + describe("image is scanned when no image type is specified", () => { |
| 7 | + it("docker image.tar is scanned successfully when image type is not specified", async () => { |
| 8 | + const fixturePath = getFixture([ |
| 9 | + "../fixtures/docker-archives", |
| 10 | + "alpine-arm64.tar", |
| 11 | + ]); |
| 12 | + const imagePath = `${fixturePath}`; |
| 13 | + |
| 14 | + const pluginResult = await plugin.scan({ |
| 15 | + path: imagePath, |
| 16 | + }); |
| 17 | + const depGraph: DepGraph = pluginResult.scanResults[0].facts.find( |
| 18 | + (fact) => fact.type === "depGraph", |
| 19 | + )!.data; |
| 20 | + }); |
| 21 | + |
| 22 | + it("kaniko image.tar is scanned successfully when image type is not specified", async () => { |
| 23 | + const fixturePath = getFixture([ |
| 24 | + "../fixtures/kaniko-archives", |
| 25 | + "kaniko-busybox.tar", |
| 26 | + ]); |
| 27 | + const imagePath = `${fixturePath}`; |
| 28 | + |
| 29 | + const pluginResult = await plugin.scan({ |
| 30 | + path: imagePath, |
| 31 | + }); |
| 32 | + const depGraph: DepGraph = pluginResult.scanResults[0].facts.find( |
| 33 | + (fact) => fact.type === "depGraph", |
| 34 | + )!.data; |
| 35 | + }); |
| 36 | + it("oci image.tar is scanned successfully when image type is not specified", async () => { |
| 37 | + const fixturePath = getFixture([ |
| 38 | + "../fixtures/docker-oci-archives", |
| 39 | + "busybox.amd64.tar", |
| 40 | + ]); |
| 41 | + const imagePath = `${fixturePath}`; |
| 42 | + |
| 43 | + const pluginResult = await plugin.scan({ |
| 44 | + path: imagePath, |
| 45 | + }); |
| 46 | + const depGraph: DepGraph = pluginResult.scanResults[0].facts.find( |
| 47 | + (fact) => fact.type === "depGraph", |
| 48 | + )!.data; |
| 49 | + }); |
| 50 | + |
| 51 | + it("fails to extract the archive when the archive type is not supported", async () => { |
| 52 | + const fixturePath = getFixture([ |
| 53 | + "../fixtures/docker-oci-archives", |
| 54 | + "unsupported-image.tar", |
| 55 | + ]); |
| 56 | + const imagePath = `${fixturePath}`; |
| 57 | + |
| 58 | + await expect( |
| 59 | + plugin.scan({ |
| 60 | + path: imagePath, |
| 61 | + }), |
| 62 | + ).rejects.toThrow( |
| 63 | + "Unsupported archive type. Please use a Docker archive, OCI image layout, or Kaniko-compatible tarball.", |
| 64 | + ); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
5 | 68 | describe("docker-archive image type throws on bad files", () => { |
6 | 69 | test("throws when a file does not exists", async () => { |
7 | 70 | const path = "docker-archive:missing-path"; |
|
0 commit comments