Skip to content

Commit

Permalink
fix: [tests] Updated tests following recent change on the location ob…
Browse files Browse the repository at this point in the history
…jects conversion
  • Loading branch information
chrisr3d committed Mar 4, 2025
1 parent 175ec39 commit aca3084
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 41 deletions.
9 changes: 5 additions & 4 deletions tests/_test_stix_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
from base64 import b64encode
from collections import defaultdict
from misp_stix_converter import (
ExternalSTIX2toMISPMapping, ExternalSTIX2toMISPParser,
InternalSTIX2toMISPParser, MISP_org_uuid)
ExternalSTIX2Mapping, ExternalSTIX2toMISPParser, InternalSTIX2toMISPParser,
MISP_org_uuid)
from uuid import UUID, uuid5
from ._test_stix import TestSTIX
from .update_documentation import AttributesDocumentationUpdater, ObjectsDocumentationUpdater
from .update_documentation import (
AttributesDocumentationUpdater, ObjectsDocumentationUpdater)


class TestSTIX2Bundles:
Expand Down Expand Up @@ -379,7 +380,7 @@ def _populate_vulnerability_documentation(self, **kwargs):


class TestExternalSTIX2Import(TestSTIX2Import):
_galaxy_name_mapping = ExternalSTIX2toMISPMapping().galaxy_name_mapping
_galaxy_name_mapping = ExternalSTIX2Mapping().galaxy_name_mapping

def setUp(self):
self.parser = ExternalSTIX2toMISPParser()
Expand Down
17 changes: 9 additions & 8 deletions tests/test_external_stix21_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,17 +978,18 @@
"modified": "2020-10-25T16:22:00.000Z",
"name": "sweden",
"description": "Sweden",
"country": "SE"
"country": "SE",
"region": "northern-europe"
},
{
"type": "location",
"administrative_area": "US-DC",
"country": "US",
"created": "2021-03-13T20:09:21.286293Z",
"id": "location--78a7f0f3-ea60-4ca2-894e-9e825b94b592",
"modified": "2021-12-01T16:19:51.601791Z",
"name": "District of Columbia",
"spec_version": "2.1",
"id": "location--f93cb275-0366-4ecc-abf0-a17928d1e177",
"created": "2020-10-25T16:22:00.000Z",
"modified": "2020-10-25T16:22:00.000Z",
"name": "Northern Europe",
"description": "Nothern Europe",
"region": "northern-europe"
"type": "location"
}
]
_MAC_ADDRESS_ATTRIBUTES = [
Expand Down
40 changes: 11 additions & 29 deletions tests/test_external_stix21_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,6 @@ def test_stix21_bundle_with_grouping_description(self):
# MISP GALAXIES IMPORT TESTS #
############################################################################

def _check_location_galaxy_features(
self, galaxies, stix_object, galaxy_type, cluster_value=None):
self.assertEqual(len(galaxies), 1)
galaxy = galaxies[0]
self.assertEqual(len(galaxy.clusters), 1)
cluster = galaxy.clusters[0]
self._assert_multiple_equal(galaxy.type, cluster.type, galaxy_type)
self.assertEqual(
galaxy.name, self._galaxy_name_mapping(galaxy_type)['name']
)
self.assertEqual(
galaxy.description,
self._galaxy_name_mapping(galaxy_type)['description']
)
if cluster_value is None:
self.assertEqual(cluster.value, stix_object.name)
else:
self.assertEqual(cluster.value, cluster_value)
if hasattr(stix_object, 'description'):
self.assertEqual(cluster.description, stix_object.description)
return cluster.meta

def test_stix21_bundle_with_attack_pattern_galaxy(self):
bundle = TestExternalSTIX21Bundles.get_bundle_with_attack_pattern_galaxy()
self.parser.load_stix_bundle(bundle)
Expand Down Expand Up @@ -178,18 +156,22 @@ def test_stix21_bundle_with_location_galaxy(self):
event = self.parser.misp_event
_, grouping, event_location, indicator, attribute_location, _ = bundle.objects
self._check_misp_event_features_from_grouping(event, grouping)
country_meta = self._check_location_galaxy_features(
event.galaxies, event_location, 'country'
country_meta = self._check_galaxy_features(
event.galaxies, event_location
)
self.assertEqual(country_meta, {})
self.assertEqual(country_meta['country'], event_location.country)
self.assertEqual(country_meta['region'], event_location.region)
self.assertEqual(len(event.attributes), 1)
attribute = event.attributes[0]
self.assertEqual(attribute.uuid, indicator.id.split('--')[1])
region_meta = self._check_location_galaxy_features(
attribute.galaxies, attribute_location, 'region',
cluster_value='154 - Northern Europe'
region_meta = self._check_galaxy_features(
attribute.galaxies, attribute_location
)
self.assertEqual(
region_meta['administrative_area'],
attribute_location.administrative_area
)
self.assertEqual(region_meta, {})
self.assertEqual(region_meta['country'], attribute_location.country)

def test_stix21_bundle_with_malware_galaxy(self):
bundle = TestExternalSTIX21Bundles.get_bundle_with_malware_galaxy()
Expand Down

0 comments on commit aca3084

Please sign in to comment.