Skip to content

Commit 9dd589a

Browse files
chore: added extra coverage for oci-archive
1 parent a9c04c6 commit 9dd589a

File tree

3 files changed

+108
-4
lines changed

3 files changed

+108
-4
lines changed
8.2 KB
Binary file not shown.

test/system/experimental.test.ts

+54-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { test } from "tap";
44
import * as plugin from "../../lib";
55

66
function getFixture(fixturePath): string {
7-
return path.join(__dirname, "../fixtures/docker-archives", fixturePath);
7+
return path.join(__dirname, "../fixtures", fixturePath);
88
}
99

1010
test("docker-archive image type can be scanned", async (t) => {
11-
const fixturePath = getFixture("docker-save/nginx.tar");
11+
const fixturePath = getFixture("docker-archives/docker-save/nginx.tar");
1212
const imageNameAndTag = `docker-archive:${fixturePath}`;
1313

1414
const dockerfile = undefined;
@@ -83,6 +83,58 @@ test("docker-archive image type throws on bad files", async (t) => {
8383
);
8484
});
8585

86+
test("oci-archive image type can be scanned", async (t) => {
87+
const fixturePath = getFixture("oci-archives/alpine-3.12.0.tar");
88+
const imageNameAndTag = `oci-archive:${fixturePath}`;
89+
90+
const dockerfile = undefined;
91+
const pluginOptions = {
92+
experimental: true,
93+
};
94+
95+
const pluginResult = await plugin.inspect(
96+
imageNameAndTag,
97+
dockerfile,
98+
pluginOptions,
99+
);
100+
101+
t.same(
102+
pluginResult.scannedProjects[0].depTree.name,
103+
"docker-image|alpine-3.12.0.tar",
104+
"Image name matches",
105+
);
106+
t.same(
107+
pluginResult.scannedProjects[0].depTree.version,
108+
"",
109+
"Version must be empty",
110+
);
111+
t.same(
112+
pluginResult.plugin.dockerImageId,
113+
"sha256:0f5f445df8ccbd8a062ad3d02d459e8549d9998c62a5b7cbf77baf68aa73bf5b",
114+
"The image ID matches",
115+
);
116+
t.same(
117+
pluginResult.plugin.packageManager,
118+
"apk",
119+
"Correct package manager detected",
120+
);
121+
t.ok(
122+
pluginResult.scannedProjects[0].depTree.dependencies &&
123+
"alpine-keys/alpine-keys" in
124+
pluginResult.scannedProjects[0].depTree.dependencies,
125+
"Contains some expected dependency",
126+
);
127+
t.deepEqual(
128+
pluginResult.plugin.imageLayers,
129+
[
130+
path.normalize(
131+
"sha256:df20fa9351a15782c64e6dddb2d4a6f50bf6d3688060a34c4014b0d9a752eb4c",
132+
),
133+
],
134+
"Layers are read correctly",
135+
);
136+
});
137+
86138
test("static scan for Identifier type image (nginx:1.19.0)", async (t) => {
87139
const imageNameAndTag = `nginx:1.19.0`;
88140
const dockerfile = undefined;

test/windows/experimental.test.ts

+54-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { test } from "tap";
44
import * as plugin from "../../lib";
55

66
function getFixture(fixturePath): string {
7-
return path.join(__dirname, "../fixtures/docker-archives", fixturePath);
7+
return path.join(__dirname, "../fixtures", fixturePath);
88
}
99

1010
test("docker-archive image type can be scanned", async (t) => {
11-
const fixturePath = getFixture("docker-save/nginx.tar");
11+
const fixturePath = getFixture("docker-archives/docker-save/nginx.tar");
1212
const imageNameAndTag = `docker-archive:${fixturePath}`;
1313

1414
const dockerfile = undefined;
@@ -58,6 +58,58 @@ test("docker-archive image type can be scanned", async (t) => {
5858
);
5959
});
6060

61+
test("oci-archive image type can be scanned", async (t) => {
62+
const fixturePath = getFixture("oci-archives/alpine-3.12.0.tar");
63+
const imageNameAndTag = `oci-archive:${fixturePath}`;
64+
65+
const dockerfile = undefined;
66+
const pluginOptions = {
67+
experimental: true,
68+
};
69+
70+
const pluginResult = await plugin.inspect(
71+
imageNameAndTag,
72+
dockerfile,
73+
pluginOptions,
74+
);
75+
76+
t.same(
77+
pluginResult.scannedProjects[0].depTree.name,
78+
"docker-image|alpine-3.12.0.tar",
79+
"Image name matches",
80+
);
81+
t.same(
82+
pluginResult.scannedProjects[0].depTree.version,
83+
"",
84+
"Version must be empty",
85+
);
86+
t.same(
87+
pluginResult.plugin.dockerImageId,
88+
"sha256:0f5f445df8ccbd8a062ad3d02d459e8549d9998c62a5b7cbf77baf68aa73bf5b",
89+
"The image ID matches",
90+
);
91+
t.same(
92+
pluginResult.plugin.packageManager,
93+
"apk",
94+
"Correct package manager detected",
95+
);
96+
t.ok(
97+
pluginResult.scannedProjects[0].depTree.dependencies &&
98+
"alpine-keys/alpine-keys" in
99+
pluginResult.scannedProjects[0].depTree.dependencies,
100+
"Contains some expected dependency",
101+
);
102+
t.deepEqual(
103+
pluginResult.plugin.imageLayers,
104+
[
105+
path.normalize(
106+
"sha256:df20fa9351a15782c64e6dddb2d4a6f50bf6d3688060a34c4014b0d9a752eb4c",
107+
),
108+
],
109+
"Layers are read correctly",
110+
);
111+
});
112+
61113
test("static scan for Identifier type image (nginx:1.19.0)", async (t) => {
62114
const imageNameAndTag = `nginx:1.19.0`;
63115
const dockerfile = undefined;

0 commit comments

Comments
 (0)