|
1
|
|
|
import tests.any_test_help |
|
2
|
|
|
import graph.oval_graph |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
def test_create_node_dict_for_sigmaJs_0(): |
|
6
|
|
|
out = { |
|
7
|
|
|
'type': 'circle', |
|
8
|
|
|
'borderColor': '#ff0000', |
|
9
|
|
|
'color': '#ff0000', |
|
10
|
|
|
'id': 1, |
|
11
|
|
|
'label': 'and', |
|
12
|
|
|
'size': 3, |
|
13
|
|
|
'text': None, |
|
14
|
|
|
'url': 'null', |
|
15
|
|
|
'title': 1, |
|
16
|
|
|
'x': 0, |
|
17
|
|
|
'y': 0 |
|
18
|
|
|
} |
|
19
|
|
|
Tree = tests.any_test_help.get_simple_tree() |
|
20
|
|
|
tests.any_test_help.any_test_create_node_dict_for_sigmaJs(Tree, out) |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
def test_create_node_dict_for_sigmaJs_1(): |
|
24
|
|
|
out = { |
|
25
|
|
|
'type': 'circle', |
|
26
|
|
|
'borderColor': '#00ff00', |
|
27
|
|
|
'color': '#00ff00', |
|
28
|
|
|
'id': 1, |
|
29
|
|
|
'label': 'and', |
|
30
|
|
|
'size': 3, |
|
31
|
|
|
'text': None, |
|
32
|
|
|
'url': 'null', |
|
33
|
|
|
'title': 1, |
|
34
|
|
|
'x': 0, |
|
35
|
|
|
'y': 0 |
|
36
|
|
|
} |
|
37
|
|
|
Tree = graph.oval_graph.OvalNode(1, 'operator', 'and', False, None, [ |
|
38
|
|
|
graph.oval_graph.OvalNode(2, 'value', "true", False, None) |
|
39
|
|
|
] |
|
40
|
|
|
) |
|
41
|
|
|
|
|
42
|
|
|
tests.any_test_help.any_test_create_node_dict_for_sigmaJs(Tree, out) |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
def test_create_node_dict_for_sigmaJs_2(): |
|
46
|
|
|
out = { |
|
47
|
|
|
'type': 'circle', |
|
48
|
|
|
'borderColor': '#000000', |
|
49
|
|
|
'color': '#000000', |
|
50
|
|
|
'id': 1, |
|
51
|
|
|
'label': 'and', |
|
52
|
|
|
'size': 3, |
|
53
|
|
|
'text': None, |
|
54
|
|
|
'url': 'null', |
|
55
|
|
|
'title': '1 and', |
|
56
|
|
|
'x': 0, |
|
57
|
|
|
'y': 0 |
|
58
|
|
|
} |
|
59
|
|
|
Tree = graph.oval_graph.OvalNode(1, 'operator', 'and', False, None, [ |
|
60
|
|
|
graph.oval_graph.OvalNode(2, 'value', "noteval", False, None) |
|
61
|
|
|
] |
|
62
|
|
|
) |
|
63
|
|
|
|
|
64
|
|
|
tests.any_test_help.any_test_create_node_dict_for_sigmaJs(Tree, out) |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
def test_create_node_dict_for_sigmaJs_3(): |
|
68
|
|
|
out = { |
|
69
|
|
|
'type': 'circle', |
|
70
|
|
|
'borderColor': '#ff0000', |
|
71
|
|
|
'color': '#ff0000', |
|
72
|
|
|
'id': 1, |
|
73
|
|
|
'label': '1', |
|
74
|
|
|
'size': 3, |
|
75
|
|
|
'text': None, |
|
76
|
|
|
'url': 'null', |
|
77
|
|
|
'title': 1, |
|
78
|
|
|
'x': 0, |
|
79
|
|
|
'y': 0 |
|
80
|
|
|
} |
|
81
|
|
|
Tree = graph.oval_graph.OvalNode(1, 'value', 'false', False, None) |
|
82
|
|
|
|
|
83
|
|
|
tests.any_test_help.any_test_create_node_dict_for_sigmaJs(Tree, out) |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
def test_create_node_dict_for_sigmaJs_4(): |
|
87
|
|
|
out = { |
|
88
|
|
|
'type': 'circle', |
|
89
|
|
|
'borderColor': '#00ff00', |
|
90
|
|
|
'color': '#00ff00', |
|
91
|
|
|
'id': 1, |
|
92
|
|
|
'label': '1', |
|
93
|
|
|
'size': 3, |
|
94
|
|
|
'text': None, |
|
95
|
|
|
'url': 'null', |
|
96
|
|
|
'title': 1, |
|
97
|
|
|
'x': 0, |
|
98
|
|
|
'y': 0 |
|
99
|
|
|
} |
|
100
|
|
|
Tree = graph.oval_graph.OvalNode(1, 'value', 'true', False, None) |
|
101
|
|
|
|
|
102
|
|
|
tests.any_test_help.any_test_create_node_dict_for_sigmaJs(Tree, out) |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
def test_create_node_dict_for_sigmaJs_5(): |
|
106
|
|
|
out = { |
|
107
|
|
|
'type': 'circle', |
|
108
|
|
|
'borderColor': '#000000', |
|
109
|
|
|
'color': '#000000', |
|
110
|
|
|
'id': 1, |
|
111
|
|
|
'label': '1', |
|
112
|
|
|
'size': 3, |
|
113
|
|
|
'text': None, |
|
114
|
|
|
'url': 'null', |
|
115
|
|
|
'title': '1 error', |
|
116
|
|
|
'x': 0, |
|
117
|
|
|
'y': 0 |
|
118
|
|
|
} |
|
119
|
|
|
Tree = graph.oval_graph.OvalNode(1, 'value', 'error', False, None) |
|
120
|
|
|
|
|
121
|
|
|
tests.any_test_help.any_test_create_node_dict_for_sigmaJs(Tree, out) |
|
122
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
def test_create_node_with_negation_dict_for_sigmaJs(): |
|
125
|
|
|
out = { |
|
126
|
|
|
'type': 'circle', |
|
127
|
|
|
'borderColor': '#ff0000', |
|
128
|
|
|
'color': '#00ff00', |
|
129
|
|
|
'id': 1, |
|
130
|
|
|
'label': 'and', |
|
131
|
|
|
'size': 3, |
|
132
|
|
|
'text': None, |
|
133
|
|
|
'url': 'null', |
|
134
|
|
|
'title': 1, |
|
135
|
|
|
'x': 0, |
|
136
|
|
|
'y': 0 |
|
137
|
|
|
} |
|
138
|
|
|
Tree = graph.oval_graph.OvalNode(1, 'operator', 'and', True, None, [ |
|
139
|
|
|
graph.oval_graph.OvalNode(2, 'value', "false", False, None) |
|
140
|
|
|
] |
|
141
|
|
|
) |
|
142
|
|
|
|
|
143
|
|
|
tests.any_test_help.any_test_create_node_dict_for_sigmaJs(Tree, out) |
|
144
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
def test_create_node_with_negation_dict_for_sigmaJs1(): |
|
147
|
|
|
out = { |
|
148
|
|
|
'type': 'circle', |
|
149
|
|
|
'borderColor': '#00ff00', |
|
150
|
|
|
'color': '#ff0000', |
|
151
|
|
|
'id': 1, |
|
152
|
|
|
'label': 'and', |
|
153
|
|
|
'size': 3, |
|
154
|
|
|
'text': None, |
|
155
|
|
|
'url': 'null', |
|
156
|
|
|
'title': 1, |
|
157
|
|
|
'x': 0, |
|
158
|
|
|
'y': 0 |
|
159
|
|
|
} |
|
160
|
|
|
Tree = graph.oval_graph.OvalNode(1, 'operator', 'and', True, None, [ |
|
161
|
|
|
graph.oval_graph.OvalNode(2, 'value', "true", False, None) |
|
162
|
|
|
] |
|
163
|
|
|
) |
|
164
|
|
|
|
|
165
|
|
|
tests.any_test_help.any_test_create_node_dict_for_sigmaJs(Tree, out) |
|
166
|
|
|
|
|
167
|
|
|
|
|
168
|
|
View Code Duplication |
def test_create_node_with_negation_dict_for_sigmaJs2(): |
|
|
|
|
|
|
169
|
|
|
out = { |
|
170
|
|
|
'type': 'circle', |
|
171
|
|
|
'borderColor': '#00ff00', |
|
172
|
|
|
'color': '#ff0000', |
|
173
|
|
|
'id': 2, |
|
174
|
|
|
'label': '2', |
|
175
|
|
|
'size': 3, |
|
176
|
|
|
'text': None, |
|
177
|
|
|
'url': 'null', |
|
178
|
|
|
'title': 2, |
|
179
|
|
|
'x': 0, |
|
180
|
|
|
'y': 0 |
|
181
|
|
|
} |
|
182
|
|
|
Tree = graph.oval_graph.OvalNode(1, 'operator', 'and', False, None, [ |
|
183
|
|
|
graph.oval_graph.OvalNode(2, 'value', "true", True, None) |
|
184
|
|
|
] |
|
185
|
|
|
) |
|
186
|
|
|
|
|
187
|
|
|
tests.any_test_help.any_test_create_node_dict_for_sigmaJs( |
|
188
|
|
|
Tree.children[0], out) |
|
189
|
|
|
|
|
190
|
|
|
|
|
191
|
|
View Code Duplication |
def test_create_node_with_negation_dict_for_sigmaJs3(): |
|
|
|
|
|
|
192
|
|
|
out = { |
|
193
|
|
|
'type': 'circle', |
|
194
|
|
|
'borderColor': '#ff0000', |
|
195
|
|
|
'color': '#00ff00', |
|
196
|
|
|
'id': 2, |
|
197
|
|
|
'label': '2', |
|
198
|
|
|
'size': 3, |
|
199
|
|
|
'text': None, |
|
200
|
|
|
'url': 'null', |
|
201
|
|
|
'title': 2, |
|
202
|
|
|
'x': 0, |
|
203
|
|
|
'y': 0 |
|
204
|
|
|
} |
|
205
|
|
|
Tree = graph.oval_graph.OvalNode(1, 'operator', 'and', False, None, [ |
|
206
|
|
|
graph.oval_graph.OvalNode(2, 'value', "false", True, None) |
|
207
|
|
|
] |
|
208
|
|
|
) |
|
209
|
|
|
|
|
210
|
|
|
tests.any_test_help.any_test_create_node_dict_for_sigmaJs( |
|
211
|
|
|
Tree.children[0], out) |
|
212
|
|
|
|
|
213
|
|
|
|
|
214
|
|
|
def test_create_edge_dict_for_sigmaJs(): |
|
215
|
|
|
out = { |
|
216
|
|
|
'id': 'random_ID', |
|
217
|
|
|
'source': 1, |
|
218
|
|
|
'target': 2, |
|
219
|
|
|
'color': '#000000' |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
target_node = { |
|
223
|
|
|
'type': 'circle', |
|
224
|
|
|
'borderColor': '#000000', |
|
225
|
|
|
'color': '#000000', |
|
226
|
|
|
'id': 2, |
|
227
|
|
|
'label': 'error', |
|
228
|
|
|
'size': 3, |
|
229
|
|
|
'text': None, |
|
230
|
|
|
'url': 'null', |
|
231
|
|
|
'title': '1 error', |
|
232
|
|
|
'x': 0, |
|
233
|
|
|
'y': 0 |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
assert tests.any_test_help.get_simple_tree()._create_edge( |
|
237
|
|
|
1, 2, target_node)['source'] == out['source'] |
|
238
|
|
|
assert tests.any_test_help.get_simple_tree()._create_edge( |
|
239
|
|
|
1, 2, target_node)['target'] == out['target'] |
|
240
|
|
|
assert tests.any_test_help.get_simple_tree()._create_edge( |
|
241
|
|
|
1, 2, target_node)['color'] == out['color'] |
|
242
|
|
|
|
|
243
|
|
|
|
|
244
|
|
|
def test_create_array_of_ids_form_tree(): |
|
245
|
|
|
array = tests.any_test_help.get_simple_tree().create_list_of_id() |
|
246
|
|
|
assert array == [1, 2, 3, 4, 5, 6] |
|
247
|
|
|
|
|
248
|
|
|
|
|
249
|
|
|
def test_transformation_tree_to_Json_for_SigmaJs_0(): |
|
250
|
|
|
test_data_src = 'test_data/sigmaJs_json0.json' |
|
251
|
|
|
src = 'data/ssg-fedora-ds-arf.xml' |
|
252
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny' |
|
253
|
|
|
|
|
254
|
|
|
tests.any_test_help.any_test_transformation_tree_to_Json_for_SigmaJs( |
|
255
|
|
|
src, test_data_src, rule_id) |
|
256
|
|
|
|
|
257
|
|
|
|
|
258
|
|
|
def test_transformation_tree_to_Json_for_SigmaJs_with_duplicated_test(): |
|
259
|
|
|
test_data_src = 'test_data/sigmaJs_json1.json' |
|
260
|
|
|
src = 'data/ssg-fedora-ds-arf.xml' |
|
261
|
|
|
rule_id = 'xccdf_org.ssgproject.content_rule_disable_host_auth' |
|
262
|
|
|
|
|
263
|
|
|
tests.any_test_help.any_test_transformation_tree_to_Json_for_SigmaJs( |
|
264
|
|
|
src, test_data_src, rule_id) |
|
265
|
|
|
|