Skip to content

Commit

Permalink
add: [tests] Tests for STIX 2.x Bundle import with specific producer …
Browse files Browse the repository at this point in the history
…or title set by user
  • Loading branch information
chrisr3d committed Aug 20, 2024
1 parent 8c7328c commit fd87de3
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 7 deletions.
12 changes: 12 additions & 0 deletions tests/test_external_stix20_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,18 @@ def __assemble_galaxy_bundle(cls, event_galaxy, attribute_galaxy):
]
return dict_to_stix2(bundle, allow_custom=True)

############################################################################
# EVENTS SAMPLES #
############################################################################

@classmethod
def get_bundle_with_event_title(cls):
bundle = deepcopy(cls.__bundle)
bundle['objects'] = [
deepcopy(cls.__identity), *_IP_ADDRESS_ATTRIBUTES
]
return dict_to_stix2(bundle, allow_custom=True)

############################################################################
# GALAXIES SAMPLES #
############################################################################
Expand Down
44 changes: 41 additions & 3 deletions tests/test_external_stix20_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,50 @@
# -*- coding: utf-8 -*-

from .test_external_stix20_bundles import TestExternalSTIX20Bundles
from ._test_stix import TestSTIX21
from ._test_stix_import import TestExternalSTIX2Import, TestSTIX21Import
from ._test_stix import TestSTIX20
from ._test_stix_import import TestExternalSTIX2Import, TestSTIX20Import
from uuid import uuid5


class TestExternalSTIX21Import(TestExternalSTIX2Import, TestSTIX21, TestSTIX21Import):
class TestExternalSTIX20Import(TestExternalSTIX2Import, TestSTIX20, TestSTIX20Import):

############################################################################
# MISP EVENT IMPORT TESTS. #
############################################################################

def test_stix20_bundle_with_event_title(self):
bundle = TestExternalSTIX20Bundles.get_bundle_with_event_title()
self.parser.load_stix_bundle(bundle)
self.parser.parse_stix_bundle(title='Malicious IP addresses report')
event = self.parser.misp_event
self.assertEqual(event.info, self.parser.event_title)

def test_stix20_bundle_with_event_title_and_producer(self):
bundle = TestExternalSTIX20Bundles.get_bundle_with_event_title()
self.parser.load_stix_bundle(bundle)
self.parser.parse_stix_bundle(
title='Malicious IP addresses report',
producer='MISP Project'
)
event = self.parser.misp_event
self.assertEqual(
event.info,
f'{self.parser.event_title} - produced by {self.parser.producer}'
)
self.assertEqual(
event.tags[0]['name'],
f'misp-galaxy:producer="{self.parser.producer}"'
)

def test_stix20_bundle_with_producer(self):
bundle = TestExternalSTIX20Bundles.get_bundle_with_event_title()
self.parser.load_stix_bundle(bundle)
self.parser.parse_stix_bundle(producer='MISP Project')
event = self.parser.misp_event
self.assertEqual(
event.tags[0]['name'],
f'misp-galaxy:producer="{self.parser.producer}"'
)

############################################################################
# MISP GALAXIES IMPORT TESTS #
Expand Down
12 changes: 12 additions & 0 deletions tests/test_external_stix21_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,18 @@ def __assemble_galaxy_bundle(cls, event_galaxy, attribute_galaxy):
]
return dict_to_stix2(bundle, allow_custom=True)

############################################################################
# EVENTS SAMPLES #
############################################################################

@classmethod
def get_bundle_with_event_title(cls):
bundle = deepcopy(cls.__bundle)
bundle['objects'] = [
deepcopy(cls.__identity), *_IP_ADDRESS_ATTRIBUTES
]
return dict_to_stix2(bundle, allow_custom=True)

############################################################################
# GALAXIES SAMPLES #
############################################################################
Expand Down
47 changes: 43 additions & 4 deletions tests/test_external_stix21_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,50 @@

class TestExternalSTIX21Import(TestExternalSTIX2Import, TestSTIX21, TestSTIX21Import):

################################################################################
# MISP GALAXIES IMPORT TESTS #
################################################################################
############################################################################
# MISP EVENT IMPORT TESTS. #
############################################################################

def test_stix21_bundle_with_event_title(self):
bundle = TestExternalSTIX21Bundles.get_bundle_with_event_title()
self.parser.load_stix_bundle(bundle)
self.parser.parse_stix_bundle(title='Malicious IP addresses report')
event = self.parser.misp_event
self.assertEqual(event.info, self.parser.event_title)

def test_stix21_bundle_with_event_title_and_producer(self):
bundle = TestExternalSTIX21Bundles.get_bundle_with_event_title()
self.parser.load_stix_bundle(bundle)
self.parser.parse_stix_bundle(
title='Malicious IP addresses report',
producer='MISP Project'
)
event = self.parser.misp_event
self.assertEqual(
event.info,
f'{self.parser.event_title} - produced by {self.parser.producer}'
)
self.assertEqual(
event.tags[0]['name'],
f'misp-galaxy:producer="{self.parser.producer}"'
)

def test_stix21_bundle_with_producer(self):
bundle = TestExternalSTIX21Bundles.get_bundle_with_event_title()
self.parser.load_stix_bundle(bundle)
self.parser.parse_stix_bundle(producer='MISP Project')
event = self.parser.misp_event
self.assertEqual(
event.tags[0]['name'],
f'misp-galaxy:producer="{self.parser.producer}"'
)

############################################################################
# MISP GALAXIES IMPORT TESTS #
############################################################################

def _check_location_galaxy_features(self, galaxies, stix_object, galaxy_type, cluster_value=None):
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)
Expand Down

0 comments on commit fd87de3

Please sign in to comment.