Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 82 additions & 86 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,87 +1,83 @@
{
"python.defaultInterpreterPath": "env/bin/python",
"python.languageServer": "Pylance",
"python.analysis.extraPaths": [
"env"
],
"python.testing.pytestEnabled": true,
"python.analysis.diagnosticSeverityOverrides": {
"reportUnusedImport": "error",
"reportDuplicateImport": "error",
},
"python.analysis.typeCheckingMode": "basic",
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"files.watcherExclude": {
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/": true,
"/node_modules/**": true,
"**/env/": true,
"/env/**": true,
"**/__pycache__": true,
"/__pycache__/**": true,
"**/.cache": true,
"**/.eggs": true,
"**/.ipynb_checkpoints": true,
"**/.mypy_cache": true,
"**/.pytest_cache": true,
"**/*.egg-info": true,
"**/*.feather": true,
"**/*.parquet*": true,
"**/*.pyc": true,
"**/*.zip": true
},
},
"cSpell.words": [
"ADDC",
"agentname",
"Antispyware",
"Antiviruses",
"Anynet",
"apitw",
"Autorun",
"bdexe",
"bdfb",
"bdurl",
"Bitdefender",
"Bitlocker",
"Bluescreen",
"BSOD",
"Clearand",
"clientname",
"Cortana",
"customidtw",
"Debugmode",
"DIMM's",
"Duplicati",
"ESET",
"Faststartup",
"fromaddress",
"fullname",
"Hudu",
"iperf",
"LAPSID",
"localadmin",
"MSITW",
"netsh",
"procname",
"Restartor",
"Screenconnect",
"Securepoint",
"sitename",
"smtpserver",
"Sophos",
"Speedtest",
"Splashtop",
"SSID",
"SUUID",
"Teamviewer",
"toaddress",
"TRMM",
"urlmsitw",
"warnwhenovermemsize",
"Winget"
]
}
"python.defaultInterpreterPath": "env/bin/python",
"python.languageServer": "Pylance",
"python.analysis.extraPaths": ["env"],
"python.testing.pytestEnabled": true,
"python.analysis.diagnosticSeverityOverrides": {
"reportUnusedImport": "error",
"reportDuplicateImport": "error"
},
"python.analysis.typeCheckingMode": "basic",
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/": true,
"/node_modules/**": true,
"**/env/": true,
"/env/**": true,
"**/__pycache__": true,
"/__pycache__/**": true,
"**/.cache": true,
"**/.eggs": true,
"**/.ipynb_checkpoints": true,
"**/.mypy_cache": true,
"**/.pytest_cache": true,
"**/*.egg-info": true,
"**/*.feather": true,
"**/*.parquet*": true,
"**/*.pyc": true,
"**/*.zip": true
},
"cSpell.words": [
"ADDC",
"agentname",
"Antispyware",
"Antiviruses",
"Anynet",
"apitw",
"Autorun",
"bdexe",
"bdfb",
"bdurl",
"Bitdefender",
"Bitlocker",
"Bluescreen",
"BSOD",
"Clearand",
"clientname",
"Cortana",
"customidtw",
"Debugmode",
"DIMM's",
"Duplicati",
"ESET",
"Faststartup",
"fromaddress",
"fullname",
"Hudu",
"iperf",
"LAPSID",
"localadmin",
"MSITW",
"netsh",
"procname",
"Restartor",
"Screenconnect",
"Securepoint",
"sitename",
"smtpserver",
"Sophos",
"Speedtest",
"Splashtop",
"SSID",
"SUUID",
"Teamviewer",
"toaddress",
"TRMM",
"urlmsitw",
"warnwhenovermemsize",
"Winget"
]
}
118 changes: 70 additions & 48 deletions test_json.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import pytest


def _check_for_duplicate_keys(items):
Expand All @@ -12,64 +13,85 @@ def _check_for_duplicate_keys(items):
return tmp


def test_community_script_json_file():
def _load_scripts():
with open("community_scripts.json") as f:
return json.load(f, object_pairs_hook=_check_for_duplicate_keys)


@pytest.mark.parametrize(
"script",
_load_scripts(),
ids=lambda script: script["filename"]
)
def test_community_script_json_file(script):
valid_shells = ["powershell", "python", "cmd", "shell"]
valid_os = ["windows", "linux", "darwin"]

with open("community_scripts.json") as f:
info = json.load(f, object_pairs_hook=_check_for_duplicate_keys)

guids = []
for script in info:
fn: str = script["filename"]
assert os.path.exists(os.path.join("scripts", fn))
assert script["filename"]
assert script["name"]
assert script["description"]
assert script["shell"]
assert script["shell"] in valid_shells

if fn.endswith(".ps1"):
assert script["shell"] == "powershell"
elif fn.endswith(".bat"):
assert script["shell"] == "cmd"
elif fn.endswith(".py"):
assert script["shell"] == "python"

if "args" in script.keys():
assert isinstance(script["args"], list)

# allows strings as long as they can be type casted to int
if "default_timeout" in script.keys():
assert isinstance(int(script["default_timeout"]), int)

# check supported platforms
if "supported_platforms" in script.keys():
assert isinstance(script["supported_platforms"], list)
for i in script["supported_platforms"]:
assert i in valid_os

assert "guid" in script.keys()
guids.append(script["guid"])

# check guids are unique
fn: str = script["filename"]
assert os.path.exists(os.path.join("scripts", fn))
assert script["filename"]
assert script["name"]
assert script["description"]
assert script["shell"]
assert script["shell"] in valid_shells

if fn.endswith(".ps1"):
assert script["shell"] == "powershell"
elif fn.endswith(".bat"):
assert script["shell"] == "cmd"
elif fn.endswith(".py"):
assert script["shell"] == "python"

if "args" in script.keys():
assert isinstance(script["args"], list)

# allows strings as long as they can be type casted to int
if "default_timeout" in script.keys():
assert isinstance(int(script["default_timeout"]), int)

# check supported platforms
if "supported_platforms" in script.keys():
assert isinstance(script["supported_platforms"], list)
for i in script["supported_platforms"]:
assert i in valid_os

assert "guid" in script.keys()


def test_guids_are_unique():
"""Test that all script GUIDs are unique"""
scripts = _load_scripts()
guids = [script["guid"] for script in scripts]
assert len(guids) == len(set(guids))


def test_community_script_has_jsonfile_entry():
with open(os.path.join("community_scripts.json")) as f:
info = json.load(f)

filenames = [i["filename"] for i in info]

def _get_script_files():
"""Get all script files from the scripts directory"""
files = []
with os.scandir("scripts") as it:
for f in it:
if not f.name.startswith(".") and f.is_file():
assert f.name in filenames
files.append(f.name)
return files


def test_script_filenames_do_not_contain_spaces():
@pytest.mark.parametrize(
"filename",
_get_script_files(),
ids=lambda filename: filename
)
def test_community_script_has_jsonfile_entry(filename):
with open(os.path.join("community_scripts.json")) as f:
info = json.load(f)
for script in info:
assert " " not in script["filename"]

filenames = [i["filename"] for i in info]
assert filename in filenames


@pytest.mark.parametrize(
"script",
_load_scripts(),
ids=lambda script: script["filename"]
)
def test_script_filenames_do_not_contain_spaces(script):
assert " " not in script["filename"]