From 5afded480ea5f22908a5af537ce83b302c938e07 Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Thu, 29 Aug 2019 18:48:35 +0300 Subject: [PATCH] Now run monkey works --- .../blackbox/monkey_island_client.py | 36 +++++++++++++++---- envs/monkey_zoo/blackbox/test_blackbox.py | 2 +- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/envs/monkey_zoo/blackbox/monkey_island_client.py b/envs/monkey_zoo/blackbox/monkey_island_client.py index 582b3a0dc..c2cde2506 100644 --- a/envs/monkey_zoo/blackbox/monkey_island_client.py +++ b/envs/monkey_zoo/blackbox/monkey_island_client.py @@ -1,3 +1,5 @@ +import json + import requests # SHA3-512 of '1234567890!@#$%^&*()_nothing_up_my_sleeve_1234567890!@#$%^&*()' @@ -15,13 +17,35 @@ class MonkeyIslandClient(object): verify=False) return resp.json()["access_token"] + def request_get(self, url): + return requests.get( + self.addr + url, + headers={"Authorization": "JWT " + self.token}, + verify=False + ) + + def request_post(self, url, data): + return requests.post( + self.addr + url, + data=data, + headers={"Authorization": "JWT " + self.token}, + verify=False + ) + + def request_json(self, url, dict_data): + return requests.post( + self.addr + url, + json=dict_data, + headers={"Authorization": "JWT " + self.token}, + verify=False + ) + def get_api_status(self): - return requests.get(self.addr + "api", headers={"Authorization": "JWT " + self.token}, verify=False) + return self.request_get("api") def import_config(self, config_contents): - resp = requests.post( - self.addr + "api/configuration/island", - headers={"Authorization": "JWT " + self.token}, - data=config_contents, - verify=False) + _ = self.request_post("api/configuration/island", data=config_contents) + + def run_monkey_local(self): + resp = self.request_json("api/local-monkey", dict_data={"action": "run"}) print(resp.text) diff --git a/envs/monkey_zoo/blackbox/test_blackbox.py b/envs/monkey_zoo/blackbox/test_blackbox.py index cacbfeb4f..15f0f276c 100644 --- a/envs/monkey_zoo/blackbox/test_blackbox.py +++ b/envs/monkey_zoo/blackbox/test_blackbox.py @@ -9,7 +9,7 @@ from envs.monkey_zoo.blackbox.monkey_island_client import MonkeyIslandClient def generic_blackbox_test_case(client, config_file_path, analyzers): with open(config_file_path, "r") as config_file: client.import_config(config_file.read()) - # run_local_monkey_on_island() + client.run_monkey_local() for analyzer in analyzers: assert analyzer.analyze_test_results()