monkey/envs/monkey_zoo/blackbox/test_blackbox.py

44 lines
1.4 KiB
Python
Raw Normal View History

2019-08-28 19:56:35 +08:00
import os
2019-08-27 20:52:39 +08:00
import unittest
import pytest
2019-08-27 21:23:09 +08:00
from envs.monkey_zoo.blackbox.monkey_island_client import MonkeyIslandClient
2019-08-29 23:18:25 +08:00
from envs.monkey_zoo.blackbox.analyzers.communication_analyzer import CommunicationAnalyzer
2019-08-27 20:52:39 +08:00
2019-08-29 19:57:04 +08:00
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())
2019-08-29 23:48:35 +08:00
client.run_monkey_local()
2019-08-28 19:56:35 +08:00
for analyzer in analyzers:
assert analyzer.analyze_test_results()
@pytest.mark.usefixtures("island")
# noinspection PyUnresolvedReferences
2019-08-29 19:57:04 +08:00
class TestMonkeyBlackbox(unittest.TestCase):
2019-08-27 20:52:39 +08:00
@classmethod
def setUpClass(cls):
# GCPHandler().start_machines("elastic-4")
2019-08-27 20:52:39 +08:00
print("Setting up all GCP machines...")
@classmethod
def tearDownClass(cls):
# GCPHandler().stop_machines("elastic-4")
2019-08-27 20:52:39 +08:00
print("Killing all GCP machines...")
2019-08-29 19:57:04 +08:00
def test_server_online(self):
client = MonkeyIslandClient(self.island)
2019-08-29 19:57:04 +08:00
assert client.get_api_status() is not None
2019-08-28 19:56:35 +08:00
def test_ssh_exec(self):
client = MonkeyIslandClient(self.island)
2019-08-29 19:57:04 +08:00
conf_file_name = "SSH.conf"
2019-08-29 23:18:25 +08:00
generic_blackbox_test_case(client, get_conf_file_path(conf_file_name),
[CommunicationAnalyzer(client, ["10.2.2.41", "10.2.2.42"])])
2019-08-28 19:56:35 +08:00
def get_conf_file_path(conf_file_name):
return os.path.join(os.path.dirname(os.path.abspath(__file__)), "island_configs", conf_file_name)