|
1 | 1 | import { DepGraph } from "@snyk/dep-graph"; |
2 | 2 | import * as plugin from "../../lib"; |
| 3 | +import * as subProcess from "../../lib/sub-process"; |
3 | 4 | import { getFixture } from "../util"; |
4 | 5 |
|
5 | 6 | describe("plugin", () => { |
@@ -91,6 +92,35 @@ describe("plugin", () => { |
91 | 92 | }); |
92 | 93 | }); |
93 | 94 |
|
| 95 | + describe("when scanning a locally loaded image", () => { |
| 96 | + const imageName = "busybox"; |
| 97 | + const imageTag = "latest"; |
| 98 | + const imageNameWithTag = `${imageName}:${imageTag}`; |
| 99 | + |
| 100 | + beforeAll(async () => { |
| 101 | + const fixturePath = getFixture([ |
| 102 | + "../fixtures/docker-archives", |
| 103 | + "skopeo-copy/busybox.tar", |
| 104 | + ]); |
| 105 | + await subProcess.execute("docker", ["load", "--input", fixturePath]); |
| 106 | + }, 10000); // 10s timeout for loading image |
| 107 | + |
| 108 | + afterAll(async () => { |
| 109 | + await subProcess.execute("docker", ["rmi", imageNameWithTag]); |
| 110 | + }); |
| 111 | + |
| 112 | + test("should successfully scan a local image loaded from a tar archive", async () => { |
| 113 | + const pluginResult = await plugin.scan({ path: imageNameWithTag }); |
| 114 | + const depGraph: DepGraph = pluginResult.scanResults[0].facts.find( |
| 115 | + (fact) => fact.type === "depGraph", |
| 116 | + )!.data; |
| 117 | + |
| 118 | + expect(depGraph.rootPkg.name).toEqual(`docker-image|${imageName}`); |
| 119 | + expect(depGraph.rootPkg.version).toEqual(imageTag); |
| 120 | + expect(pluginResult.scanResults[0].identity.type).toEqual("linux"); |
| 121 | + }); |
| 122 | + }); |
| 123 | + |
94 | 124 | test("image pulled by tag has version set", async () => { |
95 | 125 | const imageNameAndTag = `nginx:1.19.0`; |
96 | 126 |
|
|
0 commit comments