Now run monkey works

This commit is contained in:
Shay Nehmad 2019-08-29 18:48:35 +03:00
parent ebd2628516
commit 5afded480e
2 changed files with 31 additions and 7 deletions

View File

@ -1,3 +1,5 @@
import json
import requests import requests
# SHA3-512 of '1234567890!@#$%^&*()_nothing_up_my_sleeve_1234567890!@#$%^&*()' # SHA3-512 of '1234567890!@#$%^&*()_nothing_up_my_sleeve_1234567890!@#$%^&*()'
@ -15,13 +17,35 @@ class MonkeyIslandClient(object):
verify=False) verify=False)
return resp.json()["access_token"] 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): 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): def import_config(self, config_contents):
resp = requests.post( _ = self.request_post("api/configuration/island", data=config_contents)
self.addr + "api/configuration/island",
headers={"Authorization": "JWT " + self.token}, def run_monkey_local(self):
data=config_contents, resp = self.request_json("api/local-monkey", dict_data={"action": "run"})
verify=False)
print(resp.text) print(resp.text)

View File

@ -9,7 +9,7 @@ from envs.monkey_zoo.blackbox.monkey_island_client import MonkeyIslandClient
def generic_blackbox_test_case(client, config_file_path, analyzers): def generic_blackbox_test_case(client, config_file_path, analyzers):
with open(config_file_path, "r") as config_file: with open(config_file_path, "r") as config_file:
client.import_config(config_file.read()) client.import_config(config_file.read())
# run_local_monkey_on_island() client.run_monkey_local()
for analyzer in analyzers: for analyzer in analyzers:
assert analyzer.analyze_test_results() assert analyzer.analyze_test_results()