-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_models.py
75 lines (65 loc) · 2.08 KB
/
test_models.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
import pytest
from pydantic import ValidationError
from models import Atomic, extract_mustached_keys
@pytest.mark.parametrize(
"test_input,expected",
[
("#{test1} #{test2}", ["test1", "test2"]),
("cat #{test1} > ~/.bash_history", ["test1"]),
],
)
def test_keys(test_input, expected):
assert sorted(extract_mustached_keys([test_input])) == expected
@pytest.mark.parametrize(
"input_type,default",
[
("url", "github.com/redcanaryco/atomic-red-team"),
("float", "1.0"),
("int", "1"),
("string", 1),
("path", 1.0),
],
)
def test_input_args(input_type, default):
atomic = {
"name": "Curl atomic repo",
"description": "Curl atomic repo",
"supported_platforms": ["windows"],
"input_arguments": {
"random_variable": {
"description": "Some random variable",
"type": input_type,
"default": default,
}
},
"executor": {"name": "bash", "command": "curl #{random_variable}"},
}
with pytest.raises(ValidationError):
Atomic(**atomic)
def test_unused_arg():
atomic = {
"name": "Curl atomic repo",
"description": "Curl atomic repo",
"supported_platforms": ["windows"],
"input_arguments": {
"random_variable": {
"description": "Some random variable",
"type": "string",
"default": "github.com/redcanaryco/atomic-red-team",
}
},
"executor": {"name": "bash", "command": "curl"},
}
with pytest.raises(ValidationError) as exc:
Atomic(**atomic)
assert "'random_variable' is not used" in str(exc.value)
def test_missing_arg():
atomic = {
"name": "Curl atomic repo",
"description": "Curl atomic repo",
"supported_platforms": ["windows"],
"executor": {"name": "bash", "command": "curl #{random_variable}"},
}
with pytest.raises(ValidationError) as exc:
Atomic(**atomic)
assert "random_variable is not defined" in str(exc.value)