-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_cbinterface.py
92 lines (73 loc) · 2.88 KB
/
test_cbinterface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import pytest
import json
import os
HOME_PATH = os.path.dirname(os.path.abspath(__file__))
def test_version():
from cbinterface import __version__
assert __version__ == "2.3.33"
def test_timezone_settings():
from dateutil import tz
from cbinterface.config import set_timezone, get_timezone
set_timezone("GMT")
assert "GMT" == os.environ["CBINTERFACE_TIMEZONE"]
assert get_timezone() == tz.gettz("GMT")
def test_cbapi_environment_settings():
from cbinterface.config import (
set_default_cbapi_product,
set_default_cbapi_profile,
get_default_cbapi_product,
get_default_cbapi_profile,
)
set_default_cbapi_product("buckets")
assert get_default_cbapi_product() == "buckets"
set_default_cbapi_product("more_buckets")
set_default_cbapi_profile("stacks")
assert f"{get_default_cbapi_product()}:{get_default_cbapi_profile()}" == "more_buckets:stacks"
def test_playbook_map():
from cbinterface.config import get_playbook_map
playbook_map = get_playbook_map()
assert isinstance(playbook_map, dict)
playbook = list(playbook_map.values())[0]
assert list(playbook.keys()) == ["path", "name", "description"]
def test_playbook_build():
from cbinterface.scripted_live_response import build_playbook_commands
from cbinterface.commands import GetFile, PutFile, ExecuteCommand
commands = build_playbook_commands(f"{HOME_PATH}/test_data/playbooking.around.ini")
# order matters
assert len(commands) == 3
assert isinstance(commands[0], PutFile)
assert isinstance(commands[1], ExecuteCommand)
assert isinstance(commands[2], GetFile)
def test_remediation_script():
from cbinterface.scripted_live_response import build_remediation_commands
from cbinterface.commands import (
GetFile,
PutFile,
ExecuteCommand,
DeleteFile,
KillProcessByID,
KillProcessByName,
DeleteRegistryKeyValue,
DeleteRegistryKey,
)
cmds = build_remediation_commands(f"{HOME_PATH}/test_data/remediating.around.ini")
assert isinstance(cmds, list)
# for cmd in cmds:
# print(type(cmd))
assert len(cmds) == 16
assert isinstance(cmds[0], KillProcessByID)
assert isinstance(cmds[1], KillProcessByName)
assert isinstance(cmds[2], ExecuteCommand)
assert isinstance(cmds[3], GetFile)
assert isinstance(cmds[4], ExecuteCommand)
assert isinstance(cmds[5], ExecuteCommand)
assert isinstance(cmds[6], GetFile)
assert isinstance(cmds[7], ExecuteCommand)
assert isinstance(cmds[8], DeleteRegistryKeyValue)
assert isinstance(cmds[9], DeleteFile)
assert isinstance(cmds[10], ExecuteCommand)
assert isinstance(cmds[11], GetFile)
assert isinstance(cmds[12], ExecuteCommand)
assert isinstance(cmds[13], ExecuteCommand)
assert isinstance(cmds[14], GetFile)
assert isinstance(cmds[15], ExecuteCommand)