forked from OpenCTI-Platform/client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_opencti_stix2_splitter.py
55 lines (46 loc) · 1.5 KB
/
test_opencti_stix2_splitter.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
import uuid
from stix2 import Report
from pycti.utils.opencti_stix2_splitter import OpenCTIStix2Splitter
def test_split_bundle():
stix_splitter = OpenCTIStix2Splitter()
with open("./tests/data/enterprise-attack.json") as file:
content = file.read()
bundles = stix_splitter.split_bundle(content)
assert len(bundles) == 7029
#
# with open("./tests/data/test.pdf", 'w') as file:
# content = file.read()
# with pytest.raises(Exception):
# stix_splitter.split_bundle(content)
def test_crate_bundle():
stix_splitter = OpenCTIStix2Splitter()
report = Report(
report_types=["campaign"],
name="Bad Cybercrime",
published="2016-04-06T20:03:00.000Z",
object_refs=["indicator--a740531e-63ff-4e49-a9e1-a0a3eed0e3e7"],
).serialize()
observables = [report]
bundle = stix_splitter.stix2_create_bundle(
"bundle--" + str(uuid.uuid4()),
0,
observables,
use_json=False,
event_version=None,
)
for key in ["type", "id", "spec_version", "objects", "x_opencti_seq"]:
assert key in bundle
assert len(bundle.keys()) == 5
bundle = stix_splitter.stix2_create_bundle(
"bundle--" + str(uuid.uuid4()), 0, observables, use_json=False, event_version=1
)
for key in [
"type",
"id",
"spec_version",
"objects",
"x_opencti_event_version",
"x_opencti_seq",
]:
assert key in bundle
assert len(bundle.keys()) == 6