Skip to content

Commit 16823d8

Browse files
committed
test(e2e): delete single and multiple SBOMs
Signed-off-by: Vilem Obratil <vobratil@redhat.com>
1 parent ed87429 commit 16823d8

2 files changed

Lines changed: 121 additions & 0 deletions

File tree

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { expect, test } from "../fixtures";
2+
import {
3+
deleteSboms,
4+
getFullSbomPaths,
5+
uploadFiles,
6+
} from "../helpers/general-helpers";
7+
import { logger } from "../../common/constants";
8+
9+
// SBOMs to upload
10+
const sbomDir = "tests/common/assets/sbom";
11+
12+
const sbomSingle = ["cnv-4.17-product-older.json.bz2"];
13+
14+
const sbomsMultiple = [
15+
"cnv-4.17-index-older.json.bz2",
16+
"cnv-4.17-binary-1-older.json.bz2",
17+
"cnv-4.17-binary-2-older.json.bz2",
18+
"cnv-4.17-product-latest.json.bz2",
19+
"cnv-4.17-index-latest.json.bz2",
20+
"cnv-4.17-binary-1-latest.json.bz2",
21+
"cnv-4.17-binary-2-latest.json.bz2",
22+
];
23+
24+
test.describe.only("SBOM / Delete", () => {
25+
test.describe.configure({ mode: "serial" });
26+
27+
const sbomIdsDelete: string[] = [];
28+
29+
test.afterAll(async ({ axios }) => {
30+
await deleteSboms(axios, sbomIdsDelete);
31+
});
32+
33+
test("Single existing SBOM", async ({ axios }) => {
34+
const fullSbomPaths = getFullSbomPaths(sbomDir, sbomSingle);
35+
const sbomIdSingle = await uploadFiles(axios, "sbom", fullSbomPaths);
36+
sbomIdsDelete.push(...sbomIdSingle);
37+
38+
// Delete the SBOM
39+
const response = await axios.delete(
40+
`/api/v3/sbom/${encodeURIComponent(sbomIdSingle[0])}`,
41+
);
42+
if (response.status !== 204) {
43+
logger.error(
44+
`Delete single existing SBOM failed with status ${response.status}:`,
45+
response.data,
46+
);
47+
}
48+
expect(response.status).toBe(204);
49+
50+
// Verify that the SBOM is deleted
51+
const getResponse = await axios.get(
52+
`/api/v3/sbom/${encodeURIComponent(sbomIdSingle[0])}`,
53+
{ validateStatus: null },
54+
);
55+
expect(getResponse.status).toBe(404);
56+
});
57+
58+
test("Multiple existing SBOMs", async ({ axios }) => {
59+
const fullSbomPaths = getFullSbomPaths(sbomDir, sbomsMultiple);
60+
const sbomIdsMultiple = await uploadFiles(axios, "sbom", fullSbomPaths);
61+
sbomIdsDelete.push(...sbomIdsMultiple);
62+
63+
const response = await axios.delete("/api/v3/sbom", {
64+
data: sbomIdsMultiple,
65+
});
66+
if (response.status !== 204) {
67+
logger.error(
68+
`Delete multiple existing SBOMs failed with status ${response.status}:`,
69+
response.data,
70+
);
71+
}
72+
expect(response.status).toBe(204);
73+
74+
// Verify that all SBOMs are deleted
75+
for (const id of sbomIdsMultiple) {
76+
const getResponse = await axios.get(
77+
`/api/v3/sbom/${encodeURIComponent(id)}`,
78+
{ validateStatus: null },
79+
);
80+
expect(getResponse.status).toBe(404);
81+
}
82+
});
83+
84+
test("Single non-existent SBOM", async ({ axios }) => {
85+
const nonExistentId = Array.from({ length: 45 }, () =>
86+
"abcdefghijklmnopqrstuvwxyz0123456789"[Math.floor(Math.random() * 36)],
87+
).join("");
88+
89+
const response = await axios.delete(
90+
`/api/v3/sbom/${encodeURIComponent(nonExistentId)}`,
91+
{ validateStatus: null },
92+
);
93+
if (response.status !== 404) {
94+
logger.error(
95+
`Delete single non-existent SBOM failed with status ${response.status}:`,
96+
response.data,
97+
);
98+
}
99+
expect(response.status).toBe(404);
100+
});
101+
102+
test("Multiple non-existent SBOMs", async ({ axios }) => {
103+
const nonExistentIds = Array.from({ length: 7 }, () =>
104+
Array.from({ length: 45 }, () =>
105+
"abcdefghijklmnopqrstuvwxyz0123456789"[Math.floor(Math.random() * 36)],
106+
).join(""),
107+
);
108+
109+
const response = await axios.delete("/api/v3/sbom", {
110+
data: nonExistentIds,
111+
validateStatus: null,
112+
});
113+
if (response.status !== 204) {
114+
logger.error(
115+
`Delete multiple non-existent SBOMs failed with status ${response.status}:`,
116+
response.data,
117+
);
118+
}
119+
expect(response.status).toBe(204);
120+
});
121+
});

0 commit comments

Comments
 (0)