Skip to content

Commit aca3084

Browse files
committed
fix: [tests] Updated tests following recent change on the location objects conversion
1 parent 175ec39 commit aca3084

File tree

3 files changed

+25
-41
lines changed

3 files changed

+25
-41
lines changed

tests/_test_stix_import.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
from base64 import b64encode
66
from collections import defaultdict
77
from misp_stix_converter import (
8-
ExternalSTIX2toMISPMapping, ExternalSTIX2toMISPParser,
9-
InternalSTIX2toMISPParser, MISP_org_uuid)
8+
ExternalSTIX2Mapping, ExternalSTIX2toMISPParser, InternalSTIX2toMISPParser,
9+
MISP_org_uuid)
1010
from uuid import UUID, uuid5
1111
from ._test_stix import TestSTIX
12-
from .update_documentation import AttributesDocumentationUpdater, ObjectsDocumentationUpdater
12+
from .update_documentation import (
13+
AttributesDocumentationUpdater, ObjectsDocumentationUpdater)
1314

1415

1516
class TestSTIX2Bundles:
@@ -379,7 +380,7 @@ def _populate_vulnerability_documentation(self, **kwargs):
379380

380381

381382
class TestExternalSTIX2Import(TestSTIX2Import):
382-
_galaxy_name_mapping = ExternalSTIX2toMISPMapping().galaxy_name_mapping
383+
_galaxy_name_mapping = ExternalSTIX2Mapping().galaxy_name_mapping
383384

384385
def setUp(self):
385386
self.parser = ExternalSTIX2toMISPParser()

tests/test_external_stix21_bundles.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -978,17 +978,18 @@
978978
"modified": "2020-10-25T16:22:00.000Z",
979979
"name": "sweden",
980980
"description": "Sweden",
981-
"country": "SE"
981+
"country": "SE",
982+
"region": "northern-europe"
982983
},
983984
{
984-
"type": "location",
985+
"administrative_area": "US-DC",
986+
"country": "US",
987+
"created": "2021-03-13T20:09:21.286293Z",
988+
"id": "location--78a7f0f3-ea60-4ca2-894e-9e825b94b592",
989+
"modified": "2021-12-01T16:19:51.601791Z",
990+
"name": "District of Columbia",
985991
"spec_version": "2.1",
986-
"id": "location--f93cb275-0366-4ecc-abf0-a17928d1e177",
987-
"created": "2020-10-25T16:22:00.000Z",
988-
"modified": "2020-10-25T16:22:00.000Z",
989-
"name": "Northern Europe",
990-
"description": "Nothern Europe",
991-
"region": "northern-europe"
992+
"type": "location"
992993
}
993994
]
994995
_MAC_ADDRESS_ATTRIBUTES = [

tests/test_external_stix21_import.py

+11-29
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,6 @@ def test_stix21_bundle_with_grouping_description(self):
6868
# MISP GALAXIES IMPORT TESTS #
6969
############################################################################
7070

71-
def _check_location_galaxy_features(
72-
self, galaxies, stix_object, galaxy_type, cluster_value=None):
73-
self.assertEqual(len(galaxies), 1)
74-
galaxy = galaxies[0]
75-
self.assertEqual(len(galaxy.clusters), 1)
76-
cluster = galaxy.clusters[0]
77-
self._assert_multiple_equal(galaxy.type, cluster.type, galaxy_type)
78-
self.assertEqual(
79-
galaxy.name, self._galaxy_name_mapping(galaxy_type)['name']
80-
)
81-
self.assertEqual(
82-
galaxy.description,
83-
self._galaxy_name_mapping(galaxy_type)['description']
84-
)
85-
if cluster_value is None:
86-
self.assertEqual(cluster.value, stix_object.name)
87-
else:
88-
self.assertEqual(cluster.value, cluster_value)
89-
if hasattr(stix_object, 'description'):
90-
self.assertEqual(cluster.description, stix_object.description)
91-
return cluster.meta
92-
9371
def test_stix21_bundle_with_attack_pattern_galaxy(self):
9472
bundle = TestExternalSTIX21Bundles.get_bundle_with_attack_pattern_galaxy()
9573
self.parser.load_stix_bundle(bundle)
@@ -178,18 +156,22 @@ def test_stix21_bundle_with_location_galaxy(self):
178156
event = self.parser.misp_event
179157
_, grouping, event_location, indicator, attribute_location, _ = bundle.objects
180158
self._check_misp_event_features_from_grouping(event, grouping)
181-
country_meta = self._check_location_galaxy_features(
182-
event.galaxies, event_location, 'country'
159+
country_meta = self._check_galaxy_features(
160+
event.galaxies, event_location
183161
)
184-
self.assertEqual(country_meta, {})
162+
self.assertEqual(country_meta['country'], event_location.country)
163+
self.assertEqual(country_meta['region'], event_location.region)
185164
self.assertEqual(len(event.attributes), 1)
186165
attribute = event.attributes[0]
187166
self.assertEqual(attribute.uuid, indicator.id.split('--')[1])
188-
region_meta = self._check_location_galaxy_features(
189-
attribute.galaxies, attribute_location, 'region',
190-
cluster_value='154 - Northern Europe'
167+
region_meta = self._check_galaxy_features(
168+
attribute.galaxies, attribute_location
169+
)
170+
self.assertEqual(
171+
region_meta['administrative_area'],
172+
attribute_location.administrative_area
191173
)
192-
self.assertEqual(region_meta, {})
174+
self.assertEqual(region_meta['country'], attribute_location.country)
193175

194176
def test_stix21_bundle_with_malware_galaxy(self):
195177
bundle = TestExternalSTIX21Bundles.get_bundle_with_malware_galaxy()

0 commit comments

Comments
 (0)