From 6e10dd20d11ff640520b869f03703a3e0dc9f281 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 23 Sep 2020 14:47:05 +0300 Subject: [PATCH] Run monkey page: fixed a bunch of bugs, CR comments --- .travis.yml | 2 +- .../pages/RunMonkeyPage/CommandDisplay.js | 2 +- .../pages/RunMonkeyPage/InterfaceSelection.js | 2 +- .../RunMonkeyPage/LocalManualRunOptions.js | 2 +- .../pages/RunMonkeyPage/RunOnIslandButton.js | 42 ++++++++++++------- .../ui-components/DropdownSelect.js | 12 +----- 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/.travis.yml b/.travis.yml index 092090d23..cdf2049b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -89,7 +89,7 @@ script: - cd monkey_island/cc/ui - npm ci # See https://docs.npmjs.com/cli/ci.html - eslint ./src --quiet # Test for errors -- JS_WARNINGS_AMOUNT_UPPER_LIMIT=8 +- JS_WARNINGS_AMOUNT_UPPER_LIMIT=6 - eslint ./src --max-warnings $JS_WARNINGS_AMOUNT_UPPER_LIMIT # Test for max warnings # Build documentation diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/CommandDisplay.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/CommandDisplay.js index ca312722a..ff2f877dd 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/CommandDisplay.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/CommandDisplay.js @@ -43,7 +43,7 @@ export default function commandDisplay(props) { {renderNav()}
- + diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/InterfaceSelection.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/InterfaceSelection.js index 6e1e9ca02..6e74fb4a0 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/InterfaceSelection.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/InterfaceSelection.js @@ -8,7 +8,7 @@ function InterfaceSelection(props) { const getContents = (props) => { const ips = props.ips.map((ip) => -
{ip}
+
{ip}
); return (
{ips}
); } diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/LocalManualRunOptions.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/LocalManualRunOptions.js index 3bd8accae..b28285a18 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/LocalManualRunOptions.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/LocalManualRunOptions.js @@ -49,7 +49,7 @@ const getContents = (props) => { return ( <> - + diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnIslandButton.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnIslandButton.js index 23de0cd21..b7bae48f1 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnIslandButton.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnIslandButton.js @@ -6,16 +6,24 @@ import {faCheck} from '@fortawesome/free-solid-svg-icons/faCheck'; import {faSync} from '@fortawesome/free-solid-svg-icons/faSync'; import AuthComponent from '../../AuthComponent'; -import MissingBinariesModal from '../../ui-components/MissingBinariesModal'; +import IslandMonkeyRunErrorModal from '../../ui-components/IslandMonkeyRunErrorModal'; import '../../../styles/components/RunOnIslandButton.scss'; +import {faTimes} from '@fortawesome/free-solid-svg-icons'; +const MONKEY_STATES = { + RUNNING: 'running', + NOT_RUNNING: 'not_running', + STARTING: 'starting', + FAILED: 'failed' +} + class RunOnIslandButton extends AuthComponent { constructor(props) { super(props); this.state = { - runningOnIslandState: 'not_running', + runningOnIslandState: MONKEY_STATES.NOT_RUNNING, showModal: false, errorDetails: '' }; @@ -28,19 +36,19 @@ class RunOnIslandButton extends AuthComponent { .then(res => res.json()) .then(res => { if (res['is_running']) { - this.setState({runningOnIslandState: 'running'}); + this.setState({runningOnIslandState: MONKEY_STATES.RUNNING}); } else { - this.setState({runningOnIslandState: 'not_running'}); + this.setState({runningOnIslandState: MONKEY_STATES.NOT_RUNNING}); } }); } runIslandMonkey = () => { - this.setState({runningOnIslandState: 'installing'}, this.sendRunMonkeyRequest) + this.setState({runningOnIslandState: MONKEY_STATES.STARTING}, this.sendRunMonkeyRequest) }; - sendRunMonkeyRequest = () => { + sendRunMonkeyRequest() { this.authFetch('/api/local-monkey', { method: 'POST', @@ -48,23 +56,22 @@ class RunOnIslandButton extends AuthComponent { body: JSON.stringify({action: 'run'}) }) .then(res => res.json()) - .then(res => { + .then(async res => { if (res['is_running']) { + await new Promise(r => setTimeout(r, 1000)); this.setState({ - runningOnIslandState: 'running' + runningOnIslandState: MONKEY_STATES.RUNNING }); } else { /* If Monkey binaries are missing, change the state accordingly */ - if (res['error_text'].startsWith('Copy file failed')) { + if (res['error_text'] !== '') { this.setState({ showModal: true, - errorDetails: res['error_text'] + errorDetails: res['error_text'], + runningOnIslandState: MONKEY_STATES.FAILED } ); } - this.setState({ - runningOnIslandState: 'not_running' - }); } }); } @@ -76,12 +83,15 @@ class RunOnIslandButton extends AuthComponent { }; getMonkeyRunStateIcon = () => { - if (this.state.runningOnIslandState === 'running') { + if (this.state.runningOnIslandState === MONKEY_STATES.RUNNING) { return () - } else if (this.state.runningOnIslandState === 'installing') { + } else if (this.state.runningOnIslandState === MONKEY_STATES.STARTING) { return () + } else if (this.state.runningOnIslandState === MONKEY_STATES.FAILED) { + return () } else { return ''; } @@ -93,7 +103,7 @@ class RunOnIslandButton extends AuthComponent { return ( - diff --git a/monkey/monkey_island/cc/ui/src/components/ui-components/DropdownSelect.js b/monkey/monkey_island/cc/ui/src/components/ui-components/DropdownSelect.js index 5585bbc1b..8628c0b60 100644 --- a/monkey/monkey_island/cc/ui/src/components/ui-components/DropdownSelect.js +++ b/monkey/monkey_island/cc/ui/src/components/ui-components/DropdownSelect.js @@ -16,19 +16,11 @@ export default function DropdownSelect(props) { } function generateDropdownItemsFromArray(data) { - const dropdownItems = []; - for (let i = 0; i < data.length; i++) { - dropdownItems.push(generateDropdownItem(i, data[i])); - } - return dropdownItems; + return data.map((x, i) => generateDropdownItem(i, x)); } function generateDropdownItemsFromObject(data) { - const dropdownItems = []; - for (let [key, value] of Object.entries(data)) { - dropdownItems.push(generateDropdownItem(key, value)); - } - return dropdownItems; + return Object.entries(data).map(([key, value]) => generateDropdownItem(key, value)); } function generateDropdownItem(key, value) {