Skip to content
This repository has been archived by the owner on Nov 2, 2024. It is now read-only.

Commit

Permalink
Frontend - no more required analyzer in scan form (intelowlproject#2397)
Browse files Browse the repository at this point in the history
* no more requried analyzer in scan form

* fix test
  • Loading branch information
carellamartina authored and vaclavbartos committed Oct 13, 2024
1 parent fb5cf0b commit 7b1c62e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
6 changes: 4 additions & 2 deletions frontend/src/components/scan/ScanForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,11 @@ export default function ScanForm() {
}
if (
values.analysisOptionValues === ScanTypes.analyzers_and_connectors &&
values.analyzers.length === 0
values.analyzers.length === 0 &&
values.connectors.length === 0
) {
errors.analyzers = "analyzers required";
errors.analyzers = "analyzers or connectors required";
errors.connectors = "analyzers or connectors required";
}

if (!TlpChoices.includes(values.tlp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("test Connectors component", () => {
</BrowserRouter>,
);

const title = screen.getByRole("heading", { name: "Connectors 0 total" });
const title = screen.getByRole("heading", { name: "Connectors 1 total" });
expect(title).toBeInTheDocument();
// table
const tableComponent = screen.getByRole("table");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,50 @@ describe("test ScanForm component form validation", () => {
});
});

test("form validation - observable and connector selected but no analyzer", async () => {
const user = userEvent.setup();

const { container } = render(
<BrowserRouter>
<ScanForm />
</BrowserRouter>,
);

const analyzerSelectionRadioButton = screen.getAllByRole("radio")[3];
expect(analyzerSelectionRadioButton).toBeInTheDocument();
await user.click(analyzerSelectionRadioButton);
expect(screen.getByText("Select Analyzers")).toBeInTheDocument();
expect(screen.getByText("Select Connectors")).toBeInTheDocument();

const firstObservableInputElement = screen.getByRole("textbox", {
name: "",
});
expect(firstObservableInputElement).toBeInTheDocument();
await user.type(firstObservableInputElement, "google.com");
expect(firstObservableInputElement.value).toBe("google.com");

// select connector (no analyzers selected)
const connectorDropdownButton = screen.getAllByRole("combobox")[1];
expect(connectorDropdownButton).toBeInTheDocument();
await user.click(connectorDropdownButton);
const testConnectorButton = container.querySelector(
`#${connectorDropdownButton.id.replace("-input", "")}-option-0`,
);
expect(testConnectorButton).toBeInTheDocument();
await user.click(testConnectorButton);
expect(screen.getByText("TEST_CONNECTOR")).toBeInTheDocument();

const startScanButton = screen.getByRole("button", { name: "Start Scan" });
expect(startScanButton).toBeInTheDocument();
expect(startScanButton.className).not.toContain("disabled");
await waitFor(() => {
expect(RecentScans).toHaveBeenCalledWith(
{ classification: "domain", param: "google.com" },
{},
);
});
});

test("form validation - no observable and analyzer selected", async () => {
const user = userEvent.setup();

Expand Down
30 changes: 29 additions & 1 deletion frontend/tests/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,35 @@ export const mockedUsePluginConfigurationStore = {
plugin_type: "1",
},
],
connectors: [],
connectors: [
{
name: "TEST_CONNECTOR",
config: {
queue: "default",
soft_time_limit: 30,
},
python_module: "test.Test",
description: "Test connector",
disabled: false,
type: "observable",
docker_based: false,
maximum_tlp: "AMBER",
observable_supported: ["domain", "generic", "hash", "ip", "url", "file"],
supported_filetypes: [],
run_hash: false,
run_hash_type: "",
not_supported_filetypes: [],
params: {},
secrets: {},
verification: {
configured: true,
details: "Ready to use!",
missing_secrets: [],
},
orgPluginDisabled: false,
plugin_type: "2",
},
],
visualizers: [],
ingestors: [],
playbooks: [
Expand Down

0 comments on commit 7b1c62e

Please sign in to comment.