Merge pull request #983 from shreyamalviya/bugfix-run-monkey-manual-ignores-configured-ip

Show only configured IPs for Run Monkey -> Manual page
This commit is contained in:
VakarisZ 2021-03-02 14:15:39 +02:00 committed by GitHub
commit b652e0d851
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 5 deletions

View File

@ -0,0 +1,34 @@
import pytest
import monkey_island.cc.services.config
from monkey_island.cc.environment import Environment
from monkey_island.cc.services.config import ConfigService
IPS = ["0.0.0.0", "9.9.9.9"]
PORT = 9999
# If tests fail because config path is changed, sync with
# monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOptions.js
@pytest.fixture
def config(monkeypatch):
monkeypatch.setattr("monkey_island.cc.services.config.local_ip_addresses",
lambda: IPS)
monkeypatch.setattr(Environment, "_ISLAND_PORT", PORT)
config = ConfigService.get_default_config(True)
return config
def test_set_server_ips_in_config_command_servers(config):
ConfigService.set_server_ips_in_config(config)
expected_config_command_servers = [f"{ip}:{PORT}" for ip in IPS]
assert config["internal"]["island_server"]["command_servers"] ==\
expected_config_command_servers
def test_set_server_ips_in_config_current_server(config):
ConfigService.set_server_ips_in_config(config)
expected_config_current_server = f"{IPS[0]}:{PORT}"
assert config["internal"]["island_server"]["current_server"] ==\
expected_config_current_server

View File

@ -10,6 +10,8 @@ import RunOnIslandButton from './RunOnIslandButton';
import AWSRunButton from './RunOnAWS/AWSRunButton'; import AWSRunButton from './RunOnAWS/AWSRunButton';
import CloudOptions from './scoutsuite-setup/CloudOptions'; import CloudOptions from './scoutsuite-setup/CloudOptions';
const CONFIG_URL = '/api/configuration/island';
function RunOptions(props) { function RunOptions(props) {
const [currentContent, setCurrentContent] = useState(loadingContents()); const [currentContent, setCurrentContent] = useState(loadingContents());
@ -20,12 +22,16 @@ function RunOptions(props) {
useEffect(() => { useEffect(() => {
if (initialized === false) { if (initialized === false) {
authComponent.authFetch('/api') authComponent.authFetch(CONFIG_URL)
.then(res => res.json()) .then(res => res.json())
.then(res => { .then(res => {
setIps([res['ip_addresses']][0]); let commandServers = res.configuration.internal.island_server.command_servers;
setInitialized(true); let ipAddresses = commandServers.map(ip => {
return ip.split(":", 1);
}); });
setIps(ipAddresses);
setInitialized(true);
});
} }
}) })