Skip to content

Commit a125bea

Browse files
authored
Merge pull request #705 from secureCodeBox/consistency/empty-files-parser-tests
🚧 [Consistency] Adding empty file handling and test to all parsers
2 parents 90a635d + 750a50d commit a125bea

35 files changed

+182
-22
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2021 iteratec GmbH
2+
3+
SPDX-License-Identifier: Apache-2.0

scanners/angularjs-csti-scanner/parser/parser.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ function parseMethod(line) {
4343
}
4444

4545
function parseUrl(line) {
46-
console.log(line)
4746
return line.match(/http[s]?:\/\/[^\n ]+/g)[0]
4847
}
4948

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[
2+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2021 iteratec GmbH
2+
3+
SPDX-License-Identifier: Apache-2.0

scanners/git-repo-scanner/parser/parser.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ const readFile = util.promisify(fs.readFile);
1313

1414
const { parse } = require("./parser");
1515

16+
test("should properly parse empty json file", async () => {
17+
const fileContent = await readFile(
18+
__dirname + "/__testFiles__/empty-findings.json",
19+
{
20+
encoding: "utf8",
21+
}
22+
);
23+
const findings = await parse(JSON.parse(fileContent));
24+
await expect(validateParser(findings)).resolves.toBeUndefined();
25+
expect(findings).toMatchInlineSnapshot(`Array []`);
26+
});
27+
1628
test("should properly parse git-scanner json file", async () => {
1729
const fileContent = await readFile(
1830
__dirname + "/__testFiles__/git-scanner-test-findings.json",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2021 iteratec GmbH
2+
3+
SPDX-License-Identifier: Apache-2.0

scanners/kube-hunter/parser/parser.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,15 @@ test("parses result from kind-1.18-in-cluster-scan correctly", async () => {
2626
await expect(validateParser(findings)).resolves.toBeUndefined();
2727
expect(findings).toMatchSnapshot();
2828
});
29+
30+
test("should properly parse empty kube-hunter json file", async () => {
31+
const jsonContent = await readFile(
32+
__dirname + "/__testFiles__/test-empty-report.json",
33+
{
34+
encoding: "utf8",
35+
}
36+
);
37+
const findings = await parse(jsonContent);
38+
await expect(validateParser(findings)).resolves.toBeUndefined();
39+
expect(findings).toMatchInlineSnapshot("Array []");
40+
});

scanners/kubeaudit/parser/__snapshots__/parser.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`example parser parses empty json to zero findings 1`] = `
3+
exports[`should properly parse kubeaudit juice-shop results 1`] = `
44
Array [
55
Object {
66
"attributes": Object {},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

0 commit comments

Comments
 (0)