forked from yaleman/crowdstrike_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sensors.py
70 lines (60 loc) · 2.33 KB
/
test_sensors.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
#!/usr/bin/env python3
""" terrible tests for the sensors endpoints """
import json
import os
import sys
import tempfile
try:
from loguru import logger
from crowdstrike import CrowdstrikeAPI
except ImportError as import_error:
sys.exit(f"Error importing required library: {import_error}")
# grab config from the file or environment variable
try:
from config import CLIENT_ID, CLIENT_SECRET
except ImportError:
if os.environ.get('CLIENT_ID'):
logger.debug("Using Client ID from environment variable")
CLIENT_ID = os.environ.get('CLIENT_ID')
if os.environ.get('CLIENT_SECRET'):
logger.debug("Using Client Secret from environment variable")
CLIENT_SECRET = os.environ.get('CLIENT_SECRET')
if not CLIENT_ID and not CLIENT_SECRET:
sys.exit("you didn't set the config either via file or environment")
logger.enable("crowdstrike")
def test_really_replace_this_with_a_real_test():
""" terrible test, replace it with something not-terrible """
# TODO: make this some vaguely correct tests
crowdstrike = CrowdstrikeAPI(CLIENT_ID, CLIENT_SECRET)
# find a few different crowdstrike ids
ids = crowdstrike.get_sensor_installer_ids(
sort_string="release_date|desc",
filter_string='platform:"mac"'
)
assert ids is not None
ids = crowdstrike.get_sensor_installer_ids(
sort_string="release_date|desc",
)
assert ids is not None
ids = crowdstrike.get_sensor_installer_ids(
filter_string='platform:"mac"'
)
assert ids is not None
# test downloading the latest macOS installer
maclatest = crowdstrike.get_latest_sensor_id(filter_string='platform:"mac"')
logger.info(
json.dumps(
# also tests showing an installer's data
crowdstrike.get_sensor_installer_details(maclatest),
indent=2
)
)
assert maclatest is not None
logger.info("Testing download to temporary directory....")
# this'll write it to a temporary directory which is removed afterwards
with tempfile.TemporaryDirectory() as tmpdirname:
filename = f'{tmpdirname}/FalconSensorMacOS.pkg'
response = crowdstrike.download_sensor(maclatest, filename)
assert response is not None
assert os.path.exists(filename)
#raise ValueError(f'Failed to download file :(')