-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathparser.test.js
More file actions
116 lines (105 loc) · 3.45 KB
/
parser.test.js
File metadata and controls
116 lines (105 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// SPDX-FileCopyrightText: the secureCodeBox authors
//
// SPDX-License-Identifier: Apache-2.0
import { readFile } from "node:fs/promises";
import { validateParser } from "@securecodebox/parser-sdk-nodejs/parser-utils";
import { parse } from "./parser";
test("parses bkimminich/juice-shop:v10.2.0 result file into findings", async () => {
const fileContent = await readFile(
__dirname + "/__testFiles__/juice-shop-v10.2.0.json",
{
encoding: "utf8",
},
);
const findings = await parse(fileContent);
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchSnapshot();
});
test("parses bkimminich/juice-shop:v12.10.2 result file into findings", async () => {
const fileContent = await readFile(
__dirname + "/__testFiles__/juice-shop-v12.10.2.json",
{
encoding: "utf8",
},
);
const findings = await parse(fileContent);
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchSnapshot();
});
test("parses securecodebox:master result file into findings", async () => {
const fileContent = await readFile(
__dirname + "/__testFiles__/securecodebox-repo.json",
{
encoding: "utf8",
},
);
const findings = await parse(fileContent);
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchSnapshot();
});
test("should properly parse a json file with no .Results", async () => {
const fileContent = await readFile(
__dirname + "/__testFiles__/juice-shop-v12.10.2-no-results.json",
{
encoding: "utf8",
},
);
const findings = await parse(fileContent);
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchInlineSnapshot(`[]`);
});
test("should parse a trivy-k8s scan result of a cluster running secureCodeBox itself", async () => {
const jsonContent = await readFile(
__dirname + "/__testFiles__/local-k8s-scan-result.json",
{
encoding: "utf8",
},
);
const findings = await parse(jsonContent);
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchSnapshot();
});
test("should report an error in case of unexpected attributes in a trivy-k8s scan result", async () => {
const jsonContent = await readFile(
__dirname + "/__testFiles__/k8s-results_unexpected-attribute.json",
{
encoding: "utf8",
},
);
await expect(parse(jsonContent)).rejects.toThrow(
"Unexpected attribute 'Secrets' on resource-item",
);
});
test("should parse a trivy-k8s scan result", async () => {
const jsonContent = await readFile(
__dirname + "/__testFiles__/trivy--k8s-scan-results.json",
{
encoding: "utf8",
},
);
const findings = await parse(jsonContent);
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchSnapshot();
});
test("should properly parse a json file with empty .Results", async () => {
const fileContent = await readFile(
__dirname + "/__testFiles__/juice-shop-v12.10.2-empty-results.json",
{
encoding: "utf8",
},
);
const findings = await parse(fileContent);
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchInlineSnapshot(`[]`);
});
test("should properly parse empty json file", async () => {
const jsonContent = await readFile(
__dirname + "/__testFiles__/test-empty-report.json",
{
encoding: "utf8",
},
);
const findings = await parse(jsonContent);
expect(validateParser(findings)).toBeUndefined();
expect(findings).toMatchInlineSnapshot(`[]`);
});