-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding links to SAST and DAST * Fixing indentation * Fixing tests
- Loading branch information
1 parent
8d68687
commit 7e649c9
Showing
7 changed files
with
197 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,92 @@ | ||
import React from "react"; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import { getResource } from "../Utilities/Utils"; | ||
import testFixture from "./fixtures"; | ||
|
||
import App from "../App"; | ||
|
||
jest.mock("../Utilities/Utils"); | ||
|
||
describe("App", () => { | ||
const _renderAppFully = () => { | ||
//mock getResource since it will not work during testing | ||
(getResource as jest.Mock).mockImplementation( | ||
(uri: string, callback: Function, isJson: boolean) => { | ||
//testFixture structure does not match the web response. | ||
//so, we restructure it | ||
const response = { | ||
VulnerableApp: | ||
testFixture.applicationData[0].vulnerabilityDefinitions, | ||
"VulnerableApp-jsp": | ||
testFixture.applicationData[1].vulnerabilityDefinitions, | ||
"VulnerableApp-php": | ||
testFixture.applicationData[2].vulnerabilityDefinitions, | ||
}; | ||
|
||
callback({ isSuccessful: true, data: response }); | ||
} | ||
); | ||
|
||
return render(<App />); | ||
}; | ||
|
||
const _renderAppFail = () => { | ||
(getResource as jest.Mock).mockImplementation( | ||
(uri: string, callback: Function, isJson: boolean) => { | ||
callback({ isSuccessful: false, error: "error" }); | ||
} | ||
); | ||
|
||
return render(<App />); | ||
}; | ||
|
||
const _renderAppNull = () => { | ||
(getResource as jest.Mock).mockImplementation( | ||
(uri: string, callback: Function, isJson: boolean) => { | ||
callback({ isSuccessful: true, data: null }); | ||
} | ||
); | ||
|
||
return render(<App />); | ||
}; | ||
|
||
const _renderAppEmpty = () => { | ||
(getResource as jest.Mock).mockImplementation( | ||
(uri: string, callback: Function, isJson: boolean) => { | ||
callback({ isSuccessful: true, data: {} }); | ||
} | ||
); | ||
|
||
return render(<App />); | ||
}; | ||
|
||
it("renders correctly", async () => { | ||
expect(_renderAppFully().container).toMatchSnapshot(); | ||
}); | ||
|
||
it("renders content on nav item click", () => { | ||
_renderAppFully(); | ||
|
||
fireEvent( | ||
screen.getByTestId("VulnerableApp.CommandInjection.LEVEL_1"), | ||
new MouseEvent("click", { bubbles: true, cancelable: true }) | ||
); | ||
const content = screen.getByTestId("VULNERABILITY_CONTENT_DESCRIPTION"); | ||
expect(content).toBeInTheDocument(); | ||
}); | ||
|
||
it("does not render nav when data is null", async () => { | ||
_renderAppNull(); | ||
expect(screen.queryByTestId(/LEFT_NAV_CONTAINER/i)).toBeNull(); | ||
}); | ||
|
||
it("does not render nav when getResource failed", async () => { | ||
_renderAppFail(); | ||
expect(screen.queryByTestId(/LEFT_NAV_CONTAINER/i)).toBeNull(); | ||
}); | ||
|
||
it("does not render nav items when empty", async () => { | ||
_renderAppEmpty(); | ||
expect(screen.queryByTestId(/VulnerableApp.CommandInjection/i)).toBeNull(); | ||
}); | ||
}); | ||
import React from "react"; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import { getResource } from "../Utilities/Utils"; | ||
import testFixture from "./fixtures"; | ||
|
||
import App from "../App"; | ||
|
||
jest.mock("../Utilities/Utils"); | ||
|
||
describe("App", () => { | ||
const _renderAppFully = () => { | ||
//mock getResource since it will not work during testing | ||
(getResource as jest.Mock).mockImplementation( | ||
(uri: string, callback: Function, isJson: boolean) => { | ||
//testFixture structure does not match the web response. | ||
//so, we restructure it | ||
const response = { | ||
VulnerableApp: | ||
testFixture.applicationData[0].vulnerabilityDefinitions, | ||
"VulnerableApp-jsp": | ||
testFixture.applicationData[1].vulnerabilityDefinitions, | ||
"VulnerableApp-php": | ||
testFixture.applicationData[2].vulnerabilityDefinitions, | ||
}; | ||
|
||
callback({ isSuccessful: true, data: response }); | ||
} | ||
); | ||
|
||
return render(<App />); | ||
}; | ||
|
||
const _renderAppFail = () => { | ||
(getResource as jest.Mock).mockImplementation( | ||
(uri: string, callback: Function, isJson: boolean) => { | ||
callback({ isSuccessful: false, error: "error" }); | ||
} | ||
); | ||
|
||
return render(<App />); | ||
}; | ||
|
||
const _renderAppNull = () => { | ||
(getResource as jest.Mock).mockImplementation( | ||
(uri: string, callback: Function, isJson: boolean) => { | ||
callback({ isSuccessful: true, data: null }); | ||
} | ||
); | ||
|
||
return render(<App />); | ||
}; | ||
|
||
const _renderAppEmpty = () => { | ||
(getResource as jest.Mock).mockImplementation( | ||
(uri: string, callback: Function, isJson: boolean) => { | ||
callback({ isSuccessful: true, data: {} }); | ||
} | ||
); | ||
|
||
return render(<App />); | ||
}; | ||
|
||
it("renders correctly", async () => { | ||
expect(_renderAppFully().container).toMatchSnapshot(); | ||
}); | ||
|
||
it("renders content on nav item click", () => { | ||
_renderAppFully(); | ||
|
||
fireEvent( | ||
screen.getByTestId("VulnerableApp.CommandInjection.LEVEL_1"), | ||
new MouseEvent("click", { bubbles: true, cancelable: true }) | ||
); | ||
const content = screen.getByTestId("VULNERABILITY_CONTENT_DESCRIPTION"); | ||
expect(content).toBeInTheDocument(); | ||
}); | ||
|
||
it("does not render nav when data is null", async () => { | ||
_renderAppNull(); | ||
expect(screen.queryByTestId(/LEFT_NAV_CONTAINER/i)).toBeNull(); | ||
}); | ||
|
||
it("does not render nav when getResource failed", async () => { | ||
_renderAppFail(); | ||
expect(screen.queryByTestId(/LEFT_NAV_CONTAINER/i)).toBeNull(); | ||
}); | ||
|
||
it("does not render nav items when empty", async () => { | ||
_renderAppEmpty(); | ||
expect(screen.queryByTestId(/VulnerableApp.CommandInjection/i)).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.