From 7b1c62edd7c891a73e4a69ac49b23c6e2a23566f Mon Sep 17 00:00:00 2001 From: Martina Carella Date: Tue, 25 Jun 2024 11:34:18 +0200 Subject: [PATCH] Frontend - no more required analyzer in scan form (#2397) * no more requried analyzer in scan form * fix test --- frontend/src/components/scan/ScanForm.jsx | 6 ++- .../plugins/types/Connectors.test.jsx | 2 +- .../ScanForm/ScanForm.validation.test.jsx | 44 +++++++++++++++++++ frontend/tests/mock.js | 30 ++++++++++++- 4 files changed, 78 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/scan/ScanForm.jsx b/frontend/src/components/scan/ScanForm.jsx index cf2fa2f62b..375cd373dd 100644 --- a/frontend/src/components/scan/ScanForm.jsx +++ b/frontend/src/components/scan/ScanForm.jsx @@ -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)) { diff --git a/frontend/tests/components/plugins/types/Connectors.test.jsx b/frontend/tests/components/plugins/types/Connectors.test.jsx index 5e3f037c4a..1713062ca1 100644 --- a/frontend/tests/components/plugins/types/Connectors.test.jsx +++ b/frontend/tests/components/plugins/types/Connectors.test.jsx @@ -29,7 +29,7 @@ describe("test Connectors component", () => { , ); - 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"); diff --git a/frontend/tests/components/scan/ScanForm/ScanForm.validation.test.jsx b/frontend/tests/components/scan/ScanForm/ScanForm.validation.test.jsx index 0deab62ef8..b4ecd0e8c0 100644 --- a/frontend/tests/components/scan/ScanForm/ScanForm.validation.test.jsx +++ b/frontend/tests/components/scan/ScanForm/ScanForm.validation.test.jsx @@ -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( + + + , + ); + + 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(); diff --git a/frontend/tests/mock.js b/frontend/tests/mock.js index bf72453bee..c9bbe41808 100644 --- a/frontend/tests/mock.js +++ b/frontend/tests/mock.js @@ -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: [