Skip to content

Commit

Permalink
Fixing indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan Preet Singh Sasan committed Nov 10, 2023
1 parent 044725f commit a880a74
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 105 deletions.
14 changes: 7 additions & 7 deletions facade-app/src/Components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ export default class Header extends React.Component<Props, {}> {
About Us
</RSuiteNav.Item>
<RSuiteDropDown title="Scanners">
<a href="../scanner/dast">
<RSuiteDropDown.Item title="Dynamic Application Security Testing">
DAST
</RSuiteDropDown.Item>
<a href="../scanner/dast">
<RSuiteDropDown.Item title="Dynamic Application Security Testing">
DAST
</RSuiteDropDown.Item>
</a>
<a href="../scanner/sast">
<RSuiteDropDown.Item title="Static Application Security Testing">
SAST
</RSuiteDropDown.Item>
<RSuiteDropDown.Item title="Static Application Security Testing">
SAST
</RSuiteDropDown.Item>
</a>
</RSuiteDropDown>
<a href="https://github.com/SasanLabs/VulnerableApp-facade">
Expand Down
184 changes: 92 additions & 92 deletions facade-app/src/test/App.test.tsx
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();
});
});
12 changes: 6 additions & 6 deletions facade-app/src/test/Utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ describe("appendStaticResourcesToDocument()", () => {
hints: [
{
vulnerabilityTypes: [{ identifierType: "CWE", value: "WASC-1" }],
description: "vulnerability hint 1"
description: "vulnerability hint 1",
},
],
resourceInformation: {
htmlResource: {
resourceType: ResourceType.HTML,
isAbsolute: false,
uri: "/"
uri: "/",
},
staticResources: [
{
resourceType: ResourceType.JAVASCRIPT,
isAbsolute: false,
uri: "/dummy_javascript_uri"
uri: "/dummy_javascript_uri",
},
{
resourceType: ResourceType.CSS,
isAbsolute: false,
uri: "/dummy_css_uri"
}
]
uri: "/dummy_css_uri",
},
],
},
};
it("should modify the content of an element.", () => {
Expand Down

0 comments on commit a880a74

Please sign in to comment.