Skip to content

Commit

Permalink
test: show that errors in go parsing throw an uncaught exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanstanev committed Feb 9, 2021
1 parent fac3665 commit 4b2b142
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion test/system/application-scans/gomodules.spec.ts
@@ -1,7 +1,13 @@
import { scan } from "../../../lib";
import * as elf from "elfy";

import { PluginResponse, scan } from "../../../lib";
import { getFixture } from "../../util";

describe("gomodules binaries scanning", () => {
afterAll(() => {
jest.resetAllMocks();
});

it("should return expected result", async () => {
// Arrange
const fixturePath = getFixture("docker-archives/docker-save/yq.tar");
Expand All @@ -16,4 +22,28 @@ describe("gomodules binaries scanning", () => {
// Assert
expect(pluginResult).toMatchSnapshot();
});

it("throws an uncaught exception when a binary cannot be parsed", async () => {
const elfParseMock = jest.spyOn(elf, "parse").mockImplementation(() => {
throw new Error("Cannot read property 'type' of undefined");
});

const fixturePath = getFixture("docker-archives/docker-save/yq.tar");
const imageNameAndTag = `docker-archive:${fixturePath}`;

try {
const pluginResult = await scan({
path: imageNameAndTag,
"app-vulns": true,
});
expect(pluginResult).toEqual<PluginResponse>({
scanResults: expect.any(Array),
});
} catch (error) {
// This won't be executed!
expect(error).toBeDefined();
}

elfParseMock.mockRestore();
});
});

0 comments on commit 4b2b142

Please sign in to comment.