Skip to content

Commit 679d07d

Browse files
IlyesbdlalaJ12934
authored andcommitted
Fix test of error handling in scanner helpers
This is because the test would pass when there is not exception thrown. ref: https://jestjs.io/docs/expect#rejects Co-authored-by: Jannik Hollenbach <jannik.hollenbach@iteratec.com> Signed-off-by: Ilyes Ben Dlala <ilyes.bendlala@iteratec.com>
1 parent 4f34596 commit 679d07d

1 file changed

Lines changed: 24 additions & 35 deletions

File tree

scanners/helpers.test.js

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,17 @@ describe("Kubernetes interaction tests", () => {
8585

8686
const k8sApi = { k8sCRDApi:mockK8sCRDApi, k8sBatchApi:mockK8sBatchApi, k8sPodsApi:mockPodsApi }
8787

88-
try {
89-
await scan(
90-
"typo3scan-old-typo3",
91-
"typo3scan",
92-
[],
93-
180,
94-
[],
95-
[],
96-
[],
97-
k8sApi
98-
);
99-
} catch (error) {
100-
expect(error).toMatchInlineSnapshot(
101-
`[Error: Scan failed with description "Mocked Error"]`
102-
);
103-
}
88+
return expect(scan(
89+
"typo3scan-old-typo3",
90+
"typo3scan",
91+
[],
92+
180,
93+
[],
94+
[],
95+
[],
96+
k8sApi
97+
)).rejects.toThrow('Scan failed with description "Mocked Error"');
98+
10499
});
105100
});
106101

@@ -167,26 +162,20 @@ describe("Kubernetes interaction tests", () => {
167162
);
168163
const k8sApi = { k8sCRDApi:mockK8sCRDApi, k8sBatchApi:mockK8sBatchApi, k8sPodsApi:mockPodsApi }
169164

170-
try {
171-
await cascadingScan(
172-
"nmap-dummy-ssh",
173-
"nmap",
174-
["-Pn", "-sV", "dummy-ssh.demo-targets.svc"],
175-
{
176-
nameCascade: "ncrack-ssh",
177-
matchLabels: {
178-
"securecodebox.io/invasive": "invasive",
179-
"securecodebox.io/intensive": "high",
180-
},
165+
return expect(cascadingScan(
166+
"nmap-dummy-ssh",
167+
"nmap",
168+
["-Pn", "-sV", "dummy-ssh.demo-targets.svc"],
169+
{
170+
nameCascade: "ncrack-ssh",
171+
matchLabels: {
172+
"securecodebox.io/invasive": "invasive",
173+
"securecodebox.io/intensive": "high",
181174
},
182-
180,
183-
k8sApi
184-
);
185-
} catch (error) {
186-
expect(error).toMatchInlineSnapshot(
187-
`[Error: Initial Scan failed with description "Mocked Error"]`
188-
);
189-
}
175+
},
176+
180,
177+
k8sApi
178+
)).rejects.toThrow('Initial Scan failed with description "Mocked Error"');
190179
});
191180
});
192181
});

0 commit comments

Comments
 (0)