-
Notifications
You must be signed in to change notification settings - Fork 20
/
_test_stix.py
81 lines (69 loc) · 2.51 KB
/
_test_stix.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from datetime import datetime
class TestSTIX(unittest.TestCase):
def _assert_multiple_equal(self, reference, *elements):
for element in elements:
self.assertEqual(reference, element)
@staticmethod
def _datetime_from_str(timestamp):
regex = '%Y-%m-%dT%H:%M:%S'
if '.' in timestamp:
regex = f'{regex}.%f'
if timestamp.endswith('Z') or '+' in timestamp:
regex = f'{regex}%z'
return datetime.strptime(timestamp, regex)
class TestSTIX20(TestSTIX):
__hash_types_mapping = {
'sha1': 'SHA-1',
'SHA-1': 'sha1',
'sha224': 'SHA-224',
'SHA-224': 'sha224',
'sha256': 'SHA-256',
'SHA-256': 'sha256',
'sha384': 'SHA-384',
'SHA-384': 'sha384',
'sha512': 'SHA-512',
'SHA-512': 'sha512',
'sha512/224': 'SHA-224',
'sha512/256': 'SHA-256',
'ssdeep': 'ssdeep'
}
@classmethod
def hash_types_mapping(cls, hash_type):
if hash_type in cls.__hash_types_mapping:
return cls.__hash_types_mapping[hash_type]
return hash_type.lower() if hash_type.isupper() else hash_type.upper()
class TestSTIX21(TestSTIX):
__hash_types_mapping = {
'sha1': 'SHA-1',
'SHA-1': 'sha1',
'sha224': 'SHA224',
'SHA224': 'sha224',
'sha256': 'SHA-256',
'SHA-256': 'sha256',
'sha384': 'SHA384',
'SHA384': 'sha384',
'sha512': 'SHA-512',
'SHA-512': 'sha512',
'sha512/224': 'SHA224',
'sha512/256': 'SHA-256'
}
@classmethod
def hash_types_mapping(cls, hash_type):
if hash_type in cls.__hash_types_mapping:
return cls.__hash_types_mapping[hash_type]
return hash_type.lower() if hash_type.isupper() else hash_type.upper()
def _check_grouping_features(self, grouping, event, identity_id):
timestamp = event['timestamp']
if not isinstance(timestamp, datetime):
timestamp = self._datetime_from_timestamp(timestamp)
self.assertEqual(grouping.type, 'grouping')
self.assertEqual(grouping.id, f"grouping--{event['uuid']}")
self.assertEqual(grouping.created_by_ref, identity_id)
self.assertEqual(grouping.labels, self._labels)
self.assertEqual(grouping.name, event['info'])
self.assertEqual(grouping.created, timestamp)
self.assertEqual(grouping.modified, timestamp)
return grouping.object_refs