1# Copyright (c) 2017, The MITRE Corporation. All rights reserved. 2# See LICENSE.txt for complete terms. 3 4import unittest 5 6from stix import report 7from stix.core.ttps import TTPs 8 9from stix.test import EntityTestCase, data_marking_test 10from stix.test.common import (information_source_test, structured_text_test, 11 related_test) 12 13 14class HeaderTests(EntityTestCase, unittest.TestCase): 15 klass = report.Header 16 _full_dict = { 17 'title': "A Title", 18 'description': "A really, really long description", 19 'short_description': 'A really, really short description', 20 'handling': data_marking_test.MarkingTests._full_dict, 21 'information_source': information_source_test.InformationSourceTests._full_dict, 22 'intents': ["foo", "bar"] 23 } 24 25 def test_duplicate_package_intent(self): 26 # Recreate https://github.com/STIXProject/python-stix/issues/63 27 hdr = report.Header(intents=["Indicators - Watchlist"]) 28 self.assertEqual(1, len(hdr.intents)) 29 30 31class HeaderMultiDescTests(EntityTestCase, unittest.TestCase): 32 klass = report.Header 33 _full_dict = { 34 'description': structured_text_test.StructuredTextListTests._full_dict, 35 'short_description': structured_text_test.StructuredTextListTests._full_dict 36 } 37 38 39class CampaignsTests(EntityTestCase, unittest.TestCase): 40 klass = report.Campaigns 41 42 _full_dict = [ 43 {'idref': 'example:test-1'} 44 ] 45 46 47class COAsTests(EntityTestCase, unittest.TestCase): 48 klass = report.CoursesOfAction 49 50 _full_dict = [ 51 {'idref': 'example:test-1'} 52 ] 53 54 55class ExploitTargetsTests(EntityTestCase, unittest.TestCase): 56 klass = report.ExploitTargets 57 58 _full_dict = [ 59 {'idref': 'example:test-1'} 60 ] 61 62 63class IncidentsTests(EntityTestCase, unittest.TestCase): 64 klass = report.Incidents 65 66 _full_dict = [ 67 {'idref': 'example:test-1'} 68 ] 69 70 71class IndicatorsTests(EntityTestCase, unittest.TestCase): 72 klass = report.Indicators 73 74 _full_dict = [ 75 {'idref': 'example:test-1'} 76 ] 77 78 79class ThreatActorsTests(EntityTestCase, unittest.TestCase): 80 klass = report.ThreatActors 81 82 _full_dict = [ 83 {'idref': 'example:test-1'} 84 ] 85 86 87class TTPsTests(EntityTestCase, unittest.TestCase): 88 klass = report.TTPs 89 90 _full_dict = [ 91 {'idref': 'example:test-1'} 92 ] 93 94 95class ReportTests(EntityTestCase, unittest.TestCase): 96 klass = report.Report 97 _full_dict = { 98 'header': HeaderTests._full_dict, 99 'campaigns': CampaignsTests._full_dict, 100 'courses_of_action': COAsTests._full_dict, 101 'exploit_targets': ExploitTargetsTests._full_dict, 102 'incidents': IncidentsTests._full_dict, 103 'indicators': IndicatorsTests._full_dict, 104 'observables': { 105 'cybox_major_version': '2', 106 'cybox_minor_version': '1', 107 'cybox_update_version': '0', 108 'observables': [ 109 { 110 'idref': "example:Observable-1" 111 } 112 ] 113 }, 114 'threat_actors': ThreatActorsTests._full_dict, 115 'ttps': TTPsTests._full_dict, 116 'related_reports': related_test.RelatedReportsTests._full_dict, 117 'version': "1.0" 118 } 119 120 def test_report_with_stix_core_ttps_fails(self): 121 self.assertRaises(TypeError, self.klass().ttps, TTPs(), 'TTPs must be a <class \'stix.report.TTPs\'>, not a <class \'stix.core.ttps.TTPs\'>') 122 123 124if __name__ == "__main__": 125 unittest.main() 126