From 5534413b3a3e6e783310be8147ac8340d3098a7e Mon Sep 17 00:00:00 2001 From: Emiliano Ciavatta Date: Fri, 16 Oct 2020 15:09:05 +0200 Subject: Fix tests. General refactor --- frontend/src/components/panels/ConnectionsPane.js | 11 +-- frontend/src/components/panels/PcapsPane.js | 10 +-- frontend/src/components/panels/RulesPane.js | 90 +++++++++++------------ frontend/src/components/panels/SearchPane.js | 10 +-- frontend/src/components/panels/StreamsPane.js | 4 +- 5 files changed, 59 insertions(+), 66 deletions(-) (limited to 'frontend/src/components/panels') diff --git a/frontend/src/components/panels/ConnectionsPane.js b/frontend/src/components/panels/ConnectionsPane.js index 23c6114..9418fad 100644 --- a/frontend/src/components/panels/ConnectionsPane.js +++ b/frontend/src/components/panels/ConnectionsPane.js @@ -178,7 +178,7 @@ class ConnectionsPane extends Component { let firstConnection = this.state.firstConnection; let lastConnection = this.state.lastConnection; - if (additionalParams !== undefined && additionalParams.from !== undefined && additionalParams.to === undefined) { + if (additionalParams && additionalParams.from && !additionalParams.to) { if (res.length > 0) { if (!isInitial) { res = res.slice(1); @@ -194,7 +194,7 @@ class ConnectionsPane extends Component { firstConnection = connections[0]; } } - } else if (additionalParams !== undefined && additionalParams.to !== undefined && additionalParams.from === undefined) { + } else if (additionalParams && additionalParams.to && !additionalParams.from) { if (res.length > 0) { connections = res.slice(0, res.length - 1).concat(this.state.connections); firstConnection = connections[0]; @@ -215,12 +215,7 @@ class ConnectionsPane extends Component { } } - this.setState({ - loading: false, - connections: connections, - firstConnection: firstConnection, - lastConnection: lastConnection - }); + this.setState({loading: false, connections, firstConnection, lastConnection}); if (firstConnection != null && lastConnection != null) { dispatcher.dispatch("connection_updates", { diff --git a/frontend/src/components/panels/PcapsPane.js b/frontend/src/components/panels/PcapsPane.js index 64e7804..ddc5948 100644 --- a/frontend/src/components/panels/PcapsPane.js +++ b/frontend/src/components/panels/PcapsPane.js @@ -181,15 +181,15 @@ class PcapsPane extends Component { }; const uploadCurlCommand = createCurlCommand("/pcap/upload", "POST", null, { - file: "@" + ((this.state.uploadSelectedFile != null && this.state.isUploadFileValid) ? + "file": "@" + ((this.state.uploadSelectedFile != null && this.state.isUploadFileValid) ? this.state.uploadSelectedFile.name : "invalid.pcap"), - flush_all: this.state.uploadFlushAll + "flush_all": this.state.uploadFlushAll }); const fileCurlCommand = createCurlCommand("/pcap/file", "POST", { - file: this.state.fileValue, - flush_all: this.state.processFlushAll, - delete_original_file: this.state.deleteOriginalFile + "file": this.state.fileValue, + "flush_all": this.state.processFlushAll, + "delete_original_file": this.state.deleteOriginalFile }); return ( diff --git a/frontend/src/components/panels/RulesPane.js b/frontend/src/components/panels/RulesPane.js index d872b47..0bbd407 100644 --- a/frontend/src/components/panels/RulesPane.js +++ b/frontend/src/components/panels/RulesPane.js @@ -142,23 +142,23 @@ class RulesPane extends Component { this.setState({ruleColorError: "color is not hexcolor"}); valid = false; } - if (!validation.isValidPort(rule.filter.service_port)) { + if (!validation.isValidPort(rule.filter["service_port"])) { this.setState({ruleServicePortError: "service_port > 65565"}); valid = false; } - if (!validation.isValidPort(rule.filter.client_port)) { + if (!validation.isValidPort(rule.filter["client_port"])) { this.setState({ruleClientPortError: "client_port > 65565"}); valid = false; } - if (!validation.isValidAddress(rule.filter.client_address)) { + if (!validation.isValidAddress(rule.filter["client_address"])) { this.setState({ruleClientAddressError: "client_address is not ip_address"}); valid = false; } - if (rule.filter.min_duration > rule.filter.max_duration) { + if (rule.filter["min_duration"] > rule.filter["max_duration"]) { this.setState({ruleDurationError: "min_duration > max_dur."}); valid = false; } - if (rule.filter.min_bytes > rule.filter.max_bytes) { + if (rule.filter["min_bytes"] > rule.filter["max_bytes"]) { this.setState({ruleBytesError: "min_bytes > max_bytes"}); valid = false; } @@ -175,9 +175,9 @@ class RulesPane extends Component { const newPattern = _.cloneDeep(this.emptyPattern); this.setState({ selectedRule: null, - newRule: newRule, + newRule, selectedPattern: null, - newPattern: newPattern, + newPattern, patternRegexFocused: false, patternOccurrencesFocused: false, ruleNameError: null, @@ -210,9 +210,7 @@ class RulesPane extends Component { const newPattern = _.cloneDeep(this.emptyPattern); this.currentRule().patterns.push(pattern); - this.setState({ - newPattern: newPattern - }); + this.setState({newPattern}); }; editPattern = (pattern) => { @@ -237,7 +235,7 @@ class RulesPane extends Component { valid = false; this.setState({patternRegexFocused: true}); } - if (pattern.min_occurrences > pattern.max_occurrences) { + if (pattern["min_occurrences"] > pattern["max_occurrences"]) { valid = false; this.setState({patternOccurrencesFocused: true}); } @@ -273,25 +271,25 @@ class RulesPane extends Component { this.setState({patternRegexFocused: pattern.regex === ""}); }}/> - this.updateParam(() => pattern.flags.caseless = v)}/> - this.updateParam(() => pattern.flags.dot_all = v)}/> - this.updateParam(() => pattern.flags.multi_line = v)}/> - this.updateParam(() => pattern.flags.utf_8_mode = v)}/> - this.updateParam(() => pattern.flags.unicode_property = v)}/> + this.updateParam(() => pattern.flags["caseless"] = v)}/> + this.updateParam(() => pattern.flags["dot_all"] = v)}/> + this.updateParam(() => pattern.flags["multi_line"] = v)}/> + this.updateParam(() => pattern.flags["utf_8_mode"] = v)}/> + this.updateParam(() => pattern.flags["unicode_property"] = v)}/> - this.updateParam(() => pattern.min_occurrences = v)}/> + onChange={(v) => this.updateParam(() => pattern["min_occurrences"] = v)}/> - this.updateParam(() => pattern.max_occurrences = v)}/> + onChange={(v) => this.updateParam(() => pattern["max_occurrences"] = v)}/> s", "s->c"]} value={this.directions[pattern.direction]} @@ -305,13 +303,13 @@ class RulesPane extends Component { : {p.regex} - {p.flags.caseless ? "yes" : "no"} - {p.flags.dot_all ? "yes" : "no"} - {p.flags.multi_line ? "yes" : "no"} - {p.flags.utf_8_mode ? "yes" : "no"} - {p.flags.unicode_property ? "yes" : "no"} - {p.min_occurrences} - {p.max_occurrences} + {p.flags["caseless"] ? "yes" : "no"} + {p.flags["dot_all"] ? "yes" : "no"} + {p.flags["multi_line"] ? "yes" : "no"} + {p.flags["utf_8_mode"] ? "yes" : "no"} + {p.flags["unicode_property"] ? "yes" : "no"} + {p["min_occurrences"]} + {p["max_occurrences"]} {this.directions[p.direction]} {!isUpdate && this.editPattern(p)}/>} @@ -373,32 +371,32 @@ class RulesPane extends Component { filters: - this.updateParam((r) => r.filter.service_port = v)} + this.updateParam((r) => r.filter["service_port"] = v)} min={0} max={65565} error={this.state.ruleServicePortError} readonly={isUpdate}/> - this.updateParam((r) => r.filter.client_port = v)} + this.updateParam((r) => r.filter["client_port"] = v)} min={0} max={65565} error={this.state.ruleClientPortError} readonly={isUpdate}/> - this.updateParam((r) => r.filter.client_address = v)}/> + onChange={(v) => this.updateParam((r) => r.filter["client_address"] = v)}/> - this.updateParam((r) => r.filter.min_duration = v)}/> - this.updateParam((r) => r.filter["min_duration"] = v)}/> + this.updateParam((r) => r.filter.max_duration = v)}/> - this.updateParam((r) => r.filter["max_duration"] = v)}/> + this.updateParam((r) => r.filter.min_bytes = v)}/> - this.updateParam((r) => r.filter["min_bytes"] = v)}/> + this.updateParam((r) => r.filter.max_bytes = v)}/> + onChange={(v) => this.updateParam((r) => r.filter["max_bytes"] = v)}/> diff --git a/frontend/src/components/panels/SearchPane.js b/frontend/src/components/panels/SearchPane.js index d36e85e..776ebd0 100644 --- a/frontend/src/components/panels/SearchPane.js +++ b/frontend/src/components/panels/SearchPane.js @@ -70,20 +70,20 @@ class SearchPane extends Component { loadSearches = () => { backend.get("/api/searches") - .then(res => this.setState({searches: res.json, searchesStatusCode: res.status})) - .catch(res => this.setState({searchesStatusCode: res.status, searchesResponse: JSON.stringify(res.json)})); + .then((res) => this.setState({searches: res.json, searchesStatusCode: res.status})) + .catch((res) => this.setState({searchesStatusCode: res.status, searchesResponse: JSON.stringify(res.json)})); }; performSearch = () => { const options = this.state.currentSearchOptions; this.setState({loading: true}); if (this.validateSearch(options)) { - backend.post("/api/searches/perform", options).then(res => { + backend.post("/api/searches/perform", options).then((res) => { this.reset(); this.setState({searchStatusCode: res.status, loading: false}); this.loadSearches(); this.viewSearch(res.json.id); - }).catch(res => { + }).catch((res) => { this.setState({ searchStatusCode: res.status, searchResponse: JSON.stringify(res.json), loading: false @@ -168,7 +168,7 @@ class SearchPane extends Component { render() { const options = this.state.currentSearchOptions; - let searches = this.state.searches.map(s => + let searches = this.state.searches.map((s) => {s.id.substring(0, 8)} {this.extractPattern(s["search_options"])} diff --git a/frontend/src/components/panels/StreamsPane.js b/frontend/src/components/panels/StreamsPane.js index 41ab33d..1819fec 100644 --- a/frontend/src/components/panels/StreamsPane.js +++ b/frontend/src/components/panels/StreamsPane.js @@ -18,7 +18,7 @@ import DOMPurify from "dompurify"; import React, {Component} from "react"; import {Row} from "react-bootstrap"; -import ReactJson from "react-json-view" +import ReactJson from "react-json-view"; import backend from "../../backend"; import log from "../../log"; import {downloadBlob, getHeaderValue} from "../../utils"; @@ -72,7 +72,7 @@ class StreamsPane extends Component { setFormat = (format) => { if (this.validFormats.includes(format)) { - this.setState({format: format}); + this.setState({format}); } }; -- cgit v1.2.3-70-g09d2