-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathtest_tasks.py
163 lines (157 loc) · 5.54 KB
/
test_tasks.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from typing import Any
from executions.enums import Status
from tests.cases import ApiTestCase
from tests.framework import ApiTest
from tools.enums import Intensity
task1 = {
"target_id": 1,
"configuration_id": 1,
"intensity": Intensity.HARD.name.capitalize(),
}
task2 = {"target_id": 1, "process_id": 1}
invalid_task1 = {"target_id": 1, "intensity": 1}
invalid_task2 = {"target_id": 1}
invalid_task3 = {
**task1,
"configuration_id": 25,
"intensity": Intensity.SNEAKY.name.capitalize(),
}
class TaskTest(ApiTest):
endpoint = "/api/tasks/"
expected_str = "10.10.10.10 - All tools"
cases = [
ApiTestCase(["admin2", "auditor2", "reader2"], "get", 200),
ApiTestCase(
["admin1", "auditor1", "reader1"],
"get",
200,
expected=[
{
"id": 2,
"target": {"id": 1, "target": "10.10.10.10"},
"configuration": {
"id": 1,
"tool": {"id": 1, "name": "Nmap"},
"name": "TCP ports",
},
"process": None,
"executor": {"id": 3, "username": "auditor1"},
"intensity": Intensity.NORMAL.name.capitalize(),
"executions": [3],
},
{
"id": 1,
"target": {"id": 1, "target": "10.10.10.10"},
"configuration": None,
"process": {"id": 1, "name": "All tools"},
"executor": {"id": 1, "username": "admin1"},
"intensity": Intensity.NORMAL.name.capitalize(),
"executions": [1, 2],
},
],
),
ApiTestCase(
["admin2", "auditor2", "reader2"], "get", 404, endpoint="{endpoint}1/"
),
ApiTestCase(
["admin1", "auditor1", "reader1"],
"get",
200,
expected={
"id": 1,
"target": {"id": 1, "target": "10.10.10.10"},
"configuration": None,
"process": {"id": 1, "name": "All tools"},
"executor": {"id": 1, "username": "admin1"},
"intensity": Intensity.NORMAL.name.capitalize(),
"executions": [1, 2],
},
endpoint="{endpoint}1/",
),
ApiTestCase(
["admin2", "auditor2"], "post", 404, endpoint="{endpoint}1/repeat/"
),
ApiTestCase(
["reader1", "reader2"], "post", 403, endpoint="{endpoint}1/repeat/"
),
ApiTestCase(
["admin1", "auditor1"], "post", 400, endpoint="{endpoint}1/repeat/"
),
ApiTestCase(
["auditor1"],
"post",
201,
expected={
"id": 3,
"target": {"id": 1, "target": "10.10.10.10"},
"configuration": {
"id": 1,
"tool": {"id": 1, "name": "Nmap"},
"name": "TCP ports",
},
"process": None,
"intensity": Intensity.NORMAL.name.capitalize(),
},
endpoint="{endpoint}2/repeat/",
),
ApiTestCase(["admin2", "auditor2"], "delete", 404, endpoint="{endpoint}2/"),
ApiTestCase(["reader1", "reader2"], "delete", 403, endpoint="{endpoint}2/"),
ApiTestCase(["admin1", "auditor1"], "delete", 400, endpoint="{endpoint}2/"),
ApiTestCase(["admin1"], "delete", 204, endpoint="{endpoint}1/"),
ApiTestCase(["auditor1"], "delete", 400, endpoint="{endpoint}1/"),
ApiTestCase(
["admin1", "auditor1", "reader1"],
"get",
200,
expected={"id": 1, "status": Status.COMPLETED},
endpoint="/api/executions/1/",
),
ApiTestCase(
["admin1", "auditor1", "reader1"],
"get",
200,
expected={"id": 2, "status": Status.CANCELLED},
endpoint="/api/executions/2/",
),
ApiTestCase(["admin1", "auditor1"], "post", 400, invalid_task1),
ApiTestCase(["admin1", "auditor1"], "post", 400, invalid_task2),
ApiTestCase(["admin1", "auditor1"], "post", 400, invalid_task3),
ApiTestCase(["admin2", "auditor2", "reader1", "reader2"], "post", 403, task1),
ApiTestCase(
["admin1"],
"post",
201,
task1,
{
"id": 4,
"target": {"id": 1, "target": "10.10.10.10"},
"configuration": {
"id": 1,
"tool": {"id": 1, "name": "Nmap"},
"name": "TCP ports",
},
"process": None,
"executor": {"id": 1, "username": "admin1"},
"intensity": Intensity.HARD.name.capitalize(),
},
),
ApiTestCase(
["auditor1"],
"post",
201,
task2,
{
"id": 5,
"target": {"id": 1, "target": "10.10.10.10"},
"configuration": None,
"process": {"id": 1, "name": "All tools"},
"executor": {"id": 3, "username": "auditor1"},
"intensity": Intensity.NORMAL.name.capitalize(),
},
),
]
def setUp(self) -> None:
super().setUp()
self._setup_tasks_and_executions()
def _get_object(self) -> Any:
return self.running_task