From ea1df9093a89030485fb21b9c4ebe90f801dbb29 Mon Sep 17 00:00:00 2001 From: bharatarya Date: Mon, 15 Jan 2024 22:48:45 +0530 Subject: [PATCH] patch: updated stix2 module name --- docs/conf.py | 6 +- examples/taxii_example.py | 6 +- {stix2 => misp_lib_stix2}/__init__.py | 0 {stix2 => misp_lib_stix2}/base.py | 16 +- .../canonicalization/Canonicalize.py | 2 +- .../canonicalization/NumberToJson.py | 0 .../canonicalization/__init__.py | 0 .../confidence/__init__.py | 0 .../confidence/scales.py | 0 {stix2 => misp_lib_stix2}/custom.py | 0 .../datastore/__init__.py | 4 +- .../datastore/filesystem.py | 14 +- .../datastore/filters.py | 4 +- {stix2 => misp_lib_stix2}/datastore/memory.py | 10 +- {stix2 => misp_lib_stix2}/datastore/taxii.py | 12 +- {stix2 => misp_lib_stix2}/environment.py | 0 .../equivalence/__init__.py | 0 .../equivalence/graph/__init__.py | 0 .../equivalence/object/__init__.py | 0 .../equivalence/pattern/__init__.py | 0 .../equivalence/pattern/compare/__init__.py | 0 .../equivalence/pattern/compare/comparison.py | 4 +- .../pattern/compare/observation.py | 6 +- .../equivalence/pattern/transform/__init__.py | 0 .../pattern/transform/comparison.py | 10 +- .../pattern/transform/observation.py | 18 +- .../equivalence/pattern/transform/specials.py | 2 +- {stix2 => misp_lib_stix2}/exceptions.py | 0 {stix2 => misp_lib_stix2}/hashes.py | 0 .../markings/__init__.py | 2 +- .../markings/granular_markings.py | 8 +- .../markings/object_markings.py | 6 +- {stix2 => misp_lib_stix2}/markings/utils.py | 2 +- {stix2 => misp_lib_stix2}/parsing.py | 0 {stix2 => misp_lib_stix2}/pattern_visitor.py | 0 {stix2 => misp_lib_stix2}/patterns.py | 0 {stix2 => misp_lib_stix2}/properties.py | 10 +- {stix2 => misp_lib_stix2}/registration.py | 0 {stix2 => misp_lib_stix2}/registry.py | 0 {stix2 => misp_lib_stix2}/serialization.py | 8 +- {stix2 => misp_lib_stix2}/test/__init__.py | 0 {stix2 => misp_lib_stix2}/test/test_hashes.py | 2 +- .../test/test_pattern_equivalence.py | 2 +- .../test/test_properties.py | 6 +- .../test/test_spec_version_detect.py | 2 +- .../test/test_utils_type_checks.py | 98 ++-- .../test/test_workbench.py | 8 +- .../test/v20/__init__.py | 0 .../test/v20/conftest.py | 14 +- .../test/v20/constants.py | 0 .../test/v20/pattern_ast_overrides.py | 2 +- .../20170531213019735010.json | 0 .../20170531213026496201.json | 0 .../20170531213029458940.json | 0 .../20170531213045139269.json | 0 .../20170531213041022897.json | 0 .../20170531213032662702.json | 0 .../20170531213026495974.json | 0 .../20170531213041022744.json | 0 .../20170601000000000000.json | 0 .../20181101232448446000.json | 0 .../20170531213149412497.json | 0 .../20170531213153197755.json | 0 ...-6b616fc1-1505-48e3-8b2c-0d19337bff38.json | 0 .../20170531213258226477.json | 0 .../20181101232448456000.json | 0 .../20181101232448457000.json | 0 .../20170531213326565056.json | 0 .../20170531213248482655.json | 0 .../20170531213215263882.json | 0 ...-fa42a846-8d90-4e51-bc29-71d5b4802168.json | 0 .../20170531213327182784.json | 0 .../20170531213327082801.json | 0 .../20170531213327018782.json | 0 .../20170531213327100701.json | 0 .../20170531213327143973.json | 0 .../20170531213327021562.json | 0 .../20170531213327044387.json | 0 .../20170531213327051532.json | 0 .../20170531213231601148.json | 0 .../20170531213212684914.json | 0 .../test/v20/test_attack_pattern.py | 18 +- .../test/v20/test_base.py | 2 +- .../test/v20/test_bundle.py | 66 +-- .../test/v20/test_campaign.py | 6 +- .../test/v20/test_course_of_action.py | 6 +- .../test/v20/test_custom.py | 354 ++++++------ .../test/v20}/test_datastore.py | 4 +- .../test/v20/test_datastore_composite.py | 10 +- .../test/v20/test_datastore_filesystem.py | 148 ++--- .../test/v20/test_datastore_filters.py | 6 +- .../test/v20/test_datastore_memory.py | 8 +- .../test/v20/test_datastore_taxii.py | 62 +- .../test/v20/test_environment.py | 240 ++++---- .../test/v20/test_external_reference.py | 20 +- .../test/v20}/test_fixtures.py | 2 +- .../test/v20/test_granular_markings.py | 6 +- .../test/v20/test_identity.py | 12 +- .../test/v20/test_indicator.py | 70 +-- .../test/v20/test_interoperability.py | 36 +- .../test/v20/test_intrusion_set.py | 6 +- .../test/v20}/test_kill_chain_phases.py | 24 +- .../test/v20/test_malware.py | 46 +- .../test/v20/test_marking_definition.py | 4 +- .../test/v20/test_markings.py | 52 +- .../test/v20/test_object_markings.py | 4 +- .../test/v20/test_observed_data.py | 210 +++---- .../test/v20/test_parsing.py | 2 +- .../test/v20/test_pattern_equivalence.py | 2 +- .../test/v20/test_pattern_expressions.py | 330 +++++------ .../test/v20}/test_pickle.py | 4 +- .../test/v20/test_properties.py | 50 +- .../test/v20/test_relationship.py | 48 +- .../test/v20/test_report.py | 24 +- .../test/v20/test_sighting.py | 26 +- .../test/v20/test_threat_actor.py | 6 +- .../test/v20/test_tool.py | 10 +- .../test/v20/test_utils.py | 46 +- .../test/v20/test_versioning.py | 194 +++---- .../test/v20/test_vulnerability.py | 8 +- .../test/v21/__init__.py | 0 .../test/v21/conftest.py | 18 +- .../test/v21/constants.py | 0 .../test/v21/pattern_ast_overrides.py | 2 +- .../20170531213019735010.json | 0 .../20170531213026496201.json | 0 .../20170531213029458940.json | 0 .../20170531213045139269.json | 0 .../20170531213041022897.json | 0 .../20170531213032662702.json | 0 .../20170531213026495974.json | 0 .../20170531213041022744.json | 0 ...-572827aa-e0cd-44fd-afd5-a717a7585f39.json | 0 .../20170601000000000000.json | 0 .../20181101232448446000.json | 0 .../20170531213149412497.json | 0 .../20170531213153197755.json | 0 ...-6b616fc1-1505-48e3-8b2c-0d19337bff38.json | 0 .../20170531213258226477.json | 0 .../20181101232448456000.json | 0 .../20181101232448457000.json | 0 .../20170531213326565056.json | 0 .../20170531213248482655.json | 0 .../20170531213215263882.json | 0 ...-fa42a846-8d90-4e51-bc29-71d5b4802168.json | 0 .../20170531213327182784.json | 0 .../20170531213327082801.json | 0 .../20170531213327018782.json | 0 .../20170531213327100701.json | 0 .../20170531213327143973.json | 0 .../20170531213327021562.json | 0 .../20170531213327044387.json | 0 .../20170531213327051532.json | 0 .../20170531213231601148.json | 0 .../20170531213212684914.json | 0 .../test/v21/test_attack_pattern.py | 18 +- .../test/v21/test_base.py | 6 +- .../test/v21/test_bundle.py | 64 +-- .../test/v21/test_campaign.py | 6 +- .../test/v21/test_confidence.py | 2 +- .../test/v21/test_course_of_action.py | 12 +- .../test/v21/test_custom.py | 534 +++++++++--------- .../test/v21}/test_datastore.py | 4 +- .../test/v21/test_datastore_composite.py | 10 +- .../test/v21/test_datastore_filesystem.py | 148 ++--- .../test/v21/test_datastore_filters.py | 6 +- .../test/v21/test_datastore_memory.py | 8 +- .../test/v21/test_datastore_taxii.py | 58 +- .../test/v21/test_deterministic_ids.py | 64 +-- .../test/v21/test_environment.py | 458 +++++++-------- .../test/v21/test_extension_definition.py | 12 +- .../test/v21/test_external_reference.py | 24 +- .../test/v21}/test_fixtures.py | 2 +- .../test/v21/test_granular_markings.py | 6 +- .../test/v21/test_grouping.py | 30 +- .../test/v21/test_identity.py | 12 +- .../test/v21/test_incident.py | 12 +- .../test/v21/test_indicator.py | 84 +-- .../test/v21/test_infrastructure.py | 42 +- .../test/v21/test_interoperability.py | 36 +- .../test/v21/test_intrusion_set.py | 6 +- .../test/v21}/test_kill_chain_phases.py | 24 +- .../test/v21/test_language_content.py | 8 +- .../test/v21/test_location.py | 50 +- .../test/v21/test_malware.py | 54 +- .../test/v21/test_malware_analysis.py | 26 +- .../test/v21/test_marking_definition.py | 4 +- .../test/v21/test_markings.py | 56 +- .../test/v21/test_note.py | 6 +- .../test/v21/test_object_markings.py | 4 +- .../test/v21/test_observed_data.py | 258 ++++----- .../test/v21/test_opinion.py | 6 +- .../test/v21/test_parsing.py | 2 +- .../test/v21/test_pattern_equivalence.py | 2 +- .../test/v21/test_pattern_expressions.py | 366 ++++++------ .../test/v21}/test_pickle.py | 4 +- .../test/v21/test_properties.py | 48 +- .../test/v21/test_relationship.py | 52 +- .../test/v21/test_report.py | 24 +- .../test/v21/test_sighting.py | 26 +- .../test/v21/test_threat_actor.py | 12 +- .../test/v21/test_timestamp_precision.py | 6 +- .../test/v21/test_tool.py | 10 +- .../test/v21/test_utils.py | 46 +- .../test/v21/test_versioning.py | 186 +++--- .../test/v21/test_vulnerability.py | 8 +- {stix2 => misp_lib_stix2}/utils.py | 16 +- {stix2 => misp_lib_stix2}/v20/__init__.py | 0 {stix2 => misp_lib_stix2}/v20/base.py | 0 {stix2 => misp_lib_stix2}/v20/bundle.py | 0 {stix2 => misp_lib_stix2}/v20/common.py | 0 {stix2 => misp_lib_stix2}/v20/observables.py | 0 {stix2 => misp_lib_stix2}/v20/sdo.py | 0 {stix2 => misp_lib_stix2}/v20/sro.py | 0 {stix2 => misp_lib_stix2}/v20/vocab.py | 0 {stix2 => misp_lib_stix2}/v21/__init__.py | 0 {stix2 => misp_lib_stix2}/v21/base.py | 0 {stix2 => misp_lib_stix2}/v21/bundle.py | 0 {stix2 => misp_lib_stix2}/v21/common.py | 0 {stix2 => misp_lib_stix2}/v21/observables.py | 0 {stix2 => misp_lib_stix2}/v21/sdo.py | 0 {stix2 => misp_lib_stix2}/v21/sro.py | 0 {stix2 => misp_lib_stix2}/v21/vocab.py | 0 {stix2 => misp_lib_stix2}/version.py | 2 +- {stix2 => misp_lib_stix2}/versioning.py | 22 +- {stix2 => misp_lib_stix2}/workbench.py | 0 pyproject.toml | 2 +- setup.cfg | 2 +- 228 files changed, 2736 insertions(+), 2736 deletions(-) rename {stix2 => misp_lib_stix2}/__init__.py (100%) rename {stix2 => misp_lib_stix2}/base.py (97%) rename {stix2 => misp_lib_stix2}/canonicalization/Canonicalize.py (99%) rename {stix2 => misp_lib_stix2}/canonicalization/NumberToJson.py (100%) rename {stix2 => misp_lib_stix2}/canonicalization/__init__.py (100%) rename {stix2 => misp_lib_stix2}/confidence/__init__.py (100%) rename {stix2 => misp_lib_stix2}/confidence/scales.py (100%) rename {stix2 => misp_lib_stix2}/custom.py (100%) rename {stix2 => misp_lib_stix2}/datastore/__init__.py (99%) rename {stix2 => misp_lib_stix2}/datastore/filesystem.py (98%) rename {stix2 => misp_lib_stix2}/datastore/filters.py (98%) rename {stix2 => misp_lib_stix2}/datastore/memory.py (97%) rename {stix2 => misp_lib_stix2}/datastore/taxii.py (98%) rename {stix2 => misp_lib_stix2}/environment.py (100%) rename {stix2 => misp_lib_stix2}/equivalence/__init__.py (100%) rename {stix2 => misp_lib_stix2}/equivalence/graph/__init__.py (100%) rename {stix2 => misp_lib_stix2}/equivalence/object/__init__.py (100%) rename {stix2 => misp_lib_stix2}/equivalence/pattern/__init__.py (100%) rename {stix2 => misp_lib_stix2}/equivalence/pattern/compare/__init__.py (100%) rename {stix2 => misp_lib_stix2}/equivalence/pattern/compare/comparison.py (98%) rename {stix2 => misp_lib_stix2}/equivalence/pattern/compare/observation.py (95%) rename {stix2 => misp_lib_stix2}/equivalence/pattern/transform/__init__.py (100%) rename {stix2 => misp_lib_stix2}/equivalence/pattern/transform/comparison.py (97%) rename {stix2 => misp_lib_stix2}/equivalence/pattern/transform/observation.py (96%) rename {stix2 => misp_lib_stix2}/equivalence/pattern/transform/specials.py (99%) rename {stix2 => misp_lib_stix2}/exceptions.py (100%) rename {stix2 => misp_lib_stix2}/hashes.py (100%) rename {stix2 => misp_lib_stix2}/markings/__init__.py (99%) rename {stix2 => misp_lib_stix2}/markings/granular_markings.py (98%) rename {stix2 => misp_lib_stix2}/markings/object_markings.py (96%) rename {stix2 => misp_lib_stix2}/markings/utils.py (99%) rename {stix2 => misp_lib_stix2}/parsing.py (100%) rename {stix2 => misp_lib_stix2}/pattern_visitor.py (100%) rename {stix2 => misp_lib_stix2}/patterns.py (100%) rename {stix2 => misp_lib_stix2}/properties.py (99%) rename {stix2 => misp_lib_stix2}/registration.py (100%) rename {stix2 => misp_lib_stix2}/registry.py (100%) rename {stix2 => misp_lib_stix2}/serialization.py (96%) rename {stix2 => misp_lib_stix2}/test/__init__.py (100%) rename {stix2 => misp_lib_stix2}/test/test_hashes.py (97%) rename {stix2 => misp_lib_stix2}/test/test_pattern_equivalence.py (99%) rename {stix2 => misp_lib_stix2}/test/test_properties.py (98%) rename {stix2 => misp_lib_stix2}/test/test_spec_version_detect.py (99%) rename {stix2 => misp_lib_stix2}/test/test_utils_type_checks.py (58%) rename {stix2 => misp_lib_stix2}/test/test_workbench.py (98%) rename {stix2 => misp_lib_stix2}/test/v20/__init__.py (100%) rename {stix2 => misp_lib_stix2}/test/v20/conftest.py (93%) rename {stix2 => misp_lib_stix2}/test/v20/constants.py (100%) rename {stix2 => misp_lib_stix2}/test/v20/pattern_ast_overrides.py (90%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/attack-pattern/attack-pattern--0a3ead4e-6d47-4ccb-854c-a6a4f9d96b22/20170531213019735010.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/attack-pattern/attack-pattern--0f20e3cb-245b-4a61-8a91-2d93f7cb0e9b/20170531213026496201.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/attack-pattern/attack-pattern--774a3188-6ba9-4dc4-879d-d54ee48a5ce9/20170531213029458940.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/attack-pattern/attack-pattern--7e150503-88e7-4861-866b-ff1ac82c4475/20170531213045139269.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/attack-pattern/attack-pattern--ae676644-d2d2-41b7-af7e-9bed1b55898c/20170531213041022897.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/attack-pattern/attack-pattern--b3d682b6-98f2-4fb0-aa3b-b4df007ca70a/20170531213032662702.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/course-of-action/course-of-action--95ddb356-7ba0-4bd9-a889-247262b8946f/20170531213026495974.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/course-of-action/course-of-action--d9727aee-48b8-4fdb-89e2-4c49746ba4dd/20170531213041022744.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20170601000000000000.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20181101232448446000.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/intrusion-set/intrusion-set--a653431d-6a5e-4600-8ad3-609b5af57064/20170531213149412497.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/intrusion-set/intrusion-set--f3bdec95-3d62-42d9-a840-29630f6cdc1a/20170531213153197755.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20170531213258226477.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448456000.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448457000.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/malware/malware--92ec0cbd-2c30-44a2-b270-73f4ec949841/20170531213326565056.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/malware/malware--96b08451-b27a-4ff6-893f-790e26393a8e/20170531213248482655.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/malware/malware--b42378e0-f147-496f-992a-26a49705395b/20170531213215263882.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/marking-definition/marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/relationship/relationship--0d4a7788-7f3b-4df8-a498-31a38003c883/20170531213327182784.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/relationship/relationship--0e55ee98-0c6d-43d4-b424-b18a0036b227/20170531213327082801.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/relationship/relationship--1e91cd45-a725-4965-abe3-700694374432/20170531213327018782.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/relationship/relationship--3a3084f9-0302-4fd5-9b8a-e0db10f5345e/20170531213327100701.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/relationship/relationship--3a3ed0b2-0c38-441f-ac40-53b873e545d1/20170531213327143973.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/relationship/relationship--592d0c31-e61f-495e-a60e-70d7be59a719/20170531213327021562.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/relationship/relationship--70dc6b5c-c524-429e-a6ab-0dd40f0482c1/20170531213327044387.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/relationship/relationship--8797579b-e3be-4209-a71b-255a4d08243d/20170531213327051532.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/tool/tool--03342581-f790-4f03-ba41-e82e67392e23/20170531213231601148.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/stix2_data/tool/tool--242f3da3-4425-4d11-8f5c-b842886da966/20170531213212684914.json (100%) rename {stix2 => misp_lib_stix2}/test/v20/test_attack_pattern.py (87%) rename {stix2 => misp_lib_stix2}/test/v20/test_base.py (91%) rename {stix2 => misp_lib_stix2}/test/v20/test_bundle.py (83%) rename {stix2 => misp_lib_stix2}/test/v20/test_campaign.py (91%) rename {stix2 => misp_lib_stix2}/test/v20/test_course_of_action.py (94%) rename {stix2 => misp_lib_stix2}/test/v20/test_custom.py (71%) rename {stix2/test/v21 => misp_lib_stix2/test/v20}/test_datastore.py (98%) rename {stix2 => misp_lib_stix2}/test/v20/test_datastore_composite.py (93%) rename {stix2 => misp_lib_stix2}/test/v20/test_datastore_filesystem.py (87%) rename {stix2 => misp_lib_stix2}/test/v20/test_datastore_filters.py (99%) rename {stix2 => misp_lib_stix2}/test/v20/test_datastore_memory.py (98%) rename {stix2 => misp_lib_stix2}/test/v20/test_datastore_taxii.py (86%) rename {stix2 => misp_lib_stix2}/test/v20/test_environment.py (64%) rename {stix2 => misp_lib_stix2}/test/v20/test_external_reference.py (84%) rename {stix2/test/v21 => misp_lib_stix2/test/v20}/test_fixtures.py (93%) rename {stix2 => misp_lib_stix2}/test/v20/test_granular_markings.py (99%) rename {stix2 => misp_lib_stix2}/test/v20/test_identity.py (87%) rename {stix2 => misp_lib_stix2}/test/v20/test_indicator.py (72%) rename {stix2 => misp_lib_stix2}/test/v20/test_interoperability.py (77%) rename {stix2 => misp_lib_stix2}/test/v20/test_intrusion_set.py (94%) rename {stix2/test/v21 => misp_lib_stix2/test/v20}/test_kill_chain_phases.py (55%) rename {stix2 => misp_lib_stix2}/test/v20/test_malware.py (77%) rename {stix2 => misp_lib_stix2}/test/v20/test_marking_definition.py (98%) rename {stix2 => misp_lib_stix2}/test/v20/test_markings.py (83%) rename {stix2 => misp_lib_stix2}/test/v20/test_object_markings.py (99%) rename {stix2 => misp_lib_stix2}/test/v20/test_observed_data.py (87%) rename {stix2 => misp_lib_stix2}/test/v20/test_parsing.py (96%) rename {stix2 => misp_lib_stix2}/test/v20/test_pattern_equivalence.py (95%) rename {stix2 => misp_lib_stix2}/test/v20/test_pattern_expressions.py (58%) rename {stix2/test/v21 => misp_lib_stix2/test/v20}/test_pickle.py (82%) rename {stix2 => misp_lib_stix2}/test/v20/test_properties.py (92%) rename {stix2 => misp_lib_stix2}/test/v20/test_relationship.py (75%) rename {stix2 => misp_lib_stix2}/test/v20/test_report.py (88%) rename {stix2 => misp_lib_stix2}/test/v20/test_sighting.py (78%) rename {stix2 => misp_lib_stix2}/test/v20/test_threat_actor.py (93%) rename {stix2 => misp_lib_stix2}/test/v20/test_tool.py (91%) rename {stix2 => misp_lib_stix2}/test/v20/test_utils.py (89%) rename {stix2 => misp_lib_stix2}/test/v20/test_versioning.py (63%) rename {stix2 => misp_lib_stix2}/test/v20/test_vulnerability.py (90%) rename {stix2 => misp_lib_stix2}/test/v21/__init__.py (100%) rename {stix2 => misp_lib_stix2}/test/v21/conftest.py (92%) rename {stix2 => misp_lib_stix2}/test/v21/constants.py (100%) rename {stix2 => misp_lib_stix2}/test/v21/pattern_ast_overrides.py (90%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/attack-pattern/attack-pattern--0a3ead4e-6d47-4ccb-854c-a6a4f9d96b22/20170531213019735010.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/attack-pattern/attack-pattern--0f20e3cb-245b-4a61-8a91-2d93f7cb0e9b/20170531213026496201.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/attack-pattern/attack-pattern--774a3188-6ba9-4dc4-879d-d54ee48a5ce9/20170531213029458940.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/attack-pattern/attack-pattern--7e150503-88e7-4861-866b-ff1ac82c4475/20170531213045139269.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/attack-pattern/attack-pattern--ae676644-d2d2-41b7-af7e-9bed1b55898c/20170531213041022897.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/attack-pattern/attack-pattern--b3d682b6-98f2-4fb0-aa3b-b4df007ca70a/20170531213032662702.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/course-of-action/course-of-action--95ddb356-7ba0-4bd9-a889-247262b8946f/20170531213026495974.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/course-of-action/course-of-action--d9727aee-48b8-4fdb-89e2-4c49746ba4dd/20170531213041022744.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/directory/directory--572827aa-e0cd-44fd-afd5-a717a7585f39.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20170601000000000000.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20181101232448446000.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/intrusion-set/intrusion-set--a653431d-6a5e-4600-8ad3-609b5af57064/20170531213149412497.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/intrusion-set/intrusion-set--f3bdec95-3d62-42d9-a840-29630f6cdc1a/20170531213153197755.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20170531213258226477.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448456000.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448457000.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/malware/malware--92ec0cbd-2c30-44a2-b270-73f4ec949841/20170531213326565056.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/malware/malware--96b08451-b27a-4ff6-893f-790e26393a8e/20170531213248482655.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/malware/malware--b42378e0-f147-496f-992a-26a49705395b/20170531213215263882.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/marking-definition/marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/relationship/relationship--0d4a7788-7f3b-4df8-a498-31a38003c883/20170531213327182784.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/relationship/relationship--0e55ee98-0c6d-43d4-b424-b18a0036b227/20170531213327082801.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/relationship/relationship--1e91cd45-a725-4965-abe3-700694374432/20170531213327018782.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/relationship/relationship--3a3084f9-0302-4fd5-9b8a-e0db10f5345e/20170531213327100701.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/relationship/relationship--3a3ed0b2-0c38-441f-ac40-53b873e545d1/20170531213327143973.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/relationship/relationship--592d0c31-e61f-495e-a60e-70d7be59a719/20170531213327021562.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/relationship/relationship--70dc6b5c-c524-429e-a6ab-0dd40f0482c1/20170531213327044387.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/relationship/relationship--8797579b-e3be-4209-a71b-255a4d08243d/20170531213327051532.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/tool/tool--03342581-f790-4f03-ba41-e82e67392e23/20170531213231601148.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/stix2_data/tool/tool--242f3da3-4425-4d11-8f5c-b842886da966/20170531213212684914.json (100%) rename {stix2 => misp_lib_stix2}/test/v21/test_attack_pattern.py (87%) rename {stix2 => misp_lib_stix2}/test/v21/test_base.py (86%) rename {stix2 => misp_lib_stix2}/test/v21/test_bundle.py (83%) rename {stix2 => misp_lib_stix2}/test/v21/test_campaign.py (93%) rename {stix2 => misp_lib_stix2}/test/v21/test_confidence.py (99%) rename {stix2 => misp_lib_stix2}/test/v21/test_course_of_action.py (88%) rename {stix2 => misp_lib_stix2}/test/v21/test_custom.py (76%) rename {stix2/test/v20 => misp_lib_stix2/test/v21}/test_datastore.py (98%) rename {stix2 => misp_lib_stix2}/test/v21/test_datastore_composite.py (94%) rename {stix2 => misp_lib_stix2}/test/v21/test_datastore_filesystem.py (87%) rename {stix2 => misp_lib_stix2}/test/v21/test_datastore_filters.py (99%) rename {stix2 => misp_lib_stix2}/test/v21/test_datastore_memory.py (98%) rename {stix2 => misp_lib_stix2}/test/v21/test_datastore_taxii.py (87%) rename {stix2 => misp_lib_stix2}/test/v21/test_deterministic_ids.py (81%) rename {stix2 => misp_lib_stix2}/test/v21/test_environment.py (64%) rename {stix2 => misp_lib_stix2}/test/v21/test_extension_definition.py (92%) rename {stix2 => misp_lib_stix2}/test/v21/test_external_reference.py (83%) rename {stix2/test/v20 => misp_lib_stix2/test/v21}/test_fixtures.py (93%) rename {stix2 => misp_lib_stix2}/test/v21/test_granular_markings.py (99%) rename {stix2 => misp_lib_stix2}/test/v21/test_grouping.py (78%) rename {stix2 => misp_lib_stix2}/test/v21/test_identity.py (88%) rename {stix2 => misp_lib_stix2}/test/v21/test_incident.py (89%) rename {stix2 => misp_lib_stix2}/test/v21/test_indicator.py (74%) rename {stix2 => misp_lib_stix2}/test/v21/test_infrastructure.py (73%) rename {stix2 => misp_lib_stix2}/test/v21/test_interoperability.py (78%) rename {stix2 => misp_lib_stix2}/test/v21/test_intrusion_set.py (95%) rename {stix2/test/v20 => misp_lib_stix2/test/v21}/test_kill_chain_phases.py (55%) rename {stix2 => misp_lib_stix2}/test/v21/test_language_content.py (93%) rename {stix2 => misp_lib_stix2}/test/v21/test_location.py (89%) rename {stix2 => misp_lib_stix2}/test/v21/test_malware.py (77%) rename {stix2 => misp_lib_stix2}/test/v21/test_malware_analysis.py (82%) rename {stix2 => misp_lib_stix2}/test/v21/test_marking_definition.py (98%) rename {stix2 => misp_lib_stix2}/test/v21/test_markings.py (85%) rename {stix2 => misp_lib_stix2}/test/v21/test_note.py (96%) rename {stix2 => misp_lib_stix2}/test/v21/test_object_markings.py (99%) rename {stix2 => misp_lib_stix2}/test/v21/test_observed_data.py (86%) rename {stix2 => misp_lib_stix2}/test/v21/test_opinion.py (96%) rename {stix2 => misp_lib_stix2}/test/v21/test_parsing.py (97%) rename {stix2 => misp_lib_stix2}/test/v21/test_pattern_equivalence.py (95%) rename {stix2 => misp_lib_stix2}/test/v21/test_pattern_expressions.py (65%) rename {stix2/test/v20 => misp_lib_stix2/test/v21}/test_pickle.py (82%) rename {stix2 => misp_lib_stix2}/test/v21/test_properties.py (92%) rename {stix2 => misp_lib_stix2}/test/v21/test_relationship.py (79%) rename {stix2 => misp_lib_stix2}/test/v21/test_report.py (88%) rename {stix2 => misp_lib_stix2}/test/v21/test_sighting.py (80%) rename {stix2 => misp_lib_stix2}/test/v21/test_threat_actor.py (91%) rename {stix2 => misp_lib_stix2}/test/v21/test_timestamp_precision.py (98%) rename {stix2 => misp_lib_stix2}/test/v21/test_tool.py (91%) rename {stix2 => misp_lib_stix2}/test/v21/test_utils.py (89%) rename {stix2 => misp_lib_stix2}/test/v21/test_versioning.py (69%) rename {stix2 => misp_lib_stix2}/test/v21/test_vulnerability.py (91%) rename {stix2 => misp_lib_stix2}/utils.py (97%) rename {stix2 => misp_lib_stix2}/v20/__init__.py (100%) rename {stix2 => misp_lib_stix2}/v20/base.py (100%) rename {stix2 => misp_lib_stix2}/v20/bundle.py (100%) rename {stix2 => misp_lib_stix2}/v20/common.py (100%) rename {stix2 => misp_lib_stix2}/v20/observables.py (100%) rename {stix2 => misp_lib_stix2}/v20/sdo.py (100%) rename {stix2 => misp_lib_stix2}/v20/sro.py (100%) rename {stix2 => misp_lib_stix2}/v20/vocab.py (100%) rename {stix2 => misp_lib_stix2}/v21/__init__.py (100%) rename {stix2 => misp_lib_stix2}/v21/base.py (100%) rename {stix2 => misp_lib_stix2}/v21/bundle.py (100%) rename {stix2 => misp_lib_stix2}/v21/common.py (100%) rename {stix2 => misp_lib_stix2}/v21/observables.py (100%) rename {stix2 => misp_lib_stix2}/v21/sdo.py (100%) rename {stix2 => misp_lib_stix2}/v21/sro.py (100%) rename {stix2 => misp_lib_stix2}/v21/vocab.py (100%) rename {stix2 => misp_lib_stix2}/version.py (78%) rename {stix2 => misp_lib_stix2}/versioning.py (95%) rename {stix2 => misp_lib_stix2}/workbench.py (100%) diff --git a/docs/conf.py b/docs/conf.py index dc43ccf9..75d8f6f0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -6,9 +6,9 @@ from sphinx.ext.autodoc import ClassDocumenter -from stix2.base import _STIXBase -from stix2.equivalence.object import WEIGHTS -from stix2.version import __version__ +from misp_lib_stix2.base import _STIXBase +from misp_lib_stix2.equivalence.object import WEIGHTS +from misp_lib_stix2.version import __version__ sys.path.insert(0, os.path.abspath('..')) diff --git a/examples/taxii_example.py b/examples/taxii_example.py index 27b83d2c..10ace394 100644 --- a/examples/taxii_example.py +++ b/examples/taxii_example.py @@ -1,6 +1,6 @@ from taxii2client.v21 import Collection -import stix2 +import misp_lib_stix2 # This example is based on the medallion server with default_data.json # See https://github.com/oasis-open/cti-taxii-server for more information @@ -13,7 +13,7 @@ def main(): ) # instantiate TAXII data source - taxii = stix2.TAXIICollectionSource(collection) + taxii = misp_lib_stix2.TAXIICollectionSource(collection) # get (url watch indicator) indicator_fw = taxii.get("indicator--6770298f-0fd8-471a-ab8c-1c658a46574e") @@ -27,7 +27,7 @@ def main(): print(indicator.serialize(indent=4)) # add TAXII filter (ie filter should be passed to TAXII) - query_filter = stix2.Filter("type", "in", "malware") + query_filter = misp_lib_stix2.Filter("type", "in", "malware") # query() - but with filter attached. There are no malware objects in this collection malwares = taxii.query(query=query_filter) diff --git a/stix2/__init__.py b/misp_lib_stix2/__init__.py similarity index 100% rename from stix2/__init__.py rename to misp_lib_stix2/__init__.py diff --git a/stix2/base.py b/misp_lib_stix2/base.py similarity index 97% rename from stix2/base.py rename to misp_lib_stix2/base.py index 8200dc4d..eff2f3da 100644 --- a/stix2/base.py +++ b/misp_lib_stix2/base.py @@ -9,8 +9,8 @@ import simplejson as json -import stix2 -from stix2.canonicalization.Canonicalize import canonicalize +import misp_lib_stix2 +from misp_lib_stix2.canonicalization.Canonicalize import canonicalize from .exceptions import ( AtLeastOnePropertyError, DependentPropertiesError, ExtraPropertiesError, @@ -120,11 +120,11 @@ def __init__(self, allow_custom=False, interoperability=False, **kwargs): self.__now = get_timestamp() self.__INTEROPERABILITY_types = ( - stix2.properties.EmbeddedObjectProperty, stix2.properties.EnumProperty, - stix2.properties.ExtensionsProperty, stix2.properties.DictionaryProperty, - stix2.properties.HashesProperty, stix2.properties.IDProperty, - stix2.properties.ListProperty, stix2.properties.OpenVocabProperty, - stix2.properties.ReferenceProperty, stix2.properties.SelectorProperty, + misp_lib_stix2.properties.EmbeddedObjectProperty, misp_lib_stix2.properties.EnumProperty, + misp_lib_stix2.properties.ExtensionsProperty, misp_lib_stix2.properties.DictionaryProperty, + misp_lib_stix2.properties.HashesProperty, misp_lib_stix2.properties.IDProperty, + misp_lib_stix2.properties.ListProperty, misp_lib_stix2.properties.OpenVocabProperty, + misp_lib_stix2.properties.ReferenceProperty, misp_lib_stix2.properties.SelectorProperty, ) custom_props = kwargs.pop('custom_properties', {}) @@ -172,7 +172,7 @@ def __init__(self, allow_custom=False, interoperability=False, **kwargs): all_custom_prop_names = (custom_kwargs | custom_props.keys()) - \ self._properties.keys() if all_custom_prop_names: - if not isinstance(self, stix2.v20._STIXBase20): + if not isinstance(self, misp_lib_stix2.v20._STIXBase20): for prop_name in all_custom_prop_names: if not re.match(PREFIX_21_REGEX, prop_name): raise InvalidValueError( diff --git a/stix2/canonicalization/Canonicalize.py b/misp_lib_stix2/canonicalization/Canonicalize.py similarity index 99% rename from stix2/canonicalization/Canonicalize.py rename to misp_lib_stix2/canonicalization/Canonicalize.py index 72910ab5..ad338b4a 100644 --- a/stix2/canonicalization/Canonicalize.py +++ b/misp_lib_stix2/canonicalization/Canonicalize.py @@ -22,7 +22,7 @@ import re -from stix2.canonicalization.NumberToJson import convert2Es6Format +from misp_lib_stix2.canonicalization.NumberToJson import convert2Es6Format try: from _json import encode_basestring_ascii as c_encode_basestring_ascii diff --git a/stix2/canonicalization/NumberToJson.py b/misp_lib_stix2/canonicalization/NumberToJson.py similarity index 100% rename from stix2/canonicalization/NumberToJson.py rename to misp_lib_stix2/canonicalization/NumberToJson.py diff --git a/stix2/canonicalization/__init__.py b/misp_lib_stix2/canonicalization/__init__.py similarity index 100% rename from stix2/canonicalization/__init__.py rename to misp_lib_stix2/canonicalization/__init__.py diff --git a/stix2/confidence/__init__.py b/misp_lib_stix2/confidence/__init__.py similarity index 100% rename from stix2/confidence/__init__.py rename to misp_lib_stix2/confidence/__init__.py diff --git a/stix2/confidence/scales.py b/misp_lib_stix2/confidence/scales.py similarity index 100% rename from stix2/confidence/scales.py rename to misp_lib_stix2/confidence/scales.py diff --git a/stix2/custom.py b/misp_lib_stix2/custom.py similarity index 100% rename from stix2/custom.py rename to misp_lib_stix2/custom.py diff --git a/stix2/datastore/__init__.py b/misp_lib_stix2/datastore/__init__.py similarity index 99% rename from stix2/datastore/__init__.py rename to misp_lib_stix2/datastore/__init__.py index 715c6e6b..71106d2a 100644 --- a/stix2/datastore/__init__.py +++ b/misp_lib_stix2/datastore/__init__.py @@ -15,8 +15,8 @@ from abc import ABCMeta, abstractmethod import uuid -from stix2.datastore.filters import Filter, FilterSet -from stix2.utils import deduplicate +from misp_lib_stix2.datastore.filters import Filter, FilterSet +from misp_lib_stix2.utils import deduplicate def make_id(): diff --git a/stix2/datastore/filesystem.py b/misp_lib_stix2/datastore/filesystem.py similarity index 98% rename from stix2/datastore/filesystem.py rename to misp_lib_stix2/datastore/filesystem.py index 2209116a..1663a74d 100644 --- a/stix2/datastore/filesystem.py +++ b/misp_lib_stix2/datastore/filesystem.py @@ -6,15 +6,15 @@ import re import stat -from stix2 import v20, v21 -from stix2.base import _STIXBase -from stix2.datastore import ( +from misp_lib_stix2 import v20, v21 +from misp_lib_stix2.base import _STIXBase +from misp_lib_stix2.datastore import ( DataSink, DataSource, DataSourceError, DataStoreMixin, ) -from stix2.datastore.filters import Filter, FilterSet, apply_common_filters -from stix2.parsing import parse -from stix2.serialization import fp_serialize -from stix2.utils import format_datetime, get_type_from_id, parse_into_datetime +from misp_lib_stix2.datastore.filters import Filter, FilterSet, apply_common_filters +from misp_lib_stix2.parsing import parse +from misp_lib_stix2.serialization import fp_serialize +from misp_lib_stix2.utils import format_datetime, get_type_from_id, parse_into_datetime def _timestamp2filename(timestamp): diff --git a/stix2/datastore/filters.py b/misp_lib_stix2/datastore/filters.py similarity index 98% rename from stix2/datastore/filters.py rename to misp_lib_stix2/datastore/filters.py index 6d9273e1..401e2fc4 100644 --- a/stix2/datastore/filters.py +++ b/misp_lib_stix2/datastore/filters.py @@ -3,7 +3,7 @@ import collections from datetime import datetime -import stix2.utils +import misp_lib_stix2.utils """Supported filter operations""" FILTER_OPS = ['=', '!=', 'in', '>', '<', '>=', '<=', 'contains'] @@ -82,7 +82,7 @@ def _check_property(self, stix_obj_property): # try to convert the filter value to a datetime instance. if isinstance(stix_obj_property, datetime) and \ isinstance(self.value, str): - filter_value = stix2.utils.parse_into_datetime(self.value) + filter_value = misp_lib_stix2.utils.parse_into_datetime(self.value) else: filter_value = self.value diff --git a/stix2/datastore/memory.py b/misp_lib_stix2/datastore/memory.py similarity index 97% rename from stix2/datastore/memory.py rename to misp_lib_stix2/datastore/memory.py index 10fb76d7..91551c1b 100644 --- a/stix2/datastore/memory.py +++ b/misp_lib_stix2/datastore/memory.py @@ -5,11 +5,11 @@ import json import os -from stix2 import v20, v21 -from stix2.base import _STIXBase -from stix2.datastore import DataSink, DataSource, DataStoreMixin -from stix2.datastore.filters import FilterSet, apply_common_filters -from stix2.parsing import parse +from misp_lib_stix2 import v20, v21 +from misp_lib_stix2.base import _STIXBase +from misp_lib_stix2.datastore import DataSink, DataSource, DataStoreMixin +from misp_lib_stix2.datastore.filters import FilterSet, apply_common_filters +from misp_lib_stix2.parsing import parse def _add(store, stix_data, allow_custom=True, version=None): diff --git a/stix2/datastore/taxii.py b/misp_lib_stix2/datastore/taxii.py similarity index 98% rename from stix2/datastore/taxii.py rename to misp_lib_stix2/datastore/taxii.py index f82f0175..b4b3fba4 100644 --- a/stix2/datastore/taxii.py +++ b/misp_lib_stix2/datastore/taxii.py @@ -2,14 +2,14 @@ from requests.exceptions import HTTPError -from stix2 import v20, v21 -from stix2.base import _STIXBase -from stix2.datastore import ( +from misp_lib_stix2 import v20, v21 +from misp_lib_stix2.base import _STIXBase +from misp_lib_stix2.datastore import ( DataSink, DataSource, DataSourceError, DataStoreMixin, ) -from stix2.datastore.filters import Filter, FilterSet, apply_common_filters -from stix2.parsing import parse -from stix2.utils import deduplicate +from misp_lib_stix2.datastore.filters import Filter, FilterSet, apply_common_filters +from misp_lib_stix2.parsing import parse +from misp_lib_stix2.utils import deduplicate try: from taxii2client import v20 as tcv20 diff --git a/stix2/environment.py b/misp_lib_stix2/environment.py similarity index 100% rename from stix2/environment.py rename to misp_lib_stix2/environment.py diff --git a/stix2/equivalence/__init__.py b/misp_lib_stix2/equivalence/__init__.py similarity index 100% rename from stix2/equivalence/__init__.py rename to misp_lib_stix2/equivalence/__init__.py diff --git a/stix2/equivalence/graph/__init__.py b/misp_lib_stix2/equivalence/graph/__init__.py similarity index 100% rename from stix2/equivalence/graph/__init__.py rename to misp_lib_stix2/equivalence/graph/__init__.py diff --git a/stix2/equivalence/object/__init__.py b/misp_lib_stix2/equivalence/object/__init__.py similarity index 100% rename from stix2/equivalence/object/__init__.py rename to misp_lib_stix2/equivalence/object/__init__.py diff --git a/stix2/equivalence/pattern/__init__.py b/misp_lib_stix2/equivalence/pattern/__init__.py similarity index 100% rename from stix2/equivalence/pattern/__init__.py rename to misp_lib_stix2/equivalence/pattern/__init__.py diff --git a/stix2/equivalence/pattern/compare/__init__.py b/misp_lib_stix2/equivalence/pattern/compare/__init__.py similarity index 100% rename from stix2/equivalence/pattern/compare/__init__.py rename to misp_lib_stix2/equivalence/pattern/compare/__init__.py diff --git a/stix2/equivalence/pattern/compare/comparison.py b/misp_lib_stix2/equivalence/pattern/compare/comparison.py similarity index 98% rename from stix2/equivalence/pattern/compare/comparison.py rename to misp_lib_stix2/equivalence/pattern/compare/comparison.py index 7ea7e056..6a1a2ef0 100644 --- a/stix2/equivalence/pattern/compare/comparison.py +++ b/misp_lib_stix2/equivalence/pattern/compare/comparison.py @@ -4,8 +4,8 @@ import base64 import functools -from stix2.equivalence.pattern.compare import generic_cmp, iter_lex_cmp -from stix2.patterns import ( +from misp_lib_stix2.equivalence.pattern.compare import generic_cmp, iter_lex_cmp +from misp_lib_stix2.patterns import ( AndBooleanExpression, BinaryConstant, BooleanConstant, FloatConstant, HexConstant, IntegerConstant, ListConstant, ListObjectPathComponent, OrBooleanExpression, StringConstant, TimestampConstant, diff --git a/stix2/equivalence/pattern/compare/observation.py b/misp_lib_stix2/equivalence/pattern/compare/observation.py similarity index 95% rename from stix2/equivalence/pattern/compare/observation.py rename to misp_lib_stix2/equivalence/pattern/compare/observation.py index a40248b0..523c5de2 100644 --- a/stix2/equivalence/pattern/compare/observation.py +++ b/misp_lib_stix2/equivalence/pattern/compare/observation.py @@ -1,11 +1,11 @@ """ Comparison utilities for STIX pattern observation expressions. """ -from stix2.equivalence.pattern.compare import generic_cmp, iter_lex_cmp -from stix2.equivalence.pattern.compare.comparison import ( +from misp_lib_stix2.equivalence.pattern.compare import generic_cmp, iter_lex_cmp +from misp_lib_stix2.equivalence.pattern.compare.comparison import ( comparison_expression_cmp, generic_constant_cmp, ) -from stix2.patterns import ( +from misp_lib_stix2.patterns import ( AndObservationExpression, FollowedByObservationExpression, ObservationExpression, OrObservationExpression, QualifiedObservationExpression, RepeatQualifier, StartStopQualifier, diff --git a/stix2/equivalence/pattern/transform/__init__.py b/misp_lib_stix2/equivalence/pattern/transform/__init__.py similarity index 100% rename from stix2/equivalence/pattern/transform/__init__.py rename to misp_lib_stix2/equivalence/pattern/transform/__init__.py diff --git a/stix2/equivalence/pattern/transform/comparison.py b/misp_lib_stix2/equivalence/pattern/transform/comparison.py similarity index 97% rename from stix2/equivalence/pattern/transform/comparison.py rename to misp_lib_stix2/equivalence/pattern/transform/comparison.py index 9da91eff..4be713bb 100644 --- a/stix2/equivalence/pattern/transform/comparison.py +++ b/misp_lib_stix2/equivalence/pattern/transform/comparison.py @@ -4,15 +4,15 @@ import functools import itertools -from stix2.equivalence.pattern.compare import iter_in, iter_lex_cmp -from stix2.equivalence.pattern.compare.comparison import ( +from misp_lib_stix2.equivalence.pattern.compare import iter_in, iter_lex_cmp +from misp_lib_stix2.equivalence.pattern.compare.comparison import ( comparison_expression_cmp, ) -from stix2.equivalence.pattern.transform import Transformer -from stix2.equivalence.pattern.transform.specials import ( +from misp_lib_stix2.equivalence.pattern.transform import Transformer +from misp_lib_stix2.equivalence.pattern.transform.specials import ( ipv4_addr, ipv6_addr, windows_reg_key, ) -from stix2.patterns import ( +from misp_lib_stix2.patterns import ( AndBooleanExpression, ObjectPath, OrBooleanExpression, ParentheticalExpression, _BooleanExpression, _ComparisonExpression, ) diff --git a/stix2/equivalence/pattern/transform/observation.py b/misp_lib_stix2/equivalence/pattern/transform/observation.py similarity index 96% rename from stix2/equivalence/pattern/transform/observation.py rename to misp_lib_stix2/equivalence/pattern/transform/observation.py index a92fff84..d185aedb 100644 --- a/stix2/equivalence/pattern/transform/observation.py +++ b/misp_lib_stix2/equivalence/pattern/transform/observation.py @@ -4,25 +4,25 @@ import functools import itertools -from stix2.equivalence.pattern.compare import iter_in, iter_lex_cmp -from stix2.equivalence.pattern.compare.observation import ( +from misp_lib_stix2.equivalence.pattern.compare import iter_in, iter_lex_cmp +from misp_lib_stix2.equivalence.pattern.compare.observation import ( observation_expression_cmp, ) -from stix2.equivalence.pattern.transform import ( +from misp_lib_stix2.equivalence.pattern.transform import ( ChainTransformer, SettleTransformer, Transformer, ) -from stix2.equivalence.pattern.transform.comparison import ( +from misp_lib_stix2.equivalence.pattern.transform.comparison import ( SpecialValueCanonicalization, ) -from stix2.equivalence.pattern.transform.comparison import \ +from misp_lib_stix2.equivalence.pattern.transform.comparison import \ AbsorptionTransformer as CAbsorptionTransformer -from stix2.equivalence.pattern.transform.comparison import \ +from misp_lib_stix2.equivalence.pattern.transform.comparison import \ DNFTransformer as CDNFTransformer -from stix2.equivalence.pattern.transform.comparison import \ +from misp_lib_stix2.equivalence.pattern.transform.comparison import \ FlattenTransformer as CFlattenTransformer -from stix2.equivalence.pattern.transform.comparison import \ +from misp_lib_stix2.equivalence.pattern.transform.comparison import \ OrderDedupeTransformer as COrderDedupeTransformer -from stix2.patterns import ( +from misp_lib_stix2.patterns import ( AndObservationExpression, FollowedByObservationExpression, ObservationExpression, OrObservationExpression, ParentheticalExpression, QualifiedObservationExpression, _CompoundObservationExpression, diff --git a/stix2/equivalence/pattern/transform/specials.py b/misp_lib_stix2/equivalence/pattern/transform/specials.py similarity index 99% rename from stix2/equivalence/pattern/transform/specials.py rename to misp_lib_stix2/equivalence/pattern/transform/specials.py index 0533a35e..5ef619ed 100644 --- a/stix2/equivalence/pattern/transform/specials.py +++ b/misp_lib_stix2/equivalence/pattern/transform/specials.py @@ -3,7 +3,7 @@ """ import socket -from stix2.equivalence.pattern.compare.comparison import ( +from misp_lib_stix2.equivalence.pattern.compare.comparison import ( object_path_to_raw_values, ) diff --git a/stix2/exceptions.py b/misp_lib_stix2/exceptions.py similarity index 100% rename from stix2/exceptions.py rename to misp_lib_stix2/exceptions.py diff --git a/stix2/hashes.py b/misp_lib_stix2/hashes.py similarity index 100% rename from stix2/hashes.py rename to misp_lib_stix2/hashes.py diff --git a/stix2/markings/__init__.py b/misp_lib_stix2/markings/__init__.py similarity index 99% rename from stix2/markings/__init__.py rename to misp_lib_stix2/markings/__init__.py index 6d09f812..8955866d 100644 --- a/stix2/markings/__init__.py +++ b/misp_lib_stix2/markings/__init__.py @@ -19,7 +19,7 @@ | """ -from stix2.markings import granular_markings, object_markings +from misp_lib_stix2.markings import granular_markings, object_markings def get_markings(obj, selectors=None, inherited=False, descendants=False, marking_ref=True, lang=True): diff --git a/stix2/markings/granular_markings.py b/misp_lib_stix2/markings/granular_markings.py similarity index 98% rename from stix2/markings/granular_markings.py rename to misp_lib_stix2/markings/granular_markings.py index 5021ec80..3456555f 100644 --- a/stix2/markings/granular_markings.py +++ b/misp_lib_stix2/markings/granular_markings.py @@ -1,9 +1,9 @@ """Functions for working with STIX2 granular markings.""" -from stix2 import exceptions -from stix2.markings import utils -from stix2.utils import is_marking -from stix2.versioning import new_version +from misp_lib_stix2 import exceptions +from misp_lib_stix2.markings import utils +from misp_lib_stix2.utils import is_marking +from misp_lib_stix2.versioning import new_version def get_markings(obj, selectors, inherited=False, descendants=False, marking_ref=True, lang=True): diff --git a/stix2/markings/object_markings.py b/misp_lib_stix2/markings/object_markings.py similarity index 96% rename from stix2/markings/object_markings.py rename to misp_lib_stix2/markings/object_markings.py index 5d4e4f10..dd9e2f79 100644 --- a/stix2/markings/object_markings.py +++ b/misp_lib_stix2/markings/object_markings.py @@ -1,8 +1,8 @@ """Functions for working with STIX2 object markings.""" -from stix2 import exceptions -from stix2.markings import utils -from stix2.versioning import new_version +from misp_lib_stix2 import exceptions +from misp_lib_stix2.markings import utils +from misp_lib_stix2.versioning import new_version def get_markings(obj): diff --git a/stix2/markings/utils.py b/misp_lib_stix2/markings/utils.py similarity index 99% rename from stix2/markings/utils.py rename to misp_lib_stix2/markings/utils.py index 538b18b4..6fbf2bd3 100644 --- a/stix2/markings/utils.py +++ b/misp_lib_stix2/markings/utils.py @@ -2,7 +2,7 @@ import collections -from stix2 import exceptions, utils +from misp_lib_stix2 import exceptions, utils def _evaluate_expression(obj, selector): diff --git a/stix2/parsing.py b/misp_lib_stix2/parsing.py similarity index 100% rename from stix2/parsing.py rename to misp_lib_stix2/parsing.py diff --git a/stix2/pattern_visitor.py b/misp_lib_stix2/pattern_visitor.py similarity index 100% rename from stix2/pattern_visitor.py rename to misp_lib_stix2/pattern_visitor.py diff --git a/stix2/patterns.py b/misp_lib_stix2/patterns.py similarity index 100% rename from stix2/patterns.py rename to misp_lib_stix2/patterns.py diff --git a/stix2/properties.py b/misp_lib_stix2/properties.py similarity index 99% rename from stix2/properties.py rename to misp_lib_stix2/properties.py index 6f34247d..8af908bb 100644 --- a/stix2/properties.py +++ b/misp_lib_stix2/properties.py @@ -8,8 +8,8 @@ import re import uuid -import stix2 -import stix2.hashes +import misp_lib_stix2 +import misp_lib_stix2.hashes from .base import _STIXBase from .exceptions import CustomContentError, DictionaryKeyError, STIXError @@ -436,7 +436,7 @@ def __init__(self, spec_hash_names, spec_version=DEFAULT_VERSION, **kwargs): # names which are recognized as hash algorithms by this library. self.__alg_to_spec_name = {} for spec_hash_name in spec_hash_names: - alg = stix2.hashes.infer_hash_algorithm(spec_hash_name) + alg = misp_lib_stix2.hashes.infer_hash_algorithm(spec_hash_name) if alg: self.__alg_to_spec_name[alg] = spec_hash_name @@ -449,11 +449,11 @@ def clean(self, value, allow_custom, interoperability=False): has_custom = False for hash_k, hash_v in clean_dict.items(): - hash_alg = stix2.hashes.infer_hash_algorithm(hash_k) + hash_alg = misp_lib_stix2.hashes.infer_hash_algorithm(hash_k) if hash_alg: # Library-supported hash algorithm: sanity check the value. - if not stix2.hashes.check_hash(hash_alg, hash_v): + if not misp_lib_stix2.hashes.check_hash(hash_alg, hash_v): raise ValueError( "'{0}' is not a valid {1} hash".format( hash_v, hash_alg.name, diff --git a/stix2/registration.py b/misp_lib_stix2/registration.py similarity index 100% rename from stix2/registration.py rename to misp_lib_stix2/registration.py diff --git a/stix2/registry.py b/misp_lib_stix2/registry.py similarity index 100% rename from stix2/registry.py rename to misp_lib_stix2/registry.py diff --git a/stix2/serialization.py b/misp_lib_stix2/serialization.py similarity index 96% rename from stix2/serialization.py rename to misp_lib_stix2/serialization.py index 7510b37f..13606b5f 100644 --- a/stix2/serialization.py +++ b/misp_lib_stix2/serialization.py @@ -5,7 +5,7 @@ import simplejson as json -import stix2.base +import misp_lib_stix2.base from .utils import format_datetime @@ -22,7 +22,7 @@ class STIXJSONEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, (dt.date, dt.datetime)): return format_datetime(obj) - elif isinstance(obj, stix2.base._STIXBase): + elif isinstance(obj, misp_lib_stix2.base._STIXBase): tmp_obj = dict(obj) for prop_name in obj._defaulted_optional_properties: del tmp_obj[prop_name] @@ -42,7 +42,7 @@ class STIXJSONIncludeOptionalDefaultsEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, (dt.date, dt.datetime)): return format_datetime(obj) - elif isinstance(obj, stix2.base._STIXBase): + elif isinstance(obj, misp_lib_stix2.base._STIXBase): return dict(obj) else: return super(STIXJSONIncludeOptionalDefaultsEncoder, self).default(obj) @@ -174,7 +174,7 @@ def find_property_index(obj, search_key, search_value): if search_key.isdigit(): return int(search_key) - if isinstance(obj, stix2.base._STIXBase): + if isinstance(obj, misp_lib_stix2.base._STIXBase): if search_key in obj and obj[search_key] == search_value: idx = _find(list(obj), search_key) else: diff --git a/stix2/test/__init__.py b/misp_lib_stix2/test/__init__.py similarity index 100% rename from stix2/test/__init__.py rename to misp_lib_stix2/test/__init__.py diff --git a/stix2/test/test_hashes.py b/misp_lib_stix2/test/test_hashes.py similarity index 97% rename from stix2/test/test_hashes.py rename to misp_lib_stix2/test/test_hashes.py index 40ace38f..470963e6 100644 --- a/stix2/test/test_hashes.py +++ b/misp_lib_stix2/test/test_hashes.py @@ -1,6 +1,6 @@ import pytest -from stix2.hashes import Hash, check_hash, infer_hash_algorithm +from misp_lib_stix2.hashes import Hash, check_hash, infer_hash_algorithm @pytest.mark.parametrize( diff --git a/stix2/test/test_pattern_equivalence.py b/misp_lib_stix2/test/test_pattern_equivalence.py similarity index 99% rename from stix2/test/test_pattern_equivalence.py rename to misp_lib_stix2/test/test_pattern_equivalence.py index a33caecf..5672098a 100644 --- a/stix2/test/test_pattern_equivalence.py +++ b/misp_lib_stix2/test/test_pattern_equivalence.py @@ -1,6 +1,6 @@ import pytest -from stix2.equivalence.pattern import ( +from misp_lib_stix2.equivalence.pattern import ( equivalent_patterns, find_equivalent_patterns, ) diff --git a/stix2/test/test_properties.py b/misp_lib_stix2/test/test_properties.py similarity index 98% rename from stix2/test/test_properties.py rename to misp_lib_stix2/test/test_properties.py index 5116a685..b0fa9663 100644 --- a/stix2/test/test_properties.py +++ b/misp_lib_stix2/test/test_properties.py @@ -3,11 +3,11 @@ import pytest import pytz -from stix2.base import _STIXBase -from stix2.exceptions import ( +from misp_lib_stix2.base import _STIXBase +from misp_lib_stix2.exceptions import ( CustomContentError, ExtraPropertiesError, STIXError, ) -from stix2.properties import ( +from misp_lib_stix2.properties import ( BinaryProperty, BooleanProperty, EmbeddedObjectProperty, EnumProperty, FloatProperty, HashesProperty, HexProperty, IntegerProperty, ListProperty, OpenVocabProperty, Property, StringProperty, TimestampProperty, diff --git a/stix2/test/test_spec_version_detect.py b/misp_lib_stix2/test/test_spec_version_detect.py similarity index 99% rename from stix2/test/test_spec_version_detect.py rename to misp_lib_stix2/test/test_spec_version_detect.py index 0d03e03d..88fae39a 100644 --- a/stix2/test/test_spec_version_detect.py +++ b/misp_lib_stix2/test/test_spec_version_detect.py @@ -2,7 +2,7 @@ import pytest -from stix2.utils import detect_spec_version +from misp_lib_stix2.utils import detect_spec_version @pytest.mark.parametrize( diff --git a/stix2/test/test_utils_type_checks.py b/misp_lib_stix2/test/test_utils_type_checks.py similarity index 58% rename from stix2/test/test_utils_type_checks.py rename to misp_lib_stix2/test/test_utils_type_checks.py index 2144653a..e534e4b7 100644 --- a/stix2/test/test_utils_type_checks.py +++ b/misp_lib_stix2/test/test_utils_type_checks.py @@ -1,6 +1,6 @@ import pytest -import stix2.utils +import misp_lib_stix2.utils ### # Tests using types/behaviors common to STIX 2.0 and 2.1. @@ -25,13 +25,13 @@ ], ) def test_is_sdo(type_, stix_version): - assert stix2.utils.is_sdo(type_, stix_version) + assert misp_lib_stix2.utils.is_sdo(type_, stix_version) id_ = type_ + "--a12fa04c-6586-4128-8d1a-cfe0d1c081f5" - assert stix2.utils.is_sdo(id_, stix_version) + assert misp_lib_stix2.utils.is_sdo(id_, stix_version) - assert stix2.utils.is_stix_type( - type_, stix_version, stix2.utils.STIXTypeClass.SDO, + assert misp_lib_stix2.utils.is_stix_type( + type_, stix_version, misp_lib_stix2.utils.STIXTypeClass.SDO, ) @@ -48,18 +48,18 @@ def test_is_sdo(type_, stix_version): ], ) def test_is_not_sdo(type_, stix_version): - assert not stix2.utils.is_sdo(type_, stix_version) + assert not misp_lib_stix2.utils.is_sdo(type_, stix_version) id_ = type_ + "--a12fa04c-6586-4128-8d1a-cfe0d1c081f5" - assert not stix2.utils.is_sdo(id_, stix_version) + assert not misp_lib_stix2.utils.is_sdo(id_, stix_version) d = { "type": type_, } - assert not stix2.utils.is_sdo(d, stix_version) + assert not misp_lib_stix2.utils.is_sdo(d, stix_version) - assert not stix2.utils.is_stix_type( - type_, stix_version, stix2.utils.STIXTypeClass.SDO, + assert not misp_lib_stix2.utils.is_stix_type( + type_, stix_version, misp_lib_stix2.utils.STIXTypeClass.SDO, ) @@ -87,13 +87,13 @@ def test_is_not_sdo(type_, stix_version): ], ) def test_is_sco(type_, stix_version): - assert stix2.utils.is_sco(type_, stix_version) + assert misp_lib_stix2.utils.is_sco(type_, stix_version) id_ = type_ + "--a12fa04c-6586-4128-8d1a-cfe0d1c081f5" - assert stix2.utils.is_sco(id_, stix_version) + assert misp_lib_stix2.utils.is_sco(id_, stix_version) - assert stix2.utils.is_stix_type( - type_, stix_version, stix2.utils.STIXTypeClass.SCO, + assert misp_lib_stix2.utils.is_stix_type( + type_, stix_version, misp_lib_stix2.utils.STIXTypeClass.SCO, ) @@ -109,18 +109,18 @@ def test_is_sco(type_, stix_version): ], ) def test_is_not_sco(type_, stix_version): - assert not stix2.utils.is_sco(type_, stix_version) + assert not misp_lib_stix2.utils.is_sco(type_, stix_version) id_ = type_ + "--a12fa04c-6586-4128-8d1a-cfe0d1c081f5" - assert not stix2.utils.is_sco(id_, stix_version) + assert not misp_lib_stix2.utils.is_sco(id_, stix_version) d = { "type": type_, } - assert not stix2.utils.is_sco(d, stix_version) + assert not misp_lib_stix2.utils.is_sco(d, stix_version) - assert not stix2.utils.is_stix_type( - type_, stix_version, stix2.utils.STIXTypeClass.SCO, + assert not misp_lib_stix2.utils.is_stix_type( + type_, stix_version, misp_lib_stix2.utils.STIXTypeClass.SCO, ) @@ -132,13 +132,13 @@ def test_is_not_sco(type_, stix_version): ], ) def test_is_sro(type_, stix_version): - assert stix2.utils.is_sro(type_, stix_version) + assert misp_lib_stix2.utils.is_sro(type_, stix_version) id_ = type_ + "--a12fa04c-6586-4128-8d1a-cfe0d1c081f5" - assert stix2.utils.is_sro(id_, stix_version) + assert misp_lib_stix2.utils.is_sro(id_, stix_version) - assert stix2.utils.is_stix_type( - type_, stix_version, stix2.utils.STIXTypeClass.SRO, + assert misp_lib_stix2.utils.is_stix_type( + type_, stix_version, misp_lib_stix2.utils.STIXTypeClass.SRO, ) @@ -154,29 +154,29 @@ def test_is_sro(type_, stix_version): ], ) def test_is_not_sro(type_, stix_version): - assert not stix2.utils.is_sro(type_, stix_version) + assert not misp_lib_stix2.utils.is_sro(type_, stix_version) id_ = type_ + "--a12fa04c-6586-4128-8d1a-cfe0d1c081f5" - assert not stix2.utils.is_sro(id_, stix_version) + assert not misp_lib_stix2.utils.is_sro(id_, stix_version) d = { "type": type_, } - assert not stix2.utils.is_sro(d, stix_version) + assert not misp_lib_stix2.utils.is_sro(d, stix_version) - assert not stix2.utils.is_stix_type( - type_, stix_version, stix2.utils.STIXTypeClass.SRO, + assert not misp_lib_stix2.utils.is_stix_type( + type_, stix_version, misp_lib_stix2.utils.STIXTypeClass.SRO, ) @pytest.mark.parametrize("stix_version", ["2.0", "2.1"]) def test_is_marking(stix_version): - assert stix2.utils.is_marking("marking-definition", stix_version) + assert misp_lib_stix2.utils.is_marking("marking-definition", stix_version) id_ = "marking-definition--a12fa04c-6586-4128-8d1a-cfe0d1c081f5" - assert stix2.utils.is_marking(id_, stix_version) + assert misp_lib_stix2.utils.is_marking(id_, stix_version) - assert stix2.utils.is_stix_type( + assert misp_lib_stix2.utils.is_stix_type( "marking-definition", stix_version, "marking-definition", ) @@ -192,17 +192,17 @@ def test_is_marking(stix_version): ], ) def test_is_not_marking(type_, stix_version): - assert not stix2.utils.is_marking(type_, stix_version) + assert not misp_lib_stix2.utils.is_marking(type_, stix_version) id_ = type_ + "--a12fa04c-6586-4128-8d1a-cfe0d1c081f5" - assert not stix2.utils.is_marking(id_, stix_version) + assert not misp_lib_stix2.utils.is_marking(id_, stix_version) d = { "type": type_, } - assert not stix2.utils.is_marking(d, stix_version) + assert not misp_lib_stix2.utils.is_marking(d, stix_version) - assert not stix2.utils.is_stix_type( + assert not misp_lib_stix2.utils.is_stix_type( type_, stix_version, "marking-definition", ) @@ -219,44 +219,44 @@ def test_is_not_marking(type_, stix_version): ], ) def test_is_object(type_, stix_version): - assert stix2.utils.is_object(type_, stix_version) + assert misp_lib_stix2.utils.is_object(type_, stix_version) id_ = type_ + "--a12fa04c-6586-4128-8d1a-cfe0d1c081f5" - assert stix2.utils.is_object(id_, stix_version) + assert misp_lib_stix2.utils.is_object(id_, stix_version) @pytest.mark.parametrize("stix_version", ["2.0", "2.1"]) def test_is_not_object(stix_version): - assert not stix2.utils.is_object("foo", stix_version) + assert not misp_lib_stix2.utils.is_object("foo", stix_version) id_ = "foo--a12fa04c-6586-4128-8d1a-cfe0d1c081f5" - assert not stix2.utils.is_object(id_, stix_version) + assert not misp_lib_stix2.utils.is_object(id_, stix_version) d = { "type": "foo", } - assert not stix2.utils.is_object(d, stix_version) + assert not misp_lib_stix2.utils.is_object(d, stix_version) @pytest.mark.parametrize("stix_version", ["2.0", "2.1"]) def test_is_stix_type(stix_version): - assert not stix2.utils.is_stix_type( - "foo", stix_version, stix2.utils.STIXTypeClass.SDO, "foo", + assert not misp_lib_stix2.utils.is_stix_type( + "foo", stix_version, misp_lib_stix2.utils.STIXTypeClass.SDO, "foo", ) - assert stix2.utils.is_stix_type( + assert misp_lib_stix2.utils.is_stix_type( "bundle", stix_version, "foo", "bundle", ) - assert stix2.utils.is_stix_type( + assert misp_lib_stix2.utils.is_stix_type( "identity", stix_version, - stix2.utils.STIXTypeClass.SDO, - stix2.utils.STIXTypeClass.SRO, + misp_lib_stix2.utils.STIXTypeClass.SDO, + misp_lib_stix2.utils.STIXTypeClass.SRO, ) - assert stix2.utils.is_stix_type( + assert misp_lib_stix2.utils.is_stix_type( "software", stix_version, - stix2.utils.STIXTypeClass.SDO, - stix2.utils.STIXTypeClass.SCO, + misp_lib_stix2.utils.STIXTypeClass.SDO, + misp_lib_stix2.utils.STIXTypeClass.SCO, ) diff --git a/stix2/test/test_workbench.py b/misp_lib_stix2/test/test_workbench.py similarity index 98% rename from stix2/test/test_workbench.py rename to misp_lib_stix2/test/test_workbench.py index 84f97a59..0980468e 100644 --- a/stix2/test/test_workbench.py +++ b/misp_lib_stix2/test/test_workbench.py @@ -1,8 +1,8 @@ import importlib import os -import stix2 -from stix2.workbench import ( +import misp_lib_stix2 +from misp_lib_stix2.workbench import ( _STIX_VID, AttackPattern, Bundle, Campaign, CourseOfAction, ExternalReference, File, FileSystemSource, Filter, Grouping, Identity, Indicator, Infrastructure, IntrusionSet, Location, Malware, @@ -325,8 +325,8 @@ def test_default_created_timestamp(): campaign = Campaign(**constants.CAMPAIGN_KWARGS) assert 'created' not in constants.CAMPAIGN_KWARGS - assert stix2.utils.format_datetime(campaign.created) == timestamp - assert stix2.utils.format_datetime(campaign.modified) == timestamp + assert misp_lib_stix2.utils.format_datetime(campaign.created) == timestamp + assert misp_lib_stix2.utils.format_datetime(campaign.modified) == timestamp # turn off side-effects to avoid affecting future tests set_default_created(None) diff --git a/stix2/test/v20/__init__.py b/misp_lib_stix2/test/v20/__init__.py similarity index 100% rename from stix2/test/v20/__init__.py rename to misp_lib_stix2/test/v20/__init__.py diff --git a/stix2/test/v20/conftest.py b/misp_lib_stix2/test/v20/conftest.py similarity index 93% rename from stix2/test/v20/conftest.py rename to misp_lib_stix2/test/v20/conftest.py index 0e4bc4c2..072d2446 100644 --- a/stix2/test/v20/conftest.py +++ b/misp_lib_stix2/test/v20/conftest.py @@ -2,7 +2,7 @@ import pytest -import stix2 +import misp_lib_stix2 from .constants import ( FAKE_TIME, INDICATOR_KWARGS, MALWARE_KWARGS, RELATIONSHIP_KWARGS, @@ -13,12 +13,12 @@ @pytest.fixture def clock(monkeypatch): - class mydatetime(stix2.utils.STIXdatetime): + class mydatetime(misp_lib_stix2.utils.STIXdatetime): @classmethod def now(cls, tz=None): return FAKE_TIME - monkeypatch.setattr(stix2.utils, 'STIXdatetime', mydatetime) + monkeypatch.setattr(misp_lib_stix2.utils, 'STIXdatetime', mydatetime) @pytest.fixture @@ -36,17 +36,17 @@ def wrapped(): @pytest.fixture def indicator(uuid4, clock): - return stix2.v20.Indicator(**INDICATOR_KWARGS) + return misp_lib_stix2.v20.Indicator(**INDICATOR_KWARGS) @pytest.fixture def malware(uuid4, clock): - return stix2.v20.Malware(**MALWARE_KWARGS) + return misp_lib_stix2.v20.Malware(**MALWARE_KWARGS) @pytest.fixture def relationship(uuid4, clock): - return stix2.v20.Relationship(**RELATIONSHIP_KWARGS) + return misp_lib_stix2.v20.Relationship(**RELATIONSHIP_KWARGS) @pytest.fixture @@ -193,4 +193,4 @@ def stix_objs2(): @pytest.fixture def real_stix_objs2(stix_objs2): - return [stix2.parse(x, version="2.0") for x in stix_objs2] + return [misp_lib_stix2.parse(x, version="2.0") for x in stix_objs2] diff --git a/stix2/test/v20/constants.py b/misp_lib_stix2/test/v20/constants.py similarity index 100% rename from stix2/test/v20/constants.py rename to misp_lib_stix2/test/v20/constants.py diff --git a/stix2/test/v20/pattern_ast_overrides.py b/misp_lib_stix2/test/v20/pattern_ast_overrides.py similarity index 90% rename from stix2/test/v20/pattern_ast_overrides.py rename to misp_lib_stix2/test/v20/pattern_ast_overrides.py index 16473ba9..87cbcee9 100644 --- a/stix2/test/v20/pattern_ast_overrides.py +++ b/misp_lib_stix2/test/v20/pattern_ast_overrides.py @@ -1,7 +1,7 @@ """ AST node class overrides for testing the pattern AST builder. """ -from stix2.patterns import ( +from misp_lib_stix2.patterns import ( EqualityComparisonExpression, StartStopQualifier, StringConstant, ) diff --git a/stix2/test/v20/stix2_data/attack-pattern/attack-pattern--0a3ead4e-6d47-4ccb-854c-a6a4f9d96b22/20170531213019735010.json b/misp_lib_stix2/test/v20/stix2_data/attack-pattern/attack-pattern--0a3ead4e-6d47-4ccb-854c-a6a4f9d96b22/20170531213019735010.json similarity index 100% rename from stix2/test/v20/stix2_data/attack-pattern/attack-pattern--0a3ead4e-6d47-4ccb-854c-a6a4f9d96b22/20170531213019735010.json rename to misp_lib_stix2/test/v20/stix2_data/attack-pattern/attack-pattern--0a3ead4e-6d47-4ccb-854c-a6a4f9d96b22/20170531213019735010.json diff --git a/stix2/test/v20/stix2_data/attack-pattern/attack-pattern--0f20e3cb-245b-4a61-8a91-2d93f7cb0e9b/20170531213026496201.json b/misp_lib_stix2/test/v20/stix2_data/attack-pattern/attack-pattern--0f20e3cb-245b-4a61-8a91-2d93f7cb0e9b/20170531213026496201.json similarity index 100% rename from stix2/test/v20/stix2_data/attack-pattern/attack-pattern--0f20e3cb-245b-4a61-8a91-2d93f7cb0e9b/20170531213026496201.json rename to misp_lib_stix2/test/v20/stix2_data/attack-pattern/attack-pattern--0f20e3cb-245b-4a61-8a91-2d93f7cb0e9b/20170531213026496201.json diff --git a/stix2/test/v20/stix2_data/attack-pattern/attack-pattern--774a3188-6ba9-4dc4-879d-d54ee48a5ce9/20170531213029458940.json b/misp_lib_stix2/test/v20/stix2_data/attack-pattern/attack-pattern--774a3188-6ba9-4dc4-879d-d54ee48a5ce9/20170531213029458940.json similarity index 100% rename from stix2/test/v20/stix2_data/attack-pattern/attack-pattern--774a3188-6ba9-4dc4-879d-d54ee48a5ce9/20170531213029458940.json rename to misp_lib_stix2/test/v20/stix2_data/attack-pattern/attack-pattern--774a3188-6ba9-4dc4-879d-d54ee48a5ce9/20170531213029458940.json diff --git a/stix2/test/v20/stix2_data/attack-pattern/attack-pattern--7e150503-88e7-4861-866b-ff1ac82c4475/20170531213045139269.json b/misp_lib_stix2/test/v20/stix2_data/attack-pattern/attack-pattern--7e150503-88e7-4861-866b-ff1ac82c4475/20170531213045139269.json similarity index 100% rename from stix2/test/v20/stix2_data/attack-pattern/attack-pattern--7e150503-88e7-4861-866b-ff1ac82c4475/20170531213045139269.json rename to misp_lib_stix2/test/v20/stix2_data/attack-pattern/attack-pattern--7e150503-88e7-4861-866b-ff1ac82c4475/20170531213045139269.json diff --git a/stix2/test/v20/stix2_data/attack-pattern/attack-pattern--ae676644-d2d2-41b7-af7e-9bed1b55898c/20170531213041022897.json b/misp_lib_stix2/test/v20/stix2_data/attack-pattern/attack-pattern--ae676644-d2d2-41b7-af7e-9bed1b55898c/20170531213041022897.json similarity index 100% rename from stix2/test/v20/stix2_data/attack-pattern/attack-pattern--ae676644-d2d2-41b7-af7e-9bed1b55898c/20170531213041022897.json rename to misp_lib_stix2/test/v20/stix2_data/attack-pattern/attack-pattern--ae676644-d2d2-41b7-af7e-9bed1b55898c/20170531213041022897.json diff --git a/stix2/test/v20/stix2_data/attack-pattern/attack-pattern--b3d682b6-98f2-4fb0-aa3b-b4df007ca70a/20170531213032662702.json b/misp_lib_stix2/test/v20/stix2_data/attack-pattern/attack-pattern--b3d682b6-98f2-4fb0-aa3b-b4df007ca70a/20170531213032662702.json similarity index 100% rename from stix2/test/v20/stix2_data/attack-pattern/attack-pattern--b3d682b6-98f2-4fb0-aa3b-b4df007ca70a/20170531213032662702.json rename to misp_lib_stix2/test/v20/stix2_data/attack-pattern/attack-pattern--b3d682b6-98f2-4fb0-aa3b-b4df007ca70a/20170531213032662702.json diff --git a/stix2/test/v20/stix2_data/course-of-action/course-of-action--95ddb356-7ba0-4bd9-a889-247262b8946f/20170531213026495974.json b/misp_lib_stix2/test/v20/stix2_data/course-of-action/course-of-action--95ddb356-7ba0-4bd9-a889-247262b8946f/20170531213026495974.json similarity index 100% rename from stix2/test/v20/stix2_data/course-of-action/course-of-action--95ddb356-7ba0-4bd9-a889-247262b8946f/20170531213026495974.json rename to misp_lib_stix2/test/v20/stix2_data/course-of-action/course-of-action--95ddb356-7ba0-4bd9-a889-247262b8946f/20170531213026495974.json diff --git a/stix2/test/v20/stix2_data/course-of-action/course-of-action--d9727aee-48b8-4fdb-89e2-4c49746ba4dd/20170531213041022744.json b/misp_lib_stix2/test/v20/stix2_data/course-of-action/course-of-action--d9727aee-48b8-4fdb-89e2-4c49746ba4dd/20170531213041022744.json similarity index 100% rename from stix2/test/v20/stix2_data/course-of-action/course-of-action--d9727aee-48b8-4fdb-89e2-4c49746ba4dd/20170531213041022744.json rename to misp_lib_stix2/test/v20/stix2_data/course-of-action/course-of-action--d9727aee-48b8-4fdb-89e2-4c49746ba4dd/20170531213041022744.json diff --git a/stix2/test/v20/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20170601000000000000.json b/misp_lib_stix2/test/v20/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20170601000000000000.json similarity index 100% rename from stix2/test/v20/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20170601000000000000.json rename to misp_lib_stix2/test/v20/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20170601000000000000.json diff --git a/stix2/test/v20/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20181101232448446000.json b/misp_lib_stix2/test/v20/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20181101232448446000.json similarity index 100% rename from stix2/test/v20/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20181101232448446000.json rename to misp_lib_stix2/test/v20/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20181101232448446000.json diff --git a/stix2/test/v20/stix2_data/intrusion-set/intrusion-set--a653431d-6a5e-4600-8ad3-609b5af57064/20170531213149412497.json b/misp_lib_stix2/test/v20/stix2_data/intrusion-set/intrusion-set--a653431d-6a5e-4600-8ad3-609b5af57064/20170531213149412497.json similarity index 100% rename from stix2/test/v20/stix2_data/intrusion-set/intrusion-set--a653431d-6a5e-4600-8ad3-609b5af57064/20170531213149412497.json rename to misp_lib_stix2/test/v20/stix2_data/intrusion-set/intrusion-set--a653431d-6a5e-4600-8ad3-609b5af57064/20170531213149412497.json diff --git a/stix2/test/v20/stix2_data/intrusion-set/intrusion-set--f3bdec95-3d62-42d9-a840-29630f6cdc1a/20170531213153197755.json b/misp_lib_stix2/test/v20/stix2_data/intrusion-set/intrusion-set--f3bdec95-3d62-42d9-a840-29630f6cdc1a/20170531213153197755.json similarity index 100% rename from stix2/test/v20/stix2_data/intrusion-set/intrusion-set--f3bdec95-3d62-42d9-a840-29630f6cdc1a/20170531213153197755.json rename to misp_lib_stix2/test/v20/stix2_data/intrusion-set/intrusion-set--f3bdec95-3d62-42d9-a840-29630f6cdc1a/20170531213153197755.json diff --git a/stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38.json b/misp_lib_stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38.json similarity index 100% rename from stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38.json rename to misp_lib_stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38.json diff --git a/stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20170531213258226477.json b/misp_lib_stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20170531213258226477.json similarity index 100% rename from stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20170531213258226477.json rename to misp_lib_stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20170531213258226477.json diff --git a/stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448456000.json b/misp_lib_stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448456000.json similarity index 100% rename from stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448456000.json rename to misp_lib_stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448456000.json diff --git a/stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448457000.json b/misp_lib_stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448457000.json similarity index 100% rename from stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448457000.json rename to misp_lib_stix2/test/v20/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448457000.json diff --git a/stix2/test/v20/stix2_data/malware/malware--92ec0cbd-2c30-44a2-b270-73f4ec949841/20170531213326565056.json b/misp_lib_stix2/test/v20/stix2_data/malware/malware--92ec0cbd-2c30-44a2-b270-73f4ec949841/20170531213326565056.json similarity index 100% rename from stix2/test/v20/stix2_data/malware/malware--92ec0cbd-2c30-44a2-b270-73f4ec949841/20170531213326565056.json rename to misp_lib_stix2/test/v20/stix2_data/malware/malware--92ec0cbd-2c30-44a2-b270-73f4ec949841/20170531213326565056.json diff --git a/stix2/test/v20/stix2_data/malware/malware--96b08451-b27a-4ff6-893f-790e26393a8e/20170531213248482655.json b/misp_lib_stix2/test/v20/stix2_data/malware/malware--96b08451-b27a-4ff6-893f-790e26393a8e/20170531213248482655.json similarity index 100% rename from stix2/test/v20/stix2_data/malware/malware--96b08451-b27a-4ff6-893f-790e26393a8e/20170531213248482655.json rename to misp_lib_stix2/test/v20/stix2_data/malware/malware--96b08451-b27a-4ff6-893f-790e26393a8e/20170531213248482655.json diff --git a/stix2/test/v20/stix2_data/malware/malware--b42378e0-f147-496f-992a-26a49705395b/20170531213215263882.json b/misp_lib_stix2/test/v20/stix2_data/malware/malware--b42378e0-f147-496f-992a-26a49705395b/20170531213215263882.json similarity index 100% rename from stix2/test/v20/stix2_data/malware/malware--b42378e0-f147-496f-992a-26a49705395b/20170531213215263882.json rename to misp_lib_stix2/test/v20/stix2_data/malware/malware--b42378e0-f147-496f-992a-26a49705395b/20170531213215263882.json diff --git a/stix2/test/v20/stix2_data/marking-definition/marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168.json b/misp_lib_stix2/test/v20/stix2_data/marking-definition/marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168.json similarity index 100% rename from stix2/test/v20/stix2_data/marking-definition/marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168.json rename to misp_lib_stix2/test/v20/stix2_data/marking-definition/marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168.json diff --git a/stix2/test/v20/stix2_data/relationship/relationship--0d4a7788-7f3b-4df8-a498-31a38003c883/20170531213327182784.json b/misp_lib_stix2/test/v20/stix2_data/relationship/relationship--0d4a7788-7f3b-4df8-a498-31a38003c883/20170531213327182784.json similarity index 100% rename from stix2/test/v20/stix2_data/relationship/relationship--0d4a7788-7f3b-4df8-a498-31a38003c883/20170531213327182784.json rename to misp_lib_stix2/test/v20/stix2_data/relationship/relationship--0d4a7788-7f3b-4df8-a498-31a38003c883/20170531213327182784.json diff --git a/stix2/test/v20/stix2_data/relationship/relationship--0e55ee98-0c6d-43d4-b424-b18a0036b227/20170531213327082801.json b/misp_lib_stix2/test/v20/stix2_data/relationship/relationship--0e55ee98-0c6d-43d4-b424-b18a0036b227/20170531213327082801.json similarity index 100% rename from stix2/test/v20/stix2_data/relationship/relationship--0e55ee98-0c6d-43d4-b424-b18a0036b227/20170531213327082801.json rename to misp_lib_stix2/test/v20/stix2_data/relationship/relationship--0e55ee98-0c6d-43d4-b424-b18a0036b227/20170531213327082801.json diff --git a/stix2/test/v20/stix2_data/relationship/relationship--1e91cd45-a725-4965-abe3-700694374432/20170531213327018782.json b/misp_lib_stix2/test/v20/stix2_data/relationship/relationship--1e91cd45-a725-4965-abe3-700694374432/20170531213327018782.json similarity index 100% rename from stix2/test/v20/stix2_data/relationship/relationship--1e91cd45-a725-4965-abe3-700694374432/20170531213327018782.json rename to misp_lib_stix2/test/v20/stix2_data/relationship/relationship--1e91cd45-a725-4965-abe3-700694374432/20170531213327018782.json diff --git a/stix2/test/v20/stix2_data/relationship/relationship--3a3084f9-0302-4fd5-9b8a-e0db10f5345e/20170531213327100701.json b/misp_lib_stix2/test/v20/stix2_data/relationship/relationship--3a3084f9-0302-4fd5-9b8a-e0db10f5345e/20170531213327100701.json similarity index 100% rename from stix2/test/v20/stix2_data/relationship/relationship--3a3084f9-0302-4fd5-9b8a-e0db10f5345e/20170531213327100701.json rename to misp_lib_stix2/test/v20/stix2_data/relationship/relationship--3a3084f9-0302-4fd5-9b8a-e0db10f5345e/20170531213327100701.json diff --git a/stix2/test/v20/stix2_data/relationship/relationship--3a3ed0b2-0c38-441f-ac40-53b873e545d1/20170531213327143973.json b/misp_lib_stix2/test/v20/stix2_data/relationship/relationship--3a3ed0b2-0c38-441f-ac40-53b873e545d1/20170531213327143973.json similarity index 100% rename from stix2/test/v20/stix2_data/relationship/relationship--3a3ed0b2-0c38-441f-ac40-53b873e545d1/20170531213327143973.json rename to misp_lib_stix2/test/v20/stix2_data/relationship/relationship--3a3ed0b2-0c38-441f-ac40-53b873e545d1/20170531213327143973.json diff --git a/stix2/test/v20/stix2_data/relationship/relationship--592d0c31-e61f-495e-a60e-70d7be59a719/20170531213327021562.json b/misp_lib_stix2/test/v20/stix2_data/relationship/relationship--592d0c31-e61f-495e-a60e-70d7be59a719/20170531213327021562.json similarity index 100% rename from stix2/test/v20/stix2_data/relationship/relationship--592d0c31-e61f-495e-a60e-70d7be59a719/20170531213327021562.json rename to misp_lib_stix2/test/v20/stix2_data/relationship/relationship--592d0c31-e61f-495e-a60e-70d7be59a719/20170531213327021562.json diff --git a/stix2/test/v20/stix2_data/relationship/relationship--70dc6b5c-c524-429e-a6ab-0dd40f0482c1/20170531213327044387.json b/misp_lib_stix2/test/v20/stix2_data/relationship/relationship--70dc6b5c-c524-429e-a6ab-0dd40f0482c1/20170531213327044387.json similarity index 100% rename from stix2/test/v20/stix2_data/relationship/relationship--70dc6b5c-c524-429e-a6ab-0dd40f0482c1/20170531213327044387.json rename to misp_lib_stix2/test/v20/stix2_data/relationship/relationship--70dc6b5c-c524-429e-a6ab-0dd40f0482c1/20170531213327044387.json diff --git a/stix2/test/v20/stix2_data/relationship/relationship--8797579b-e3be-4209-a71b-255a4d08243d/20170531213327051532.json b/misp_lib_stix2/test/v20/stix2_data/relationship/relationship--8797579b-e3be-4209-a71b-255a4d08243d/20170531213327051532.json similarity index 100% rename from stix2/test/v20/stix2_data/relationship/relationship--8797579b-e3be-4209-a71b-255a4d08243d/20170531213327051532.json rename to misp_lib_stix2/test/v20/stix2_data/relationship/relationship--8797579b-e3be-4209-a71b-255a4d08243d/20170531213327051532.json diff --git a/stix2/test/v20/stix2_data/tool/tool--03342581-f790-4f03-ba41-e82e67392e23/20170531213231601148.json b/misp_lib_stix2/test/v20/stix2_data/tool/tool--03342581-f790-4f03-ba41-e82e67392e23/20170531213231601148.json similarity index 100% rename from stix2/test/v20/stix2_data/tool/tool--03342581-f790-4f03-ba41-e82e67392e23/20170531213231601148.json rename to misp_lib_stix2/test/v20/stix2_data/tool/tool--03342581-f790-4f03-ba41-e82e67392e23/20170531213231601148.json diff --git a/stix2/test/v20/stix2_data/tool/tool--242f3da3-4425-4d11-8f5c-b842886da966/20170531213212684914.json b/misp_lib_stix2/test/v20/stix2_data/tool/tool--242f3da3-4425-4d11-8f5c-b842886da966/20170531213212684914.json similarity index 100% rename from stix2/test/v20/stix2_data/tool/tool--242f3da3-4425-4d11-8f5c-b842886da966/20170531213212684914.json rename to misp_lib_stix2/test/v20/stix2_data/tool/tool--242f3da3-4425-4d11-8f5c-b842886da966/20170531213212684914.json diff --git a/stix2/test/v20/test_attack_pattern.py b/misp_lib_stix2/test/v20/test_attack_pattern.py similarity index 87% rename from stix2/test/v20/test_attack_pattern.py rename to misp_lib_stix2/test/v20/test_attack_pattern.py index 1f534502..e514d177 100644 --- a/stix2/test/v20/test_attack_pattern.py +++ b/misp_lib_stix2/test/v20/test_attack_pattern.py @@ -3,8 +3,8 @@ import pytest import pytz -import stix2 -import stix2.exceptions +import misp_lib_stix2 +import misp_lib_stix2.exceptions from .constants import ATTACK_PATTERN_ID @@ -25,7 +25,7 @@ def test_attack_pattern_example(): - ap = stix2.v20.AttackPattern( + ap = misp_lib_stix2.v20.AttackPattern( id=ATTACK_PATTERN_ID, created="2016-05-12T08:17:27.000Z", modified="2016-05-12T08:17:27.000Z", @@ -60,7 +60,7 @@ def test_attack_pattern_example(): ], ) def test_parse_attack_pattern(data): - ap = stix2.parse(data, version="2.0") + ap = misp_lib_stix2.parse(data, version="2.0") assert ap.type == 'attack-pattern' assert ap.id == ATTACK_PATTERN_ID @@ -73,8 +73,8 @@ def test_parse_attack_pattern(data): def test_attack_pattern_invalid_labels(): - with pytest.raises(stix2.exceptions.InvalidValueError): - stix2.v20.AttackPattern( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError): + misp_lib_stix2.v20.AttackPattern( id=ATTACK_PATTERN_ID, created="2016-05-12T08:17:27Z", modified="2016-05-12T08:17:27Z", @@ -84,8 +84,8 @@ def test_attack_pattern_invalid_labels(): def test_overly_precise_timestamps(): - with pytest.raises(stix2.exceptions.InvalidValueError): - stix2.v20.AttackPattern( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError): + misp_lib_stix2.v20.AttackPattern( id=ATTACK_PATTERN_ID, created="2016-05-12T08:17:27.0000342Z", modified="2016-05-12T08:17:27.000287Z", @@ -99,7 +99,7 @@ def test_overly_precise_timestamps(): def test_less_precise_timestamps(): - ap = stix2.v20.AttackPattern( + ap = misp_lib_stix2.v20.AttackPattern( id=ATTACK_PATTERN_ID, created="2016-05-12T08:17:27.00Z", modified="2016-05-12T08:17:27.0Z", diff --git a/stix2/test/v20/test_base.py b/misp_lib_stix2/test/v20/test_base.py similarity index 91% rename from stix2/test/v20/test_base.py rename to misp_lib_stix2/test/v20/test_base.py index 18d3a50a..2b116e6d 100644 --- a/stix2/test/v20/test_base.py +++ b/misp_lib_stix2/test/v20/test_base.py @@ -4,7 +4,7 @@ import pytest import pytz -from stix2.base import STIXJSONEncoder +from misp_lib_stix2.base import STIXJSONEncoder def test_encode_json_datetime(): diff --git a/stix2/test/v20/test_bundle.py b/misp_lib_stix2/test/v20/test_bundle.py similarity index 83% rename from stix2/test/v20/test_bundle.py rename to misp_lib_stix2/test/v20/test_bundle.py index 07fa24da..146ee640 100644 --- a/stix2/test/v20/test_bundle.py +++ b/misp_lib_stix2/test/v20/test_bundle.py @@ -3,7 +3,7 @@ import pytest -import stix2 +import misp_lib_stix2 from ...exceptions import InvalidValueError from .constants import IDENTITY_ID @@ -86,7 +86,7 @@ def test_empty_bundle(): - bundle = stix2.v20.Bundle() + bundle = misp_lib_stix2.v20.Bundle() assert bundle.type == "bundle" assert bundle.id.startswith("bundle--") @@ -95,27 +95,27 @@ def test_empty_bundle(): def test_bundle_with_wrong_type(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Bundle(type="not-a-bundle") + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Bundle(type="not-a-bundle") - assert excinfo.value.cls == stix2.v20.Bundle + assert excinfo.value.cls == misp_lib_stix2.v20.Bundle assert excinfo.value.prop_name == "type" assert excinfo.value.reason == "must equal 'bundle'." assert str(excinfo.value) == "Invalid value for Bundle 'type': must equal 'bundle'." def test_bundle_id_must_start_with_bundle(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Bundle(id='my-prefix--') + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Bundle(id='my-prefix--') - assert excinfo.value.cls == stix2.v20.Bundle + assert excinfo.value.cls == misp_lib_stix2.v20.Bundle assert excinfo.value.prop_name == "id" assert excinfo.value.reason == "must start with 'bundle--'." assert str(excinfo.value) == "Invalid value for Bundle 'id': must start with 'bundle--'." def test_create_bundle_fp_serialize_pretty(indicator, malware, relationship): - bundle = stix2.v20.Bundle(objects=[indicator, malware, relationship]) + bundle = misp_lib_stix2.v20.Bundle(objects=[indicator, malware, relationship]) buffer = io.StringIO() bundle.fp_serialize(buffer, pretty=True) @@ -125,7 +125,7 @@ def test_create_bundle_fp_serialize_pretty(indicator, malware, relationship): def test_create_bundle_fp_serialize_nonpretty(indicator, malware, relationship): - bundle = stix2.v20.Bundle(objects=[indicator, malware, relationship]) + bundle = misp_lib_stix2.v20.Bundle(objects=[indicator, malware, relationship]) buffer = io.StringIO() bundle.fp_serialize(buffer, sort_keys=True) @@ -135,69 +135,69 @@ def test_create_bundle_fp_serialize_nonpretty(indicator, malware, relationship): def test_create_bundle1(indicator, malware, relationship): - bundle = stix2.v20.Bundle(objects=[indicator, malware, relationship]) + bundle = misp_lib_stix2.v20.Bundle(objects=[indicator, malware, relationship]) assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE def test_create_bundle2(indicator, malware, relationship): - bundle = stix2.v20.Bundle(objects=[indicator, malware, relationship]) + bundle = misp_lib_stix2.v20.Bundle(objects=[indicator, malware, relationship]) assert json.loads(bundle.serialize()) == EXPECTED_BUNDLE_DICT def test_create_bundle_with_positional_args(indicator, malware, relationship): - bundle = stix2.v20.Bundle(indicator, malware, relationship) + bundle = misp_lib_stix2.v20.Bundle(indicator, malware, relationship) assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE def test_create_bundle_with_positional_listarg(indicator, malware, relationship): - bundle = stix2.v20.Bundle([indicator, malware, relationship]) + bundle = misp_lib_stix2.v20.Bundle([indicator, malware, relationship]) assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE def test_create_bundle_with_listarg_and_positional_arg(indicator, malware, relationship): - bundle = stix2.v20.Bundle([indicator, malware], relationship) + bundle = misp_lib_stix2.v20.Bundle([indicator, malware], relationship) assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE def test_create_bundle_with_listarg_and_kwarg(indicator, malware, relationship): - bundle = stix2.v20.Bundle([indicator, malware], objects=[relationship]) + bundle = misp_lib_stix2.v20.Bundle([indicator, malware], objects=[relationship]) assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE def test_create_bundle_with_arg_listarg_and_kwarg(indicator, malware, relationship): - bundle = stix2.v20.Bundle([indicator], malware, objects=[relationship]) + bundle = misp_lib_stix2.v20.Bundle([indicator], malware, objects=[relationship]) assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE def test_create_bundle_invalid(indicator, malware, relationship): with pytest.raises(InvalidValueError) as excinfo: - stix2.v20.Bundle(objects=[1]) + misp_lib_stix2.v20.Bundle(objects=[1]) assert excinfo.value.reason == "This property may only contain a dictionary or object" with pytest.raises(InvalidValueError) as excinfo: - stix2.v20.Bundle(objects=[{}]) + misp_lib_stix2.v20.Bundle(objects=[{}]) assert excinfo.value.reason == "This property may only contain a non-empty dictionary or object" with pytest.raises(InvalidValueError) as excinfo: - stix2.v20.Bundle(objects=[{'type': 'bundle'}]) + misp_lib_stix2.v20.Bundle(objects=[{'type': 'bundle'}]) assert excinfo.value.reason == 'This property may not contain a Bundle object' @pytest.mark.parametrize("version", ["2.0"]) def test_parse_bundle(version): - bundle = stix2.parse(EXPECTED_BUNDLE, version=version) + bundle = misp_lib_stix2.parse(EXPECTED_BUNDLE, version=version) assert bundle.type == "bundle" assert bundle.id.startswith("bundle--") - assert isinstance(bundle.objects[0], stix2.v20.Indicator) + assert isinstance(bundle.objects[0], misp_lib_stix2.v20.Indicator) assert bundle.objects[0].type == 'indicator' assert bundle.objects[1].type == 'malware' assert bundle.objects[2].type == 'relationship' @@ -214,15 +214,15 @@ def test_parse_unknown_type(): "name": "Green Group Attacks Against Finance", } - with pytest.raises(stix2.exceptions.ParseError) as excinfo: - stix2.parse(unknown, version="2.0") + with pytest.raises(misp_lib_stix2.exceptions.ParseError) as excinfo: + misp_lib_stix2.parse(unknown, version="2.0") assert str(excinfo.value) == "Can't parse unknown object type 'other'! For custom types, use the CustomObject decorator." def test_stix_object_property(): - prop = stix2.properties.STIXObjectProperty(spec_version='2.0') + prop = misp_lib_stix2.properties.STIXObjectProperty(spec_version='2.0') - identity = stix2.v20.Identity(name="test", identity_class="individual") + identity = misp_lib_stix2.v20.Identity(name="test", identity_class="individual") assert prop.clean(identity, False) == (identity, False) @@ -255,13 +255,13 @@ def test_bundle_with_different_spec_objects(): ] with pytest.raises(InvalidValueError) as excinfo: - stix2.v20.Bundle(objects=data) + misp_lib_stix2.v20.Bundle(objects=data) assert "Spec version 2.0 bundles don't yet support containing objects of a different spec version." in str(excinfo.value) def test_bundle_obj_id_found(): - bundle = stix2.parse(EXPECTED_BUNDLE) + bundle = misp_lib_stix2.parse(EXPECTED_BUNDLE) mal_list = bundle.get_obj("malware--00000000-0000-4000-8000-000000000003") assert bundle.objects[1] == mal_list[0] @@ -318,7 +318,7 @@ def test_bundle_obj_id_found(): }], ) def test_bundle_objs_ids_found(bundle_data): - bundle = stix2.parse(bundle_data) + bundle = misp_lib_stix2.parse(bundle_data) mal_list = bundle.get_obj("malware--00000000-0000-4000-8000-000000000003") assert bundle.objects[1] == mal_list[0] @@ -327,14 +327,14 @@ def test_bundle_objs_ids_found(bundle_data): def test_bundle_getitem_overload_property_found(): - bundle = stix2.parse(EXPECTED_BUNDLE) + bundle = misp_lib_stix2.parse(EXPECTED_BUNDLE) assert bundle.type == "bundle" assert bundle['type'] == "bundle" def test_bundle_getitem_overload_obj_id_found(): - bundle = stix2.parse(EXPECTED_BUNDLE) + bundle = misp_lib_stix2.parse(EXPECTED_BUNDLE) mal_list = bundle["malware--00000000-0000-4000-8000-000000000003"] assert bundle.objects[1] == mal_list[0] @@ -342,7 +342,7 @@ def test_bundle_getitem_overload_obj_id_found(): def test_bundle_obj_id_not_found(): - bundle = stix2.parse(EXPECTED_BUNDLE) + bundle = misp_lib_stix2.parse(EXPECTED_BUNDLE) with pytest.raises(KeyError) as excinfo: bundle.get_obj('non existent') @@ -350,7 +350,7 @@ def test_bundle_obj_id_not_found(): def test_bundle_getitem_overload_obj_id_not_found(): - bundle = stix2.parse(EXPECTED_BUNDLE) + bundle = misp_lib_stix2.parse(EXPECTED_BUNDLE) with pytest.raises(KeyError) as excinfo: bundle['non existent'] diff --git a/stix2/test/v20/test_campaign.py b/misp_lib_stix2/test/v20/test_campaign.py similarity index 91% rename from stix2/test/v20/test_campaign.py rename to misp_lib_stix2/test/v20/test_campaign.py index 13b47b01..23ed4805 100644 --- a/stix2/test/v20/test_campaign.py +++ b/misp_lib_stix2/test/v20/test_campaign.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import CAMPAIGN_ID, CAMPAIGN_MORE_KWARGS, IDENTITY_ID @@ -19,7 +19,7 @@ def test_campaign_example(): - campaign = stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign = misp_lib_stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) assert campaign.serialize(pretty=True) == EXPECTED @@ -39,7 +39,7 @@ def test_campaign_example(): ], ) def test_parse_campaign(data): - cmpn = stix2.parse(data, version="2.0") + cmpn = misp_lib_stix2.parse(data, version="2.0") assert cmpn.type == 'campaign' assert cmpn.id == CAMPAIGN_ID diff --git a/stix2/test/v20/test_course_of_action.py b/misp_lib_stix2/test/v20/test_course_of_action.py similarity index 94% rename from stix2/test/v20/test_course_of_action.py rename to misp_lib_stix2/test/v20/test_course_of_action.py index c778316f..1159bc59 100644 --- a/stix2/test/v20/test_course_of_action.py +++ b/misp_lib_stix2/test/v20/test_course_of_action.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import COURSE_OF_ACTION_ID, IDENTITY_ID @@ -19,7 +19,7 @@ def test_course_of_action_example(): - coa = stix2.v20.CourseOfAction( + coa = misp_lib_stix2.v20.CourseOfAction( id=COURSE_OF_ACTION_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T20:03:48.000Z", @@ -46,7 +46,7 @@ def test_course_of_action_example(): ], ) def test_parse_course_of_action(data): - coa = stix2.parse(data, version="2.0") + coa = misp_lib_stix2.parse(data, version="2.0") assert coa.type == 'course-of-action' assert coa.id == COURSE_OF_ACTION_ID diff --git a/stix2/test/v20/test_custom.py b/misp_lib_stix2/test/v20/test_custom.py similarity index 71% rename from stix2/test/v20/test_custom.py rename to misp_lib_stix2/test/v20/test_custom.py index 3264af9b..85e033b0 100644 --- a/stix2/test/v20/test_custom.py +++ b/misp_lib_stix2/test/v20/test_custom.py @@ -1,15 +1,15 @@ import pytest -import stix2 -import stix2.parsing -import stix2.registration -import stix2.registry -import stix2.v20 +import misp_lib_stix2 +import misp_lib_stix2.parsing +import misp_lib_stix2.registration +import misp_lib_stix2.registry +import misp_lib_stix2.v20 from ...exceptions import DuplicateRegistrationError, InvalidValueError from .constants import FAKE_TIME, IDENTITY_ID, MARKING_DEFINITION_ID -IDENTITY_CUSTOM_PROP = stix2.v20.Identity( +IDENTITY_CUSTOM_PROP = misp_lib_stix2.v20.Identity( name="John Smith", identity_class="individual", x_foo="bar", @@ -19,7 +19,7 @@ def test_identity_custom_property(): with pytest.raises(ValueError) as excinfo: - stix2.v20.Identity( + misp_lib_stix2.v20.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11Z", modified="2015-12-21T19:59:11Z", @@ -29,8 +29,8 @@ def test_identity_custom_property(): ) assert str(excinfo.value) == "'custom_properties' must be a dictionary" - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v20.Identity( + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v20.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11Z", modified="2015-12-21T19:59:11Z", @@ -43,7 +43,7 @@ def test_identity_custom_property(): ) assert "Unexpected properties for Identity" in str(excinfo.value) - identity = stix2.v20.Identity( + identity = misp_lib_stix2.v20.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11Z", modified="2015-12-21T19:59:11Z", @@ -57,8 +57,8 @@ def test_identity_custom_property(): def test_identity_custom_property_invalid(): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v20.Identity( + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v20.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11Z", modified="2015-12-21T19:59:11Z", @@ -66,13 +66,13 @@ def test_identity_custom_property_invalid(): identity_class="individual", x_foo="bar", ) - assert excinfo.value.cls == stix2.v20.Identity + assert excinfo.value.cls == misp_lib_stix2.v20.Identity assert excinfo.value.properties == ['x_foo'] assert "Unexpected properties for" in str(excinfo.value) def test_identity_custom_property_allowed(): - identity = stix2.v20.Identity( + identity = misp_lib_stix2.v20.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11Z", modified="2015-12-21T19:59:11Z", @@ -98,32 +98,32 @@ def test_identity_custom_property_allowed(): ], ) def test_parse_identity_custom_property(data): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.parse(data, version="2.0") - assert issubclass(excinfo.value.cls, stix2.v20.Identity) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.parse(data, version="2.0") + assert issubclass(excinfo.value.cls, misp_lib_stix2.v20.Identity) assert excinfo.value.properties == ['foo'] assert "Unexpected properties for" in str(excinfo.value) - identity = stix2.parse(data, version="2.0", allow_custom=True) + identity = misp_lib_stix2.parse(data, version="2.0", allow_custom=True) assert identity.foo == "bar" def test_custom_property_object_in_bundled_object(): - bundle = stix2.v20.Bundle(IDENTITY_CUSTOM_PROP, allow_custom=True) + bundle = misp_lib_stix2.v20.Bundle(IDENTITY_CUSTOM_PROP, allow_custom=True) assert bundle.objects[0].x_foo == "bar" assert '"x_foo": "bar"' in str(bundle) def test_custom_properties_object_in_bundled_object(): - obj = stix2.v20.Identity( + obj = misp_lib_stix2.v20.Identity( name="John Smith", identity_class="individual", custom_properties={ "x_foo": "bar", }, ) - bundle = stix2.v20.Bundle(obj, allow_custom=True) + bundle = misp_lib_stix2.v20.Bundle(obj, allow_custom=True) assert bundle.objects[0].x_foo == "bar" assert '"x_foo": "bar"' in str(bundle) @@ -139,9 +139,9 @@ def test_custom_property_dict_in_bundled_object(): 'x_foo': 'bar', } with pytest.raises(InvalidValueError): - stix2.v20.Bundle(custom_identity) + misp_lib_stix2.v20.Bundle(custom_identity) - bundle = stix2.v20.Bundle(custom_identity, allow_custom=True) + bundle = misp_lib_stix2.v20.Bundle(custom_identity, allow_custom=True) assert bundle.objects[0].x_foo == "bar" assert '"x_foo": "bar"' in str(bundle) @@ -161,16 +161,16 @@ def test_custom_properties_dict_in_bundled_object(): # must not succeed: allow_custom was not set to True when creating # the bundle, so it must reject the customized identity object. with pytest.raises(InvalidValueError): - stix2.v20.Bundle(custom_identity) + misp_lib_stix2.v20.Bundle(custom_identity) def test_custom_property_in_observed_data(): - artifact = stix2.v20.File( + artifact = misp_lib_stix2.v20.File( allow_custom=True, name='test', x_foo='bar', ) - observed_data = stix2.v20.ObservedData( + observed_data = misp_lib_stix2.v20.ObservedData( allow_custom=True, first_observed="2015-12-21T19:00:00Z", last_observed="2015-12-21T19:00:00Z", @@ -183,17 +183,17 @@ def test_custom_property_in_observed_data(): def test_custom_property_object_in_observable_extension(): - ntfs = stix2.v20.NTFSExt( + ntfs = misp_lib_stix2.v20.NTFSExt( allow_custom=True, sid=1, x_foo='bar', ) - artifact = stix2.v20.File( + artifact = misp_lib_stix2.v20.File( allow_custom=True, name='test', extensions={'ntfs-ext': ntfs}, ) - observed_data = stix2.v20.ObservedData( + observed_data = misp_lib_stix2.v20.ObservedData( allow_custom=True, first_observed="2015-12-21T19:00:00Z", last_observed="2015-12-21T19:00:00Z", @@ -207,7 +207,7 @@ def test_custom_property_object_in_observable_extension(): def test_custom_property_dict_in_observable_extension(): with pytest.raises(InvalidValueError): - stix2.v20.File( + misp_lib_stix2.v20.File( name='test', extensions={ 'ntfs-ext': { @@ -217,7 +217,7 @@ def test_custom_property_dict_in_observable_extension(): }, ) - artifact = stix2.v20.File( + artifact = misp_lib_stix2.v20.File( allow_custom=True, name='test', extensions={ @@ -227,7 +227,7 @@ def test_custom_property_dict_in_observable_extension(): }, }, ) - observed_data = stix2.v20.ObservedData( + observed_data = misp_lib_stix2.v20.ObservedData( allow_custom=True, first_observed="2015-12-21T19:00:00Z", last_observed="2015-12-21T19:00:00Z", @@ -245,15 +245,15 @@ def test_identity_custom_property_revoke(): def test_identity_custom_property_edit_markings(): - marking_obj = stix2.v20.MarkingDefinition( + marking_obj = misp_lib_stix2.v20.MarkingDefinition( id=MARKING_DEFINITION_ID, definition_type="statement", - definition=stix2.v20.StatementMarking(statement="Copyright 2016, Example Corp"), + definition=misp_lib_stix2.v20.StatementMarking(statement="Copyright 2016, Example Corp"), ) - marking_obj2 = stix2.v20.MarkingDefinition( + marking_obj2 = misp_lib_stix2.v20.MarkingDefinition( id=MARKING_DEFINITION_ID, definition_type="statement", - definition=stix2.v20.StatementMarking(statement="Another one"), + definition=misp_lib_stix2.v20.StatementMarking(statement="Another one"), ) # None of the following should throw exceptions @@ -266,9 +266,9 @@ def test_identity_custom_property_edit_markings(): def test_custom_marking_no_init_1(): - @stix2.v20.CustomMarking( + @misp_lib_stix2.v20.CustomMarking( 'x-new-obj', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj(): @@ -279,9 +279,9 @@ class NewObj(): def test_custom_marking_no_init_2(): - @stix2.v20.CustomMarking( + @misp_lib_stix2.v20.CustomMarking( 'x-new-obj2', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj2(object): @@ -293,9 +293,9 @@ class NewObj2(object): def test_register_duplicate_marking(): with pytest.raises(DuplicateRegistrationError) as excinfo: - @stix2.v20.CustomMarking( + @misp_lib_stix2.v20.CustomMarking( 'x-new-obj2', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj2(): @@ -303,10 +303,10 @@ class NewObj2(): assert "cannot be registered again" in str(excinfo.value) -@stix2.v20.CustomObject( +@misp_lib_stix2.v20.CustomObject( 'x-new-type', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewType(object): @@ -328,7 +328,7 @@ def test_custom_object_type(): nt = NewType(property1='something') assert nt.property1 == 'something' - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: NewType(property2=42) assert "No values for required properties" in str(excinfo.value) @@ -338,9 +338,9 @@ def test_custom_object_type(): def test_custom_object_no_init_1(): - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x-new-obj', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj(): @@ -351,9 +351,9 @@ class NewObj(): def test_custom_object_no_init_2(): - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x-new-obj2', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj2(object): @@ -365,9 +365,9 @@ class NewObj2(object): def test_custom_object_invalid_type_name(): with pytest.raises(ValueError) as excinfo: - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj(object): @@ -375,9 +375,9 @@ class NewObj(object): assert "Invalid type name 'x': " in str(excinfo.value) with pytest.raises(ValueError) as excinfo: - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x_new_object', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj2(object): @@ -386,9 +386,9 @@ class NewObj2(object): def test_custom_object_ref_property_as_identifier(): - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x-new-obj-with-ref', [ - ('property_ref', stix2.properties.ReferenceProperty(invalid_types=[])), + ('property_ref', misp_lib_stix2.properties.ReferenceProperty(invalid_types=[])), ], ) class NewObs(): @@ -396,9 +396,9 @@ class NewObs(): def test_custom_object_refs_property_containing_identifiers(): - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x-new-obj-with-refs', [ - ('property_refs', stix2.properties.ListProperty(stix2.properties.ReferenceProperty(invalid_types=[]))), + ('property_refs', misp_lib_stix2.properties.ListProperty(misp_lib_stix2.properties.ReferenceProperty(invalid_types=[]))), ], ) class NewObs(): @@ -407,9 +407,9 @@ class NewObs(): def test_custom_object_ref_property_as_objectref(): with pytest.raises(ValueError, match=r"not a subclass of 'ReferenceProperty"): - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x-new-obj-with-objref', [ - ('property_ref', stix2.properties.ObjectReferenceProperty()), + ('property_ref', misp_lib_stix2.properties.ObjectReferenceProperty()), ], ) class NewObs(): @@ -418,9 +418,9 @@ class NewObs(): def test_custom_object_refs_property_containing_objectrefs(): with pytest.raises(ValueError, match=r"not a 'ListProperty' containing a subclass of 'ReferenceProperty"): - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x-new-obj-with-objrefs', [ - ('property_refs', stix2.properties.ListProperty(stix2.properties.ObjectReferenceProperty())), + ('property_refs', misp_lib_stix2.properties.ListProperty(misp_lib_stix2.properties.ObjectReferenceProperty())), ], ) class NewObs(): @@ -429,9 +429,9 @@ class NewObs(): def test_custom_object_invalid_ref_property(): with pytest.raises(ValueError) as excinfo: - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x-new-obj', [ - ('property_ref', stix2.properties.StringProperty()), + ('property_ref', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs(): @@ -441,9 +441,9 @@ class NewObs(): def test_custom_object_invalid_refs_property(): with pytest.raises(ValueError) as excinfo: - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x-new-obj', [ - ('property_refs', stix2.properties.StringProperty()), + ('property_refs', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs(): @@ -453,9 +453,9 @@ class NewObs(): def test_custom_object_invalid_refs_list_property(): with pytest.raises(ValueError) as excinfo: - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x-new-obj', [ - ('property_refs', stix2.properties.ListProperty(stix2.properties.StringProperty)), + ('property_refs', misp_lib_stix2.properties.ListProperty(misp_lib_stix2.properties.StringProperty)), ], ) class NewObs(): @@ -477,16 +477,16 @@ def test_custom_subobject_dict(): ], } - obj = stix2.parse(obj_dict, allow_custom=True) + obj = misp_lib_stix2.parse(obj_dict, allow_custom=True) assert obj["objects"][0]["x_foo"] == 123 assert obj.has_custom with pytest.raises(InvalidValueError): - stix2.parse(obj_dict, allow_custom=False) + misp_lib_stix2.parse(obj_dict, allow_custom=False) def test_custom_subobject_obj(): - ident = stix2.v20.Identity( + ident = misp_lib_stix2.v20.Identity( name="alice", identity_class=123, x_foo=123, allow_custom=True, ) @@ -496,12 +496,12 @@ def test_custom_subobject_obj(): "objects": [ident], } - obj = stix2.parse(obj_dict, allow_custom=True) + obj = misp_lib_stix2.parse(obj_dict, allow_custom=True) assert obj["objects"][0]["x_foo"] == 123 assert obj.has_custom with pytest.raises(InvalidValueError): - stix2.parse(obj_dict, allow_custom=False) + misp_lib_stix2.parse(obj_dict, allow_custom=False) def test_parse_custom_object_type(): @@ -511,7 +511,7 @@ def test_parse_custom_object_type(): "property1": "something" }""" - nt = stix2.parse(nt_string, version="2.0", allow_custom=True) + nt = misp_lib_stix2.parse(nt_string, version="2.0", allow_custom=True) assert nt["property1"] == 'something' @@ -522,8 +522,8 @@ def test_parse_unregistered_custom_object_type(): "property1": "something" }""" - with pytest.raises(stix2.exceptions.ParseError) as excinfo: - stix2.parse(nt_string, version="2.0") + with pytest.raises(misp_lib_stix2.exceptions.ParseError) as excinfo: + misp_lib_stix2.parse(nt_string, version="2.0") assert "Can't parse unknown object type" in str(excinfo.value) assert "use the CustomObject decorator." in str(excinfo.value) @@ -538,15 +538,15 @@ def test_parse_unregistered_custom_object_type_w_allow_custom(): "property1": "something" }""" - custom_obj = stix2.parse(nt_string, version="2.0", allow_custom=True) + custom_obj = misp_lib_stix2.parse(nt_string, version="2.0", allow_custom=True) assert custom_obj["type"] == "x-foobar-observable" -@stix2.v20.CustomObservable( +@misp_lib_stix2.v20.CustomObservable( 'x-new-observable', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), - ('x_property3', stix2.properties.BooleanProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), + ('x_property3', misp_lib_stix2.properties.BooleanProperty()), ], ) class NewObservable(): @@ -561,7 +561,7 @@ def test_custom_observable_object_1(): no = NewObservable( property1='something', extensions={ - 'archive-ext': stix2.v20.observables.ArchiveExt( + 'archive-ext': misp_lib_stix2.v20.observables.ArchiveExt( contains_refs=['file--e277603e-1060-5ad4-9937-c26c97f1ca68'], version='2.0', comment='for real', @@ -573,7 +573,7 @@ def test_custom_observable_object_1(): def test_custom_observable_object_2(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: NewObservable(property2=42) assert excinfo.value.properties == ['property1'] assert "No values for required properties" in str(excinfo.value) @@ -593,9 +593,9 @@ def test_custom_observable_raises_exception(): def test_custom_observable_object_no_init_1(): - @stix2.v20.CustomObservable( + @misp_lib_stix2.v20.CustomObservable( 'x-new-observable-1', [ - ('property1', stix2.properties.StringProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs(): @@ -606,9 +606,9 @@ class NewObs(): def test_custom_observable_object_no_init_2(): - @stix2.v20.CustomObservable( + @misp_lib_stix2.v20.CustomObservable( 'x-new-obs2', [ - ('property1', stix2.properties.StringProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs2(object): @@ -620,9 +620,9 @@ class NewObs2(object): def test_custom_observable_object_invalid_type_name(): with pytest.raises(ValueError) as excinfo: - @stix2.v20.CustomObservable( + @misp_lib_stix2.v20.CustomObservable( 'x', [ - ('property1', stix2.properties.StringProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs(object): @@ -630,9 +630,9 @@ class NewObs(object): assert "Invalid type name 'x':" in str(excinfo.value) with pytest.raises(ValueError) as excinfo: - @stix2.v20.CustomObservable( + @misp_lib_stix2.v20.CustomObservable( 'x_new_obs', [ - ('property1', stix2.properties.StringProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs2(object): @@ -642,9 +642,9 @@ class NewObs2(object): def test_custom_observable_object_ref_property_as_identifier(): with pytest.raises(ValueError, match=r"not a subclass of 'ObjectReferenceProperty"): - @stix2.v20.CustomObservable( + @misp_lib_stix2.v20.CustomObservable( 'x-new-obs-with-ref', [ - ('property_ref', stix2.properties.ReferenceProperty(invalid_types=[])), + ('property_ref', misp_lib_stix2.properties.ReferenceProperty(invalid_types=[])), ], ) class NewObs(): @@ -653,9 +653,9 @@ class NewObs(): def test_custom_observable_object_refs_property_containing_identifiers(): with pytest.raises(ValueError, match=r"not a 'ListProperty' containing a subclass of 'ObjectReferenceProperty"): - @stix2.v20.CustomObservable( + @misp_lib_stix2.v20.CustomObservable( 'x-new-obs-with-refs', [ - ('property_refs', stix2.properties.ListProperty(stix2.properties.ReferenceProperty(invalid_types=[]))), + ('property_refs', misp_lib_stix2.properties.ListProperty(misp_lib_stix2.properties.ReferenceProperty(invalid_types=[]))), ], ) class NewObs(): @@ -663,9 +663,9 @@ class NewObs(): def test_custom_observable_object_ref_property_as_objectref(): - @stix2.v20.CustomObservable( + @misp_lib_stix2.v20.CustomObservable( 'x-new-obs-with-objref', [ - ('property_ref', stix2.properties.ObjectReferenceProperty()), + ('property_ref', misp_lib_stix2.properties.ObjectReferenceProperty()), ], ) class NewObs(): @@ -673,9 +673,9 @@ class NewObs(): def test_custom_observable_object_refs_property_containing_objectrefs(): - @stix2.v20.CustomObservable( + @misp_lib_stix2.v20.CustomObservable( 'x-new-obs-with-objrefs', [ - ('property_refs', stix2.properties.ListProperty(stix2.properties.ObjectReferenceProperty())), + ('property_refs', misp_lib_stix2.properties.ListProperty(misp_lib_stix2.properties.ObjectReferenceProperty())), ], ) class NewObs(): @@ -684,9 +684,9 @@ class NewObs(): def test_custom_observable_object_invalid_ref_property(): with pytest.raises(ValueError) as excinfo: - @stix2.v20.CustomObservable( + @misp_lib_stix2.v20.CustomObservable( 'x-new-obs', [ - ('property_ref', stix2.properties.StringProperty()), + ('property_ref', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs(): @@ -696,9 +696,9 @@ class NewObs(): def test_custom_observable_object_invalid_refs_property(): with pytest.raises(ValueError) as excinfo: - @stix2.v20.CustomObservable( + @misp_lib_stix2.v20.CustomObservable( 'x-new-obs', [ - ('property_refs', stix2.properties.StringProperty()), + ('property_refs', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs(): @@ -708,9 +708,9 @@ class NewObs(): def test_custom_observable_object_invalid_refs_list_property(): with pytest.raises(ValueError) as excinfo: - @stix2.v20.CustomObservable( + @misp_lib_stix2.v20.CustomObservable( 'x-new-obs', [ - ('property_refs', stix2.properties.ListProperty(stix2.properties.StringProperty)), + ('property_refs', misp_lib_stix2.properties.ListProperty(misp_lib_stix2.properties.StringProperty)), ], ) class NewObs(): @@ -719,10 +719,10 @@ class NewObs(): def test_custom_observable_object_invalid_valid_refs(): - @stix2.v20.CustomObservable( + @misp_lib_stix2.v20.CustomObservable( 'x-new-obs', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property_ref', stix2.properties.ObjectReferenceProperty(valid_types='email-addr')), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property_ref', misp_lib_stix2.properties.ObjectReferenceProperty(valid_types='email-addr')), ], ) class NewObs(): @@ -740,7 +740,7 @@ class NewObs(): def test_custom_no_properties_raises_exception(): with pytest.raises(TypeError): - @stix2.v20.CustomObject('x-new-object-type') + @misp_lib_stix2.v20.CustomObject('x-new-object-type') class NewObject1(object): pass @@ -748,7 +748,7 @@ class NewObject1(object): def test_custom_wrong_properties_arg_raises_exception(): with pytest.raises(ValueError): - @stix2.v20.CustomObservable('x-new-object-type', (("prop", stix2.properties.BooleanProperty()))) + @misp_lib_stix2.v20.CustomObservable('x-new-object-type', (("prop", misp_lib_stix2.properties.BooleanProperty()))) class NewObject2(object): pass @@ -759,8 +759,8 @@ def test_parse_custom_observable_object(): "property1": "something" }""" - nt = stix2.parse_observable(nt_string, [], version='2.0') - assert isinstance(nt, stix2.base._STIXBase) + nt = misp_lib_stix2.parse_observable(nt_string, [], version='2.0') + assert isinstance(nt, misp_lib_stix2.base._STIXBase) assert nt.property1 == 'something' @@ -770,15 +770,15 @@ def test_parse_unregistered_custom_observable_object(): "property1": "something" }""" - with pytest.raises(stix2.exceptions.ParseError) as excinfo: - stix2.parse_observable(nt_string, version='2.0') + with pytest.raises(misp_lib_stix2.exceptions.ParseError) as excinfo: + misp_lib_stix2.parse_observable(nt_string, version='2.0') assert "Can't parse unknown observable type" in str(excinfo.value) - parsed_custom = stix2.parse_observable(nt_string, allow_custom=True, version='2.0') + parsed_custom = misp_lib_stix2.parse_observable(nt_string, allow_custom=True, version='2.0') assert parsed_custom['property1'] == 'something' with pytest.raises(AttributeError) as excinfo: assert parsed_custom.property1 == 'something' - assert not isinstance(parsed_custom, stix2.base._STIXBase) + assert not isinstance(parsed_custom, misp_lib_stix2.base._STIXBase) def test_parse_unregistered_custom_observable_object_with_no_type(): @@ -786,8 +786,8 @@ def test_parse_unregistered_custom_observable_object_with_no_type(): "property1": "something" }""" - with pytest.raises(stix2.exceptions.ParseError) as excinfo: - stix2.parse_observable(nt_string, allow_custom=True, version='2.0') + with pytest.raises(misp_lib_stix2.exceptions.ParseError) as excinfo: + misp_lib_stix2.parse_observable(nt_string, allow_custom=True, version='2.0') assert "Can't parse observable with no 'type' property" in str(excinfo.value) @@ -807,7 +807,7 @@ def test_parse_observed_data_with_custom_observable(): } } }""" - parsed = stix2.parse(input_str, version="2.0", allow_custom=True) + parsed = misp_lib_stix2.parse(input_str, version="2.0", allow_custom=True) assert parsed.objects['0']['property1'] == 'something' @@ -816,8 +816,8 @@ def test_parse_invalid_custom_observable_object(): "property1": "something" }""" - with pytest.raises(stix2.exceptions.ParseError) as excinfo: - stix2.parse_observable(nt_string, version='2.0') + with pytest.raises(misp_lib_stix2.exceptions.ParseError) as excinfo: + misp_lib_stix2.parse_observable(nt_string, version='2.0') assert "Can't parse observable with no 'type' property" in str(excinfo.value) @@ -839,7 +839,7 @@ def test_observable_custom_property(): def test_observable_custom_property_invalid(): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: NewObservable( property1='something', x_foo="bar", @@ -859,7 +859,7 @@ def test_observable_custom_property_allowed(): def test_observed_data_with_custom_observable_object(): no = NewObservable(property1='something') - ob_data = stix2.v20.ObservedData( + ob_data = misp_lib_stix2.v20.ObservedData( first_observed=FAKE_TIME, last_observed=FAKE_TIME, number_observed=1, @@ -869,10 +869,10 @@ def test_observed_data_with_custom_observable_object(): assert ob_data.objects['0'].property1 == 'something' -@stix2.v20.CustomExtension( +@misp_lib_stix2.v20.CustomExtension( 'x-new-ext', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewExtension(): @@ -894,7 +894,7 @@ def test_custom_extension(): ext = NewExtension(property1='something') assert ext.property1 == 'something' - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: NewExtension(property2=42) assert excinfo.value.properties == ['property1'] assert str(excinfo.value) == "No values for required properties for NewExtension: (property1)." @@ -908,7 +908,7 @@ def test_custom_extension_wrong_observable_type(): # NewExtension is an extension of DomainName, not File ext = NewExtension(property1='something') with pytest.raises(InvalidValueError) as excinfo: - stix2.v20.File( + misp_lib_stix2.v20.File( name="abc.txt", extensions={ "ntfs-ext": ext, @@ -931,9 +931,9 @@ def test_custom_extension_wrong_observable_type(): ], ) def test_custom_extension_with_list_and_dict_properties_observable_type(data): - @stix2.v20.CustomExtension( + @misp_lib_stix2.v20.CustomExtension( 'some-extension', [ - ('keys', stix2.properties.ListProperty(stix2.properties.DictionaryProperty, required=True)), + ('keys', misp_lib_stix2.properties.ListProperty(misp_lib_stix2.properties.DictionaryProperty, required=True)), ], ) class SomeCustomExtension: @@ -945,9 +945,9 @@ class SomeCustomExtension: def test_custom_extension_invalid_type_name(): with pytest.raises(ValueError) as excinfo: - @stix2.v20.CustomExtension( + @misp_lib_stix2.v20.CustomExtension( 'x', { - 'property1': stix2.properties.StringProperty(required=True), + 'property1': misp_lib_stix2.properties.StringProperty(required=True), }, ) class FooExtension(): @@ -955,9 +955,9 @@ class FooExtension(): assert "Invalid type name 'x':" in str(excinfo.value) with pytest.raises(ValueError) as excinfo: - @stix2.v20.CustomExtension( + @misp_lib_stix2.v20.CustomExtension( 'x_new_ext', { - 'property1': stix2.properties.StringProperty(required=True), + 'property1': misp_lib_stix2.properties.StringProperty(required=True), }, ) class BlaExtension(): @@ -967,29 +967,29 @@ class BlaExtension(): def test_custom_extension_no_properties(): with pytest.raises(ValueError): - @stix2.v20.CustomExtension('x-new-ext2', None) + @misp_lib_stix2.v20.CustomExtension('x-new-ext2', None) class BarExtension(): pass def test_custom_extension_empty_properties(): with pytest.raises(ValueError): - @stix2.v20.CustomExtension('x-new-ext2', []) + @misp_lib_stix2.v20.CustomExtension('x-new-ext2', []) class BarExtension(): pass def test_custom_extension_dict_properties(): with pytest.raises(ValueError): - @stix2.v20.CustomExtension('x-new-ext2', {}) + @misp_lib_stix2.v20.CustomExtension('x-new-ext2', {}) class BarExtension(): pass def test_custom_extension_no_init_1(): - @stix2.v20.CustomExtension( + @misp_lib_stix2.v20.CustomExtension( 'x-new-extension', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewExt(): @@ -1000,9 +1000,9 @@ class NewExt(): def test_custom_extension_no_init_2(): - @stix2.v20.CustomExtension( + @misp_lib_stix2.v20.CustomExtension( 'x-new-ext2', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewExt2(object): @@ -1024,7 +1024,7 @@ def test_parse_observable_with_custom_extension(): } }""" - parsed = stix2.parse_observable(input_str, version='2.0') + parsed = misp_lib_stix2.parse_observable(input_str, version='2.0') assert parsed.extensions['x-new-ext'].property2 == 12 @@ -1049,12 +1049,12 @@ def test_parse_observable_with_custom_extension_property(): } }""" - parsed = stix2.parse(input_str, version='2.0', allow_custom=True) + parsed = misp_lib_stix2.parse(input_str, version='2.0', allow_custom=True) assert parsed.has_custom assert parsed["objects"]["0"]["extensions"]["raster-image-ext"]["x-foo"] is False with pytest.raises(InvalidValueError): - stix2.parse(input_str, version="2.0", allow_custom=False) + misp_lib_stix2.parse(input_str, version="2.0", allow_custom=False) def test_custom_and_spec_extension_mix(): @@ -1063,7 +1063,7 @@ def test_custom_and_spec_extension_mix(): extension doesn't result in a completely uncleaned extensions property. """ - file_obs = stix2.v20.File( + file_obs = misp_lib_stix2.v20.File( name="my_file.dat", extensions={ "x-custom1": { @@ -1093,10 +1093,10 @@ def test_custom_and_spec_extension_mix(): # Both of these should have been converted to objects, not left as dicts. assert isinstance( - file_obs.extensions["raster-image-ext"], stix2.v20.RasterImageExt, + file_obs.extensions["raster-image-ext"], misp_lib_stix2.v20.RasterImageExt, ) assert isinstance( - file_obs.extensions["ntfs-ext"], stix2.v20.NTFSExt, + file_obs.extensions["ntfs-ext"], misp_lib_stix2.v20.NTFSExt, ) @@ -1128,12 +1128,12 @@ def test_custom_and_spec_extension_mix(): ) def test_parse_observable_with_unregistered_custom_extension(data): with pytest.raises(InvalidValueError) as excinfo: - stix2.parse_observable(data, version='2.0') + misp_lib_stix2.parse_observable(data, version='2.0') assert "Can't parse unknown extension type" in str(excinfo.value) - parsed_ob = stix2.parse_observable(data, allow_custom=True, version='2.0') + parsed_ob = misp_lib_stix2.parse_observable(data, allow_custom=True, version='2.0') assert parsed_ob['extensions']['x-foobar-ext']['property1'] == 'foo' - assert not isinstance(parsed_ob['extensions']['x-foobar-ext'], stix2.base._STIXBase) + assert not isinstance(parsed_ob['extensions']['x-foobar-ext'], misp_lib_stix2.base._STIXBase) def test_register_custom_object(): @@ -1142,12 +1142,12 @@ class CustomObject2(object): _type = 'awesome-object' with pytest.raises(ValueError): - stix2.registration._register_object(CustomObject2, version="2.0") + misp_lib_stix2.registration._register_object(CustomObject2, version="2.0") def test_extension_property_location(): - assert 'extensions' in stix2.v20.OBJ_MAP_OBSERVABLE['x-new-observable']._properties - assert 'extensions' not in stix2.v20.EXT_MAP['x-new-ext']._properties + assert 'extensions' in misp_lib_stix2.v20.OBJ_MAP_OBSERVABLE['x-new-observable']._properties + assert 'extensions' not in misp_lib_stix2.v20.EXT_MAP['x-new-ext']._properties @pytest.mark.parametrize( @@ -1167,9 +1167,9 @@ def test_extension_property_location(): ], ) def test_custom_object_nested_dictionary(data): - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x-example', [ - ('dictionary', stix2.properties.DictionaryProperty()), + ('dictionary', misp_lib_stix2.properties.DictionaryProperty()), ], ) class Example(object): @@ -1186,10 +1186,10 @@ def __init__(self, **kwargs): assert data == example.serialize(pretty=True) -@stix2.v20.CustomObject( +@misp_lib_stix2.v20.CustomObject( 'x-new-type-2', [ - ('property1', stix2.properties.StringProperty()), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewType2(object): @@ -1202,9 +1202,9 @@ def test_register_custom_object_with_version(): "id": "x-new-type-2--00000000-0000-4000-8000-000000000007", } - cust_obj_1 = stix2.parsing.dict_to_stix2(custom_obj_1, version='2.0') + cust_obj_1 = misp_lib_stix2.parsing.dict_to_stix2(custom_obj_1, version='2.0') - assert cust_obj_1.type in stix2.registry.STIX2_OBJ_MAPS['2.0']['objects'] + assert cust_obj_1.type in misp_lib_stix2.registry.STIX2_OBJ_MAPS['2.0']['objects'] # spec_version is not in STIX 2.0, and is required in 2.1, so this # suffices as a test for a STIX 2.0 object. assert "spec_version" not in cust_obj_1 @@ -1212,10 +1212,10 @@ def test_register_custom_object_with_version(): def test_register_duplicate_object_with_version(): with pytest.raises(DuplicateRegistrationError) as excinfo: - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x-new-type-2', [ - ('property1', stix2.properties.StringProperty()), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewType2(object): @@ -1223,9 +1223,9 @@ class NewType2(object): assert "cannot be registered again" in str(excinfo.value) -@stix2.v20.CustomObservable( +@misp_lib_stix2.v20.CustomObservable( 'x-new-observable-2', [ - ('property1', stix2.properties.StringProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), ], ) class NewObservable2(object): @@ -1235,14 +1235,14 @@ class NewObservable2(object): def test_register_observable_with_version(): custom_obs = NewObservable2(property1="Test Observable") - assert custom_obs.type in stix2.registry.STIX2_OBJ_MAPS['2.0']['observables'] + assert custom_obs.type in misp_lib_stix2.registry.STIX2_OBJ_MAPS['2.0']['observables'] def test_register_duplicate_observable_with_version(): with pytest.raises(DuplicateRegistrationError) as excinfo: - @stix2.v20.CustomObservable( + @misp_lib_stix2.v20.CustomObservable( 'x-new-observable-2', [ - ('property1', stix2.properties.StringProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), ], ) class NewObservable2(object): @@ -1251,22 +1251,22 @@ class NewObservable2(object): def test_register_marking_with_version(): - @stix2.v20.CustomMarking( + @misp_lib_stix2.v20.CustomMarking( 'x-new-obj-2', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj2(): pass no = NewObj2(property1='something') - assert no._type in stix2.registry.STIX2_OBJ_MAPS['2.0']['markings'] + assert no._type in misp_lib_stix2.registry.STIX2_OBJ_MAPS['2.0']['markings'] def test_register_observable_extension_with_version(): - @stix2.v20.CustomExtension( + @misp_lib_stix2.v20.CustomExtension( 'some-extension-2', [ - ('keys', stix2.properties.StringProperty(required=True)), + ('keys', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class SomeCustomExtension2: @@ -1274,15 +1274,15 @@ class SomeCustomExtension2: example = SomeCustomExtension2(keys='test123') - assert example._type in stix2.registry.STIX2_OBJ_MAPS['2.0']['extensions'] + assert example._type in misp_lib_stix2.registry.STIX2_OBJ_MAPS['2.0']['extensions'] def test_register_duplicate_observable_extension(): with pytest.raises(DuplicateRegistrationError) as excinfo: - @stix2.v20.CustomExtension( + @misp_lib_stix2.v20.CustomExtension( 'some-extension-2', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewExtension2(): diff --git a/stix2/test/v21/test_datastore.py b/misp_lib_stix2/test/v20/test_datastore.py similarity index 98% rename from stix2/test/v21/test_datastore.py rename to misp_lib_stix2/test/v20/test_datastore.py index 8bb5494c..a0238a5a 100644 --- a/stix2/test/v21/test_datastore.py +++ b/misp_lib_stix2/test/v20/test_datastore.py @@ -1,9 +1,9 @@ import pytest -from stix2.datastore import ( +from misp_lib_stix2.datastore import ( CompositeDataSource, DataSink, DataSource, DataStoreMixin, ) -from stix2.datastore.filters import Filter +from misp_lib_stix2.datastore.filters import Filter from .constants import CAMPAIGN_MORE_KWARGS diff --git a/stix2/test/v20/test_datastore_composite.py b/misp_lib_stix2/test/v20/test_datastore_composite.py similarity index 93% rename from stix2/test/v20/test_datastore_composite.py rename to misp_lib_stix2/test/v20/test_datastore_composite.py index 640458d8..ed8793f7 100644 --- a/stix2/test/v20/test_datastore_composite.py +++ b/misp_lib_stix2/test/v20/test_datastore_composite.py @@ -1,10 +1,10 @@ import pytest -from stix2.datastore import CompositeDataSource, make_id -from stix2.datastore.filters import Filter -from stix2.datastore.memory import MemorySink, MemorySource, MemoryStore -from stix2.utils import parse_into_datetime -from stix2.v20.common import TLP_GREEN +from misp_lib_stix2.datastore import CompositeDataSource, make_id +from misp_lib_stix2.datastore.filters import Filter +from misp_lib_stix2.datastore.memory import MemorySink, MemorySource, MemoryStore +from misp_lib_stix2.utils import parse_into_datetime +from misp_lib_stix2.v20.common import TLP_GREEN def test_add_remove_composite_datasource(): diff --git a/stix2/test/v20/test_datastore_filesystem.py b/misp_lib_stix2/test/v20/test_datastore_filesystem.py similarity index 87% rename from stix2/test/v20/test_datastore_filesystem.py rename to misp_lib_stix2/test/v20/test_datastore_filesystem.py index 7ce3ecf0..dfb190a6 100644 --- a/stix2/test/v20/test_datastore_filesystem.py +++ b/misp_lib_stix2/test/v20/test_datastore_filesystem.py @@ -8,13 +8,13 @@ import pytest import pytz -import stix2 -from stix2.datastore import DataSourceError -from stix2.datastore.filesystem import ( +import misp_lib_stix2 +from misp_lib_stix2.datastore import DataSourceError +from misp_lib_stix2.datastore.filesystem import ( AuthSet, _find_search_optimizations, _get_matching_dir_entries, _timestamp2filename, ) -from stix2.exceptions import STIXError +from misp_lib_stix2.exceptions import STIXError from .constants import ( CAMPAIGN_ID, CAMPAIGN_KWARGS, IDENTITY_ID, IDENTITY_KWARGS, INDICATOR_ID, @@ -27,7 +27,7 @@ @pytest.fixture def fs_store(): # create - yield stix2.FileSystemStore(FS_PATH) + yield misp_lib_stix2.FileSystemStore(FS_PATH) # remove campaign dir shutil.rmtree(os.path.join(FS_PATH, "campaign"), True) @@ -36,7 +36,7 @@ def fs_store(): @pytest.fixture def fs_source(): # create - fs = stix2.FileSystemSource(FS_PATH) + fs = misp_lib_stix2.FileSystemSource(FS_PATH) assert fs.stix_dir == FS_PATH yield fs @@ -47,7 +47,7 @@ def fs_source(): @pytest.fixture def fs_sink(): # create - fs = stix2.FileSystemSink(FS_PATH) + fs = misp_lib_stix2.FileSystemSink(FS_PATH) assert fs.stix_dir == FS_PATH yield fs @@ -92,15 +92,15 @@ def bad_stix_files(): @pytest.fixture(scope='module') def rel_fs_store(): - cam = stix2.v20.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) - idy = stix2.v20.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) - ind = stix2.v20.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) - mal = stix2.v20.Malware(id=MALWARE_ID, **MALWARE_KWARGS) - rel1 = stix2.v20.Relationship(ind, 'indicates', mal, id=RELATIONSHIP_IDS[0]) - rel2 = stix2.v20.Relationship(mal, 'targets', idy, id=RELATIONSHIP_IDS[1]) - rel3 = stix2.v20.Relationship(cam, 'uses', mal, id=RELATIONSHIP_IDS[2]) + cam = misp_lib_stix2.v20.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) + idy = misp_lib_stix2.v20.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) + ind = misp_lib_stix2.v20.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) + mal = misp_lib_stix2.v20.Malware(id=MALWARE_ID, **MALWARE_KWARGS) + rel1 = misp_lib_stix2.v20.Relationship(ind, 'indicates', mal, id=RELATIONSHIP_IDS[0]) + rel2 = misp_lib_stix2.v20.Relationship(mal, 'targets', idy, id=RELATIONSHIP_IDS[1]) + rel3 = misp_lib_stix2.v20.Relationship(cam, 'uses', mal, id=RELATIONSHIP_IDS[2]) stix_objs = [cam, idy, ind, mal, rel1, rel2, rel3] - fs = stix2.FileSystemStore(FS_PATH) + fs = misp_lib_stix2.FileSystemStore(FS_PATH) for o in stix_objs: fs.add(o) yield fs @@ -126,12 +126,12 @@ def rel_fs_store(): def test_filesystem_source_nonexistent_folder(): with pytest.raises(ValueError): - stix2.FileSystemSource('nonexistent-folder') + misp_lib_stix2.FileSystemSource('nonexistent-folder') def test_filesystem_sink_nonexistent_folder(): with pytest.raises(ValueError): - stix2.FileSystemSink('nonexistent-folder') + misp_lib_stix2.FileSystemSink('nonexistent-folder') def test_filesystem_source_bad_json_file(fs_source, bad_json_files): @@ -184,7 +184,7 @@ def test_filesystem_source_all_versions(fs_source): def test_filesystem_source_query_single(fs_source): # query2 - is_2 = fs_source.query([stix2.Filter("external_references.external_id", '=', "T1027")]) + is_2 = fs_source.query([misp_lib_stix2.Filter("external_references.external_id", '=', "T1027")]) assert len(is_2) == 1 is_2 = is_2[0] @@ -194,7 +194,7 @@ def test_filesystem_source_query_single(fs_source): def test_filesystem_source_query_multiple(fs_source): # query - intrusion_sets = fs_source.query([stix2.Filter("type", '=', "intrusion-set")]) + intrusion_sets = fs_source.query([misp_lib_stix2.Filter("type", '=', "intrusion-set")]) assert len(intrusion_sets) == 2 assert "intrusion-set--a653431d-6a5e-4600-8ad3-609b5af57064" in [is_.id for is_ in intrusion_sets] assert "intrusion-set--f3bdec95-3d62-42d9-a840-29630f6cdc1a" in [is_.id for is_ in intrusion_sets] @@ -209,9 +209,9 @@ def test_filesystem_source_backward_compatible(fs_source): # it. modified = datetime.datetime(2018, 11, 16, 22, 54, 20, 390000, pytz.utc) results = fs_source.query([ - stix2.Filter("type", "=", "malware"), - stix2.Filter("id", "=", "malware--6b616fc1-1505-48e3-8b2c-0d19337bff38"), - stix2.Filter("modified", "=", modified), + misp_lib_stix2.Filter("type", "=", "malware"), + misp_lib_stix2.Filter("id", "=", "malware--6b616fc1-1505-48e3-8b2c-0d19337bff38"), + misp_lib_stix2.Filter("modified", "=", modified), ]) assert len(results) == 1 @@ -224,7 +224,7 @@ def test_filesystem_source_backward_compatible(fs_source): def test_filesystem_sink_add_python_stix_object(fs_sink, fs_source): # add python stix object - camp1 = stix2.v20.Campaign( + camp1 = misp_lib_stix2.v20.Campaign( name="Hannibal", objective="Targeting Italian and Spanish Diplomat internet accounts", aliases=["War Elephant"], @@ -266,7 +266,7 @@ def test_filesystem_sink_add_stix_object_dict(fs_sink, fs_source): # as what's in the dict, since the parsing process can enforce a precision # constraint (e.g. truncate to milliseconds), which results in a slightly # different name. - camp2obj = stix2.parse(camp2) + camp2obj = misp_lib_stix2.parse(camp2) filepath = os.path.join( FS_PATH, "campaign", camp2obj["id"], _timestamp2filename(camp2obj["modified"]) + ".json", @@ -303,7 +303,7 @@ def test_filesystem_sink_add_stix_bundle_dict(fs_sink, fs_source): fs_sink.add(bund) - camp_obj = stix2.parse(bund["objects"][0]) + camp_obj = misp_lib_stix2.parse(bund["objects"][0]) filepath = os.path.join( FS_PATH, "campaign", camp_obj["id"], _timestamp2filename(camp_obj["modified"]) + ".json", @@ -328,7 +328,7 @@ def test_filesystem_sink_add_json_stix_object(fs_sink, fs_source): fs_sink.add(camp4) - camp4obj = stix2.parse(camp4) + camp4obj = misp_lib_stix2.parse(camp4) filepath = os.path.join( FS_PATH, "campaign", "campaign--6a6ca372-ba07-42cc-81ef-9840fc1f963d", @@ -353,7 +353,7 @@ def test_filesystem_sink_json_stix_bundle(fs_sink, fs_source): ' "name": "Spartacus", "objective": "Oppressive regimes of Africa and Middle East"}]}' fs_sink.add(bund2) - bund2obj = stix2.parse(bund2) + bund2obj = misp_lib_stix2.parse(bund2) camp_obj = bund2obj["objects"][0] filepath = os.path.join( @@ -373,7 +373,7 @@ def test_filesystem_sink_json_stix_bundle(fs_sink, fs_source): def test_filesystem_sink_add_objects_list(fs_sink, fs_source): # add list of objects - camp6 = stix2.v20.Campaign( + camp6 = misp_lib_stix2.v20.Campaign( name="Comanche", objective="US Midwest manufacturing firms, oil refineries, and businesses", aliases=["Horse Warrior"], @@ -391,7 +391,7 @@ def test_filesystem_sink_add_objects_list(fs_sink, fs_source): fs_sink.add([camp6, camp7]) - camp7obj = stix2.parse(camp7) + camp7obj = misp_lib_stix2.parse(camp7) camp6filepath = os.path.join( FS_PATH, "campaign", camp6.id, @@ -421,7 +421,7 @@ def test_filesystem_sink_add_objects_list(fs_sink, fs_source): def test_filesystem_attempt_stix_file_overwrite(fs_store): # add python stix object - camp8 = stix2.v20.Campaign( + camp8 = misp_lib_stix2.v20.Campaign( name="George Washington", objective="Create an awesome country", aliases=["Georgey"], @@ -446,11 +446,11 @@ def test_filesystem_attempt_stix_file_overwrite(fs_store): def test_filesystem_sink_marking(fs_sink): - marking = stix2.v20.MarkingDefinition( + marking = misp_lib_stix2.v20.MarkingDefinition( id="marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da", created="2017-01-20T00:00:00.000Z", definition_type="tlp", - definition=stix2.v20.TLPMarking(tlp="green"), + definition=misp_lib_stix2.v20.TLPMarking(tlp="green"), ) fs_sink.add(marking) @@ -485,14 +485,14 @@ def test_filesystem_store_all_versions(fs_store): def test_filesystem_store_query(fs_store): # query() - tools = fs_store.query([stix2.Filter("labels", "in", "tool")]) + tools = fs_store.query([misp_lib_stix2.Filter("labels", "in", "tool")]) assert len(tools) == 2 assert "tool--242f3da3-4425-4d11-8f5c-b842886da966" in [tool.id for tool in tools] assert "tool--03342581-f790-4f03-ba41-e82e67392e23" in [tool.id for tool in tools] def test_filesystem_store_query_single_filter(fs_store): - query = stix2.Filter("labels", "in", "tool") + query = misp_lib_stix2.Filter("labels", "in", "tool") tools = fs_store.query(query) assert len(tools) == 2 assert "tool--242f3da3-4425-4d11-8f5c-b842886da966" in [tool.id for tool in tools] @@ -507,20 +507,20 @@ def test_filesystem_store_empty_query(fs_store): def test_filesystem_store_query_multiple_filters(fs_store): - fs_store.source.filters.add(stix2.Filter("labels", "in", "tool")) - tools = fs_store.query(stix2.Filter("id", "=", "tool--242f3da3-4425-4d11-8f5c-b842886da966")) + fs_store.source.filters.add(misp_lib_stix2.Filter("labels", "in", "tool")) + tools = fs_store.query(misp_lib_stix2.Filter("id", "=", "tool--242f3da3-4425-4d11-8f5c-b842886da966")) assert len(tools) == 1 assert tools[0].id == "tool--242f3da3-4425-4d11-8f5c-b842886da966" def test_filesystem_store_query_dont_include_type_folder(fs_store): - results = fs_store.query(stix2.Filter("type", "!=", "tool")) + results = fs_store.query(misp_lib_stix2.Filter("type", "!=", "tool")) assert len(results) == 28 def test_filesystem_store_add(fs_store): # add() - camp1 = stix2.v20.Campaign( + camp1 = misp_lib_stix2.v20.Campaign( name="Great Heathen Army", objective="Targeting the government of United Kingdom and insitutions affiliated with the Church Of England", aliases=["Ragnar"], @@ -541,9 +541,9 @@ def test_filesystem_store_add(fs_store): def test_filesystem_store_add_as_bundle(): - fs_store = stix2.FileSystemStore(FS_PATH, bundlify=True) + fs_store = misp_lib_stix2.FileSystemStore(FS_PATH, bundlify=True) - camp1 = stix2.v20.Campaign( + camp1 = misp_lib_stix2.v20.Campaign( name="Great Heathen Army", objective="Targeting the government of United Kingdom and insitutions affiliated with the Church Of England", aliases=["Ragnar"], @@ -566,7 +566,7 @@ def test_filesystem_store_add_as_bundle(): def test_filesystem_add_bundle_object(fs_store): - bundle = stix2.v20.Bundle() + bundle = misp_lib_stix2.v20.Bundle() fs_store.add(bundle) @@ -581,11 +581,11 @@ def test_filesystem_store_add_invalid_object(fs_store): def test_filesystem_store_add_marking(fs_store): - marking = stix2.v20.MarkingDefinition( + marking = misp_lib_stix2.v20.MarkingDefinition( id="marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da", created="2017-01-20T00:00:00.000Z", definition_type="tlp", - definition=stix2.v20.TLPMarking(tlp="green"), + definition=misp_lib_stix2.v20.TLPMarking(tlp="green"), ) fs_store.add(marking) @@ -603,7 +603,7 @@ def test_filesystem_store_add_marking(fs_store): def test_filesystem_object_with_custom_property(fs_store): - camp = stix2.v20.Campaign( + camp = misp_lib_stix2.v20.Campaign( name="Scipio Africanus", objective="Defeat the Carthaginians", x_empire="Roman", @@ -618,14 +618,14 @@ def test_filesystem_object_with_custom_property(fs_store): def test_filesystem_object_with_custom_property_in_bundle(fs_store): - camp = stix2.v20.Campaign( + camp = misp_lib_stix2.v20.Campaign( name="Scipio Africanus", objective="Defeat the Carthaginians", x_empire="Roman", allow_custom=True, ) - bundle = stix2.v20.Bundle(camp, allow_custom=True) + bundle = misp_lib_stix2.v20.Bundle(camp, allow_custom=True) fs_store.add(bundle) camp_r = fs_store.get(camp.id) @@ -654,9 +654,9 @@ def test_filesystem_custom_object_dict(fs_store): def test_filesystem_custom_object(fs_store): - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x-new-obj-2', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj(): @@ -775,7 +775,7 @@ def test_auth_set_black1(): def test_optimize_types1(): filters = [ - stix2.Filter("type", "=", "foo"), + misp_lib_stix2.Filter("type", "=", "foo"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -788,8 +788,8 @@ def test_optimize_types1(): def test_optimize_types2(): filters = [ - stix2.Filter("type", "=", "foo"), - stix2.Filter("type", "=", "bar"), + misp_lib_stix2.Filter("type", "=", "foo"), + misp_lib_stix2.Filter("type", "=", "bar"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -802,8 +802,8 @@ def test_optimize_types2(): def test_optimize_types3(): filters = [ - stix2.Filter("type", "in", ["A", "B", "C"]), - stix2.Filter("type", "in", ["B", "C", "D"]), + misp_lib_stix2.Filter("type", "in", ["A", "B", "C"]), + misp_lib_stix2.Filter("type", "in", ["B", "C", "D"]), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -816,8 +816,8 @@ def test_optimize_types3(): def test_optimize_types4(): filters = [ - stix2.Filter("type", "in", ["A", "B", "C"]), - stix2.Filter("type", "in", ["D", "E", "F"]), + misp_lib_stix2.Filter("type", "in", ["A", "B", "C"]), + misp_lib_stix2.Filter("type", "in", ["D", "E", "F"]), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -830,8 +830,8 @@ def test_optimize_types4(): def test_optimize_types5(): filters = [ - stix2.Filter("type", "in", ["foo", "bar"]), - stix2.Filter("type", "!=", "bar"), + misp_lib_stix2.Filter("type", "in", ["foo", "bar"]), + misp_lib_stix2.Filter("type", "!=", "bar"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -844,8 +844,8 @@ def test_optimize_types5(): def test_optimize_types6(): filters = [ - stix2.Filter("type", "!=", "foo"), - stix2.Filter("type", "!=", "bar"), + misp_lib_stix2.Filter("type", "!=", "foo"), + misp_lib_stix2.Filter("type", "!=", "bar"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -858,8 +858,8 @@ def test_optimize_types6(): def test_optimize_types7(): filters = [ - stix2.Filter("type", "=", "foo"), - stix2.Filter("type", "!=", "foo"), + misp_lib_stix2.Filter("type", "=", "foo"), + misp_lib_stix2.Filter("type", "!=", "foo"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -883,8 +883,8 @@ def test_optimize_types8(): def test_optimize_types_ids1(): filters = [ - stix2.Filter("type", "in", ["foo", "bar"]), - stix2.Filter("id", "=", "foo--00000000-0000-0000-0000-000000000000"), + misp_lib_stix2.Filter("type", "in", ["foo", "bar"]), + misp_lib_stix2.Filter("id", "=", "foo--00000000-0000-0000-0000-000000000000"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -897,8 +897,8 @@ def test_optimize_types_ids1(): def test_optimize_types_ids2(): filters = [ - stix2.Filter("type", "=", "foo"), - stix2.Filter("id", "=", "bar--00000000-0000-0000-0000-000000000000"), + misp_lib_stix2.Filter("type", "=", "foo"), + misp_lib_stix2.Filter("id", "=", "bar--00000000-0000-0000-0000-000000000000"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -911,8 +911,8 @@ def test_optimize_types_ids2(): def test_optimize_types_ids3(): filters = [ - stix2.Filter("type", "in", ["foo", "bar"]), - stix2.Filter("id", "!=", "bar--00000000-0000-0000-0000-000000000000"), + misp_lib_stix2.Filter("type", "in", ["foo", "bar"]), + misp_lib_stix2.Filter("id", "!=", "bar--00000000-0000-0000-0000-000000000000"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -925,8 +925,8 @@ def test_optimize_types_ids3(): def test_optimize_types_ids4(): filters = [ - stix2.Filter("type", "in", ["A", "B", "C"]), - stix2.Filter( + misp_lib_stix2.Filter("type", "in", ["A", "B", "C"]), + misp_lib_stix2.Filter( "id", "in", [ "B--00000000-0000-0000-0000-000000000000", "C--00000000-0000-0000-0000-000000000000", @@ -948,16 +948,16 @@ def test_optimize_types_ids4(): def test_optimize_types_ids5(): filters = [ - stix2.Filter("type", "in", ["A", "B", "C"]), - stix2.Filter("type", "!=", "C"), - stix2.Filter( + misp_lib_stix2.Filter("type", "in", ["A", "B", "C"]), + misp_lib_stix2.Filter("type", "!=", "C"), + misp_lib_stix2.Filter( "id", "in", [ "B--00000000-0000-0000-0000-000000000000", "C--00000000-0000-0000-0000-000000000000", "D--00000000-0000-0000-0000-000000000000", ], ), - stix2.Filter("id", "!=", "D--00000000-0000-0000-0000-000000000000"), + misp_lib_stix2.Filter("id", "!=", "D--00000000-0000-0000-0000-000000000000"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -970,7 +970,7 @@ def test_optimize_types_ids5(): def test_optimize_types_ids6(): filters = [ - stix2.Filter("id", "=", "A--00000000-0000-0000-0000-000000000000"), + misp_lib_stix2.Filter("id", "=", "A--00000000-0000-0000-0000-000000000000"), ] auth_types, auth_ids = _find_search_optimizations(filters) diff --git a/stix2/test/v20/test_datastore_filters.py b/misp_lib_stix2/test/v20/test_datastore_filters.py similarity index 99% rename from stix2/test/v20/test_datastore_filters.py rename to misp_lib_stix2/test/v20/test_datastore_filters.py index bcbd08f5..7563396c 100644 --- a/stix2/test/v20/test_datastore_filters.py +++ b/misp_lib_stix2/test/v20/test_datastore_filters.py @@ -1,8 +1,8 @@ import pytest -from stix2 import parse -from stix2.datastore.filters import Filter, apply_common_filters -from stix2.utils import STIXdatetime, parse_into_datetime +from misp_lib_stix2 import parse +from misp_lib_stix2.datastore.filters import Filter, apply_common_filters +from misp_lib_stix2.utils import STIXdatetime, parse_into_datetime stix_objs = [ { diff --git a/stix2/test/v20/test_datastore_memory.py b/misp_lib_stix2/test/v20/test_datastore_memory.py similarity index 98% rename from stix2/test/v20/test_datastore_memory.py rename to misp_lib_stix2/test/v20/test_datastore_memory.py index 23b39668..7a9fd15d 100644 --- a/stix2/test/v20/test_datastore_memory.py +++ b/misp_lib_stix2/test/v20/test_datastore_memory.py @@ -3,10 +3,10 @@ import pytest -from stix2 import Filter, MemorySource, MemoryStore, properties -from stix2.datastore import make_id -from stix2.utils import parse_into_datetime -from stix2.v20 import ( +from misp_lib_stix2 import Filter, MemorySource, MemoryStore, properties +from misp_lib_stix2.datastore import make_id +from misp_lib_stix2.utils import parse_into_datetime +from misp_lib_stix2.v20 import ( Bundle, Campaign, CustomObject, Identity, Indicator, Malware, Relationship, ) diff --git a/stix2/test/v20/test_datastore_taxii.py b/misp_lib_stix2/test/v20/test_datastore_taxii.py similarity index 86% rename from stix2/test/v20/test_datastore_taxii.py rename to misp_lib_stix2/test/v20/test_datastore_taxii.py index 075f0a3d..10715790 100644 --- a/stix2/test/v20/test_datastore_taxii.py +++ b/misp_lib_stix2/test/v20/test_datastore_taxii.py @@ -6,10 +6,10 @@ from taxii2client.common import _filter_kwargs_to_query_params from taxii2client.v20 import MEDIA_TYPE_STIX_V20, Collection -import stix2 -from stix2.datastore import DataSourceError -from stix2.datastore.filters import Filter -from stix2.utils import get_timestamp +import misp_lib_stix2 +from misp_lib_stix2.datastore import DataSourceError +from misp_lib_stix2.datastore.filters import Filter +from misp_lib_stix2.utils import get_timestamp COLLECTION_URL = 'https://example.com/api1/collections/91a7b528-80eb-42ed-a74d-c6fbd5a26116/' @@ -55,7 +55,7 @@ def get_objects(self, accept=MEDIA_TYPE_STIX_V20, start=0, per_request=0, **filt resp.status_code = 200 resp.headers["Content-Range"] = f"items 0-{len(objs)}/{len(objs)}" resp.encoding = "utf-8" - resp._content = bytes(stix2.v20.Bundle(objects=objs).serialize(ensure_ascii=False), resp.encoding) + resp._content = bytes(misp_lib_stix2.v20.Bundle(objects=objs).serialize(ensure_ascii=False), resp.encoding) return resp else: resp = Response() @@ -80,7 +80,7 @@ def get_object(self, id, **filter_kwargs): else: filtered_objects = [] if filtered_objects: - return stix2.v20.Bundle(objects=filtered_objects) + return misp_lib_stix2.v20.Bundle(objects=filtered_objects) else: resp = Response() resp.status_code = 404 @@ -128,15 +128,15 @@ def collection_no_rw_access(stix_objs1, stix_objs1_manifests): def test_ds_taxii(collection): - ds = stix2.TAXIICollectionSource(collection) + ds = misp_lib_stix2.TAXIICollectionSource(collection) assert ds.collection is not None def test_add_stix2_object(collection): - tc_sink = stix2.TAXIICollectionSink(collection) + tc_sink = misp_lib_stix2.TAXIICollectionSink(collection) # create new STIX threat-actor - ta = stix2.v20.ThreatActor( + ta = misp_lib_stix2.v20.ThreatActor( name="Teddy Bear", labels=["nation-state"], sophistication="innovator", @@ -151,10 +151,10 @@ def test_add_stix2_object(collection): def test_add_stix2_with_custom_object(collection): - tc_sink = stix2.TAXIICollectionStore(collection, allow_custom=True) + tc_sink = misp_lib_stix2.TAXIICollectionStore(collection, allow_custom=True) # create new STIX threat-actor - ta = stix2.v20.ThreatActor( + ta = misp_lib_stix2.v20.ThreatActor( name="Teddy Bear", labels=["nation-state"], sophistication="innovator", @@ -171,10 +171,10 @@ def test_add_stix2_with_custom_object(collection): def test_add_list_object(collection, indicator): - tc_sink = stix2.TAXIICollectionSink(collection) + tc_sink = misp_lib_stix2.TAXIICollectionSink(collection) # create new STIX threat-actor - ta = stix2.v20.ThreatActor( + ta = misp_lib_stix2.v20.ThreatActor( name="Teddy Bear", labels=["nation-state"], sophistication="innovator", @@ -189,24 +189,24 @@ def test_add_list_object(collection, indicator): def test_get_object_found(collection): - tc_source = stix2.TAXIICollectionSource(collection) + tc_source = misp_lib_stix2.TAXIICollectionSource(collection) result = tc_source.query([ - stix2.Filter("id", "=", "indicator--00000000-0000-4000-8000-000000000001"), + misp_lib_stix2.Filter("id", "=", "indicator--00000000-0000-4000-8000-000000000001"), ]) assert result def test_get_object_not_found(collection): - tc_source = stix2.TAXIICollectionSource(collection) + tc_source = misp_lib_stix2.TAXIICollectionSource(collection) result = tc_source.get("indicator--00000000-0000-4000-8000-000000000005") assert result is None def test_add_stix2_bundle_object(collection): - tc_sink = stix2.TAXIICollectionSink(collection) + tc_sink = misp_lib_stix2.TAXIICollectionSink(collection) # create new STIX threat-actor - ta = stix2.v20.ThreatActor( + ta = misp_lib_stix2.v20.ThreatActor( name="Teddy Bear", labels=["nation-state"], sophistication="innovator", @@ -217,11 +217,11 @@ def test_add_stix2_bundle_object(collection): ], ) - tc_sink.add(stix2.v20.Bundle(objects=[ta])) + tc_sink.add(misp_lib_stix2.v20.Bundle(objects=[ta])) def test_add_str_object(collection): - tc_sink = stix2.TAXIICollectionSink(collection) + tc_sink = misp_lib_stix2.TAXIICollectionSink(collection) # create new STIX threat-actor ta = """{ @@ -245,7 +245,7 @@ def test_add_str_object(collection): def test_add_dict_object(collection): - tc_sink = stix2.TAXIICollectionSink(collection) + tc_sink = misp_lib_stix2.TAXIICollectionSink(collection) ta = { "type": "threat-actor", @@ -268,7 +268,7 @@ def test_add_dict_object(collection): def test_add_dict_bundle_object(collection): - tc_sink = stix2.TAXIICollectionSink(collection) + tc_sink = misp_lib_stix2.TAXIICollectionSink(collection) ta = { "type": "bundle", @@ -297,7 +297,7 @@ def test_add_dict_bundle_object(collection): def test_get_stix2_object(collection): - tc_sink = stix2.TAXIICollectionSource(collection) + tc_sink = misp_lib_stix2.TAXIICollectionSource(collection) objects = tc_sink.get("indicator--00000000-0000-4000-8000-000000000001") @@ -320,7 +320,7 @@ def test_parse_taxii_filters(collection): Filter("version", "=", "first"), ] - ds = stix2.TAXIICollectionSource(collection) + ds = misp_lib_stix2.TAXIICollectionSource(collection) taxii_filters = ds._parse_taxii_filters(query) @@ -328,7 +328,7 @@ def test_parse_taxii_filters(collection): def test_add_get_remove_filter(collection): - ds = stix2.TAXIICollectionSource(collection) + ds = misp_lib_stix2.TAXIICollectionSource(collection) # First 3 filters are valid, remaining properties are erroneous in some way valid_filters = [ @@ -364,7 +364,7 @@ def test_add_get_remove_filter(collection): def test_get_all_versions(collection): - ds = stix2.TAXIICollectionStore(collection) + ds = misp_lib_stix2.TAXIICollectionStore(collection) indicators = ds.all_versions('indicator--00000000-0000-4000-8000-000000000001') # There are 3 indicators but 2 share the same 'modified' timestamp @@ -376,7 +376,7 @@ def test_can_read_error(collection_no_rw_access): instance that does not have read access, check ValueError exception is raised""" with pytest.raises(DataSourceError) as excinfo: - stix2.TAXIICollectionSource(collection_no_rw_access) + misp_lib_stix2.TAXIICollectionSource(collection_no_rw_access) assert "Collection object provided does not have read access" in str(excinfo.value) @@ -385,7 +385,7 @@ def test_can_write_error(collection_no_rw_access): instance that does not have write access, check ValueError exception is raised""" with pytest.raises(DataSourceError) as excinfo: - stix2.TAXIICollectionSink(collection_no_rw_access) + misp_lib_stix2.TAXIICollectionSink(collection_no_rw_access) assert "Collection object provided does not have write access" in str(excinfo.value) @@ -406,7 +406,7 @@ def get_object(self, id, version=None): resp.status_code = 404 resp.raise_for_status() - ds = stix2.TAXIICollectionSource(TAXIICollection404()) + ds = misp_lib_stix2.TAXIICollectionSource(TAXIICollection404()) # this will raise 404 from mock TAXII Client but TAXIICollectionStore # should handle gracefully and return None @@ -418,7 +418,7 @@ def test_all_versions_404(collection): """ a TAXIICollectionSource.all_version() call that recieves an HTTP 404 response code from the taxii2client should be returned as an exception""" - ds = stix2.TAXIICollectionStore(collection) + ds = misp_lib_stix2.TAXIICollectionStore(collection) with pytest.raises(DataSourceError) as excinfo: ds.all_versions("indicator--1") @@ -430,7 +430,7 @@ def test_query_404(collection): """ a TAXIICollectionSource.query() call that recieves an HTTP 404 response code from the taxii2client should be returned as an exception""" - ds = stix2.TAXIICollectionStore(collection) + ds = misp_lib_stix2.TAXIICollectionStore(collection) query = [Filter("type", "=", "malware")] with pytest.raises(DataSourceError) as excinfo: diff --git a/stix2/test/v20/test_environment.py b/misp_lib_stix2/test/v20/test_environment.py similarity index 64% rename from stix2/test/v20/test_environment.py rename to misp_lib_stix2/test/v20/test_environment.py index c8867b01..3952fbc3 100644 --- a/stix2/test/v20/test_environment.py +++ b/misp_lib_stix2/test/v20/test_environment.py @@ -3,9 +3,9 @@ import pytest -import stix2 -import stix2.equivalence.graph -import stix2.equivalence.object +import misp_lib_stix2 +import misp_lib_stix2.equivalence.graph +import misp_lib_stix2.equivalence.object from .constants import ( CAMPAIGN_ID, CAMPAIGN_KWARGS, FAKE_TIME, IDENTITY_ID, IDENTITY_KWARGS, @@ -18,46 +18,46 @@ @pytest.fixture def ds(): - cam = stix2.v20.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) - idy = stix2.v20.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) - ind = stix2.v20.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) - mal = stix2.v20.Malware(id=MALWARE_ID, **MALWARE_KWARGS) - rel1 = stix2.v20.Relationship(ind, 'indicates', mal, id=RELATIONSHIP_IDS[0]) - rel2 = stix2.v20.Relationship(mal, 'targets', idy, id=RELATIONSHIP_IDS[1]) - rel3 = stix2.v20.Relationship(cam, 'uses', mal, id=RELATIONSHIP_IDS[2]) - reprt = stix2.v20.Report( + cam = misp_lib_stix2.v20.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) + idy = misp_lib_stix2.v20.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) + ind = misp_lib_stix2.v20.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) + mal = misp_lib_stix2.v20.Malware(id=MALWARE_ID, **MALWARE_KWARGS) + rel1 = misp_lib_stix2.v20.Relationship(ind, 'indicates', mal, id=RELATIONSHIP_IDS[0]) + rel2 = misp_lib_stix2.v20.Relationship(mal, 'targets', idy, id=RELATIONSHIP_IDS[1]) + rel3 = misp_lib_stix2.v20.Relationship(cam, 'uses', mal, id=RELATIONSHIP_IDS[2]) + reprt = misp_lib_stix2.v20.Report( name="Malware Report", published="2021-05-09T08:22:22Z", labels=["campaign"], object_refs=[mal.id, rel1.id, ind.id], ) stix_objs = [cam, idy, ind, mal, rel1, rel2, rel3, reprt] - yield stix2.MemoryStore(stix_objs) + yield misp_lib_stix2.MemoryStore(stix_objs) @pytest.fixture def ds2(): - cam = stix2.v20.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) - idy = stix2.v20.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) - ind = stix2.v20.Indicator(id=INDICATOR_ID, created_by_ref=idy.id, **INDICATOR_KWARGS) + cam = misp_lib_stix2.v20.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) + idy = misp_lib_stix2.v20.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) + ind = misp_lib_stix2.v20.Indicator(id=INDICATOR_ID, created_by_ref=idy.id, **INDICATOR_KWARGS) indv2 = ind.new_version( external_references=[{ "source_name": "unknown", "url": "https://examplewebsite.com/", }], ) - mal = stix2.v20.Malware(id=MALWARE_ID, created_by_ref=idy.id, **MALWARE_KWARGS) + mal = misp_lib_stix2.v20.Malware(id=MALWARE_ID, created_by_ref=idy.id, **MALWARE_KWARGS) malv2 = mal.new_version( external_references=[{ "source_name": "unknown", "url": "https://examplewebsite2.com/", }], ) - rel1 = stix2.v20.Relationship(ind, 'indicates', mal, id=RELATIONSHIP_IDS[0]) - rel2 = stix2.v20.Relationship(mal, 'targets', idy, id=RELATIONSHIP_IDS[1]) - rel3 = stix2.v20.Relationship(cam, 'uses', mal, id=RELATIONSHIP_IDS[2]) + rel1 = misp_lib_stix2.v20.Relationship(ind, 'indicates', mal, id=RELATIONSHIP_IDS[0]) + rel2 = misp_lib_stix2.v20.Relationship(mal, 'targets', idy, id=RELATIONSHIP_IDS[1]) + rel3 = misp_lib_stix2.v20.Relationship(cam, 'uses', mal, id=RELATIONSHIP_IDS[2]) stix_objs = [cam, idy, ind, indv2, mal, malv2, rel1, rel2, rel3] - reprt = stix2.v20.Report( + reprt = misp_lib_stix2.v20.Report( created_by_ref=idy.id, name="example", labels=["campaign"], @@ -65,115 +65,115 @@ def ds2(): object_refs=stix_objs, ) stix_objs.append(reprt) - yield stix2.MemoryStore(stix_objs) + yield misp_lib_stix2.MemoryStore(stix_objs) @pytest.fixture def fs(): - yield stix2.FileSystemSource(FS_PATH) + yield misp_lib_stix2.FileSystemSource(FS_PATH) def test_object_factory_created_by_ref_str(): - factory = stix2.ObjectFactory(created_by_ref=IDENTITY_ID) - ind = factory.create(stix2.v20.Indicator, **INDICATOR_KWARGS) + factory = misp_lib_stix2.ObjectFactory(created_by_ref=IDENTITY_ID) + ind = factory.create(misp_lib_stix2.v20.Indicator, **INDICATOR_KWARGS) assert ind.created_by_ref == IDENTITY_ID def test_object_factory_created_by_ref_obj(): - id_obj = stix2.v20.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) - factory = stix2.ObjectFactory(created_by_ref=id_obj) - ind = factory.create(stix2.v20.Indicator, **INDICATOR_KWARGS) + id_obj = misp_lib_stix2.v20.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) + factory = misp_lib_stix2.ObjectFactory(created_by_ref=id_obj) + ind = factory.create(misp_lib_stix2.v20.Indicator, **INDICATOR_KWARGS) assert ind.created_by_ref == IDENTITY_ID def test_object_factory_override_default(): - factory = stix2.ObjectFactory(created_by_ref=IDENTITY_ID) + factory = misp_lib_stix2.ObjectFactory(created_by_ref=IDENTITY_ID) new_id = "identity--983b3172-44fe-4a80-8091-eb8098841fe8" - ind = factory.create(stix2.v20.Indicator, created_by_ref=new_id, **INDICATOR_KWARGS) + ind = factory.create(misp_lib_stix2.v20.Indicator, created_by_ref=new_id, **INDICATOR_KWARGS) assert ind.created_by_ref == new_id def test_object_factory_created(): - factory = stix2.ObjectFactory(created=FAKE_TIME) - ind = factory.create(stix2.v20.Indicator, **INDICATOR_KWARGS) + factory = misp_lib_stix2.ObjectFactory(created=FAKE_TIME) + ind = factory.create(misp_lib_stix2.v20.Indicator, **INDICATOR_KWARGS) assert ind.created == FAKE_TIME assert ind.modified == FAKE_TIME def test_object_factory_external_reference(): - ext_ref = stix2.v20.ExternalReference( + ext_ref = misp_lib_stix2.v20.ExternalReference( source_name="ACME Threat Intel", description="Threat report", ) - factory = stix2.ObjectFactory(external_references=ext_ref) - ind = factory.create(stix2.v20.Indicator, **INDICATOR_KWARGS) + factory = misp_lib_stix2.ObjectFactory(external_references=ext_ref) + ind = factory.create(misp_lib_stix2.v20.Indicator, **INDICATOR_KWARGS) assert ind.external_references[0].source_name == "ACME Threat Intel" assert ind.external_references[0].description == "Threat report" - ind2 = factory.create(stix2.v20.Indicator, external_references=None, **INDICATOR_KWARGS) + ind2 = factory.create(misp_lib_stix2.v20.Indicator, external_references=None, **INDICATOR_KWARGS) assert 'external_references' not in ind2 def test_object_factory_obj_markings(): - stmt_marking = stix2.v20.StatementMarking("Copyright 2016, Example Corp") - mark_def = stix2.v20.MarkingDefinition( + stmt_marking = misp_lib_stix2.v20.StatementMarking("Copyright 2016, Example Corp") + mark_def = misp_lib_stix2.v20.MarkingDefinition( definition_type="statement", definition=stmt_marking, ) - factory = stix2.ObjectFactory(object_marking_refs=[mark_def, stix2.v20.TLP_AMBER]) - ind = factory.create(stix2.v20.Indicator, **INDICATOR_KWARGS) + factory = misp_lib_stix2.ObjectFactory(object_marking_refs=[mark_def, misp_lib_stix2.v20.TLP_AMBER]) + ind = factory.create(misp_lib_stix2.v20.Indicator, **INDICATOR_KWARGS) assert mark_def.id in ind.object_marking_refs - assert stix2.v20.TLP_AMBER.id in ind.object_marking_refs + assert misp_lib_stix2.v20.TLP_AMBER.id in ind.object_marking_refs - factory = stix2.ObjectFactory(object_marking_refs=stix2.v20.TLP_RED) - ind = factory.create(stix2.v20.Indicator, **INDICATOR_KWARGS) - assert stix2.v20.TLP_RED.id in ind.object_marking_refs + factory = misp_lib_stix2.ObjectFactory(object_marking_refs=misp_lib_stix2.v20.TLP_RED) + ind = factory.create(misp_lib_stix2.v20.Indicator, **INDICATOR_KWARGS) + assert misp_lib_stix2.v20.TLP_RED.id in ind.object_marking_refs def test_object_factory_list_append(): - ext_ref = stix2.v20.ExternalReference( + ext_ref = misp_lib_stix2.v20.ExternalReference( source_name="ACME Threat Intel", description="Threat report from ACME", ) - ext_ref2 = stix2.v20.ExternalReference( + ext_ref2 = misp_lib_stix2.v20.ExternalReference( source_name="Yet Another Threat Report", description="Threat report from YATR", ) - ext_ref3 = stix2.v20.ExternalReference( + ext_ref3 = misp_lib_stix2.v20.ExternalReference( source_name="Threat Report #3", description="One more threat report", ) - factory = stix2.ObjectFactory(external_references=ext_ref) - ind = factory.create(stix2.v20.Indicator, external_references=ext_ref2, **INDICATOR_KWARGS) + factory = misp_lib_stix2.ObjectFactory(external_references=ext_ref) + ind = factory.create(misp_lib_stix2.v20.Indicator, external_references=ext_ref2, **INDICATOR_KWARGS) assert ind.external_references[1].source_name == "Yet Another Threat Report" - ind = factory.create(stix2.v20.Indicator, external_references=[ext_ref2, ext_ref3], **INDICATOR_KWARGS) + ind = factory.create(misp_lib_stix2.v20.Indicator, external_references=[ext_ref2, ext_ref3], **INDICATOR_KWARGS) assert ind.external_references[2].source_name == "Threat Report #3" def test_object_factory_list_replace(): - ext_ref = stix2.v20.ExternalReference( + ext_ref = misp_lib_stix2.v20.ExternalReference( source_name="ACME Threat Intel", description="Threat report from ACME", ) - ext_ref2 = stix2.v20.ExternalReference( + ext_ref2 = misp_lib_stix2.v20.ExternalReference( source_name="Yet Another Threat Report", description="Threat report from YATR", ) - factory = stix2.ObjectFactory(external_references=ext_ref, list_append=False) - ind = factory.create(stix2.v20.Indicator, external_references=ext_ref2, **INDICATOR_KWARGS) + factory = misp_lib_stix2.ObjectFactory(external_references=ext_ref, list_append=False) + ind = factory.create(misp_lib_stix2.v20.Indicator, external_references=ext_ref2, **INDICATOR_KWARGS) assert len(ind.external_references) == 1 assert ind.external_references[0].source_name == "Yet Another Threat Report" def test_environment_functions(): - env = stix2.Environment( - stix2.ObjectFactory(created_by_ref=IDENTITY_ID), - stix2.MemoryStore(), + env = misp_lib_stix2.Environment( + misp_lib_stix2.ObjectFactory(created_by_ref=IDENTITY_ID), + misp_lib_stix2.MemoryStore(), ) # Create a STIX object - ind = env.create(stix2.v20.Indicator, id=INDICATOR_ID, **INDICATOR_KWARGS) + ind = env.create(misp_lib_stix2.v20.Indicator, id=INDICATOR_ID, **INDICATOR_KWARGS) assert ind.created_by_ref == IDENTITY_ID # Add objects to datastore @@ -189,40 +189,40 @@ def test_environment_functions(): assert resp['labels'][0] == 'benign' # Search on something other than id - query = [stix2.Filter('type', '=', 'vulnerability')] + query = [misp_lib_stix2.Filter('type', '=', 'vulnerability')] resp = env.query(query) assert len(resp) == 0 # See different results after adding filters to the environment env.add_filters([ - stix2.Filter('type', '=', 'indicator'), - stix2.Filter('created_by_ref', '=', IDENTITY_ID), + misp_lib_stix2.Filter('type', '=', 'indicator'), + misp_lib_stix2.Filter('created_by_ref', '=', IDENTITY_ID), ]) - env.add_filter(stix2.Filter('labels', '=', 'benign')) # should be 'malicious-activity' + env.add_filter(misp_lib_stix2.Filter('labels', '=', 'benign')) # should be 'malicious-activity' resp = env.get(INDICATOR_ID) assert resp['labels'][0] == 'benign' # should be 'malicious-activity' def test_environment_source_and_sink(): - ind = stix2.v20.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) - env = stix2.Environment(source=stix2.MemorySource([ind]), sink=stix2.MemorySink([ind])) + ind = misp_lib_stix2.v20.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) + env = misp_lib_stix2.Environment(source=misp_lib_stix2.MemorySource([ind]), sink=misp_lib_stix2.MemorySink([ind])) assert env.get(INDICATOR_ID).labels[0] == 'malicious-activity' def test_environment_datastore_and_sink(): with pytest.raises(ValueError) as excinfo: - stix2.Environment( - factory=stix2.ObjectFactory(), - store=stix2.MemoryStore(), sink=stix2.MemorySink, + misp_lib_stix2.Environment( + factory=misp_lib_stix2.ObjectFactory(), + store=misp_lib_stix2.MemoryStore(), sink=misp_lib_stix2.MemorySink, ) assert 'Data store already provided' in str(excinfo.value) def test_environment_no_datastore(): - env = stix2.Environment(factory=stix2.ObjectFactory()) + env = misp_lib_stix2.Environment(factory=misp_lib_stix2.ObjectFactory()) with pytest.raises(AttributeError) as excinfo: - env.add(stix2.v20.Indicator(**INDICATOR_KWARGS)) + env.add(misp_lib_stix2.v20.Indicator(**INDICATOR_KWARGS)) assert 'Environment has no data sink to put objects in' in str(excinfo.value) with pytest.raises(AttributeError) as excinfo: @@ -247,20 +247,20 @@ def test_environment_no_datastore(): def test_environment_add_filters(): - env = stix2.Environment(factory=stix2.ObjectFactory()) + env = misp_lib_stix2.Environment(factory=misp_lib_stix2.ObjectFactory()) env.add_filters([INDICATOR_ID]) env.add_filter(INDICATOR_ID) def test_environment_datastore_and_no_object_factory(): # Uses a default object factory - env = stix2.Environment(store=stix2.MemoryStore()) - ind = env.create(stix2.v20.Indicator, id=INDICATOR_ID, **INDICATOR_KWARGS) + env = misp_lib_stix2.Environment(store=misp_lib_stix2.MemoryStore()) + ind = env.create(misp_lib_stix2.v20.Indicator, id=INDICATOR_ID, **INDICATOR_KWARGS) assert ind.id == INDICATOR_ID def test_parse_malware(): - env = stix2.Environment() + env = misp_lib_stix2.Environment() data = """{ "type": "malware", "id": "malware--9c4638ec-f1de-4ddb-abf4-1b760417654e", @@ -282,46 +282,46 @@ def test_parse_malware(): def test_creator_of(): - identity = stix2.v20.Identity(**IDENTITY_KWARGS) - factory = stix2.ObjectFactory(created_by_ref=identity.id) - env = stix2.Environment(store=stix2.MemoryStore(), factory=factory) + identity = misp_lib_stix2.v20.Identity(**IDENTITY_KWARGS) + factory = misp_lib_stix2.ObjectFactory(created_by_ref=identity.id) + env = misp_lib_stix2.Environment(store=misp_lib_stix2.MemoryStore(), factory=factory) env.add(identity) - ind = env.create(stix2.v20.Indicator, **INDICATOR_KWARGS) + ind = env.create(misp_lib_stix2.v20.Indicator, **INDICATOR_KWARGS) creator = env.creator_of(ind) assert creator is identity def test_creator_of_no_datasource(): - identity = stix2.v20.Identity(**IDENTITY_KWARGS) - factory = stix2.ObjectFactory(created_by_ref=identity.id) - env = stix2.Environment(factory=factory) + identity = misp_lib_stix2.v20.Identity(**IDENTITY_KWARGS) + factory = misp_lib_stix2.ObjectFactory(created_by_ref=identity.id) + env = misp_lib_stix2.Environment(factory=factory) - ind = env.create(stix2.v20.Indicator, **INDICATOR_KWARGS) + ind = env.create(misp_lib_stix2.v20.Indicator, **INDICATOR_KWARGS) with pytest.raises(AttributeError) as excinfo: env.creator_of(ind) assert 'Environment has no data source' in str(excinfo.value) def test_creator_of_not_found(): - identity = stix2.v20.Identity(**IDENTITY_KWARGS) - factory = stix2.ObjectFactory(created_by_ref=identity.id) - env = stix2.Environment(store=stix2.MemoryStore(), factory=factory) + identity = misp_lib_stix2.v20.Identity(**IDENTITY_KWARGS) + factory = misp_lib_stix2.ObjectFactory(created_by_ref=identity.id) + env = misp_lib_stix2.Environment(store=misp_lib_stix2.MemoryStore(), factory=factory) - ind = env.create(stix2.v20.Indicator, **INDICATOR_KWARGS) + ind = env.create(misp_lib_stix2.v20.Indicator, **INDICATOR_KWARGS) creator = env.creator_of(ind) assert creator is None def test_creator_of_no_created_by_ref(): - env = stix2.Environment(store=stix2.MemoryStore()) - ind = env.create(stix2.v20.Indicator, **INDICATOR_KWARGS) + env = misp_lib_stix2.Environment(store=misp_lib_stix2.MemoryStore()) + ind = env.create(misp_lib_stix2.v20.Indicator, **INDICATOR_KWARGS) creator = env.creator_of(ind) assert creator is None def test_relationships(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) mal = env.get(MALWARE_ID) resp = env.relationships(mal) @@ -332,7 +332,7 @@ def test_relationships(ds): def test_relationships_no_id(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) mal = { "type": "malware", "name": "some variant", @@ -343,7 +343,7 @@ def test_relationships_no_id(ds): def test_relationships_by_type(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) mal = env.get(MALWARE_ID) resp = env.relationships(mal, relationship_type='indicates') @@ -352,7 +352,7 @@ def test_relationships_by_type(ds): def test_relationships_by_source(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) resp = env.relationships(MALWARE_ID, source_only=True) assert len(resp) == 1 @@ -360,7 +360,7 @@ def test_relationships_by_source(ds): def test_relationships_by_target(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) resp = env.relationships(MALWARE_ID, target_only=True) assert len(resp) == 2 @@ -369,7 +369,7 @@ def test_relationships_by_target(ds): def test_relationships_by_target_and_type(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) resp = env.relationships(MALWARE_ID, relationship_type='uses', target_only=True) assert len(resp) == 1 @@ -377,7 +377,7 @@ def test_relationships_by_target_and_type(ds): def test_relationships_by_target_and_source(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) with pytest.raises(ValueError) as excinfo: env.relationships(MALWARE_ID, target_only=True, source_only=True) @@ -385,7 +385,7 @@ def test_relationships_by_target_and_source(ds): def test_related_to(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) mal = env.get(MALWARE_ID) resp = env.related_to(mal) @@ -396,7 +396,7 @@ def test_related_to(ds): def test_related_to_no_id(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) mal = { "type": "malware", "name": "some variant", @@ -407,7 +407,7 @@ def test_related_to_no_id(ds): def test_related_to_by_source(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) resp = env.related_to(MALWARE_ID, source_only=True) assert len(resp) == 1 @@ -415,7 +415,7 @@ def test_related_to_by_source(ds): def test_related_to_by_target(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) resp = env.related_to(MALWARE_ID, target_only=True) assert len(resp) == 2 @@ -424,7 +424,7 @@ def test_related_to_by_target(ds): def test_versioned_checks(ds, ds2): - weights = stix2.equivalence.graph.WEIGHTS.copy() + weights = misp_lib_stix2.equivalence.graph.WEIGHTS.copy() weights.update({ "_internal": { "ignore_spec_version": True, @@ -432,12 +432,12 @@ def test_versioned_checks(ds, ds2): "max_depth": 1, }, }) - score = stix2.equivalence.object._versioned_checks(INDICATOR_ID, INDICATOR_ID, ds, ds2, **weights) + score = misp_lib_stix2.equivalence.object._versioned_checks(INDICATOR_ID, INDICATOR_ID, ds, ds2, **weights) assert round(score) == 100 def test_semantic_check_with_versioning(ds, ds2): - weights = stix2.equivalence.graph.WEIGHTS.copy() + weights = misp_lib_stix2.equivalence.graph.WEIGHTS.copy() weights.update({ "_internal": { "ignore_spec_version": False, @@ -447,7 +447,7 @@ def test_semantic_check_with_versioning(ds, ds2): "max_depth": 1, }, }) - ind = stix2.v20.Indicator( + ind = misp_lib_stix2.v20.Indicator( **dict( labels=["malicious-activity"], pattern="[file:hashes.'SHA-256' = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855']", @@ -458,16 +458,16 @@ def test_semantic_check_with_versioning(ds, ds2): "url": "https://examplewebsite2.com/", }, ], - object_marking_refs=[stix2.v20.TLP_WHITE], + object_marking_refs=[misp_lib_stix2.v20.TLP_WHITE], ) ) ds.add(ind) - score = stix2.equivalence.object.reference_check(ind.id, INDICATOR_ID, ds, ds2, **weights) + score = misp_lib_stix2.equivalence.object.reference_check(ind.id, INDICATOR_ID, ds, ds2, **weights) assert round(score) == 0 # Since pattern is different score is really low def test_list_semantic_check(ds, ds2): - weights = stix2.equivalence.graph.WEIGHTS.copy() + weights = misp_lib_stix2.equivalence.graph.WEIGHTS.copy() weights.update({ "_internal": { "ignore_spec_version": False, @@ -491,7 +491,7 @@ def test_list_semantic_check(ds, ds2): "relationship--a0cbb21c-8daf-4a7f-96aa-7155a4ef8f70", ] - score = stix2.equivalence.object.list_reference_check( + score = misp_lib_stix2.equivalence.object.list_reference_check( object_refs1, object_refs2, ds, @@ -504,16 +504,16 @@ def test_list_semantic_check(ds, ds2): def test_graph_similarity_raises_value_error(ds): with pytest.raises(ValueError): prop_scores1 = {} - stix2.Environment().graph_similarity(ds, ds2, prop_scores1, max_depth=-1) + misp_lib_stix2.Environment().graph_similarity(ds, ds2, prop_scores1, max_depth=-1) def test_graph_similarity_with_filesystem_source(ds, fs): prop_scores1 = {} - env1 = stix2.Environment().graph_similarity(fs, ds, prop_scores1, ignore_spec_version=True) + env1 = misp_lib_stix2.Environment().graph_similarity(fs, ds, prop_scores1, ignore_spec_version=True) # Switching parameters prop_scores2 = {} - env2 = stix2.Environment().graph_similarity(ds, fs, prop_scores2, ignore_spec_version=True) + env2 = misp_lib_stix2.Environment().graph_similarity(ds, fs, prop_scores2, ignore_spec_version=True) assert round(env1) == 25 assert round(prop_scores1["matching_score"]) == 451 @@ -530,7 +530,7 @@ def test_graph_similarity_with_filesystem_source(ds, fs): def test_graph_similarity_with_duplicate_graph(ds): prop_scores = {} - env = stix2.Environment().graph_similarity(ds, ds, prop_scores) + env = misp_lib_stix2.Environment().graph_similarity(ds, ds, prop_scores) assert round(env) == 100 assert round(prop_scores["matching_score"]) == 800 assert round(prop_scores["len_pairs"]) == 8 @@ -538,11 +538,11 @@ def test_graph_similarity_with_duplicate_graph(ds): def test_graph_similarity_with_versioning_check_on(ds2, ds): prop_scores1 = {} - env1 = stix2.Environment().graph_similarity(ds, ds2, prop_scores1, versioning_checks=True) + env1 = misp_lib_stix2.Environment().graph_similarity(ds, ds2, prop_scores1, versioning_checks=True) # Switching parameters prop_scores2 = {} - env2 = stix2.Environment().graph_similarity(ds2, ds, prop_scores2, versioning_checks=True) + env2 = misp_lib_stix2.Environment().graph_similarity(ds2, ds, prop_scores2, versioning_checks=True) assert round(env1) == 88 assert round(prop_scores1["matching_score"]) == 789 @@ -559,11 +559,11 @@ def test_graph_similarity_with_versioning_check_on(ds2, ds): def test_graph_similarity_with_versioning_check_off(ds2, ds): prop_scores1 = {} - env1 = stix2.Environment().graph_similarity(ds, ds2, prop_scores1) + env1 = misp_lib_stix2.Environment().graph_similarity(ds, ds2, prop_scores1) # Switching parameters prop_scores2 = {} - env2 = stix2.Environment().graph_similarity(ds2, ds, prop_scores2) + env2 = misp_lib_stix2.Environment().graph_similarity(ds2, ds, prop_scores2) assert round(env1) == 88 assert round(prop_scores1["matching_score"]) == 789 @@ -580,11 +580,11 @@ def test_graph_similarity_with_versioning_check_off(ds2, ds): def test_graph_equivalence_with_filesystem_source(ds, fs): prop_scores1 = {} - env1 = stix2.Environment().graph_equivalence(fs, ds, prop_scores1, ignore_spec_version=True) + env1 = misp_lib_stix2.Environment().graph_equivalence(fs, ds, prop_scores1, ignore_spec_version=True) # Switching parameters prop_scores2 = {} - env2 = stix2.Environment().graph_equivalence(ds, fs, prop_scores2, ignore_spec_version=True) + env2 = misp_lib_stix2.Environment().graph_equivalence(ds, fs, prop_scores2, ignore_spec_version=True) assert env1 is False assert round(prop_scores1["matching_score"]) == 451 @@ -601,7 +601,7 @@ def test_graph_equivalence_with_filesystem_source(ds, fs): def test_graph_equivalence_with_duplicate_graph(ds): prop_scores = {} - env = stix2.Environment().graph_equivalence(ds, ds, prop_scores) + env = misp_lib_stix2.Environment().graph_equivalence(ds, ds, prop_scores) assert env is True assert round(prop_scores["matching_score"]) == 800 assert round(prop_scores["len_pairs"]) == 8 @@ -609,11 +609,11 @@ def test_graph_equivalence_with_duplicate_graph(ds): def test_graph_equivalence_with_versioning_check_on(ds2, ds): prop_scores1 = {} - env1 = stix2.Environment().graph_equivalence(ds, ds2, prop_scores1, versioning_checks=True) + env1 = misp_lib_stix2.Environment().graph_equivalence(ds, ds2, prop_scores1, versioning_checks=True) # Switching parameters prop_scores2 = {} - env2 = stix2.Environment().graph_equivalence(ds2, ds, prop_scores2, versioning_checks=True) + env2 = misp_lib_stix2.Environment().graph_equivalence(ds2, ds, prop_scores2, versioning_checks=True) assert env1 is True assert round(prop_scores1["matching_score"]) == 789 @@ -630,11 +630,11 @@ def test_graph_equivalence_with_versioning_check_on(ds2, ds): def test_graph_equivalence_with_versioning_check_off(ds2, ds): prop_scores1 = {} - env1 = stix2.Environment().graph_equivalence(ds, ds2, prop_scores1) + env1 = misp_lib_stix2.Environment().graph_equivalence(ds, ds2, prop_scores1) # Switching parameters prop_scores2 = {} - env2 = stix2.Environment().graph_equivalence(ds2, ds, prop_scores2) + env2 = misp_lib_stix2.Environment().graph_equivalence(ds2, ds, prop_scores2) assert env1 is True assert round(prop_scores1["matching_score"]) == 789 diff --git a/stix2/test/v20/test_external_reference.py b/misp_lib_stix2/test/v20/test_external_reference.py similarity index 84% rename from stix2/test/v20/test_external_reference.py rename to misp_lib_stix2/test/v20/test_external_reference.py index 04821cd4..e0c93efe 100644 --- a/stix2/test/v20/test_external_reference.py +++ b/misp_lib_stix2/test/v20/test_external_reference.py @@ -4,7 +4,7 @@ import pytest -import stix2 +import misp_lib_stix2 VERIS = """{ "source_name": "veris", @@ -17,7 +17,7 @@ def test_external_reference_veris(): - ref = stix2.v20.ExternalReference( + ref = misp_lib_stix2.v20.ExternalReference( source_name="veris", external_id="0001AA7F-C601-424A-B2B8-BE6C9F5164E7", hashes={ @@ -36,7 +36,7 @@ def test_external_reference_veris(): def test_external_reference_capec(): - ref = stix2.v20.ExternalReference( + ref = misp_lib_stix2.v20.ExternalReference( source_name="capec", external_id="CAPEC-550", ) @@ -53,7 +53,7 @@ def test_external_reference_capec(): def test_external_reference_capec_url(): - ref = stix2.v20.ExternalReference( + ref = misp_lib_stix2.v20.ExternalReference( source_name="capec", external_id="CAPEC-550", url="http://capec.mitre.org/data/definitions/550.html", @@ -70,7 +70,7 @@ def test_external_reference_capec_url(): def test_external_reference_threat_report(): - ref = stix2.v20.ExternalReference( + ref = misp_lib_stix2.v20.ExternalReference( source_name="ACME Threat Intel", description="Threat report", url="http://www.example.com/threat-report.pdf", @@ -87,7 +87,7 @@ def test_external_reference_threat_report(): def test_external_reference_bugzilla(): - ref = stix2.v20.ExternalReference( + ref = misp_lib_stix2.v20.ExternalReference( source_name="ACME Bugzilla", external_id="1370", url="https://www.example.com/bugs/1370", @@ -103,7 +103,7 @@ def test_external_reference_bugzilla(): def test_external_reference_offline(): - ref = stix2.v20.ExternalReference( + ref = misp_lib_stix2.v20.ExternalReference( source_name="ACME Threat Intel", description="Threat report", ) @@ -115,8 +115,8 @@ def test_external_reference_offline(): def test_external_reference_source_required(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v20.ExternalReference() + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v20.ExternalReference() - assert excinfo.value.cls == stix2.v20.ExternalReference + assert excinfo.value.cls == misp_lib_stix2.v20.ExternalReference assert excinfo.value.properties == ["source_name"] diff --git a/stix2/test/v21/test_fixtures.py b/misp_lib_stix2/test/v20/test_fixtures.py similarity index 93% rename from stix2/test/v21/test_fixtures.py rename to misp_lib_stix2/test/v20/test_fixtures.py index 23ad8a4e..48305eb0 100644 --- a/stix2/test/v21/test_fixtures.py +++ b/misp_lib_stix2/test/v20/test_fixtures.py @@ -1,6 +1,6 @@ import uuid -from stix2 import utils +from misp_lib_stix2 import utils from .constants import FAKE_TIME diff --git a/stix2/test/v20/test_granular_markings.py b/misp_lib_stix2/test/v20/test_granular_markings.py similarity index 99% rename from stix2/test/v20/test_granular_markings.py rename to misp_lib_stix2/test/v20/test_granular_markings.py index ae2da3b0..fd296d3f 100644 --- a/stix2/test/v20/test_granular_markings.py +++ b/misp_lib_stix2/test/v20/test_granular_markings.py @@ -1,9 +1,9 @@ import pytest -from stix2 import markings -from stix2.exceptions import InvalidSelectorError, MarkingNotFoundError -from stix2.v20 import TLP_RED, Malware +from misp_lib_stix2 import markings +from misp_lib_stix2.exceptions import InvalidSelectorError, MarkingNotFoundError +from misp_lib_stix2.v20 import TLP_RED, Malware from .constants import MALWARE_MORE_KWARGS as MALWARE_KWARGS_CONST from .constants import MARKING_IDS diff --git a/stix2/test/v20/test_identity.py b/misp_lib_stix2/test/v20/test_identity.py similarity index 87% rename from stix2/test/v20/test_identity.py rename to misp_lib_stix2/test/v20/test_identity.py index 93787b3a..18ea7b27 100644 --- a/stix2/test/v20/test_identity.py +++ b/misp_lib_stix2/test/v20/test_identity.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import IDENTITY_ID @@ -18,7 +18,7 @@ def test_identity_example(): - identity = stix2.v20.Identity( + identity = misp_lib_stix2.v20.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11.000Z", modified="2015-12-21T19:59:11.000Z", @@ -43,7 +43,7 @@ def test_identity_example(): ], ) def test_parse_identity(data): - identity = stix2.parse(data, version="2.0") + identity = misp_lib_stix2.parse(data, version="2.0") assert identity.type == 'identity' assert identity.id == IDENTITY_ID @@ -53,8 +53,8 @@ def test_parse_identity(data): def test_parse_no_type(): - with pytest.raises(stix2.exceptions.ParseError): - stix2.parse( + with pytest.raises(misp_lib_stix2.exceptions.ParseError): + misp_lib_stix2.parse( """ { "id": "identity--311b2d2d-f010-4473-83ec-1edf84858f4c", @@ -67,7 +67,7 @@ def test_parse_no_type(): def test_identity_with_custom(): - identity = stix2.v20.Identity( + identity = misp_lib_stix2.v20.Identity( name="John Smith", identity_class="individual", custom_properties={'x_foo': 'bar'}, diff --git a/stix2/test/v20/test_indicator.py b/misp_lib_stix2/test/v20/test_indicator.py similarity index 72% rename from stix2/test/v20/test_indicator.py rename to misp_lib_stix2/test/v20/test_indicator.py index 10a70156..81dd2f99 100644 --- a/stix2/test/v20/test_indicator.py +++ b/misp_lib_stix2/test/v20/test_indicator.py @@ -4,7 +4,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import FAKE_TIME, INDICATOR_ID, INDICATOR_KWARGS @@ -38,7 +38,7 @@ def test_indicator_with_all_required_properties(): now = dt.datetime(2017, 1, 1, 0, 0, 1, tzinfo=pytz.utc) epoch = dt.datetime(1970, 1, 1, 0, 0, 1, tzinfo=pytz.utc) - ind = stix2.v20.Indicator( + ind = misp_lib_stix2.v20.Indicator( type="indicator", id=INDICATOR_ID, created=now, @@ -73,78 +73,78 @@ def test_indicator_autogenerated_properties(indicator): def test_indicator_type_must_be_indicator(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Indicator(type='xxx', **INDICATOR_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Indicator(type='xxx', **INDICATOR_KWARGS) - assert excinfo.value.cls == stix2.v20.Indicator + assert excinfo.value.cls == misp_lib_stix2.v20.Indicator assert excinfo.value.prop_name == "type" assert excinfo.value.reason == "must equal 'indicator'." assert str(excinfo.value) == "Invalid value for Indicator 'type': must equal 'indicator'." def test_indicator_id_must_start_with_indicator(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Indicator(id='my-prefix--', **INDICATOR_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Indicator(id='my-prefix--', **INDICATOR_KWARGS) - assert excinfo.value.cls == stix2.v20.Indicator + assert excinfo.value.cls == misp_lib_stix2.v20.Indicator assert excinfo.value.prop_name == "id" assert excinfo.value.reason == "must start with 'indicator--'." assert str(excinfo.value) == "Invalid value for Indicator 'id': must start with 'indicator--'." def test_indicator_required_properties(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v20.Indicator() + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v20.Indicator() - assert excinfo.value.cls == stix2.v20.Indicator + assert excinfo.value.cls == misp_lib_stix2.v20.Indicator assert excinfo.value.properties == ["labels", "pattern"] assert str(excinfo.value) == "No values for required properties for Indicator: (labels, pattern)." def test_indicator_required_property_pattern(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v20.Indicator(labels=['malicious-activity']) + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v20.Indicator(labels=['malicious-activity']) - assert excinfo.value.cls == stix2.v20.Indicator + assert excinfo.value.cls == misp_lib_stix2.v20.Indicator assert excinfo.value.properties == ["pattern"] def test_indicator_created_ref_invalid_format(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Indicator(created_by_ref='myprefix--12345678', **INDICATOR_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Indicator(created_by_ref='myprefix--12345678', **INDICATOR_KWARGS) - assert excinfo.value.cls == stix2.v20.Indicator + assert excinfo.value.cls == misp_lib_stix2.v20.Indicator assert excinfo.value.prop_name == "created_by_ref" def test_indicator_revoked_invalid(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Indicator(revoked='no', **INDICATOR_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Indicator(revoked='no', **INDICATOR_KWARGS) - assert excinfo.value.cls == stix2.v20.Indicator + assert excinfo.value.cls == misp_lib_stix2.v20.Indicator assert excinfo.value.prop_name == "revoked" assert excinfo.value.reason == "must be a boolean value." def test_cannot_assign_to_indicator_attributes(indicator): - with pytest.raises(stix2.exceptions.ImmutableError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.ImmutableError) as excinfo: indicator.valid_from = dt.datetime.now() assert str(excinfo.value) == "Cannot modify 'valid_from' property in 'Indicator' after creation." def test_invalid_kwarg_to_indicator(): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v20.Indicator(my_custom_property="foo", **INDICATOR_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v20.Indicator(my_custom_property="foo", **INDICATOR_KWARGS) - assert excinfo.value.cls == stix2.v20.Indicator + assert excinfo.value.cls == misp_lib_stix2.v20.Indicator assert excinfo.value.properties == ['my_custom_property'] assert str(excinfo.value) == "Unexpected properties for Indicator: (my_custom_property)." def test_created_modified_time_are_identical_by_default(): """By default, the created and modified times should be the same.""" - ind = stix2.v20.Indicator(**INDICATOR_KWARGS) + ind = misp_lib_stix2.v20.Indicator(**INDICATOR_KWARGS) assert ind.created == ind.modified @@ -166,7 +166,7 @@ def test_created_modified_time_are_identical_by_default(): ], ) def test_parse_indicator(data): - idctr = stix2.parse(data, version="2.0") + idctr = misp_lib_stix2.parse(data, version="2.0") assert idctr.type == 'indicator' assert idctr.id == INDICATOR_ID @@ -178,21 +178,21 @@ def test_parse_indicator(data): def test_invalid_indicator_pattern(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Indicator( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Indicator( labels=['malicious-activity'], pattern="file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e'", ) - assert excinfo.value.cls == stix2.v20.Indicator + assert excinfo.value.cls == misp_lib_stix2.v20.Indicator assert excinfo.value.prop_name == 'pattern' assert 'input is missing square brackets' in excinfo.value.reason - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Indicator( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Indicator( labels=['malicious-activity'], pattern='[file:hashes.MD5 = "d41d8cd98f00b204e9800998ecf8427e"]', ) - assert excinfo.value.cls == stix2.v20.Indicator + assert excinfo.value.cls == misp_lib_stix2.v20.Indicator assert excinfo.value.prop_name == 'pattern' assert 'mismatched input' in excinfo.value.reason @@ -202,8 +202,8 @@ def test_indicator_stix21_invalid_pattern(): epoch = dt.datetime(1970, 1, 1, 0, 0, 1, tzinfo=pytz.utc) patrn = "[EXISTS windows-registry-key:values]" - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Indicator( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Indicator( type="indicator", id=INDICATOR_ID, created=now, @@ -213,5 +213,5 @@ def test_indicator_stix21_invalid_pattern(): labels=["malicious-activity"], ) - assert excinfo.value.cls == stix2.v20.Indicator + assert excinfo.value.cls == misp_lib_stix2.v20.Indicator assert "FAIL: Error found at line 1:8. no viable alternative at input 'EXISTS" in str(excinfo.value) diff --git a/stix2/test/v20/test_interoperability.py b/misp_lib_stix2/test/v20/test_interoperability.py similarity index 77% rename from stix2/test/v20/test_interoperability.py rename to misp_lib_stix2/test/v20/test_interoperability.py index d8eb1438..26738db9 100644 --- a/stix2/test/v20/test_interoperability.py +++ b/misp_lib_stix2/test/v20/test_interoperability.py @@ -2,7 +2,7 @@ import pytz -import stix2 +import misp_lib_stix2 FAKE_TIME = datetime.datetime(2017, 1, 1, 12, 34, 56, tzinfo=pytz.utc) @@ -169,22 +169,22 @@ if __name__ == '__main__': - attack_pattern = stix2.v20.AttackPattern(**ATTACK_PATTERN_KWARGS, interoperability=True) - campaign = stix2.v20.Campaign(**CAMPAIGN_KWARGS, interoperability=True) - course_of_action = stix2.v20.CourseOfAction(**COURSE_OF_ACTION_KWARGS, interoperability=True) - identity = stix2.v20.Identity(**IDENTITY_KWARGS, interoperability=True) - indicator = stix2.v20.Indicator(**INDICATOR_KWARGS, interoperability=True) - intrusion_set = stix2.v20.IntrusionSet(**INTRUSION_SET_KWARGS, interoperability=True) - malware = stix2.v20.Malware(**MALWARE_KWARGS, interoperability=True) - marking_definition = stix2.v20.MarkingDefinition(**MARKING_DEFINITION_KWARGS, interoperability=True) - observed_data = stix2.v20.ObservedData(**OBSERVED_DATA_KWARGS, interoperability=True) - relationship = stix2.v20.Relationship(**RELATIONSHIP_KWARGS, interoperability=True) - sighting = stix2.v20.Sighting(**SIGHTING_KWARGS, interoperability=True) - threat_actor = stix2.v20.ThreatActor(**THREAT_ACTOR_KWARGS, interoperability=True) - tool = stix2.v20.Tool(**TOOL_KWARGS) - vulnerability = stix2.v20.Vulnerability(**VULNERABILITY_KWARGS, interoperability=True) - report = stix2.v20.Report(**REPORT_KWARGS, interoperability=True) - bundle = stix2.v20.Bundle( + attack_pattern = misp_lib_stix2.v20.AttackPattern(**ATTACK_PATTERN_KWARGS, interoperability=True) + campaign = misp_lib_stix2.v20.Campaign(**CAMPAIGN_KWARGS, interoperability=True) + course_of_action = misp_lib_stix2.v20.CourseOfAction(**COURSE_OF_ACTION_KWARGS, interoperability=True) + identity = misp_lib_stix2.v20.Identity(**IDENTITY_KWARGS, interoperability=True) + indicator = misp_lib_stix2.v20.Indicator(**INDICATOR_KWARGS, interoperability=True) + intrusion_set = misp_lib_stix2.v20.IntrusionSet(**INTRUSION_SET_KWARGS, interoperability=True) + malware = misp_lib_stix2.v20.Malware(**MALWARE_KWARGS, interoperability=True) + marking_definition = misp_lib_stix2.v20.MarkingDefinition(**MARKING_DEFINITION_KWARGS, interoperability=True) + observed_data = misp_lib_stix2.v20.ObservedData(**OBSERVED_DATA_KWARGS, interoperability=True) + relationship = misp_lib_stix2.v20.Relationship(**RELATIONSHIP_KWARGS, interoperability=True) + sighting = misp_lib_stix2.v20.Sighting(**SIGHTING_KWARGS, interoperability=True) + threat_actor = misp_lib_stix2.v20.ThreatActor(**THREAT_ACTOR_KWARGS, interoperability=True) + tool = misp_lib_stix2.v20.Tool(**TOOL_KWARGS) + vulnerability = misp_lib_stix2.v20.Vulnerability(**VULNERABILITY_KWARGS, interoperability=True) + report = misp_lib_stix2.v20.Report(**REPORT_KWARGS, interoperability=True) + bundle = misp_lib_stix2.v20.Bundle( **BUNDLE_KWARGS, interoperability=True, objects=[ attack_pattern, campaign, course_of_action, identity, indicator, @@ -192,5 +192,5 @@ relationship, sighting, threat_actor, vulnerability, report, ] ) - stix2.parse(dict(bundle), interoperability=True) + misp_lib_stix2.parse(dict(bundle), interoperability=True) print("All interoperability tests passed !") diff --git a/stix2/test/v20/test_intrusion_set.py b/misp_lib_stix2/test/v20/test_intrusion_set.py similarity index 94% rename from stix2/test/v20/test_intrusion_set.py rename to misp_lib_stix2/test/v20/test_intrusion_set.py index 59a99050..4cd2b2f6 100644 --- a/stix2/test/v20/test_intrusion_set.py +++ b/misp_lib_stix2/test/v20/test_intrusion_set.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import IDENTITY_ID, INTRUSION_SET_ID @@ -27,7 +27,7 @@ def test_intrusion_set_example(): - intrusion_set = stix2.v20.IntrusionSet( + intrusion_set = misp_lib_stix2.v20.IntrusionSet( id=INTRUSION_SET_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T20:03:48.000Z", @@ -64,7 +64,7 @@ def test_intrusion_set_example(): ], ) def test_parse_intrusion_set(data): - intset = stix2.parse(data, version="2.0") + intset = misp_lib_stix2.parse(data, version="2.0") assert intset.type == "intrusion-set" assert intset.id == INTRUSION_SET_ID diff --git a/stix2/test/v21/test_kill_chain_phases.py b/misp_lib_stix2/test/v20/test_kill_chain_phases.py similarity index 55% rename from stix2/test/v21/test_kill_chain_phases.py rename to misp_lib_stix2/test/v20/test_kill_chain_phases.py index 9e29e884..ecf6d50a 100644 --- a/stix2/test/v21/test_kill_chain_phases.py +++ b/misp_lib_stix2/test/v20/test_kill_chain_phases.py @@ -2,7 +2,7 @@ import pytest -import stix2 +import misp_lib_stix2 LMCO_RECON = """{ "kill_chain_name": "lockheed-martin-cyber-kill-chain", @@ -11,7 +11,7 @@ def test_lockheed_martin_cyber_kill_chain(): - recon = stix2.v21.KillChainPhase( + recon = misp_lib_stix2.v20.KillChainPhase( kill_chain_name="lockheed-martin-cyber-kill-chain", phase_name="reconnaissance", ) @@ -26,7 +26,7 @@ def test_lockheed_martin_cyber_kill_chain(): def test_kill_chain_example(): - preattack = stix2.v21.KillChainPhase( + preattack = misp_lib_stix2.v20.KillChainPhase( kill_chain_name="foo", phase_name="pre-attack", ) @@ -36,26 +36,26 @@ def test_kill_chain_example(): def test_kill_chain_required_properties(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v21.KillChainPhase() + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v20.KillChainPhase() - assert excinfo.value.cls == stix2.v21.KillChainPhase + assert excinfo.value.cls == misp_lib_stix2.v20.KillChainPhase assert excinfo.value.properties == ["kill_chain_name", "phase_name"] def test_kill_chain_required_property_chain_name(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v21.KillChainPhase(phase_name="weaponization") + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v20.KillChainPhase(phase_name="weaponization") - assert excinfo.value.cls == stix2.v21.KillChainPhase + assert excinfo.value.cls == misp_lib_stix2.v20.KillChainPhase assert excinfo.value.properties == ["kill_chain_name"] def test_kill_chain_required_property_phase_name(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v21.KillChainPhase(kill_chain_name="lockheed-martin-cyber-kill-chain") + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v20.KillChainPhase(kill_chain_name="lockheed-martin-cyber-kill-chain") - assert excinfo.value.cls == stix2.v21.KillChainPhase + assert excinfo.value.cls == misp_lib_stix2.v20.KillChainPhase assert excinfo.value.properties == ["phase_name"] diff --git a/stix2/test/v20/test_malware.py b/misp_lib_stix2/test/v20/test_malware.py similarity index 77% rename from stix2/test/v20/test_malware.py rename to misp_lib_stix2/test/v20/test_malware.py index 974caf03..85a48aba 100644 --- a/stix2/test/v20/test_malware.py +++ b/misp_lib_stix2/test/v20/test_malware.py @@ -4,7 +4,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from ...exceptions import InvalidValueError from .constants import FAKE_TIME, MALWARE_ID, MALWARE_KWARGS @@ -24,7 +24,7 @@ def test_malware_with_all_required_properties(): now = dt.datetime(2016, 5, 12, 8, 17, 27, tzinfo=pytz.utc) - mal = stix2.v20.Malware( + mal = misp_lib_stix2.v20.Malware( type="malware", id=MALWARE_ID, created=now, @@ -39,7 +39,7 @@ def test_malware_with_all_required_properties(): def test_malware_with_empty_optional_field(): now = dt.datetime(2016, 5, 12, 8, 17, 27, tzinfo=pytz.utc) - mal = stix2.v20.Malware( + mal = misp_lib_stix2.v20.Malware( type="malware", id=MALWARE_ID, created=now, @@ -69,53 +69,53 @@ def test_malware_autogenerated_properties(malware): def test_malware_type_must_be_malware(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Malware(type='xxx', **MALWARE_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Malware(type='xxx', **MALWARE_KWARGS) - assert excinfo.value.cls == stix2.v20.Malware + assert excinfo.value.cls == misp_lib_stix2.v20.Malware assert excinfo.value.prop_name == "type" assert excinfo.value.reason == "must equal 'malware'." assert str(excinfo.value) == "Invalid value for Malware 'type': must equal 'malware'." def test_malware_id_must_start_with_malware(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Malware(id='my-prefix--', **MALWARE_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Malware(id='my-prefix--', **MALWARE_KWARGS) - assert excinfo.value.cls == stix2.v20.Malware + assert excinfo.value.cls == misp_lib_stix2.v20.Malware assert excinfo.value.prop_name == "id" assert excinfo.value.reason == "must start with 'malware--'." assert str(excinfo.value) == "Invalid value for Malware 'id': must start with 'malware--'." def test_malware_required_properties(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v20.Malware() + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v20.Malware() - assert excinfo.value.cls == stix2.v20.Malware + assert excinfo.value.cls == misp_lib_stix2.v20.Malware assert excinfo.value.properties == ["labels", "name"] def test_malware_required_property_name(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v20.Malware(labels=['ransomware']) + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v20.Malware(labels=['ransomware']) - assert excinfo.value.cls == stix2.v20.Malware + assert excinfo.value.cls == misp_lib_stix2.v20.Malware assert excinfo.value.properties == ["name"] def test_cannot_assign_to_malware_attributes(malware): - with pytest.raises(stix2.exceptions.ImmutableError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.ImmutableError) as excinfo: malware.name = "Cryptolocker II" assert str(excinfo.value) == "Cannot modify 'name' property in 'Malware' after creation." def test_invalid_kwarg_to_malware(): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v20.Malware(my_custom_property="foo", **MALWARE_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v20.Malware(my_custom_property="foo", **MALWARE_KWARGS) - assert excinfo.value.cls == stix2.v20.Malware + assert excinfo.value.cls == misp_lib_stix2.v20.Malware assert excinfo.value.properties == ['my_custom_property'] assert str(excinfo.value) == "Unexpected properties for Malware: (my_custom_property)." @@ -134,7 +134,7 @@ def test_invalid_kwarg_to_malware(): ], ) def test_parse_malware(data): - mal = stix2.parse(data, version="2.0") + mal = misp_lib_stix2.parse(data, version="2.0") assert mal.type == 'malware' assert mal.id == MALWARE_ID @@ -147,7 +147,7 @@ def test_parse_malware(data): def test_parse_malware_invalid_labels(): data = re.compile('\\[.+\\]', re.DOTALL).sub('1', EXPECTED_MALWARE) with pytest.raises(InvalidValueError) as excinfo: - stix2.parse(data, version="2.0") + misp_lib_stix2.parse(data, version="2.0") assert "Invalid value for Malware 'labels'" in str(excinfo.value) @@ -160,7 +160,7 @@ def test_parse_malware_kill_chain_phases(): } ]""" data = EXPECTED_MALWARE.replace('malware"', 'malware",%s' % kill_chain) - mal = stix2.parse(data, version="2.0") + mal = misp_lib_stix2.parse(data, version="2.0") assert mal.kill_chain_phases[0].kill_chain_name == "lockheed-martin-cyber-kill-chain" assert mal.kill_chain_phases[0].phase_name == "reconnaissance" assert mal['kill_chain_phases'][0]['kill_chain_name'] == "lockheed-martin-cyber-kill-chain" @@ -176,5 +176,5 @@ def test_parse_malware_clean_kill_chain_phases(): } ]""" data = EXPECTED_MALWARE.replace('malware"', 'malware",%s' % kill_chain) - mal = stix2.parse(data, version="2.0") + mal = misp_lib_stix2.parse(data, version="2.0") assert mal['kill_chain_phases'][0]['phase_name'] == "1" diff --git a/stix2/test/v20/test_marking_definition.py b/misp_lib_stix2/test/v20/test_marking_definition.py similarity index 98% rename from stix2/test/v20/test_marking_definition.py rename to misp_lib_stix2/test/v20/test_marking_definition.py index 20575fa2..c01e1312 100644 --- a/stix2/test/v20/test_marking_definition.py +++ b/misp_lib_stix2/test/v20/test_marking_definition.py @@ -1,8 +1,8 @@ import pytest -from stix2 import exceptions -from stix2.v20 import ( +from misp_lib_stix2 import exceptions +from misp_lib_stix2.v20 import ( TLP_AMBER, TLP_GREEN, TLP_RED, TLP_WHITE, MarkingDefinition, TLPMarking, ) diff --git a/stix2/test/v20/test_markings.py b/misp_lib_stix2/test/v20/test_markings.py similarity index 83% rename from stix2/test/v20/test_markings.py rename to misp_lib_stix2/test/v20/test_markings.py index 70b46a65..c1efa967 100644 --- a/stix2/test/v20/test_markings.py +++ b/misp_lib_stix2/test/v20/test_markings.py @@ -3,8 +3,8 @@ import pytest import pytz -import stix2 -from stix2.v20 import TLP_WHITE +import misp_lib_stix2 +from misp_lib_stix2.v20 import TLP_WHITE from .constants import CAMPAIGN_ID, IDENTITY_ID, MARKING_DEFINITION_ID @@ -75,11 +75,11 @@ def test_marking_def_example_with_tlp(): def test_marking_def_example_with_statement_positional_argument(): - marking_definition = stix2.v20.MarkingDefinition( + marking_definition = misp_lib_stix2.v20.MarkingDefinition( id=MARKING_DEFINITION_ID, created="2017-01-20T00:00:00.000Z", definition_type="statement", - definition=stix2.v20.StatementMarking(statement="Copyright 2016, Example Corp"), + definition=misp_lib_stix2.v20.StatementMarking(statement="Copyright 2016, Example Corp"), ) assert marking_definition.serialize(pretty=True) == EXPECTED_STATEMENT_MARKING_DEFINITION @@ -87,11 +87,11 @@ def test_marking_def_example_with_statement_positional_argument(): def test_marking_def_example_with_kwargs_statement(): kwargs = dict(statement="Copyright 2016, Example Corp") - marking_definition = stix2.v20.MarkingDefinition( + marking_definition = misp_lib_stix2.v20.MarkingDefinition( id=MARKING_DEFINITION_ID, created="2017-01-20T00:00:00.000Z", definition_type="statement", - definition=stix2.v20.StatementMarking(**kwargs), + definition=misp_lib_stix2.v20.StatementMarking(**kwargs), ) assert marking_definition.serialize(pretty=True) == EXPECTED_STATEMENT_MARKING_DEFINITION @@ -99,16 +99,16 @@ def test_marking_def_example_with_kwargs_statement(): def test_marking_def_invalid_type(): with pytest.raises(ValueError): - stix2.v20.MarkingDefinition( + misp_lib_stix2.v20.MarkingDefinition( id=MARKING_DEFINITION_ID, created="2017-01-20T00:00:00.000Z", definition_type="my-definition-type", - definition=stix2.v20.StatementMarking("Copyright 2016, Example Corp"), + definition=misp_lib_stix2.v20.StatementMarking("Copyright 2016, Example Corp"), ) def test_campaign_with_markings_example(): - campaign = stix2.v20.Campaign( + campaign = misp_lib_stix2.v20.Campaign( type='campaign', id=CAMPAIGN_ID, created_by_ref=IDENTITY_ID, @@ -122,7 +122,7 @@ def test_campaign_with_markings_example(): def test_granular_example(): - granular_marking = stix2.v20.GranularMarking( + granular_marking = misp_lib_stix2.v20.GranularMarking( marking_ref=MARKING_DEFINITION_ID, selectors=["abc", "abc.[23]", "abc.def", "abc.[2].efg"], ) @@ -131,20 +131,20 @@ def test_granular_example(): def test_granular_example_with_bad_selector(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.GranularMarking( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.GranularMarking( marking_ref=MARKING_DEFINITION_ID, selectors=["abc[0]"], # missing "." ) - assert excinfo.value.cls == stix2.v20.GranularMarking + assert excinfo.value.cls == misp_lib_stix2.v20.GranularMarking assert excinfo.value.prop_name == "selectors" assert excinfo.value.reason == "must adhere to selector syntax." assert str(excinfo.value) == "Invalid value for GranularMarking 'selectors': must adhere to selector syntax." def test_campaign_with_granular_markings_example(): - campaign = stix2.v20.Campaign( + campaign = misp_lib_stix2.v20.Campaign( type='campaign', id=CAMPAIGN_ID, created_by_ref=IDENTITY_ID, @@ -153,7 +153,7 @@ def test_campaign_with_granular_markings_example(): name="Green Group Attacks Against Finance", description="Campaign by Green Group against a series of targets in the financial services sector.", granular_markings=[ - stix2.v20.GranularMarking( + misp_lib_stix2.v20.GranularMarking( marking_ref=MARKING_DEFINITION_ID, selectors=["description"], ), @@ -177,7 +177,7 @@ def test_campaign_with_granular_markings_example(): ], ) def test_parse_marking_definition(data): - gm = stix2.parse(data, version="2.0") + gm = misp_lib_stix2.parse(data, version="2.0") assert gm.type == 'marking-definition' assert gm.id == MARKING_DEFINITION_ID @@ -186,10 +186,10 @@ def test_parse_marking_definition(data): assert gm.definition_type == "tlp" -@stix2.v20.CustomMarking( +@misp_lib_stix2.v20.CustomMarking( 'x-new-marking-type', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewMarking(object): @@ -201,7 +201,7 @@ def __init__(self, property2=None, **kwargs): def test_registered_custom_marking(): nm = NewMarking(property1='something', property2=55) - marking_def = stix2.v20.MarkingDefinition( + marking_def = misp_lib_stix2.v20.MarkingDefinition( id="marking-definition--00000000-0000-4000-8000-000000000012", created="2017-01-22T00:00:00.000Z", definition_type="x-new-marking-type", @@ -226,10 +226,10 @@ def test_registered_custom_marking_raises_exception(): def test_not_registered_marking_raises_exception(): with pytest.raises(ValueError) as excinfo: # Used custom object on purpose to demonstrate a not-registered marking - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x-new-marking-type2', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewObject2(object): @@ -238,7 +238,7 @@ def __init__(self, property2=None, **kwargs): no = NewObject2(property1='something', property2=55) - stix2.v20.MarkingDefinition( + misp_lib_stix2.v20.MarkingDefinition( id="marking-definition--00000000-0000-4000-8000-000000000012", created="2017-01-22T00:00:00.000Z", definition_type="x-new-marking-type2", @@ -251,13 +251,13 @@ def __init__(self, property2=None, **kwargs): def test_marking_wrong_type_construction(): with pytest.raises(ValueError): # Test passing wrong type for properties. - @stix2.v20.CustomMarking('x-new-marking-type2', ("a", "b")) + @misp_lib_stix2.v20.CustomMarking('x-new-marking-type2', ("a", "b")) class NewObject3(object): pass def test_campaign_add_markings(): - campaign = stix2.v20.Campaign( + campaign = misp_lib_stix2.v20.Campaign( id=CAMPAIGN_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T20:03:00Z", diff --git a/stix2/test/v20/test_object_markings.py b/misp_lib_stix2/test/v20/test_object_markings.py similarity index 99% rename from stix2/test/v20/test_object_markings.py rename to misp_lib_stix2/test/v20/test_object_markings.py index 6bd2269d..ff5d7735 100644 --- a/stix2/test/v20/test_object_markings.py +++ b/misp_lib_stix2/test/v20/test_object_markings.py @@ -1,8 +1,8 @@ import pytest -from stix2 import exceptions, markings -from stix2.v20 import TLP_AMBER, Malware +from misp_lib_stix2 import exceptions, markings +from misp_lib_stix2.v20 import TLP_AMBER, Malware from ...exceptions import MarkingNotFoundError from .constants import FAKE_TIME, MALWARE_ID diff --git a/stix2/test/v20/test_observed_data.py b/misp_lib_stix2/test/v20/test_observed_data.py similarity index 87% rename from stix2/test/v20/test_observed_data.py rename to misp_lib_stix2/test/v20/test_observed_data.py index 196fb46d..906243b7 100644 --- a/stix2/test/v20/test_observed_data.py +++ b/misp_lib_stix2/test/v20/test_observed_data.py @@ -4,7 +4,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from ...exceptions import InvalidValueError from .constants import IDENTITY_ID, OBSERVED_DATA_ID @@ -31,7 +31,7 @@ def test_observed_data_example(): - observed_data = stix2.v20.ObservedData( + observed_data = misp_lib_stix2.v20.ObservedData( id=OBSERVED_DATA_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T19:58:16.000Z", @@ -76,7 +76,7 @@ def test_observed_data_example(): def test_observed_data_example_with_refs(): - observed_data = stix2.v20.ObservedData( + observed_data = misp_lib_stix2.v20.ObservedData( id=OBSERVED_DATA_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T19:58:16.000Z", @@ -101,8 +101,8 @@ def test_observed_data_example_with_refs(): def test_observed_data_example_with_bad_refs(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.ObservedData( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.ObservedData( id=OBSERVED_DATA_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T19:58:16.000Z", @@ -123,14 +123,14 @@ def test_observed_data_example_with_bad_refs(): }, ) - assert excinfo.value.cls == stix2.v20.ObservedData + assert excinfo.value.cls == misp_lib_stix2.v20.ObservedData assert excinfo.value.prop_name == "objects" assert excinfo.value.reason == "Invalid object reference for 'Directory:contains_refs': '2' is not a valid object in local scope" def test_observed_data_example_with_non_dictionary(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.ObservedData( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.ObservedData( id=OBSERVED_DATA_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T19:58:16.000Z", @@ -141,14 +141,14 @@ def test_observed_data_example_with_non_dictionary(): objects="file: foo.exe", ) - assert excinfo.value.cls == stix2.v20.ObservedData + assert excinfo.value.cls == misp_lib_stix2.v20.ObservedData assert excinfo.value.prop_name == "objects" assert 'must contain a dictionary' in excinfo.value.reason def test_observed_data_example_with_empty_dictionary(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.ObservedData( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.ObservedData( id=OBSERVED_DATA_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T19:58:16.000Z", @@ -159,7 +159,7 @@ def test_observed_data_example_with_empty_dictionary(): objects={}, ) - assert excinfo.value.cls == stix2.v20.ObservedData + assert excinfo.value.cls == misp_lib_stix2.v20.ObservedData assert excinfo.value.prop_name == "objects" assert 'must contain a non-empty dictionary' in excinfo.value.reason @@ -186,7 +186,7 @@ def test_observed_data_example_with_empty_dictionary(): ], ) def test_parse_observed_data(data): - odata = stix2.parse(data, version="2.0") + odata = misp_lib_stix2.parse(data, version="2.0") assert odata.type == 'observed-data' assert odata.id == OBSERVED_DATA_ID @@ -217,7 +217,7 @@ def test_parse_observed_data(data): ) def test_parse_artifact_valid(data): odata_str = OBJECTS_REGEX.sub('"objects": { %s }' % data, EXPECTED) - odata = stix2.parse(odata_str, version="2.0") + odata = misp_lib_stix2.parse(odata_str, version="2.0") assert odata.objects["0"].type == "artifact" @@ -241,12 +241,12 @@ def test_parse_artifact_valid(data): def test_parse_artifact_invalid(data): odata_str = OBJECTS_REGEX.sub('"objects": { %s }' % data, EXPECTED) with pytest.raises(InvalidValueError): - stix2.parse(odata_str, version="2.0") + misp_lib_stix2.parse(odata_str, version="2.0") def test_artifact_example_dependency_error(): - with pytest.raises(stix2.exceptions.DependentPropertiesError) as excinfo: - stix2.v20.Artifact(url="http://example.com/sirvizio.exe") + with pytest.raises(misp_lib_stix2.exceptions.DependentPropertiesError) as excinfo: + misp_lib_stix2.v20.Artifact(url="http://example.com/sirvizio.exe") assert excinfo.value.dependencies == [("hashes", "url")] assert str(excinfo.value) == "The property dependencies for Artifact: (hashes, url) are not met." @@ -264,7 +264,7 @@ def test_artifact_example_dependency_error(): ) def test_parse_autonomous_system_valid(data): odata_str = OBJECTS_REGEX.sub('"objects": { %s }' % data, EXPECTED) - odata = stix2.parse(odata_str, version="2.0") + odata = misp_lib_stix2.parse(odata_str, version="2.0") assert odata.objects["0"].type == "autonomous-system" assert odata.objects["0"].number == 15139 assert odata.objects["0"].name == "Slime Industries" @@ -282,12 +282,12 @@ def test_parse_autonomous_system_valid(data): ], ) def test_parse_email_address(data): - odata = stix2.parse_observable(data, {"0": "user-account"}, version='2.0') + odata = misp_lib_stix2.parse_observable(data, {"0": "user-account"}, version='2.0') assert odata.type == "email-addr" odata_str = re.compile('"belongs_to_ref": "0"', re.DOTALL).sub('"belongs_to_ref": "3"', data) - with pytest.raises(stix2.exceptions.InvalidObjRefError): - stix2.parse_observable(odata_str, {"0": "user-account"}, version='2.0') + with pytest.raises(misp_lib_stix2.exceptions.InvalidObjRefError): + misp_lib_stix2.parse_observable(odata_str, {"0": "user-account"}, version='2.0') @pytest.mark.parametrize( @@ -341,7 +341,7 @@ def test_parse_email_message(data): "4": "artifact", "5": "file", } - odata = stix2.parse_observable(data, valid_refs, version='2.0') + odata = misp_lib_stix2.parse_observable(data, valid_refs, version='2.0') assert odata.type == "email-message" assert odata.body_multipart[0].content_disposition == "inline" @@ -366,10 +366,10 @@ def test_parse_email_message_not_multipart(data): "0": "email-addr", "1": "email-addr", } - with pytest.raises(stix2.exceptions.DependentPropertiesError) as excinfo: - stix2.parse_observable(data, valid_refs, version='2.0') + with pytest.raises(misp_lib_stix2.exceptions.DependentPropertiesError) as excinfo: + misp_lib_stix2.parse_observable(data, valid_refs, version='2.0') - assert excinfo.value.cls == stix2.v20.EmailMessage + assert excinfo.value.cls == misp_lib_stix2.v20.EmailMessage assert excinfo.value.dependencies == [("is_multipart", "body")] @@ -415,7 +415,7 @@ def test_parse_email_message_not_multipart(data): ) def test_parse_file_archive(data): odata_str = OBJECTS_REGEX.sub('"objects": { %s }' % data, EXPECTED) - odata = stix2.parse(odata_str, version="2.0") + odata = misp_lib_stix2.parse(odata_str, version="2.0") assert odata.objects["3"].extensions['archive-ext'].version == "5.0" @@ -470,9 +470,9 @@ def test_parse_email_message_with_at_least_one_error(data): "5": "file", } with pytest.raises(InvalidValueError) as excinfo: - stix2.parse_observable(data, valid_refs, version='2.0') + misp_lib_stix2.parse_observable(data, valid_refs, version='2.0') - assert excinfo.value.cls == stix2.v20.EmailMessage + assert excinfo.value.cls == misp_lib_stix2.v20.EmailMessage assert "At least one of the" in str(excinfo.value) assert "must be populated" in str(excinfo.value) @@ -492,7 +492,7 @@ def test_parse_email_message_with_at_least_one_error(data): ], ) def test_parse_basic_tcp_traffic(data): - odata = stix2.parse_observable( + odata = misp_lib_stix2.parse_observable( data, {"0": "ipv4-addr", "1": "ipv4-addr"}, version='2.0', ) @@ -524,10 +524,10 @@ def test_parse_basic_tcp_traffic(data): ], ) def test_parse_basic_tcp_traffic_with_error(data): - with pytest.raises(stix2.exceptions.AtLeastOnePropertyError) as excinfo: - stix2.parse_observable(data, {"4": "network-traffic"}, version='2.0') + with pytest.raises(misp_lib_stix2.exceptions.AtLeastOnePropertyError) as excinfo: + misp_lib_stix2.parse_observable(data, {"4": "network-traffic"}, version='2.0') - assert excinfo.value.cls == stix2.v20.NetworkTraffic + assert excinfo.value.cls == misp_lib_stix2.v20.NetworkTraffic assert excinfo.value.properties == ["dst_ref", "src_ref"] @@ -562,7 +562,7 @@ def test_parse_basic_tcp_traffic_with_error(data): def test_observed_data_with_process_example(): - observed_data = stix2.v20.ObservedData( + observed_data = misp_lib_stix2.v20.ObservedData( id=OBSERVED_DATA_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T19:58:16.000Z", @@ -601,7 +601,7 @@ def test_observed_data_with_process_example(): # creating cyber observables directly def test_artifact_example(): - art = stix2.v20.Artifact( + art = misp_lib_stix2.v20.Artifact( mime_type="image/jpeg", url="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg", hashes={ @@ -614,8 +614,8 @@ def test_artifact_example(): def test_artifact_mutual_exclusion_error(): - with pytest.raises(stix2.exceptions.MutuallyExclusivePropertiesError) as excinfo: - stix2.v20.Artifact( + with pytest.raises(misp_lib_stix2.exceptions.MutuallyExclusivePropertiesError) as excinfo: + misp_lib_stix2.v20.Artifact( mime_type="image/jpeg", url="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg", hashes={ @@ -624,13 +624,13 @@ def test_artifact_mutual_exclusion_error(): payload_bin="VBORw0KGgoAAAANSUhEUgAAADI==", ) - assert excinfo.value.cls == stix2.v20.Artifact + assert excinfo.value.cls == misp_lib_stix2.v20.Artifact assert excinfo.value.properties == ["payload_bin", "url"] assert 'are mutually exclusive' in str(excinfo.value) def test_directory_example(): - dir = stix2.v20.Directory( + dir = misp_lib_stix2.v20.Directory( _valid_refs={"1": "file"}, path='/usr/lib', created="2015-12-21T19:00:00Z", @@ -647,8 +647,8 @@ def test_directory_example(): def test_directory_example_ref_error(): - with pytest.raises(stix2.exceptions.InvalidObjRefError) as excinfo: - stix2.v20.Directory( + with pytest.raises(misp_lib_stix2.exceptions.InvalidObjRefError) as excinfo: + misp_lib_stix2.v20.Directory( _valid_refs=[], path='/usr/lib', created="2015-12-21T19:00:00Z", @@ -657,12 +657,12 @@ def test_directory_example_ref_error(): contains_refs=["1"], ) - assert excinfo.value.cls == stix2.v20.Directory + assert excinfo.value.cls == misp_lib_stix2.v20.Directory assert excinfo.value.prop_name == "contains_refs" def test_domain_name_example(): - dn = stix2.v20.DomainName( + dn = misp_lib_stix2.v20.DomainName( _valid_refs={"1": 'domain-name'}, value="example.com", resolves_to_refs=["1"], @@ -673,19 +673,19 @@ def test_domain_name_example(): def test_domain_name_example_invalid_ref_type(): - with pytest.raises(stix2.exceptions.InvalidObjRefError) as excinfo: - stix2.v20.DomainName( + with pytest.raises(misp_lib_stix2.exceptions.InvalidObjRefError) as excinfo: + misp_lib_stix2.v20.DomainName( _valid_refs={"1": "file"}, value="example.com", resolves_to_refs=["1"], ) - assert excinfo.value.cls == stix2.v20.DomainName + assert excinfo.value.cls == misp_lib_stix2.v20.DomainName assert excinfo.value.prop_name == "resolves_to_refs" def test_file_example(): - f = stix2.v20.File( + f = misp_lib_stix2.v20.File( name="qwerty.dll", hashes={ "SHA-256": "ceafbfd424be2ca4a5f0402cae090dda2fb0526cf521b60b60077c0f622b285a", @@ -715,7 +715,7 @@ def test_file_example(): def test_file_ssdeep_example(): - f = stix2.v20.File( + f = misp_lib_stix2.v20.File( name="example.dll", hashes={ "SHA-256": "ceafbfd424be2ca4a5f0402cae090dda2fb0526cf521b60b60077c0f622b285a", @@ -731,7 +731,7 @@ def test_file_ssdeep_example(): def test_file_example_with_NTFSExt(): - f = stix2.v20.File( + f = misp_lib_stix2.v20.File( name="abc.txt", extensions={ "ntfs-ext": { @@ -751,18 +751,18 @@ def test_file_example_with_NTFSExt(): def test_file_example_with_empty_NTFSExt(): with pytest.raises(InvalidValueError) as excinfo: - stix2.v20.File( + misp_lib_stix2.v20.File( name="abc.txt", extensions={ "ntfs-ext": {}, }, ) - assert excinfo.value.cls == stix2.v20.File + assert excinfo.value.cls == misp_lib_stix2.v20.File def test_file_example_with_PDFExt(): - f = stix2.v20.File( + f = misp_lib_stix2.v20.File( name="qwerty.dll", extensions={ "pdf-ext": { @@ -786,10 +786,10 @@ def test_file_example_with_PDFExt(): def test_file_example_with_PDFExt_Object(): - f = stix2.v20.File( + f = misp_lib_stix2.v20.File( name="qwerty.dll", extensions={ - "pdf-ext": stix2.v20.PDFExt( + "pdf-ext": misp_lib_stix2.v20.PDFExt( version="1.7", document_info_dict={ "Title": "Sample document", @@ -810,7 +810,7 @@ def test_file_example_with_PDFExt_Object(): def test_file_example_with_RasterImageExt_Object(): - f = stix2.v20.File( + f = misp_lib_stix2.v20.File( name="qwerty.jpeg", extensions={ "raster-image-ext": { @@ -865,17 +865,17 @@ def test_file_example_with_RasterImageExt_Object(): def test_raster_image_ext_parse(): - obj = stix2.parse(RASTER_IMAGE_EXT, version="2.0") + obj = misp_lib_stix2.parse(RASTER_IMAGE_EXT, version="2.0") assert obj.objects["0"].extensions['raster-image-ext'].image_width == 1024 def test_raster_images_ext_create(): - ext = stix2.v20.RasterImageExt(image_width=1024) + ext = misp_lib_stix2.v20.RasterImageExt(image_width=1024) assert "image_width" in str(ext) def test_file_example_with_WindowsPEBinaryExt(): - f = stix2.v20.File( + f = misp_lib_stix2.v20.File( name="qwerty.dll", extensions={ "windows-pebinary-ext": { @@ -945,27 +945,27 @@ def test_file_example_with_WindowsPEBinaryExt(): def test_file_example_encryption_error(): - with pytest.raises(stix2.exceptions.DependentPropertiesError) as excinfo: - stix2.v20.File( + with pytest.raises(misp_lib_stix2.exceptions.DependentPropertiesError) as excinfo: + misp_lib_stix2.v20.File( name="qwerty.dll", is_encrypted=False, encryption_algorithm="AES128-CBC", ) - assert excinfo.value.cls == stix2.v20.File + assert excinfo.value.cls == misp_lib_stix2.v20.File assert excinfo.value.dependencies == [("is_encrypted", "encryption_algorithm")] assert "property dependencies" in str(excinfo.value) assert "are not met" in str(excinfo.value) - with pytest.raises(stix2.exceptions.DependentPropertiesError) as excinfo: - stix2.v20.File( + with pytest.raises(misp_lib_stix2.exceptions.DependentPropertiesError) as excinfo: + misp_lib_stix2.v20.File( name="qwerty.dll", encryption_algorithm="AES128-CBC", ) def test_ip4_address_example(): - ip4 = stix2.v20.IPv4Address( + ip4 = misp_lib_stix2.v20.IPv4Address( _valid_refs={"4": "mac-addr", "5": "mac-addr"}, value="198.51.100.3", resolves_to_refs=["4", "5"], @@ -976,14 +976,14 @@ def test_ip4_address_example(): def test_ip4_address_valid_refs(): - mac1 = stix2.v20.MACAddress( + mac1 = misp_lib_stix2.v20.MACAddress( value="a1:b2:c3:d4:e5:f6", ) - mac2 = stix2.v20.MACAddress( + mac2 = misp_lib_stix2.v20.MACAddress( value="a7:b8:c9:d0:e1:f2", ) - ip4 = stix2.v20.IPv4Address( + ip4 = misp_lib_stix2.v20.IPv4Address( _valid_refs={"1": mac1, "2": mac2}, value="177.60.40.7", resolves_to_refs=["1", "2"], @@ -994,25 +994,25 @@ def test_ip4_address_valid_refs(): def test_ip4_address_example_cidr(): - ip4 = stix2.v20.IPv4Address(value="198.51.100.0/24") + ip4 = misp_lib_stix2.v20.IPv4Address(value="198.51.100.0/24") assert ip4.value == "198.51.100.0/24" def test_ip6_address_example(): - ip6 = stix2.v20.IPv6Address(value="2001:0db8:85a3:0000:0000:8a2e:0370:7334") + ip6 = misp_lib_stix2.v20.IPv6Address(value="2001:0db8:85a3:0000:0000:8a2e:0370:7334") assert ip6.value == "2001:0db8:85a3:0000:0000:8a2e:0370:7334" def test_mac_address_example(): - ip6 = stix2.v20.MACAddress(value="d2:fb:49:24:37:18") + ip6 = misp_lib_stix2.v20.MACAddress(value="d2:fb:49:24:37:18") assert ip6.value == "d2:fb:49:24:37:18" def test_network_traffic_example(): - nt = stix2.v20.NetworkTraffic( + nt = misp_lib_stix2.v20.NetworkTraffic( _valid_refs={"0": "ipv4-addr", "1": "ipv4-addr"}, protocols="tcp", src_ref="0", @@ -1024,7 +1024,7 @@ def test_network_traffic_example(): def test_network_traffic_http_request_example(): - h = stix2.v20.HTTPRequestExt( + h = misp_lib_stix2.v20.HTTPRequestExt( request_method="get", request_value="/download.html", request_version="http/1.1", @@ -1034,7 +1034,7 @@ def test_network_traffic_http_request_example(): "Host": "www.example.com", }, ) - nt = stix2.v20.NetworkTraffic( + nt = misp_lib_stix2.v20.NetworkTraffic( _valid_refs={"0": "ipv4-addr"}, protocols="tcp", src_ref="0", @@ -1049,8 +1049,8 @@ def test_network_traffic_http_request_example(): def test_network_traffic_icmp_example(): - h = stix2.v20.ICMPExt(icmp_type_hex="08", icmp_code_hex="00") - nt = stix2.v20.NetworkTraffic( + h = misp_lib_stix2.v20.ICMPExt(icmp_type_hex="08", icmp_code_hex="00") + nt = misp_lib_stix2.v20.NetworkTraffic( _valid_refs={"0": "ipv4-addr"}, protocols="tcp", src_ref="0", @@ -1061,13 +1061,13 @@ def test_network_traffic_icmp_example(): def test_network_traffic_socket_example(): - h = stix2.v20.SocketExt( + h = misp_lib_stix2.v20.SocketExt( is_listening=True, address_family="AF_INET", protocol_family="PF_INET", socket_type="SOCK_STREAM", ) - nt = stix2.v20.NetworkTraffic( + nt = misp_lib_stix2.v20.NetworkTraffic( _valid_refs={"0": "ipv4-addr"}, protocols="tcp", src_ref="0", @@ -1080,8 +1080,8 @@ def test_network_traffic_socket_example(): def test_network_traffic_tcp_example(): - h = stix2.v20.TCPExt(src_flags_hex="00000002") - nt = stix2.v20.NetworkTraffic( + h = misp_lib_stix2.v20.TCPExt(src_flags_hex="00000002") + nt = misp_lib_stix2.v20.NetworkTraffic( _valid_refs={"0": "ipv4-addr"}, protocols="tcp", src_ref="0", @@ -1091,13 +1091,13 @@ def test_network_traffic_tcp_example(): def test_mutex_example(): - m = stix2.v20.Mutex(name="barney") + m = misp_lib_stix2.v20.Mutex(name="barney") assert m.name == "barney" def test_process_example(): - p = stix2.v20.Process( + p = misp_lib_stix2.v20.Process( _valid_refs={"0": "file"}, pid=1221, name="gedit-bin", @@ -1111,17 +1111,17 @@ def test_process_example(): def test_process_example_empty_error(): - with pytest.raises(stix2.exceptions.AtLeastOnePropertyError) as excinfo: - stix2.v20.Process() + with pytest.raises(misp_lib_stix2.exceptions.AtLeastOnePropertyError) as excinfo: + misp_lib_stix2.v20.Process() - assert excinfo.value.cls == stix2.v20.Process - properties_of_process = list(stix2.v20.Process._properties.keys()) + assert excinfo.value.cls == misp_lib_stix2.v20.Process + properties_of_process = list(misp_lib_stix2.v20.Process._properties.keys()) properties_of_process.remove("type") properties_of_process.remove("extensions") assert excinfo.value.properties == sorted(properties_of_process) msg = "At least one of the ({1}) properties for {0} must be populated." msg = msg.format( - stix2.v20.Process.__name__, + misp_lib_stix2.v20.Process.__name__, ", ".join(sorted(properties_of_process)), ) assert str(excinfo.value) == msg @@ -1129,17 +1129,17 @@ def test_process_example_empty_error(): def test_process_example_empty_with_extensions(): with pytest.raises(InvalidValueError) as excinfo: - stix2.v20.Process( + misp_lib_stix2.v20.Process( extensions={ "windows-process-ext": {}, }, ) - assert excinfo.value.cls == stix2.v20.Process + assert excinfo.value.cls == misp_lib_stix2.v20.Process def test_process_example_windows_process_ext(): - proc = stix2.v20.Process( + proc = misp_lib_stix2.v20.Process( pid=314, name="foobar.exe", extensions={ @@ -1159,7 +1159,7 @@ def test_process_example_windows_process_ext(): def test_process_example_windows_process_ext_empty(): with pytest.raises(InvalidValueError) as excinfo: - stix2.v20.Process( + misp_lib_stix2.v20.Process( pid=1221, name="gedit-bin", extensions={ @@ -1167,11 +1167,11 @@ def test_process_example_windows_process_ext_empty(): }, ) - assert excinfo.value.cls == stix2.v20.Process + assert excinfo.value.cls == misp_lib_stix2.v20.Process def test_process_example_extensions_empty(): - proc = stix2.v20.Process( + proc = misp_lib_stix2.v20.Process( pid=314, name="foobar.exe", extensions={}, @@ -1181,9 +1181,9 @@ def test_process_example_extensions_empty(): def test_process_example_with_WindowsProcessExt_Object(): - p = stix2.v20.Process( + p = misp_lib_stix2.v20.Process( extensions={ - "windows-process-ext": stix2.v20.WindowsProcessExt( + "windows-process-ext": misp_lib_stix2.v20.WindowsProcessExt( aslr_enabled=True, dep_enabled=True, priority="HIGH_PRIORITY_CLASS", @@ -1197,7 +1197,7 @@ def test_process_example_with_WindowsProcessExt_Object(): def test_process_example_with_WindowsServiceExt(): - p = stix2.v20.Process( + p = misp_lib_stix2.v20.Process( extensions={ "windows-service-ext": { "service_name": "sirvizio", @@ -1214,7 +1214,7 @@ def test_process_example_with_WindowsServiceExt(): def test_process_example_with_WindowsProcessServiceExt(): - p = stix2.v20.Process( + p = misp_lib_stix2.v20.Process( extensions={ "windows-service-ext": { "service_name": "sirvizio", @@ -1239,7 +1239,7 @@ def test_process_example_with_WindowsProcessServiceExt(): def test_software_example(): - s = stix2.v20.Software( + s = misp_lib_stix2.v20.Software( name="Word", cpe="cpe:2.3:a:microsoft:word:2000:*:*:*:*:*:*:*", version="2002", @@ -1253,14 +1253,14 @@ def test_software_example(): def test_url_example(): - s = stix2.v20.URL(value="https://example.com/research/index.html") + s = misp_lib_stix2.v20.URL(value="https://example.com/research/index.html") assert s.type == "url" assert s.value == "https://example.com/research/index.html" def test_user_account_example(): - a = stix2.v20.UserAccount( + a = misp_lib_stix2.v20.UserAccount( user_id="1001", account_login="jdoe", account_type="unix", @@ -1288,13 +1288,13 @@ def test_user_account_example(): def test_user_account_unix_account_ext_example(): - u = stix2.v20.UNIXAccountExt( + u = misp_lib_stix2.v20.UNIXAccountExt( gid=1001, groups=["wheel"], home_dir="/home/jdoe", shell="/bin/bash", ) - a = stix2.v20.UserAccount( + a = misp_lib_stix2.v20.UserAccount( user_id="1001", account_login="jdoe", account_type="unix", @@ -1308,18 +1308,18 @@ def test_user_account_unix_account_ext_example(): def test_windows_registry_key_example(): with pytest.raises(InvalidValueError): - stix2.v20.WindowsRegistryValueType( + misp_lib_stix2.v20.WindowsRegistryValueType( name="Foo", data="qwerty", data_type="string", ) - v = stix2.v20.WindowsRegistryValueType( + v = misp_lib_stix2.v20.WindowsRegistryValueType( name="Foo", data="qwerty", data_type="REG_SZ", ) - w = stix2.v20.WindowsRegistryKey( + w = misp_lib_stix2.v20.WindowsRegistryKey( key="hkey_local_machine\\system\\bar\\foo", values=[v], ) @@ -1332,7 +1332,7 @@ def test_windows_registry_key_example(): def test_x509_certificate_example(): - x509 = stix2.v20.X509Certificate( + x509 = misp_lib_stix2.v20.X509Certificate( issuer="C=ZA, ST=Western Cape, L=Cape Town, O=Thawte Consulting cc, OU=Certification Services Division, CN=Thawte Server CA/emailAddress=server-certs@thawte.com", # noqa validity_not_before="2016-03-12T12:00:00Z", validity_not_after="2016-08-21T12:00:00Z", @@ -1345,7 +1345,7 @@ def test_x509_certificate_example(): def test_new_version_with_related_objects(): - data = stix2.v20.ObservedData( + data = misp_lib_stix2.v20.ObservedData( first_observed="2016-03-12T12:00:00Z", last_observed="2016-03-12T12:00:00Z", number_observed=1, diff --git a/stix2/test/v20/test_parsing.py b/misp_lib_stix2/test/v20/test_parsing.py similarity index 96% rename from stix2/test/v20/test_parsing.py rename to misp_lib_stix2/test/v20/test_parsing.py index 6317e5a0..129af764 100644 --- a/stix2/test/v20/test_parsing.py +++ b/misp_lib_stix2/test/v20/test_parsing.py @@ -2,7 +2,7 @@ import pytest -from stix2 import DEFAULT_VERSION, exceptions, parsing, registration, registry +from misp_lib_stix2 import DEFAULT_VERSION, exceptions, parsing, registration, registry BUNDLE = { "type": "bundle", diff --git a/stix2/test/v20/test_pattern_equivalence.py b/misp_lib_stix2/test/v20/test_pattern_equivalence.py similarity index 95% rename from stix2/test/v20/test_pattern_equivalence.py rename to misp_lib_stix2/test/v20/test_pattern_equivalence.py index aab85336..81010970 100644 --- a/stix2/test/v20/test_pattern_equivalence.py +++ b/misp_lib_stix2/test/v20/test_pattern_equivalence.py @@ -4,7 +4,7 @@ import pytest -from stix2.equivalence.pattern import equivalent_patterns +from misp_lib_stix2.equivalence.pattern import equivalent_patterns @pytest.mark.parametrize( diff --git a/stix2/test/v20/test_pattern_expressions.py b/misp_lib_stix2/test/v20/test_pattern_expressions.py similarity index 58% rename from stix2/test/v20/test_pattern_expressions.py rename to misp_lib_stix2/test/v20/test_pattern_expressions.py index 9579ef4c..e76e98c5 100644 --- a/stix2/test/v20/test_pattern_expressions.py +++ b/misp_lib_stix2/test/v20/test_pattern_expressions.py @@ -3,10 +3,10 @@ import pytest import pytz -import stix2 -from stix2.pattern_visitor import create_pattern_object -import stix2.patterns -import stix2.utils +import misp_lib_stix2 +from misp_lib_stix2.pattern_visitor import create_pattern_object +import misp_lib_stix2.patterns +import misp_lib_stix2.utils # flake8 does not approve of star imports. # flake8: noqa: F405 @@ -14,139 +14,139 @@ def test_create_comparison_expression(): - exp = stix2.EqualityComparisonExpression( + exp = misp_lib_stix2.EqualityComparisonExpression( "file:hashes.'SHA-256'", - stix2.HashConstant("aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f", "SHA-256"), + misp_lib_stix2.HashConstant("aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f", "SHA-256"), ) # noqa assert str(exp) == "file:hashes.'SHA-256' = 'aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f'" def test_boolean_expression(): - exp1 = stix2.MatchesComparisonExpression( + exp1 = misp_lib_stix2.MatchesComparisonExpression( "email-message:from_ref.value", - stix2.StringConstant(".+\\@example\\.com$"), + misp_lib_stix2.StringConstant(".+\\@example\\.com$"), ) - exp2 = stix2.MatchesComparisonExpression( + exp2 = misp_lib_stix2.MatchesComparisonExpression( "email-message:body_multipart[*].body_raw_ref.name", - stix2.StringConstant("^Final Report.+\\.exe$"), + misp_lib_stix2.StringConstant("^Final Report.+\\.exe$"), ) - exp = stix2.AndBooleanExpression([exp1, exp2]) + exp = misp_lib_stix2.AndBooleanExpression([exp1, exp2]) assert str(exp) == "email-message:from_ref.value MATCHES '.+\\\\@example\\\\.com$' AND email-message:body_multipart[*].body_raw_ref.name MATCHES '^Final Report.+\\\\.exe$'" # noqa def test_boolean_expression_with_parentheses(): - exp1 = stix2.MatchesComparisonExpression( - stix2.ObjectPath( + exp1 = misp_lib_stix2.MatchesComparisonExpression( + misp_lib_stix2.ObjectPath( "email-message", [ - stix2.ReferenceObjectPathComponent("from_ref"), - stix2.BasicObjectPathComponent("value", False), + misp_lib_stix2.ReferenceObjectPathComponent("from_ref"), + misp_lib_stix2.BasicObjectPathComponent("value", False), ], ), - stix2.StringConstant(".+\\@example\\.com$"), + misp_lib_stix2.StringConstant(".+\\@example\\.com$"), ) - exp2 = stix2.MatchesComparisonExpression( + exp2 = misp_lib_stix2.MatchesComparisonExpression( "email-message:body_multipart[*].body_raw_ref.name", - stix2.StringConstant("^Final Report.+\\.exe$"), + misp_lib_stix2.StringConstant("^Final Report.+\\.exe$"), ) - exp = stix2.ParentheticalExpression(stix2.AndBooleanExpression([exp1, exp2])) + exp = misp_lib_stix2.ParentheticalExpression(misp_lib_stix2.AndBooleanExpression([exp1, exp2])) assert str(exp) == "(email-message:from_ref.value MATCHES '.+\\\\@example\\\\.com$' AND email-message:body_multipart[*].body_raw_ref.name MATCHES '^Final Report.+\\\\.exe$')" # noqa def test_hash_followed_by_registryKey_expression_python_constant(): - hash_exp = stix2.EqualityComparisonExpression( + hash_exp = misp_lib_stix2.EqualityComparisonExpression( "file:hashes.MD5", - stix2.HashConstant("79054025255fb1a26e4bc422aef54eb4", "MD5"), - ) - o_exp1 = stix2.ObservationExpression(hash_exp) - reg_exp = stix2.EqualityComparisonExpression( - stix2.ObjectPath("windows-registry-key", ["key"]), - stix2.StringConstant("HKEY_LOCAL_MACHINE\\foo\\bar"), - ) - o_exp2 = stix2.ObservationExpression(reg_exp) - fb_exp = stix2.FollowedByObservationExpression([o_exp1, o_exp2]) - para_exp = stix2.ParentheticalExpression(fb_exp) - qual_exp = stix2.WithinQualifier(300) - exp = stix2.QualifiedObservationExpression(para_exp, qual_exp) + misp_lib_stix2.HashConstant("79054025255fb1a26e4bc422aef54eb4", "MD5"), + ) + o_exp1 = misp_lib_stix2.ObservationExpression(hash_exp) + reg_exp = misp_lib_stix2.EqualityComparisonExpression( + misp_lib_stix2.ObjectPath("windows-registry-key", ["key"]), + misp_lib_stix2.StringConstant("HKEY_LOCAL_MACHINE\\foo\\bar"), + ) + o_exp2 = misp_lib_stix2.ObservationExpression(reg_exp) + fb_exp = misp_lib_stix2.FollowedByObservationExpression([o_exp1, o_exp2]) + para_exp = misp_lib_stix2.ParentheticalExpression(fb_exp) + qual_exp = misp_lib_stix2.WithinQualifier(300) + exp = misp_lib_stix2.QualifiedObservationExpression(para_exp, qual_exp) assert str(exp) == "([file:hashes.MD5 = '79054025255fb1a26e4bc422aef54eb4'] FOLLOWEDBY [windows-registry-key:key = 'HKEY_LOCAL_MACHINE\\\\foo\\\\bar']) WITHIN 300 SECONDS" # noqa def test_hash_followed_by_registryKey_expression(): - hash_exp = stix2.EqualityComparisonExpression( + hash_exp = misp_lib_stix2.EqualityComparisonExpression( "file:hashes.MD5", - stix2.HashConstant("79054025255fb1a26e4bc422aef54eb4", "MD5"), - ) - o_exp1 = stix2.ObservationExpression(hash_exp) - reg_exp = stix2.EqualityComparisonExpression( - stix2.ObjectPath("windows-registry-key", ["key"]), - stix2.StringConstant("HKEY_LOCAL_MACHINE\\foo\\bar"), - ) - o_exp2 = stix2.ObservationExpression(reg_exp) - fb_exp = stix2.FollowedByObservationExpression([o_exp1, o_exp2]) - para_exp = stix2.ParentheticalExpression(fb_exp) - qual_exp = stix2.WithinQualifier(stix2.IntegerConstant(300)) - exp = stix2.QualifiedObservationExpression(para_exp, qual_exp) + misp_lib_stix2.HashConstant("79054025255fb1a26e4bc422aef54eb4", "MD5"), + ) + o_exp1 = misp_lib_stix2.ObservationExpression(hash_exp) + reg_exp = misp_lib_stix2.EqualityComparisonExpression( + misp_lib_stix2.ObjectPath("windows-registry-key", ["key"]), + misp_lib_stix2.StringConstant("HKEY_LOCAL_MACHINE\\foo\\bar"), + ) + o_exp2 = misp_lib_stix2.ObservationExpression(reg_exp) + fb_exp = misp_lib_stix2.FollowedByObservationExpression([o_exp1, o_exp2]) + para_exp = misp_lib_stix2.ParentheticalExpression(fb_exp) + qual_exp = misp_lib_stix2.WithinQualifier(misp_lib_stix2.IntegerConstant(300)) + exp = misp_lib_stix2.QualifiedObservationExpression(para_exp, qual_exp) assert str(exp) == "([file:hashes.MD5 = '79054025255fb1a26e4bc422aef54eb4'] FOLLOWEDBY [windows-registry-key:key = 'HKEY_LOCAL_MACHINE\\\\foo\\\\bar']) WITHIN 300 SECONDS" # noqa def test_file_observable_expression(): - exp1 = stix2.EqualityComparisonExpression( + exp1 = misp_lib_stix2.EqualityComparisonExpression( "file:hashes.'SHA-256'", - stix2.HashConstant( + misp_lib_stix2.HashConstant( "aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f", 'SHA-256', ), ) - exp2 = stix2.EqualityComparisonExpression("file:mime_type", stix2.StringConstant("application/x-pdf")) - bool_exp = stix2.ObservationExpression(stix2.AndBooleanExpression([exp1, exp2])) + exp2 = misp_lib_stix2.EqualityComparisonExpression("file:mime_type", misp_lib_stix2.StringConstant("application/x-pdf")) + bool_exp = misp_lib_stix2.ObservationExpression(misp_lib_stix2.AndBooleanExpression([exp1, exp2])) assert str(bool_exp) == "[file:hashes.'SHA-256' = 'aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f' AND file:mime_type = 'application/x-pdf']" # noqa @pytest.mark.parametrize( "observation_class, op", [ - (stix2.AndObservationExpression, 'AND'), - (stix2.OrObservationExpression, 'OR'), + (misp_lib_stix2.AndObservationExpression, 'AND'), + (misp_lib_stix2.OrObservationExpression, 'OR'), ], ) def test_multiple_file_observable_expression(observation_class, op): - exp1 = stix2.EqualityComparisonExpression( + exp1 = misp_lib_stix2.EqualityComparisonExpression( "file:hashes.'SHA-256'", - stix2.HashConstant( + misp_lib_stix2.HashConstant( "bf07a7fbb825fc0aae7bf4a1177b2b31fcf8a3feeaf7092761e18c859ee52a9c", 'SHA-256', ), ) - exp2 = stix2.EqualityComparisonExpression( + exp2 = misp_lib_stix2.EqualityComparisonExpression( "file:hashes.MD5", - stix2.HashConstant("cead3f77f6cda6ec00f57d76c9a6879f", "MD5"), + misp_lib_stix2.HashConstant("cead3f77f6cda6ec00f57d76c9a6879f", "MD5"), ) - bool1_exp = stix2.OrBooleanExpression([exp1, exp2]) - exp3 = stix2.EqualityComparisonExpression( + bool1_exp = misp_lib_stix2.OrBooleanExpression([exp1, exp2]) + exp3 = misp_lib_stix2.EqualityComparisonExpression( "file:hashes.'SHA-256'", - stix2.HashConstant( + misp_lib_stix2.HashConstant( "aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f", 'SHA-256', ), ) - op1_exp = stix2.ObservationExpression(bool1_exp) - op2_exp = stix2.ObservationExpression(exp3) + op1_exp = misp_lib_stix2.ObservationExpression(bool1_exp) + op2_exp = misp_lib_stix2.ObservationExpression(exp3) exp = observation_class([op1_exp, op2_exp]) assert str(exp) == "[file:hashes.'SHA-256' = 'bf07a7fbb825fc0aae7bf4a1177b2b31fcf8a3feeaf7092761e18c859ee52a9c' OR file:hashes.MD5 = 'cead3f77f6cda6ec00f57d76c9a6879f'] {} [file:hashes.'SHA-256' = 'aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f']".format(op) # noqa def test_root_types(): - ast = stix2.ObservationExpression( - stix2.AndBooleanExpression( + ast = misp_lib_stix2.ObservationExpression( + misp_lib_stix2.AndBooleanExpression( [ - stix2.ParentheticalExpression( - stix2.OrBooleanExpression([ - stix2.EqualityComparisonExpression("a:b", stix2.StringConstant("1")), - stix2.EqualityComparisonExpression("b:c", stix2.StringConstant("2")), + misp_lib_stix2.ParentheticalExpression( + misp_lib_stix2.OrBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression("a:b", misp_lib_stix2.StringConstant("1")), + misp_lib_stix2.EqualityComparisonExpression("b:c", misp_lib_stix2.StringConstant("2")), ]), ), - stix2.EqualityComparisonExpression(u"b:d", stix2.StringConstant("3")), + misp_lib_stix2.EqualityComparisonExpression(u"b:d", misp_lib_stix2.StringConstant("3")), ], ), ) @@ -154,40 +154,40 @@ def test_root_types(): def test_artifact_payload(): - exp1 = stix2.EqualityComparisonExpression( + exp1 = misp_lib_stix2.EqualityComparisonExpression( "artifact:mime_type", "application/vnd.tcpdump.pcap", ) - exp2 = stix2.MatchesComparisonExpression( + exp2 = misp_lib_stix2.MatchesComparisonExpression( "artifact:payload_bin", - stix2.StringConstant("\\xd4\\xc3\\xb2\\xa1\\x02\\x00\\x04\\x00"), + misp_lib_stix2.StringConstant("\\xd4\\xc3\\xb2\\xa1\\x02\\x00\\x04\\x00"), ) - and_exp = stix2.ObservationExpression(stix2.AndBooleanExpression([exp1, exp2])) + and_exp = misp_lib_stix2.ObservationExpression(misp_lib_stix2.AndBooleanExpression([exp1, exp2])) assert str(and_exp) == "[artifact:mime_type = 'application/vnd.tcpdump.pcap' AND artifact:payload_bin MATCHES '\\\\xd4\\\\xc3\\\\xb2\\\\xa1\\\\x02\\\\x00\\\\x04\\\\x00']" # noqa def test_greater_than_python_constant(): - exp1 = stix2.GreaterThanComparisonExpression("file:extensions.'windows-pebinary-ext'.sections[*].entropy", 7.0) - exp = stix2.ObservationExpression(exp1) + exp1 = misp_lib_stix2.GreaterThanComparisonExpression("file:extensions.'windows-pebinary-ext'.sections[*].entropy", 7.0) + exp = misp_lib_stix2.ObservationExpression(exp1) assert str(exp) == "[file:extensions.'windows-pebinary-ext'.sections[*].entropy > 7.0]" def test_greater_than(): - exp1 = stix2.GreaterThanComparisonExpression( + exp1 = misp_lib_stix2.GreaterThanComparisonExpression( "file:extensions.'windows-pebinary-ext'.sections[*].entropy", - stix2.FloatConstant(7.0), + misp_lib_stix2.FloatConstant(7.0), ) - exp = stix2.ObservationExpression(exp1) + exp = misp_lib_stix2.ObservationExpression(exp1) assert str(exp) == "[file:extensions.'windows-pebinary-ext'.sections[*].entropy > 7.0]" def test_less_than(): - exp = stix2.LessThanComparisonExpression("file:size", 1024) + exp = misp_lib_stix2.LessThanComparisonExpression("file:size", 1024) assert str(exp) == "file:size < 1024" def test_greater_than_or_equal(): - exp = stix2.GreaterThanEqualComparisonExpression( + exp = misp_lib_stix2.GreaterThanEqualComparisonExpression( "file:size", 1024, ) @@ -196,7 +196,7 @@ def test_greater_than_or_equal(): def test_less_than_or_equal(): - exp = stix2.LessThanEqualComparisonExpression( + exp = misp_lib_stix2.LessThanEqualComparisonExpression( "file:size", 1024, ) @@ -204,7 +204,7 @@ def test_less_than_or_equal(): def test_not(): - exp = stix2.LessThanComparisonExpression( + exp = misp_lib_stix2.LessThanComparisonExpression( "file:size", 1024, negated=True, @@ -213,106 +213,106 @@ def test_not(): def test_and_observable_expression(): - exp1 = stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + exp1 = misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_type", "unix", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:user_id", - stix2.StringConstant("1007"), + misp_lib_stix2.StringConstant("1007"), ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_login", "Peter", ), ]) - exp2 = stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + exp2 = misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_type", "unix", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:user_id", - stix2.StringConstant("1008"), + misp_lib_stix2.StringConstant("1008"), ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_login", "Paul", ), ]) - exp3 = stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + exp3 = misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_type", "unix", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:user_id", - stix2.StringConstant("1009"), + misp_lib_stix2.StringConstant("1009"), ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_login", "Mary", ), ]) - exp = stix2.AndObservationExpression([ - stix2.ObservationExpression(exp1), - stix2.ObservationExpression(exp2), - stix2.ObservationExpression(exp3), + exp = misp_lib_stix2.AndObservationExpression([ + misp_lib_stix2.ObservationExpression(exp1), + misp_lib_stix2.ObservationExpression(exp2), + misp_lib_stix2.ObservationExpression(exp3), ]) assert str(exp) == "[user-account:account_type = 'unix' AND user-account:user_id = '1007' AND user-account:account_login = 'Peter'] AND [user-account:account_type = 'unix' AND user-account:user_id = '1008' AND user-account:account_login = 'Paul'] AND [user-account:account_type = 'unix' AND user-account:user_id = '1009' AND user-account:account_login = 'Mary']" # noqa def test_invalid_and_observable_expression(): with pytest.raises(ValueError): - stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "user-account:display_name", "admin", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "email-addr:display_name", - stix2.StringConstant("admin"), + misp_lib_stix2.StringConstant("admin"), ), ]) def test_hex(): - exp_and = stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + exp_and = misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "file:mime_type", "image/bmp", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "file:magic_number_hex", - stix2.HexConstant("ffd8"), + misp_lib_stix2.HexConstant("ffd8"), ), ]) - exp = stix2.ObservationExpression(exp_and) + exp = misp_lib_stix2.ObservationExpression(exp_and) assert str(exp) == "[file:mime_type = 'image/bmp' AND file:magic_number_hex = h'ffd8']" def test_multiple_qualifiers(): - exp_and = stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + exp_and = misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "network-traffic:dst_ref.type", "domain-name", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "network-traffic:dst_ref.value", "example.com", ), ]) - exp_ob = stix2.ObservationExpression(exp_and) - qual_rep = stix2.RepeatQualifier(5) - qual_within = stix2.WithinQualifier(stix2.IntegerConstant(1800)) - exp = stix2.QualifiedObservationExpression(stix2.QualifiedObservationExpression(exp_ob, qual_rep), qual_within) + exp_ob = misp_lib_stix2.ObservationExpression(exp_and) + qual_rep = misp_lib_stix2.RepeatQualifier(5) + qual_within = misp_lib_stix2.WithinQualifier(misp_lib_stix2.IntegerConstant(1800)) + exp = misp_lib_stix2.QualifiedObservationExpression(misp_lib_stix2.QualifiedObservationExpression(exp_ob, qual_rep), qual_within) assert str(exp) == "[network-traffic:dst_ref.type = 'domain-name' AND network-traffic:dst_ref.value = 'example.com'] REPEATS 5 TIMES WITHIN 1800 SECONDS" # noqa def test_set_op(): - exp = stix2.ObservationExpression( - stix2.IsSubsetComparisonExpression( + exp = misp_lib_stix2.ObservationExpression( + misp_lib_stix2.IsSubsetComparisonExpression( "network-traffic:dst_ref.value", "2001:0db8:dead:beef:0000:0000:0000:0000/64", ), @@ -321,12 +321,12 @@ def test_set_op(): def test_timestamp(): - ts = stix2.StringConstant('2014-01-13T07:03:17Z') + ts = misp_lib_stix2.StringConstant('2014-01-13T07:03:17Z') assert str(ts) == "'2014-01-13T07:03:17Z'" def test_boolean(): - exp = stix2.EqualityComparisonExpression( + exp = misp_lib_stix2.EqualityComparisonExpression( "email-message:is_multipart", True, ) @@ -334,8 +334,8 @@ def test_boolean(): def test_binary(): - const = stix2.BinaryConstant("dGhpcyBpcyBhIHRlc3Q=") - exp = stix2.EqualityComparisonExpression( + const = misp_lib_stix2.BinaryConstant("dGhpcyBpcyBhIHRlc3Q=") + exp = misp_lib_stix2.EqualityComparisonExpression( "artifact:payload_bin", const, ) @@ -343,7 +343,7 @@ def test_binary(): def test_list(): - exp = stix2.InComparisonExpression( + exp = misp_lib_stix2.InComparisonExpression( "process:name", ['proccy', 'proximus', 'badproc'], ) @@ -352,7 +352,7 @@ def test_list(): def test_list2(): # alternate way to construct an "IN" Comparison Expression - exp = stix2.EqualityComparisonExpression( + exp = misp_lib_stix2.EqualityComparisonExpression( "process:name", ['proccy', 'proximus', 'badproc'], ) @@ -361,7 +361,7 @@ def test_list2(): def test_invalid_constant_type(): with pytest.raises(ValueError): - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "artifact:payload_bin", {'foo': 'bar'}, ) @@ -369,12 +369,12 @@ def test_invalid_constant_type(): def test_invalid_integer_constant(): with pytest.raises(ValueError): - stix2.IntegerConstant('foo') + misp_lib_stix2.IntegerConstant('foo') def test_invalid_float_constant(): with pytest.raises(ValueError): - stix2.FloatConstant('foo') + misp_lib_stix2.FloatConstant('foo') @pytest.mark.parametrize( @@ -394,13 +394,13 @@ def test_invalid_float_constant(): ], ) def test_boolean_constant(data, result): - boolean = stix2.BooleanConstant(data) + boolean = misp_lib_stix2.BooleanConstant(data) assert boolean.value == result def test_invalid_boolean_constant(): with pytest.raises(ValueError): - stix2.BooleanConstant('foo') + misp_lib_stix2.BooleanConstant('foo') @pytest.mark.parametrize( @@ -411,21 +411,21 @@ def test_invalid_boolean_constant(): ) def test_invalid_hash_constant(hashtype, data): with pytest.raises(ValueError): - stix2.HashConstant(data, hashtype) + misp_lib_stix2.HashConstant(data, hashtype) def test_invalid_hex_constant(): with pytest.raises(ValueError): - stix2.HexConstant('mm') + misp_lib_stix2.HexConstant('mm') def test_invalid_binary_constant(): with pytest.raises(ValueError): - stix2.BinaryConstant('foo') + misp_lib_stix2.BinaryConstant('foo') def test_escape_quotes_and_backslashes(): - exp = stix2.MatchesComparisonExpression( + exp = misp_lib_stix2.MatchesComparisonExpression( "file:name", "^Final Report.+\\.exe$", ) @@ -433,7 +433,7 @@ def test_escape_quotes_and_backslashes(): def test_like(): - exp = stix2.LikeComparisonExpression( + exp = misp_lib_stix2.LikeComparisonExpression( "directory:path", "C:\\Windows\\%\\foo", ) @@ -441,7 +441,7 @@ def test_like(): def test_issuperset(): - exp = stix2.IsSupersetComparisonExpression( + exp = misp_lib_stix2.IsSupersetComparisonExpression( "ipv4-addr:value", "198.51.100.0/24", ) @@ -449,43 +449,43 @@ def test_issuperset(): def test_repeat_qualifier(): - qual = stix2.RepeatQualifier(stix2.IntegerConstant(5)) + qual = misp_lib_stix2.RepeatQualifier(misp_lib_stix2.IntegerConstant(5)) assert str(qual) == 'REPEATS 5 TIMES' def test_invalid_repeat_qualifier(): with pytest.raises(ValueError): - stix2.RepeatQualifier('foo') + misp_lib_stix2.RepeatQualifier('foo') def test_invalid_within_qualifier(): with pytest.raises(ValueError): - stix2.WithinQualifier('foo') + misp_lib_stix2.WithinQualifier('foo') def test_startstop_qualifier(): - qual = stix2.StartStopQualifier( - stix2.StringConstant('2016-06-01T00:00:00Z'), - stix2.StringConstant('2017-03-12T08:30:00Z'), + qual = misp_lib_stix2.StartStopQualifier( + misp_lib_stix2.StringConstant('2016-06-01T00:00:00Z'), + misp_lib_stix2.StringConstant('2017-03-12T08:30:00Z'), ) assert str(qual) == "START '2016-06-01T00:00:00Z' STOP '2017-03-12T08:30:00Z'" - qual2 = stix2.StartStopQualifier( - stix2.StringConstant("2016-06-01T00:00:00Z"), - stix2.StringConstant('2016-07-01T00:00:00Z'), + qual2 = misp_lib_stix2.StartStopQualifier( + misp_lib_stix2.StringConstant("2016-06-01T00:00:00Z"), + misp_lib_stix2.StringConstant('2016-07-01T00:00:00Z'), ) assert str(qual2) == "START '2016-06-01T00:00:00Z' STOP '2016-07-01T00:00:00Z'" def test_invalid_startstop_qualifier(): with pytest.raises(ValueError): - stix2.StartStopQualifier( + misp_lib_stix2.StartStopQualifier( 'foo', - stix2.StringConstant('2016-06-01T00:00:00Z'), + misp_lib_stix2.StringConstant('2016-06-01T00:00:00Z'), ) with pytest.raises(ValueError): - stix2.StartStopQualifier( + misp_lib_stix2.StartStopQualifier( datetime.date(2016, 6, 1), 'foo', ) @@ -493,34 +493,34 @@ def test_invalid_startstop_qualifier(): @pytest.mark.parametrize( "input_, expected_class, expected_value", [ - (1, stix2.patterns.IntegerConstant, 1), - (1.5, stix2.patterns.FloatConstant, 1.5), - ("abc", stix2.patterns.StringConstant, "abc"), - (True, stix2.patterns.BooleanConstant, True), + (1, misp_lib_stix2.patterns.IntegerConstant, 1), + (1.5, misp_lib_stix2.patterns.FloatConstant, 1.5), + ("abc", misp_lib_stix2.patterns.StringConstant, "abc"), + (True, misp_lib_stix2.patterns.BooleanConstant, True), ( - "2001-02-10T21:36:15Z", stix2.patterns.TimestampConstant, - stix2.utils.STIXdatetime(2001, 2, 10, 21, 36, 15, tzinfo=pytz.utc), + "2001-02-10T21:36:15Z", misp_lib_stix2.patterns.TimestampConstant, + misp_lib_stix2.utils.STIXdatetime(2001, 2, 10, 21, 36, 15, tzinfo=pytz.utc), ), ( datetime.datetime(2001, 2, 10, 21, 36, 15, tzinfo=pytz.utc), - stix2.patterns.TimestampConstant, - stix2.utils.STIXdatetime(2001, 2, 10, 21, 36, 15, tzinfo=pytz.utc), + misp_lib_stix2.patterns.TimestampConstant, + misp_lib_stix2.utils.STIXdatetime(2001, 2, 10, 21, 36, 15, tzinfo=pytz.utc), ), ], ) def test_make_constant_simple(input_, expected_class, expected_value): - const = stix2.patterns.make_constant(input_) + const = misp_lib_stix2.patterns.make_constant(input_) assert isinstance(const, expected_class) assert const.value == expected_value def test_make_constant_list(): - list_const = stix2.patterns.make_constant([1, 2, 3]) + list_const = misp_lib_stix2.patterns.make_constant([1, 2, 3]) - assert isinstance(list_const, stix2.patterns.ListConstant) + assert isinstance(list_const, misp_lib_stix2.patterns.ListConstant) assert all( - isinstance(elt, stix2.patterns.IntegerConstant) + isinstance(elt, misp_lib_stix2.patterns.IntegerConstant) for elt in list_const.value ) assert all( @@ -530,8 +530,8 @@ def test_make_constant_list(): def test_make_constant_already_a_constant(): - str_const = stix2.StringConstant('Foo') - result = stix2.patterns.make_constant(str_const) + str_const = misp_lib_stix2.StringConstant('Foo') + result = misp_lib_stix2.patterns.make_constant(str_const) assert result is str_const @@ -600,7 +600,7 @@ def test_ast_class_override_comp_equals(): version="2.0", ) - assert isinstance(patt_ast, stix2.patterns.ObservationExpression) + assert isinstance(patt_ast, misp_lib_stix2.patterns.ObservationExpression) assert isinstance(patt_ast.operand, EqualityComparisonExpressionForTesting) assert str(patt_ast) == "[a:b = 1]" @@ -612,9 +612,9 @@ def test_ast_class_override_string_constant(): version="2.0", ) - assert isinstance(patt_ast, stix2.patterns.ObservationExpression) + assert isinstance(patt_ast, misp_lib_stix2.patterns.ObservationExpression) assert isinstance( - patt_ast.operand, stix2.patterns.LessThanComparisonExpression, + patt_ast.operand, misp_lib_stix2.patterns.LessThanComparisonExpression, ) assert isinstance( patt_ast.operand.lhs.property_path[0].property_name, @@ -635,9 +635,9 @@ def test_ast_class_override_startstop_qualifier(): "Testing", "stix2.test.v20.pattern_ast_overrides", version="2.0", ) - assert isinstance(patt_ast, stix2.patterns.QualifiedObservationExpression) + assert isinstance(patt_ast, misp_lib_stix2.patterns.QualifiedObservationExpression) assert isinstance( - patt_ast.observation_expression, stix2.patterns.ObservationExpression, + patt_ast.observation_expression, misp_lib_stix2.patterns.ObservationExpression, ) assert isinstance( patt_ast.observation_expression.operand, diff --git a/stix2/test/v21/test_pickle.py b/misp_lib_stix2/test/v20/test_pickle.py similarity index 82% rename from stix2/test/v21/test_pickle.py rename to misp_lib_stix2/test/v20/test_pickle.py index 55e81394..c25c594b 100644 --- a/stix2/test/v21/test_pickle.py +++ b/misp_lib_stix2/test/v20/test_pickle.py @@ -1,6 +1,6 @@ import pickle -import stix2 +import misp_lib_stix2 from .constants import IDENTITY_ID @@ -9,7 +9,7 @@ def test_pickling(): """ Ensure a pickle/unpickle cycle works okay. """ - identity = stix2.v21.Identity( + identity = misp_lib_stix2.v20.Identity( id=IDENTITY_ID, name="alice", description="this is a pickle test", diff --git a/stix2/test/v20/test_properties.py b/misp_lib_stix2/test/v20/test_properties.py similarity index 92% rename from stix2/test/v20/test_properties.py rename to misp_lib_stix2/test/v20/test_properties.py index fba92033..edcffecd 100644 --- a/stix2/test/v20/test_properties.py +++ b/misp_lib_stix2/test/v20/test_properties.py @@ -2,17 +2,17 @@ import pytest -import stix2 -from stix2.exceptions import ( +import misp_lib_stix2 +from misp_lib_stix2.exceptions import ( AtLeastOnePropertyError, CustomContentError, DictionaryKeyError, ExtraPropertiesError, ParseError, ) -from stix2.properties import ( +from misp_lib_stix2.properties import ( DictionaryProperty, EmbeddedObjectProperty, ExtensionsProperty, HashesProperty, IDProperty, ListProperty, ObservableProperty, ReferenceProperty, STIXObjectProperty, ) -from stix2.v20.common import MarkingProperty +from misp_lib_stix2.v20.common import MarkingProperty from . import constants @@ -342,7 +342,7 @@ def test_dictionary_property_invalid(d): def test_property_list_of_dictionary(): - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( 'x-new-obj-4', [ ('property1', ListProperty(DictionaryProperty(spec_version="2.0"), required=True)), ], @@ -381,8 +381,8 @@ def test_hash_property_invalid_key(key): def test_embedded_property(): - emb_prop = EmbeddedObjectProperty(type=stix2.v20.EmailMIMEComponent) - mime = stix2.v20.EmailMIMEComponent( + emb_prop = EmbeddedObjectProperty(type=misp_lib_stix2.v20.EmailMIMEComponent) + mime = misp_lib_stix2.v20.EmailMIMEComponent( content_type="text/plain; charset=utf-8", content_disposition="inline", body="Cats are funny!", @@ -398,7 +398,7 @@ def test_embedded_property(): def test_embedded_property_dict(): - emb_prop = EmbeddedObjectProperty(type=stix2.v20.EmailMIMEComponent) + emb_prop = EmbeddedObjectProperty(type=misp_lib_stix2.v20.EmailMIMEComponent) mime = { "content_type": "text/plain; charset=utf-8", "content_disposition": "inline", @@ -406,19 +406,19 @@ def test_embedded_property_dict(): } result = emb_prop.clean(mime, False) - assert isinstance(result[0], stix2.v20.EmailMIMEComponent) + assert isinstance(result[0], misp_lib_stix2.v20.EmailMIMEComponent) assert result[0]["body"] == "Cats are funny!" assert not result[1] result = emb_prop.clean(mime, True) - assert isinstance(result[0], stix2.v20.EmailMIMEComponent) + assert isinstance(result[0], misp_lib_stix2.v20.EmailMIMEComponent) assert result[0]["body"] == "Cats are funny!" assert not result[1] def test_embedded_property_custom(): - emb_prop = EmbeddedObjectProperty(type=stix2.v20.EmailMIMEComponent) - mime = stix2.v20.EmailMIMEComponent( + emb_prop = EmbeddedObjectProperty(type=misp_lib_stix2.v20.EmailMIMEComponent) + mime = misp_lib_stix2.v20.EmailMIMEComponent( content_type="text/plain; charset=utf-8", content_disposition="inline", body="Cats are funny!", @@ -434,7 +434,7 @@ def test_embedded_property_custom(): def test_embedded_property_dict_custom(): - emb_prop = EmbeddedObjectProperty(type=stix2.v20.EmailMIMEComponent) + emb_prop = EmbeddedObjectProperty(type=misp_lib_stix2.v20.EmailMIMEComponent) mime = { "content_type": "text/plain; charset=utf-8", "content_disposition": "inline", @@ -446,7 +446,7 @@ def test_embedded_property_dict_custom(): emb_prop.clean(mime, False) result = emb_prop.clean(mime, True) - assert isinstance(result[0], stix2.v20.EmailMIMEComponent) + assert isinstance(result[0], misp_lib_stix2.v20.EmailMIMEComponent) assert result[0]["body"] == "Cats are funny!" assert result[1] @@ -462,7 +462,7 @@ def test_extension_property_valid(): ) assert isinstance( - result[0]["windows-pebinary-ext"], stix2.v20.WindowsPEBinaryExt, + result[0]["windows-pebinary-ext"], misp_lib_stix2.v20.WindowsPEBinaryExt, ) assert not result[1] @@ -475,7 +475,7 @@ def test_extension_property_valid(): ) assert isinstance( - result[0]["windows-pebinary-ext"], stix2.v20.WindowsPEBinaryExt, + result[0]["windows-pebinary-ext"], misp_lib_stix2.v20.WindowsPEBinaryExt, ) assert not result[1] @@ -531,7 +531,7 @@ def test_extension_property_invalid3(): ) assert isinstance( - result[0]["windows-pebinary-ext"], stix2.v20.WindowsPEBinaryExt, + result[0]["windows-pebinary-ext"], misp_lib_stix2.v20.WindowsPEBinaryExt, ) assert result[0]["windows-pebinary-ext"]["abc"] == 123 assert result[1] @@ -539,7 +539,7 @@ def test_extension_property_invalid3(): def test_extension_at_least_one_property_constraint(): with pytest.raises(AtLeastOnePropertyError): - stix2.v20.TCPExt() + misp_lib_stix2.v20.TCPExt() def test_marking_property_error(): @@ -553,7 +553,7 @@ def test_marking_property_error(): def test_stix_property_not_compliant_spec(): # This is a 2.0 test only... - indicator = stix2.v20.Indicator(spec_version="2.0", allow_custom=True, **constants.INDICATOR_KWARGS) + indicator = misp_lib_stix2.v20.Indicator(spec_version="2.0", allow_custom=True, **constants.INDICATOR_KWARGS) stix_prop = STIXObjectProperty(spec_version="2.0") with pytest.raises(ValueError) as excinfo: @@ -565,7 +565,7 @@ def test_stix_property_not_compliant_spec(): def test_observable_property_obj(): prop = ObservableProperty(spec_version="2.0") - obs = stix2.v20.File(name="data.dat") + obs = misp_lib_stix2.v20.File(name="data.dat") obs_dict = { "0": obs, } @@ -590,12 +590,12 @@ def test_observable_property_dict(): } result = prop.clean(obs_dict, False) - assert isinstance(result[0]["0"], stix2.v20.File) + assert isinstance(result[0]["0"], misp_lib_stix2.v20.File) assert result[0]["0"]["name"] == "data.dat" assert not result[1] result = prop.clean(obs_dict, True) - assert isinstance(result[0]["0"], stix2.v20.File) + assert isinstance(result[0]["0"], misp_lib_stix2.v20.File) assert result[0]["0"]["name"] == "data.dat" assert not result[1] @@ -603,7 +603,7 @@ def test_observable_property_dict(): def test_observable_property_obj_custom(): prop = ObservableProperty(spec_version="2.0") - obs = stix2.v20.File(name="data.dat", foo=True, allow_custom=True) + obs = misp_lib_stix2.v20.File(name="data.dat", foo=True, allow_custom=True) obs_dict = { "0": obs, } @@ -631,7 +631,7 @@ def test_observable_property_dict_custom(): prop.clean(obs_dict, False) result = prop.clean(obs_dict, True) - assert isinstance(result[0]["0"], stix2.v20.File) + assert isinstance(result[0]["0"], misp_lib_stix2.v20.File) assert result[0]["0"]["foo"] assert result[1] @@ -650,7 +650,7 @@ def test_stix_object_property_custom_prop(): prop.clean(obj_dict, False) result = prop.clean(obj_dict, True) - assert isinstance(result[0], stix2.v20.Identity) + assert isinstance(result[0], misp_lib_stix2.v20.Identity) assert result[0]["foo"] == "bar" assert result[1] diff --git a/stix2/test/v20/test_relationship.py b/misp_lib_stix2/test/v20/test_relationship.py similarity index 75% rename from stix2/test/v20/test_relationship.py rename to misp_lib_stix2/test/v20/test_relationship.py index f8ad67e8..13da0c4e 100644 --- a/stix2/test/v20/test_relationship.py +++ b/misp_lib_stix2/test/v20/test_relationship.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import ( FAKE_TIME, INDICATOR_ID, MALWARE_ID, RELATIONSHIP_ID, RELATIONSHIP_KWARGS, @@ -23,7 +23,7 @@ def test_relationship_all_required_properties(): now = dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc) - rel = stix2.v20.Relationship( + rel = misp_lib_stix2.v20.Relationship( type='relationship', id=RELATIONSHIP_ID, created=now, @@ -54,69 +54,69 @@ def test_relationship_autogenerated_properties(relationship): def test_relationship_type_must_be_relationship(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Relationship(type='xxx', **RELATIONSHIP_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Relationship(type='xxx', **RELATIONSHIP_KWARGS) - assert excinfo.value.cls == stix2.v20.Relationship + assert excinfo.value.cls == misp_lib_stix2.v20.Relationship assert excinfo.value.prop_name == "type" assert excinfo.value.reason == "must equal 'relationship'." assert str(excinfo.value) == "Invalid value for Relationship 'type': must equal 'relationship'." def test_relationship_id_must_start_with_relationship(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Relationship(id='my-prefix--', **RELATIONSHIP_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Relationship(id='my-prefix--', **RELATIONSHIP_KWARGS) - assert excinfo.value.cls == stix2.v20.Relationship + assert excinfo.value.cls == misp_lib_stix2.v20.Relationship assert excinfo.value.prop_name == "id" assert excinfo.value.reason == "must start with 'relationship--'." assert str(excinfo.value) == "Invalid value for Relationship 'id': must start with 'relationship--'." def test_relationship_required_property_relationship_type(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v20.Relationship() - assert excinfo.value.cls == stix2.v20.Relationship + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v20.Relationship() + assert excinfo.value.cls == misp_lib_stix2.v20.Relationship assert excinfo.value.properties == ["relationship_type", "source_ref", "target_ref"] def test_relationship_missing_some_required_properties(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v20.Relationship(relationship_type='indicates') + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v20.Relationship(relationship_type='indicates') - assert excinfo.value.cls == stix2.v20.Relationship + assert excinfo.value.cls == misp_lib_stix2.v20.Relationship assert excinfo.value.properties == ["source_ref", "target_ref"] def test_relationship_required_properties_target_ref(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v20.Relationship( + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v20.Relationship( relationship_type='indicates', source_ref=INDICATOR_ID, ) - assert excinfo.value.cls == stix2.v20.Relationship + assert excinfo.value.cls == misp_lib_stix2.v20.Relationship assert excinfo.value.properties == ["target_ref"] def test_cannot_assign_to_relationship_attributes(relationship): - with pytest.raises(stix2.exceptions.ImmutableError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.ImmutableError) as excinfo: relationship.relationship_type = "derived-from" assert str(excinfo.value) == "Cannot modify 'relationship_type' property in 'Relationship' after creation." def test_invalid_kwarg_to_relationship(): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v20.Relationship(my_custom_property="foo", **RELATIONSHIP_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v20.Relationship(my_custom_property="foo", **RELATIONSHIP_KWARGS) - assert excinfo.value.cls == stix2.v20.Relationship + assert excinfo.value.cls == misp_lib_stix2.v20.Relationship assert excinfo.value.properties == ['my_custom_property'] assert str(excinfo.value) == "Unexpected properties for Relationship: (my_custom_property)." def test_create_relationship_from_objects_rather_than_ids(indicator, malware): - rel = stix2.v20.Relationship( + rel = misp_lib_stix2.v20.Relationship( relationship_type="indicates", source_ref=indicator, target_ref=malware, @@ -129,7 +129,7 @@ def test_create_relationship_from_objects_rather_than_ids(indicator, malware): def test_create_relationship_with_positional_args(indicator, malware): - rel = stix2.v20.Relationship(indicator, 'indicates', malware) + rel = misp_lib_stix2.v20.Relationship(indicator, 'indicates', malware) assert rel.relationship_type == 'indicates' assert rel.source_ref == 'indicator--00000000-0000-4000-8000-000000000001' @@ -152,7 +152,7 @@ def test_create_relationship_with_positional_args(indicator, malware): ], ) def test_parse_relationship(data): - rel = stix2.parse(data, version="2.0") + rel = misp_lib_stix2.parse(data, version="2.0") assert rel.type == 'relationship' assert rel.id == RELATIONSHIP_ID diff --git a/stix2/test/v20/test_report.py b/misp_lib_stix2/test/v20/test_report.py similarity index 88% rename from stix2/test/v20/test_report.py rename to misp_lib_stix2/test/v20/test_report.py index 6ef5c08c..c9e5dc93 100644 --- a/stix2/test/v20/test_report.py +++ b/misp_lib_stix2/test/v20/test_report.py @@ -3,8 +3,8 @@ import pytest import pytz -import stix2 -from stix2.exceptions import InvalidValueError +import misp_lib_stix2 +from misp_lib_stix2.exceptions import InvalidValueError from .constants import ( CAMPAIGN_ID, IDENTITY_ID, INDICATOR_ID, INDICATOR_KWARGS, RELATIONSHIP_ID, @@ -32,7 +32,7 @@ def test_report_example(): - report = stix2.v20.Report( + report = misp_lib_stix2.v20.Report( id=REPORT_ID, created_by_ref=IDENTITY_ID, created="2015-12-21T19:59:11.000Z", @@ -52,7 +52,7 @@ def test_report_example(): def test_report_example_objects_in_object_refs(): - report = stix2.v20.Report( + report = misp_lib_stix2.v20.Report( id=REPORT_ID, created_by_ref=IDENTITY_ID, created="2015-12-21T19:59:11.000Z", @@ -62,7 +62,7 @@ def test_report_example_objects_in_object_refs(): published="2016-01-20T17:00:00Z", labels=["campaign"], object_refs=[ - stix2.v20.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS), + misp_lib_stix2.v20.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS), CAMPAIGN_ID, RELATIONSHIP_ID, ], @@ -72,8 +72,8 @@ def test_report_example_objects_in_object_refs(): def test_report_example_objects_in_object_refs_with_bad_id(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Report( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Report( id=REPORT_ID, created_by_ref=IDENTITY_ID, created="2015-12-21T19:59:11.000Z", @@ -83,13 +83,13 @@ def test_report_example_objects_in_object_refs_with_bad_id(): published="2016-01-20T17:00:00Z", labels=["campaign"], object_refs=[ - stix2.v20.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS), + misp_lib_stix2.v20.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS), "campaign-83422c77-904c-4dc1-aff5-5c38f3a2c55c", # the "bad" id, missing a "-" RELATIONSHIP_ID, ], ) - assert excinfo.value.cls == stix2.v20.Report + assert excinfo.value.cls == misp_lib_stix2.v20.Report assert excinfo.value.prop_name == "object_refs" @@ -117,7 +117,7 @@ def test_report_example_objects_in_object_refs_with_bad_id(): ], ) def test_parse_report(data): - rept = stix2.parse(data, version="2.0") + rept = misp_lib_stix2.parse(data, version="2.0") assert rept.type == 'report' assert rept.id == REPORT_ID @@ -138,7 +138,7 @@ def test_parse_report(data): def test_report_on_custom(): with pytest.raises(InvalidValueError): - stix2.v20.Report( + misp_lib_stix2.v20.Report( name="my report", labels=["a label"], published="2016-01-20T17:00:00Z", @@ -148,7 +148,7 @@ def test_report_on_custom(): ], ) - report = stix2.v20.Report( + report = misp_lib_stix2.v20.Report( name="my report", labels=["a label"], published="2016-01-20T17:00:00Z", diff --git a/stix2/test/v20/test_sighting.py b/misp_lib_stix2/test/v20/test_sighting.py similarity index 78% rename from stix2/test/v20/test_sighting.py rename to misp_lib_stix2/test/v20/test_sighting.py index 35cd1f1b..0946a89c 100644 --- a/stix2/test/v20/test_sighting.py +++ b/misp_lib_stix2/test/v20/test_sighting.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import IDENTITY_ID, INDICATOR_ID, SIGHTING_ID, SIGHTING_KWARGS @@ -33,7 +33,7 @@ def test_sighting_all_required_properties(): now = dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc) - sighting = stix2.v20.Sighting( + sighting = misp_lib_stix2.v20.Sighting( type='sighting', id=SIGHTING_ID, created=now, @@ -47,8 +47,8 @@ def test_sighting_all_required_properties(): def test_sighting_bad_where_sighted_refs(): now = dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc) - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Sighting( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Sighting( type='sighting', id=SIGHTING_ID, created=now, @@ -57,29 +57,29 @@ def test_sighting_bad_where_sighted_refs(): where_sighted_refs=["malware--8cc7afd6-5455-4d2b-a736-e614ee631d99"], ) - assert excinfo.value.cls == stix2.v20.Sighting + assert excinfo.value.cls == misp_lib_stix2.v20.Sighting assert excinfo.value.prop_name == "where_sighted_refs" def test_sighting_type_must_be_sightings(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v20.Sighting(type='xxx', **SIGHTING_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v20.Sighting(type='xxx', **SIGHTING_KWARGS) - assert excinfo.value.cls == stix2.v20.Sighting + assert excinfo.value.cls == misp_lib_stix2.v20.Sighting assert excinfo.value.prop_name == "type" def test_invalid_kwarg_to_sighting(): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v20.Sighting(my_custom_property="foo", **SIGHTING_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v20.Sighting(my_custom_property="foo", **SIGHTING_KWARGS) - assert excinfo.value.cls == stix2.v20.Sighting + assert excinfo.value.cls == misp_lib_stix2.v20.Sighting assert excinfo.value.properties == ['my_custom_property'] assert str(excinfo.value) == "Unexpected properties for Sighting: (my_custom_property)." def test_create_sighting_from_objects_rather_than_ids(malware): # noqa: F811 - rel = stix2.v20.Sighting(sighting_of_ref=malware) + rel = misp_lib_stix2.v20.Sighting(sighting_of_ref=malware) assert rel.sighting_of_ref == 'malware--00000000-0000-4000-8000-000000000001' assert rel.id == 'sighting--00000000-0000-4000-8000-000000000003' @@ -101,7 +101,7 @@ def test_create_sighting_from_objects_rather_than_ids(malware): # noqa: F811 ], ) def test_parse_sighting(data): - sighting = stix2.parse(data, version="2.0") + sighting = misp_lib_stix2.parse(data, version="2.0") assert sighting.type == 'sighting' assert sighting.id == SIGHTING_ID diff --git a/stix2/test/v20/test_threat_actor.py b/misp_lib_stix2/test/v20/test_threat_actor.py similarity index 93% rename from stix2/test/v20/test_threat_actor.py rename to misp_lib_stix2/test/v20/test_threat_actor.py index 0214f9b7..7cd728f4 100644 --- a/stix2/test/v20/test_threat_actor.py +++ b/misp_lib_stix2/test/v20/test_threat_actor.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import IDENTITY_ID, THREAT_ACTOR_ID @@ -22,7 +22,7 @@ def test_threat_actor_example(): - threat_actor = stix2.v20.ThreatActor( + threat_actor = misp_lib_stix2.v20.ThreatActor( id=THREAT_ACTOR_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T20:03:48.000Z", @@ -51,7 +51,7 @@ def test_threat_actor_example(): ], ) def test_parse_threat_actor(data): - actor = stix2.parse(data, version="2.0") + actor = misp_lib_stix2.parse(data, version="2.0") assert actor.type == 'threat-actor' assert actor.id == THREAT_ACTOR_ID diff --git a/stix2/test/v20/test_tool.py b/misp_lib_stix2/test/v20/test_tool.py similarity index 91% rename from stix2/test/v20/test_tool.py rename to misp_lib_stix2/test/v20/test_tool.py index dcb94be1..cab2e46d 100644 --- a/stix2/test/v20/test_tool.py +++ b/misp_lib_stix2/test/v20/test_tool.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import IDENTITY_ID, TOOL_ID @@ -34,7 +34,7 @@ def test_tool_example(): - tool = stix2.v20.Tool( + tool = misp_lib_stix2.v20.Tool( id=TOOL_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T20:03:48.000Z", @@ -61,7 +61,7 @@ def test_tool_example(): ], ) def test_parse_tool(data): - tool = stix2.parse(data, version="2.0") + tool = misp_lib_stix2.parse(data, version="2.0") assert tool.type == 'tool' assert tool.id == TOOL_ID @@ -73,13 +73,13 @@ def test_parse_tool(data): def test_tool_no_workbench_wrappers(): - tool = stix2.v20.Tool(name='VNC', labels=['remote-access']) + tool = misp_lib_stix2.v20.Tool(name='VNC', labels=['remote-access']) with pytest.raises(AttributeError): tool.created_by() def test_tool_serialize_with_defaults(): - tool = stix2.v20.Tool( + tool = misp_lib_stix2.v20.Tool( id=TOOL_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T20:03:48.000Z", diff --git a/stix2/test/v20/test_utils.py b/misp_lib_stix2/test/v20/test_utils.py similarity index 89% rename from stix2/test/v20/test_utils.py rename to misp_lib_stix2/test/v20/test_utils.py index f61369b9..4648456e 100644 --- a/stix2/test/v20/test_utils.py +++ b/misp_lib_stix2/test/v20/test_utils.py @@ -6,8 +6,8 @@ import pytest import pytz -import stix2.serialization -import stix2.utils +import misp_lib_stix2.serialization +import misp_lib_stix2.utils from .constants import IDENTITY_ID @@ -23,12 +23,12 @@ (eastern.localize(dt.datetime(2017, 7, 1)), '2017-07-01T04:00:00Z'), (dt.datetime(2017, 7, 1), '2017-07-01T00:00:00Z'), (dt.datetime(2017, 7, 1, 0, 0, 0, 1), '2017-07-01T00:00:00.000001Z'), - (stix2.utils.STIXdatetime(2017, 7, 1, 0, 0, 0, 1, precision='millisecond'), '2017-07-01T00:00:00.000Z'), - (stix2.utils.STIXdatetime(2017, 7, 1, 0, 0, 0, 1, precision='second'), '2017-07-01T00:00:00Z'), + (misp_lib_stix2.utils.STIXdatetime(2017, 7, 1, 0, 0, 0, 1, precision='millisecond'), '2017-07-01T00:00:00.000Z'), + (misp_lib_stix2.utils.STIXdatetime(2017, 7, 1, 0, 0, 0, 1, precision='second'), '2017-07-01T00:00:00Z'), ], ) def test_timestamp_formatting(dttm, timestamp): - assert stix2.utils.format_datetime(dttm) == timestamp + assert misp_lib_stix2.utils.format_datetime(dttm) == timestamp @pytest.mark.parametrize( @@ -39,7 +39,7 @@ def test_timestamp_formatting(dttm, timestamp): ], ) def test_parse_datetime(timestamp, dttm): - assert stix2.utils.parse_into_datetime(timestamp) == dttm + assert misp_lib_stix2.utils.parse_into_datetime(timestamp) == dttm @pytest.mark.parametrize( @@ -52,7 +52,7 @@ def test_parse_datetime(timestamp, dttm): ], ) def test_parse_datetime_precision(timestamp, dttm, precision): - assert stix2.utils.parse_into_datetime(timestamp, precision) == dttm + assert misp_lib_stix2.utils.parse_into_datetime(timestamp, precision) == dttm @pytest.mark.parametrize( @@ -63,7 +63,7 @@ def test_parse_datetime_precision(timestamp, dttm, precision): ) def test_parse_datetime_invalid(ts): with pytest.raises(ValueError): - stix2.utils.parse_into_datetime('foobar') + misp_lib_stix2.utils.parse_into_datetime('foobar') @pytest.mark.parametrize( @@ -75,7 +75,7 @@ def test_parse_datetime_invalid(ts): ], ) def test_get_dict(data): - assert stix2.utils._get_dict(data) + assert misp_lib_stix2.utils._get_dict(data) @pytest.mark.parametrize( @@ -88,7 +88,7 @@ def test_get_dict(data): ) def test_get_dict_invalid(data): with pytest.raises(ValueError): - stix2.utils._get_dict(data) + misp_lib_stix2.utils._get_dict(data) @pytest.mark.parametrize( @@ -98,11 +98,11 @@ def test_get_dict_invalid(data): ], ) def test_get_type_from_id(stix_id, type): - assert stix2.utils.get_type_from_id(stix_id) == type + assert misp_lib_stix2.utils.get_type_from_id(stix_id) == type def test_deduplicate(stix_objs1): - unique = stix2.utils.deduplicate(stix_objs1) + unique = misp_lib_stix2.utils.deduplicate(stix_objs1) # Only 3 objects are unique # 2 id's vary @@ -122,7 +122,7 @@ def test_deduplicate(stix_objs1): @pytest.mark.parametrize( 'object, tuple_to_find, expected_index', [ ( - stix2.v20.ObservedData( + misp_lib_stix2.v20.ObservedData( id="observed-data--b67d30ff-02ac-498a-92f9-32f845f448cf", created_by_ref=IDENTITY_ID, created="2016-04-06T19:58:16.000Z", @@ -199,7 +199,7 @@ def test_deduplicate(stix_objs1): ], ) def test_find_property_index(object, tuple_to_find, expected_index): - assert stix2.serialization.find_property_index( + assert misp_lib_stix2.serialization.find_property_index( object, *tuple_to_find ) == expected_index @@ -236,7 +236,7 @@ def test_find_property_index(object, tuple_to_find, expected_index): ], ) def test_iterate_over_values(dict_value, tuple_to_find, expected_index): - assert stix2.serialization._find_property_in_seq(dict_value.values(), *tuple_to_find) == expected_index + assert misp_lib_stix2.serialization._find_property_in_seq(dict_value.values(), *tuple_to_find) == expected_index @pytest.mark.parametrize( @@ -259,7 +259,7 @@ def test_is_sdo_dict(type_): d = { "type": type_, } - assert stix2.utils.is_sdo(d, "2.0") + assert misp_lib_stix2.utils.is_sdo(d, "2.0") @pytest.mark.parametrize( @@ -280,7 +280,7 @@ def test_is_sdo_dict(type_): ], ) def test_is_not_sdo_dict(dict_): - assert not stix2.utils.is_sdo(dict_, "2.0") + assert not misp_lib_stix2.utils.is_sdo(dict_, "2.0") def test_is_sco_dict(): @@ -288,7 +288,7 @@ def test_is_sco_dict(): "type": "file", } - assert stix2.utils.is_sco(d, "2.0") + assert misp_lib_stix2.utils.is_sco(d, "2.0") @pytest.mark.parametrize( @@ -309,7 +309,7 @@ def test_is_sco_dict(): ], ) def test_is_not_sco_dict(dict_): - assert not stix2.utils.is_sco(dict_, "2.0") + assert not misp_lib_stix2.utils.is_sco(dict_, "2.0") @pytest.mark.parametrize( @@ -319,7 +319,7 @@ def test_is_not_sco_dict(dict_): ], ) def test_is_sro_dict(dict_): - assert stix2.utils.is_sro(dict_, "2.0") + assert misp_lib_stix2.utils.is_sro(dict_, "2.0") @pytest.mark.parametrize( @@ -341,7 +341,7 @@ def test_is_sro_dict(dict_): ], ) def test_is_not_sro_dict(dict_): - assert not stix2.utils.is_sro(dict_, "2.0") + assert not misp_lib_stix2.utils.is_sro(dict_, "2.0") @pytest.mark.parametrize( @@ -366,7 +366,7 @@ def test_is_not_sro_dict(dict_): ], ) def test_is_object_dict(dict_): - assert stix2.utils.is_object(dict_, "2.0") + assert misp_lib_stix2.utils.is_object(dict_, "2.0") @pytest.mark.parametrize( @@ -391,4 +391,4 @@ def test_is_object_dict(dict_): ], ) def test_is_not_object_dict(dict_): - assert not stix2.utils.is_object(dict_, "2.0") + assert not misp_lib_stix2.utils.is_object(dict_, "2.0") diff --git a/stix2/test/v20/test_versioning.py b/misp_lib_stix2/test/v20/test_versioning.py similarity index 63% rename from stix2/test/v20/test_versioning.py rename to misp_lib_stix2/test/v20/test_versioning.py index d3973f03..86047c9d 100644 --- a/stix2/test/v20/test_versioning.py +++ b/misp_lib_stix2/test/v20/test_versioning.py @@ -1,16 +1,16 @@ import pytest -import stix2 -import stix2.exceptions -import stix2.utils -import stix2.v20 -import stix2.versioning +import misp_lib_stix2 +import misp_lib_stix2.exceptions +import misp_lib_stix2.utils +import misp_lib_stix2.v20 +import misp_lib_stix2.versioning from .constants import CAMPAIGN_MORE_KWARGS def test_making_new_version(): - campaign_v1 = stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) campaign_v2 = campaign_v1.new_version(name="fred") @@ -24,7 +24,7 @@ def test_making_new_version(): def test_making_new_version_with_unset(): - campaign_v1 = stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) campaign_v2 = campaign_v1.new_version(description=None) @@ -38,7 +38,7 @@ def test_making_new_version_with_unset(): def test_making_new_version_with_embedded_object(): - campaign_v1 = stix2.v20.Campaign( + campaign_v1 = misp_lib_stix2.v20.Campaign( external_references=[{ "source_name": "capec", "external_id": "CAPEC-163", @@ -63,7 +63,7 @@ def test_making_new_version_with_embedded_object(): def test_revoke(): - campaign_v1 = stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) campaign_v2 = campaign_v1.revoke() @@ -78,21 +78,21 @@ def test_revoke(): def test_versioning_error_invalid_property(): - campaign_v1 = stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) - with pytest.raises(stix2.exceptions.UnmodifiablePropertyError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.UnmodifiablePropertyError) as excinfo: campaign_v1.new_version(type="threat-actor") assert str(excinfo.value) == "These properties cannot be changed when making a new version: type." def test_versioning_error_bad_modified_value(): - campaign_v1 = stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: campaign_v1.new_version(modified="2015-04-06T20:03:00.000Z") - assert excinfo.value.cls == stix2.v20.Campaign + assert excinfo.value.cls == misp_lib_stix2.v20.Campaign assert excinfo.value.prop_name == "modified" assert excinfo.value.reason == "The new modified datetime cannot be before than or equal to the current modified datetime." \ "It cannot be equal, as according to STIX 2 specification, objects that are different " \ @@ -100,7 +100,7 @@ def test_versioning_error_bad_modified_value(): msg = "Invalid value for {0} '{1}': {2}" msg = msg.format( - stix2.v20.Campaign.__name__, "modified", + misp_lib_stix2.v20.Campaign.__name__, "modified", "The new modified datetime cannot be before than or equal to the current modified datetime." "It cannot be equal, as according to STIX 2 specification, objects that are different " "but have the same id and modified timestamp do not have defined consumer behavior.", @@ -109,24 +109,24 @@ def test_versioning_error_bad_modified_value(): def test_versioning_error_usetting_required_property(): - campaign_v1 = stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: campaign_v1.new_version(name=None) - assert excinfo.value.cls == stix2.v20.Campaign + assert excinfo.value.cls == misp_lib_stix2.v20.Campaign assert excinfo.value.properties == ["name"] msg = "No values for required properties for {0}: ({1})." - msg = msg.format(stix2.v20.Campaign.__name__, "name") + msg = msg.format(misp_lib_stix2.v20.Campaign.__name__, "name") assert str(excinfo.value) == msg def test_versioning_error_new_version_of_revoked(): - campaign_v1 = stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) campaign_v2 = campaign_v1.revoke() - with pytest.raises(stix2.exceptions.RevokeError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.RevokeError) as excinfo: campaign_v2.new_version(name="barney") assert str(excinfo.value) == "Cannot create a new version of a revoked object." @@ -135,10 +135,10 @@ def test_versioning_error_new_version_of_revoked(): def test_versioning_error_revoke_of_revoked(): - campaign_v1 = stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) campaign_v2 = campaign_v1.revoke() - with pytest.raises(stix2.exceptions.RevokeError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.RevokeError) as excinfo: campaign_v2.revoke() assert str(excinfo.value) == "Cannot revoke an already revoked object." @@ -148,7 +148,7 @@ def test_versioning_error_revoke_of_revoked(): def test_making_new_version_dict(): campaign_v1 = CAMPAIGN_MORE_KWARGS - campaign_v2 = stix2.versioning.new_version(CAMPAIGN_MORE_KWARGS, name="fred") + campaign_v2 = misp_lib_stix2.versioning.new_version(CAMPAIGN_MORE_KWARGS, name="fred") assert campaign_v1['id'] == campaign_v2['id'] assert campaign_v1['created_by_ref'] == campaign_v2['created_by_ref'] @@ -156,12 +156,12 @@ def test_making_new_version_dict(): assert campaign_v1['name'] != campaign_v2['name'] assert campaign_v2['name'] == "fred" assert campaign_v1['description'] == campaign_v2['description'] - assert stix2.utils.parse_into_datetime(campaign_v1['modified'], precision='millisecond') < campaign_v2['modified'] + assert misp_lib_stix2.utils.parse_into_datetime(campaign_v1['modified'], precision='millisecond') < campaign_v2['modified'] def test_versioning_error_dict_bad_modified_value(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.versioning.new_version(CAMPAIGN_MORE_KWARGS, modified="2015-04-06T20:03:00.000Z") + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.versioning.new_version(CAMPAIGN_MORE_KWARGS, modified="2015-04-06T20:03:00.000Z") assert excinfo.value.cls == dict assert excinfo.value.prop_name == "modified" @@ -177,11 +177,11 @@ def test_versioning_dict_unregistered_no_modified(): "created": "1995-04-07T15:37:48.178Z", } - new_d = stix2.versioning.new_version(d) + new_d = misp_lib_stix2.versioning.new_version(d) assert "modified" in new_d - assert new_d["modified"] > stix2.utils.parse_into_datetime(d["created"]) + assert new_d["modified"] > misp_lib_stix2.utils.parse_into_datetime(d["created"]) - new_d = stix2.versioning.new_version(d, modified="1996-11-20T01:19:29.134Z") + new_d = misp_lib_stix2.versioning.new_version(d, modified="1996-11-20T01:19:29.134Z") assert new_d["modified"] == "1996-11-20T01:19:29.134Z" @@ -192,36 +192,36 @@ def test_versioning_dict_unregistered_unversionable(): "modified": "1995-04-07T15:37:48.178Z", } - with pytest.raises(stix2.exceptions.ObjectNotVersionableError): - stix2.versioning.new_version(d) + with pytest.raises(misp_lib_stix2.exceptions.ObjectNotVersionableError): + misp_lib_stix2.versioning.new_version(d) - with pytest.raises(stix2.exceptions.ObjectNotVersionableError): + with pytest.raises(misp_lib_stix2.exceptions.ObjectNotVersionableError): # should fail even if we provide a "created" kwarg. - stix2.versioning.new_version(d, created="1985-06-29T06:09:51.157Z") + misp_lib_stix2.versioning.new_version(d, created="1985-06-29T06:09:51.157Z") def test_versioning_custom_object(): - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( "x-versionable-all-optional-20", [ - ("created", stix2.properties.TimestampProperty()), - ("modified", stix2.properties.TimestampProperty()), - ("revoked", stix2.properties.BooleanProperty()), + ("created", misp_lib_stix2.properties.TimestampProperty()), + ("modified", misp_lib_stix2.properties.TimestampProperty()), + ("revoked", misp_lib_stix2.properties.BooleanProperty()), ], ) class CustomSDO: pass obj = CustomSDO(created="1990-12-18T17:56:11.346234Z") - new_obj = stix2.versioning.new_version(obj) + new_obj = misp_lib_stix2.versioning.new_version(obj) assert "modified" in new_obj assert new_obj["modified"] > new_obj["created"] obj = CustomSDO() - with pytest.raises(stix2.exceptions.ObjectNotVersionableError): + with pytest.raises(misp_lib_stix2.exceptions.ObjectNotVersionableError): # fails due to insufficient properties on the object, even though its # type supports versioning. - stix2.versioning.new_version(obj) + misp_lib_stix2.versioning.new_version(obj) def test_versioning_error_dict_no_modified_value(): @@ -231,45 +231,45 @@ def test_versioning_error_dict_no_modified_value(): 'created': "2016-04-06T20:03:00.000Z", 'name': "Green Group Attacks Against Finance", } - campaign_v2 = stix2.versioning.new_version(campaign_v1, modified="2017-04-06T20:03:00.000Z") + campaign_v2 = misp_lib_stix2.versioning.new_version(campaign_v1, modified="2017-04-06T20:03:00.000Z") assert str(campaign_v2['modified']) == "2017-04-06T20:03:00.000Z" def test_making_new_version_invalid_cls(): campaign_v1 = "This is a campaign." - with pytest.raises(stix2.exceptions.TypeNotVersionableError) as excinfo: - stix2.versioning.new_version(campaign_v1, name="fred") + with pytest.raises(misp_lib_stix2.exceptions.TypeNotVersionableError) as excinfo: + misp_lib_stix2.versioning.new_version(campaign_v1, name="fred") assert excinfo.value.object is campaign_v1 def test_revoke_dict(): campaign_v1 = CAMPAIGN_MORE_KWARGS - campaign_v2 = stix2.versioning.revoke(campaign_v1) + campaign_v2 = misp_lib_stix2.versioning.revoke(campaign_v1) assert campaign_v1['id'] == campaign_v2['id'] assert campaign_v1['created_by_ref'] == campaign_v2['created_by_ref'] assert campaign_v1['created'] == campaign_v2['created'] assert campaign_v1['name'] == campaign_v2['name'] assert campaign_v1['description'] == campaign_v2['description'] - assert stix2.utils.parse_into_datetime(campaign_v1['modified'], precision='millisecond') < campaign_v2['modified'] + assert misp_lib_stix2.utils.parse_into_datetime(campaign_v1['modified'], precision='millisecond') < campaign_v2['modified'] assert campaign_v2['revoked'] def test_revoke_unversionable(): - sco = stix2.v20.File(name="data.txt") - with pytest.raises(stix2.exceptions.TypeNotVersionableError): + sco = misp_lib_stix2.v20.File(name="data.txt") + with pytest.raises(misp_lib_stix2.exceptions.TypeNotVersionableError): sco.revoke() def test_versioning_error_revoke_of_revoked_dict(): campaign_v1 = CAMPAIGN_MORE_KWARGS - campaign_v2 = stix2.versioning.revoke(campaign_v1) + campaign_v2 = misp_lib_stix2.versioning.revoke(campaign_v1) - with pytest.raises(stix2.exceptions.RevokeError) as excinfo: - stix2.versioning.revoke(campaign_v2) + with pytest.raises(misp_lib_stix2.exceptions.RevokeError) as excinfo: + misp_lib_stix2.versioning.revoke(campaign_v2) assert excinfo.value.called_by == "revoke" @@ -277,33 +277,33 @@ def test_versioning_error_revoke_of_revoked_dict(): def test_revoke_invalid_cls(): campaign_v1 = "This is a campaign." with pytest.raises(ValueError) as excinfo: - stix2.versioning.revoke(campaign_v1) + misp_lib_stix2.versioning.revoke(campaign_v1) assert 'cannot revoke object of this type' in str(excinfo.value) def test_remove_custom_stix_property(): - mal = stix2.v20.Malware( + mal = misp_lib_stix2.v20.Malware( name="ColePowers", labels=["rootkit"], x_custom="armada", allow_custom=True, ) - mal_nc = stix2.versioning.remove_custom_stix(mal) + mal_nc = misp_lib_stix2.versioning.remove_custom_stix(mal) assert "x_custom" not in mal_nc assert ( - stix2.utils.parse_into_datetime(mal["modified"], precision="millisecond") < - stix2.utils.parse_into_datetime(mal_nc["modified"], precision="millisecond") + misp_lib_stix2.utils.parse_into_datetime(mal["modified"], precision="millisecond") < + misp_lib_stix2.utils.parse_into_datetime(mal_nc["modified"], precision="millisecond") ) def test_remove_custom_stix_object(): - @stix2.v20.CustomObject( + @misp_lib_stix2.v20.CustomObject( "x-animal", [ - ("species", stix2.properties.StringProperty(required=True)), - ("animal_class", stix2.properties.StringProperty()), + ("species", misp_lib_stix2.properties.StringProperty(required=True)), + ("animal_class", misp_lib_stix2.properties.StringProperty()), ], ) class Animal(object): @@ -311,14 +311,14 @@ class Animal(object): animal = Animal(species="lion", animal_class="mammal") - nc = stix2.versioning.remove_custom_stix(animal) + nc = misp_lib_stix2.versioning.remove_custom_stix(animal) assert nc is None def test_remove_custom_stix_no_custom(): - campaign_v1 = stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) - campaign_v2 = stix2.versioning.remove_custom_stix(campaign_v1) + campaign_v1 = misp_lib_stix2.v20.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v2 = misp_lib_stix2.versioning.remove_custom_stix(campaign_v1) assert len(campaign_v1.keys()) == len(campaign_v2.keys()) assert campaign_v1.id == campaign_v2.id @@ -331,8 +331,8 @@ def test_version_unversionable_dict(): "name": "data.txt", } - with pytest.raises(stix2.exceptions.TypeNotVersionableError): - stix2.versioning.new_version(f) + with pytest.raises(misp_lib_stix2.exceptions.TypeNotVersionableError): + misp_lib_stix2.versioning.new_version(f) def test_version_sco_with_modified(): @@ -349,23 +349,23 @@ def test_version_sco_with_modified(): "modified": "1991-05-13T19:24:57Z", } - with pytest.raises(stix2.exceptions.TypeNotVersionableError): - stix2.versioning.new_version(file_sco, name="newname.txt") + with pytest.raises(misp_lib_stix2.exceptions.TypeNotVersionableError): + misp_lib_stix2.versioning.new_version(file_sco, name="newname.txt") - with pytest.raises(stix2.exceptions.TypeNotVersionableError): - stix2.versioning.revoke(file_sco) + with pytest.raises(misp_lib_stix2.exceptions.TypeNotVersionableError): + misp_lib_stix2.versioning.revoke(file_sco) - file_sco_obj = stix2.v20.File( + file_sco_obj = misp_lib_stix2.v20.File( name="data.txt", created="1973-11-23T02:31:37Z", modified="1991-05-13T19:24:57Z", ) - with pytest.raises(stix2.exceptions.TypeNotVersionableError): - stix2.versioning.new_version(file_sco_obj, name="newname.txt") + with pytest.raises(misp_lib_stix2.exceptions.TypeNotVersionableError): + misp_lib_stix2.versioning.new_version(file_sco_obj, name="newname.txt") - with pytest.raises(stix2.exceptions.TypeNotVersionableError): - stix2.versioning.revoke(file_sco_obj) + with pytest.raises(misp_lib_stix2.exceptions.TypeNotVersionableError): + misp_lib_stix2.versioning.revoke(file_sco_obj) def test_version_sco_with_custom(): @@ -374,7 +374,7 @@ def test_version_sco_with_custom(): type which is otherwise unversionable, versioning should start working. """ - file_sco_obj = stix2.v20.File( + file_sco_obj = misp_lib_stix2.v20.File( name="data.txt", created="1973-11-23T02:31:37Z", modified="1991-05-13T19:24:57Z", @@ -382,13 +382,13 @@ def test_version_sco_with_custom(): allow_custom=True, ) - new_file_sco_obj = stix2.versioning.new_version( + new_file_sco_obj = misp_lib_stix2.versioning.new_version( file_sco_obj, name="newname.txt", ) assert new_file_sco_obj.name == "newname.txt" - revoked_obj = stix2.versioning.revoke(new_file_sco_obj) + revoked_obj = misp_lib_stix2.versioning.revoke(new_file_sco_obj) assert revoked_obj.revoked # Same thing with a dict @@ -400,22 +400,22 @@ def test_version_sco_with_custom(): "revoked": False, } - new_d = stix2.versioning.new_version(d, size=1234) + new_d = misp_lib_stix2.versioning.new_version(d, size=1234) assert new_d["size"] == 1234 - revoked_d = stix2.versioning.revoke(new_d) + revoked_d = misp_lib_stix2.versioning.revoke(new_d) assert revoked_d["revoked"] def test_version_marking(): - m = stix2.v20.MarkingDefinition( + m = misp_lib_stix2.v20.MarkingDefinition( created="1982-11-29T12:20:13.723Z", definition_type="statement", definition={"statement": "Copyright (c) 2000-2020 Acme Corp"}, ) - with pytest.raises(stix2.exceptions.TypeNotVersionableError): - stix2.versioning.new_version(m) + with pytest.raises(misp_lib_stix2.exceptions.TypeNotVersionableError): + misp_lib_stix2.versioning.new_version(m) m = { "type": "marking-definition", @@ -427,59 +427,59 @@ def test_version_marking(): }, } - with pytest.raises(stix2.exceptions.TypeNotVersionableError): - stix2.versioning.new_version(m) + with pytest.raises(misp_lib_stix2.exceptions.TypeNotVersionableError): + misp_lib_stix2.versioning.new_version(m) def test_version_disable_custom(): - m = stix2.v20.Malware( + m = misp_lib_stix2.v20.Malware( name="foo", labels=["spyware"], description="Steals your identity!", x_custom=123, allow_custom=True, ) # Remove the custom property, and disallow custom properties in the # resulting object. - m2 = stix2.versioning.new_version(m, x_custom=None, allow_custom=False) + m2 = misp_lib_stix2.versioning.new_version(m, x_custom=None, allow_custom=False) assert "x_custom" not in m2 # Remove a regular property and leave the custom one, disallow custom # properties, and make sure we get an error. - with pytest.raises(stix2.exceptions.ExtraPropertiesError): - stix2.versioning.new_version(m, description=None, allow_custom=False) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError): + misp_lib_stix2.versioning.new_version(m, description=None, allow_custom=False) def test_version_enable_custom(): - m = stix2.v20.Malware( + m = misp_lib_stix2.v20.Malware( name="foo", labels=["spyware"], description="Steals your identity!", ) # Add a custom property to an object for which it was previously disallowed - m2 = stix2.versioning.new_version(m, x_custom=123, allow_custom=True) + m2 = misp_lib_stix2.versioning.new_version(m, x_custom=123, allow_custom=True) assert "x_custom" in m2 # Add a custom property without enabling it, make sure we get an error - with pytest.raises(stix2.exceptions.ExtraPropertiesError): - stix2.versioning.new_version(m, x_custom=123, allow_custom=False) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError): + misp_lib_stix2.versioning.new_version(m, x_custom=123, allow_custom=False) def test_version_propagate_custom(): - m = stix2.v20.Malware( + m = misp_lib_stix2.v20.Malware( name="foo", labels=["spyware"], ) # Remember custom-not-allowed setting from original; produce error - with pytest.raises(stix2.exceptions.ExtraPropertiesError): - stix2.versioning.new_version(m, x_custom=123) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError): + misp_lib_stix2.versioning.new_version(m, x_custom=123) - m2 = stix2.versioning.new_version(m, description="Steals your identity!") + m2 = misp_lib_stix2.versioning.new_version(m, description="Steals your identity!") assert "description" in m2 assert m2.description == "Steals your identity!" - m_custom = stix2.v20.Malware( + m_custom = misp_lib_stix2.v20.Malware( name="foo", labels=["spyware"], x_custom=123, allow_custom=True, ) # Remember custom-allowed setting from original; should work - m2_custom = stix2.versioning.new_version(m_custom, x_other_custom="abc") + m2_custom = misp_lib_stix2.versioning.new_version(m_custom, x_other_custom="abc") assert "x_other_custom" in m2_custom assert m2_custom.x_other_custom == "abc" diff --git a/stix2/test/v20/test_vulnerability.py b/misp_lib_stix2/test/v20/test_vulnerability.py similarity index 90% rename from stix2/test/v20/test_vulnerability.py rename to misp_lib_stix2/test/v20/test_vulnerability.py index b87152f4..00c2efef 100644 --- a/stix2/test/v20/test_vulnerability.py +++ b/misp_lib_stix2/test/v20/test_vulnerability.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import VULNERABILITY_ID @@ -23,13 +23,13 @@ def test_vulnerability_example(): - vulnerability = stix2.v20.Vulnerability( + vulnerability = misp_lib_stix2.v20.Vulnerability( id=VULNERABILITY_ID, created="2016-05-12T08:17:27.000Z", modified="2016-05-12T08:17:27.000Z", name="CVE-2016-1234", external_references=[ - stix2.v20.ExternalReference( + misp_lib_stix2.v20.ExternalReference( source_name='cve', external_id="CVE-2016-1234", ), @@ -58,7 +58,7 @@ def test_vulnerability_example(): ], ) def test_parse_vulnerability(data): - vuln = stix2.parse(data, version="2.0") + vuln = misp_lib_stix2.parse(data, version="2.0") assert vuln.type == 'vulnerability' assert vuln.id == VULNERABILITY_ID diff --git a/stix2/test/v21/__init__.py b/misp_lib_stix2/test/v21/__init__.py similarity index 100% rename from stix2/test/v21/__init__.py rename to misp_lib_stix2/test/v21/__init__.py diff --git a/stix2/test/v21/conftest.py b/misp_lib_stix2/test/v21/conftest.py similarity index 92% rename from stix2/test/v21/conftest.py rename to misp_lib_stix2/test/v21/conftest.py index 9e37d92b..23471070 100644 --- a/stix2/test/v21/conftest.py +++ b/misp_lib_stix2/test/v21/conftest.py @@ -2,7 +2,7 @@ import pytest -import stix2 +import misp_lib_stix2 from .constants import ( FAKE_TIME, GROUPING_KWARGS, INDICATOR_KWARGS, INFRASTRUCTURE_KWARGS, @@ -14,12 +14,12 @@ @pytest.fixture def clock(monkeypatch): - class mydatetime(stix2.utils.STIXdatetime): + class mydatetime(misp_lib_stix2.utils.STIXdatetime): @classmethod def now(cls, tz=None): return FAKE_TIME - monkeypatch.setattr(stix2.utils, 'STIXdatetime', mydatetime) + monkeypatch.setattr(misp_lib_stix2.utils, 'STIXdatetime', mydatetime) @pytest.fixture @@ -37,27 +37,27 @@ def wrapped(): @pytest.fixture def indicator(uuid4, clock): - return stix2.v21.Indicator(**INDICATOR_KWARGS) + return misp_lib_stix2.v21.Indicator(**INDICATOR_KWARGS) @pytest.fixture def infrastructure(uuid4, clock): - return stix2.v21.Infrastructure(**INFRASTRUCTURE_KWARGS) + return misp_lib_stix2.v21.Infrastructure(**INFRASTRUCTURE_KWARGS) @pytest.fixture def grouping(uuid4, clock): - return stix2.v21.Grouping(**GROUPING_KWARGS) + return misp_lib_stix2.v21.Grouping(**GROUPING_KWARGS) @pytest.fixture def malware(uuid4, clock): - return stix2.v21.Malware(**MALWARE_KWARGS) + return misp_lib_stix2.v21.Malware(**MALWARE_KWARGS) @pytest.fixture def relationship(uuid4, clock): - return stix2.v21.Relationship(**RELATIONSHIP_KWARGS) + return misp_lib_stix2.v21.Relationship(**RELATIONSHIP_KWARGS) @pytest.fixture @@ -226,4 +226,4 @@ def stix_objs2(): @pytest.fixture def real_stix_objs2(stix_objs2): - return [stix2.parse(x, version="2.1") for x in stix_objs2] + return [misp_lib_stix2.parse(x, version="2.1") for x in stix_objs2] diff --git a/stix2/test/v21/constants.py b/misp_lib_stix2/test/v21/constants.py similarity index 100% rename from stix2/test/v21/constants.py rename to misp_lib_stix2/test/v21/constants.py diff --git a/stix2/test/v21/pattern_ast_overrides.py b/misp_lib_stix2/test/v21/pattern_ast_overrides.py similarity index 90% rename from stix2/test/v21/pattern_ast_overrides.py rename to misp_lib_stix2/test/v21/pattern_ast_overrides.py index 16473ba9..87cbcee9 100644 --- a/stix2/test/v21/pattern_ast_overrides.py +++ b/misp_lib_stix2/test/v21/pattern_ast_overrides.py @@ -1,7 +1,7 @@ """ AST node class overrides for testing the pattern AST builder. """ -from stix2.patterns import ( +from misp_lib_stix2.patterns import ( EqualityComparisonExpression, StartStopQualifier, StringConstant, ) diff --git a/stix2/test/v21/stix2_data/attack-pattern/attack-pattern--0a3ead4e-6d47-4ccb-854c-a6a4f9d96b22/20170531213019735010.json b/misp_lib_stix2/test/v21/stix2_data/attack-pattern/attack-pattern--0a3ead4e-6d47-4ccb-854c-a6a4f9d96b22/20170531213019735010.json similarity index 100% rename from stix2/test/v21/stix2_data/attack-pattern/attack-pattern--0a3ead4e-6d47-4ccb-854c-a6a4f9d96b22/20170531213019735010.json rename to misp_lib_stix2/test/v21/stix2_data/attack-pattern/attack-pattern--0a3ead4e-6d47-4ccb-854c-a6a4f9d96b22/20170531213019735010.json diff --git a/stix2/test/v21/stix2_data/attack-pattern/attack-pattern--0f20e3cb-245b-4a61-8a91-2d93f7cb0e9b/20170531213026496201.json b/misp_lib_stix2/test/v21/stix2_data/attack-pattern/attack-pattern--0f20e3cb-245b-4a61-8a91-2d93f7cb0e9b/20170531213026496201.json similarity index 100% rename from stix2/test/v21/stix2_data/attack-pattern/attack-pattern--0f20e3cb-245b-4a61-8a91-2d93f7cb0e9b/20170531213026496201.json rename to misp_lib_stix2/test/v21/stix2_data/attack-pattern/attack-pattern--0f20e3cb-245b-4a61-8a91-2d93f7cb0e9b/20170531213026496201.json diff --git a/stix2/test/v21/stix2_data/attack-pattern/attack-pattern--774a3188-6ba9-4dc4-879d-d54ee48a5ce9/20170531213029458940.json b/misp_lib_stix2/test/v21/stix2_data/attack-pattern/attack-pattern--774a3188-6ba9-4dc4-879d-d54ee48a5ce9/20170531213029458940.json similarity index 100% rename from stix2/test/v21/stix2_data/attack-pattern/attack-pattern--774a3188-6ba9-4dc4-879d-d54ee48a5ce9/20170531213029458940.json rename to misp_lib_stix2/test/v21/stix2_data/attack-pattern/attack-pattern--774a3188-6ba9-4dc4-879d-d54ee48a5ce9/20170531213029458940.json diff --git a/stix2/test/v21/stix2_data/attack-pattern/attack-pattern--7e150503-88e7-4861-866b-ff1ac82c4475/20170531213045139269.json b/misp_lib_stix2/test/v21/stix2_data/attack-pattern/attack-pattern--7e150503-88e7-4861-866b-ff1ac82c4475/20170531213045139269.json similarity index 100% rename from stix2/test/v21/stix2_data/attack-pattern/attack-pattern--7e150503-88e7-4861-866b-ff1ac82c4475/20170531213045139269.json rename to misp_lib_stix2/test/v21/stix2_data/attack-pattern/attack-pattern--7e150503-88e7-4861-866b-ff1ac82c4475/20170531213045139269.json diff --git a/stix2/test/v21/stix2_data/attack-pattern/attack-pattern--ae676644-d2d2-41b7-af7e-9bed1b55898c/20170531213041022897.json b/misp_lib_stix2/test/v21/stix2_data/attack-pattern/attack-pattern--ae676644-d2d2-41b7-af7e-9bed1b55898c/20170531213041022897.json similarity index 100% rename from stix2/test/v21/stix2_data/attack-pattern/attack-pattern--ae676644-d2d2-41b7-af7e-9bed1b55898c/20170531213041022897.json rename to misp_lib_stix2/test/v21/stix2_data/attack-pattern/attack-pattern--ae676644-d2d2-41b7-af7e-9bed1b55898c/20170531213041022897.json diff --git a/stix2/test/v21/stix2_data/attack-pattern/attack-pattern--b3d682b6-98f2-4fb0-aa3b-b4df007ca70a/20170531213032662702.json b/misp_lib_stix2/test/v21/stix2_data/attack-pattern/attack-pattern--b3d682b6-98f2-4fb0-aa3b-b4df007ca70a/20170531213032662702.json similarity index 100% rename from stix2/test/v21/stix2_data/attack-pattern/attack-pattern--b3d682b6-98f2-4fb0-aa3b-b4df007ca70a/20170531213032662702.json rename to misp_lib_stix2/test/v21/stix2_data/attack-pattern/attack-pattern--b3d682b6-98f2-4fb0-aa3b-b4df007ca70a/20170531213032662702.json diff --git a/stix2/test/v21/stix2_data/course-of-action/course-of-action--95ddb356-7ba0-4bd9-a889-247262b8946f/20170531213026495974.json b/misp_lib_stix2/test/v21/stix2_data/course-of-action/course-of-action--95ddb356-7ba0-4bd9-a889-247262b8946f/20170531213026495974.json similarity index 100% rename from stix2/test/v21/stix2_data/course-of-action/course-of-action--95ddb356-7ba0-4bd9-a889-247262b8946f/20170531213026495974.json rename to misp_lib_stix2/test/v21/stix2_data/course-of-action/course-of-action--95ddb356-7ba0-4bd9-a889-247262b8946f/20170531213026495974.json diff --git a/stix2/test/v21/stix2_data/course-of-action/course-of-action--d9727aee-48b8-4fdb-89e2-4c49746ba4dd/20170531213041022744.json b/misp_lib_stix2/test/v21/stix2_data/course-of-action/course-of-action--d9727aee-48b8-4fdb-89e2-4c49746ba4dd/20170531213041022744.json similarity index 100% rename from stix2/test/v21/stix2_data/course-of-action/course-of-action--d9727aee-48b8-4fdb-89e2-4c49746ba4dd/20170531213041022744.json rename to misp_lib_stix2/test/v21/stix2_data/course-of-action/course-of-action--d9727aee-48b8-4fdb-89e2-4c49746ba4dd/20170531213041022744.json diff --git a/stix2/test/v21/stix2_data/directory/directory--572827aa-e0cd-44fd-afd5-a717a7585f39.json b/misp_lib_stix2/test/v21/stix2_data/directory/directory--572827aa-e0cd-44fd-afd5-a717a7585f39.json similarity index 100% rename from stix2/test/v21/stix2_data/directory/directory--572827aa-e0cd-44fd-afd5-a717a7585f39.json rename to misp_lib_stix2/test/v21/stix2_data/directory/directory--572827aa-e0cd-44fd-afd5-a717a7585f39.json diff --git a/stix2/test/v21/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20170601000000000000.json b/misp_lib_stix2/test/v21/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20170601000000000000.json similarity index 100% rename from stix2/test/v21/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20170601000000000000.json rename to misp_lib_stix2/test/v21/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20170601000000000000.json diff --git a/stix2/test/v21/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20181101232448446000.json b/misp_lib_stix2/test/v21/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20181101232448446000.json similarity index 100% rename from stix2/test/v21/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20181101232448446000.json rename to misp_lib_stix2/test/v21/stix2_data/identity/identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5/20181101232448446000.json diff --git a/stix2/test/v21/stix2_data/intrusion-set/intrusion-set--a653431d-6a5e-4600-8ad3-609b5af57064/20170531213149412497.json b/misp_lib_stix2/test/v21/stix2_data/intrusion-set/intrusion-set--a653431d-6a5e-4600-8ad3-609b5af57064/20170531213149412497.json similarity index 100% rename from stix2/test/v21/stix2_data/intrusion-set/intrusion-set--a653431d-6a5e-4600-8ad3-609b5af57064/20170531213149412497.json rename to misp_lib_stix2/test/v21/stix2_data/intrusion-set/intrusion-set--a653431d-6a5e-4600-8ad3-609b5af57064/20170531213149412497.json diff --git a/stix2/test/v21/stix2_data/intrusion-set/intrusion-set--f3bdec95-3d62-42d9-a840-29630f6cdc1a/20170531213153197755.json b/misp_lib_stix2/test/v21/stix2_data/intrusion-set/intrusion-set--f3bdec95-3d62-42d9-a840-29630f6cdc1a/20170531213153197755.json similarity index 100% rename from stix2/test/v21/stix2_data/intrusion-set/intrusion-set--f3bdec95-3d62-42d9-a840-29630f6cdc1a/20170531213153197755.json rename to misp_lib_stix2/test/v21/stix2_data/intrusion-set/intrusion-set--f3bdec95-3d62-42d9-a840-29630f6cdc1a/20170531213153197755.json diff --git a/stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38.json b/misp_lib_stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38.json similarity index 100% rename from stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38.json rename to misp_lib_stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38.json diff --git a/stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20170531213258226477.json b/misp_lib_stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20170531213258226477.json similarity index 100% rename from stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20170531213258226477.json rename to misp_lib_stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20170531213258226477.json diff --git a/stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448456000.json b/misp_lib_stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448456000.json similarity index 100% rename from stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448456000.json rename to misp_lib_stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448456000.json diff --git a/stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448457000.json b/misp_lib_stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448457000.json similarity index 100% rename from stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448457000.json rename to misp_lib_stix2/test/v21/stix2_data/malware/malware--6b616fc1-1505-48e3-8b2c-0d19337bff38/20181101232448457000.json diff --git a/stix2/test/v21/stix2_data/malware/malware--92ec0cbd-2c30-44a2-b270-73f4ec949841/20170531213326565056.json b/misp_lib_stix2/test/v21/stix2_data/malware/malware--92ec0cbd-2c30-44a2-b270-73f4ec949841/20170531213326565056.json similarity index 100% rename from stix2/test/v21/stix2_data/malware/malware--92ec0cbd-2c30-44a2-b270-73f4ec949841/20170531213326565056.json rename to misp_lib_stix2/test/v21/stix2_data/malware/malware--92ec0cbd-2c30-44a2-b270-73f4ec949841/20170531213326565056.json diff --git a/stix2/test/v21/stix2_data/malware/malware--96b08451-b27a-4ff6-893f-790e26393a8e/20170531213248482655.json b/misp_lib_stix2/test/v21/stix2_data/malware/malware--96b08451-b27a-4ff6-893f-790e26393a8e/20170531213248482655.json similarity index 100% rename from stix2/test/v21/stix2_data/malware/malware--96b08451-b27a-4ff6-893f-790e26393a8e/20170531213248482655.json rename to misp_lib_stix2/test/v21/stix2_data/malware/malware--96b08451-b27a-4ff6-893f-790e26393a8e/20170531213248482655.json diff --git a/stix2/test/v21/stix2_data/malware/malware--b42378e0-f147-496f-992a-26a49705395b/20170531213215263882.json b/misp_lib_stix2/test/v21/stix2_data/malware/malware--b42378e0-f147-496f-992a-26a49705395b/20170531213215263882.json similarity index 100% rename from stix2/test/v21/stix2_data/malware/malware--b42378e0-f147-496f-992a-26a49705395b/20170531213215263882.json rename to misp_lib_stix2/test/v21/stix2_data/malware/malware--b42378e0-f147-496f-992a-26a49705395b/20170531213215263882.json diff --git a/stix2/test/v21/stix2_data/marking-definition/marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168.json b/misp_lib_stix2/test/v21/stix2_data/marking-definition/marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168.json similarity index 100% rename from stix2/test/v21/stix2_data/marking-definition/marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168.json rename to misp_lib_stix2/test/v21/stix2_data/marking-definition/marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168.json diff --git a/stix2/test/v21/stix2_data/relationship/relationship--0d4a7788-7f3b-4df8-a498-31a38003c883/20170531213327182784.json b/misp_lib_stix2/test/v21/stix2_data/relationship/relationship--0d4a7788-7f3b-4df8-a498-31a38003c883/20170531213327182784.json similarity index 100% rename from stix2/test/v21/stix2_data/relationship/relationship--0d4a7788-7f3b-4df8-a498-31a38003c883/20170531213327182784.json rename to misp_lib_stix2/test/v21/stix2_data/relationship/relationship--0d4a7788-7f3b-4df8-a498-31a38003c883/20170531213327182784.json diff --git a/stix2/test/v21/stix2_data/relationship/relationship--0e55ee98-0c6d-43d4-b424-b18a0036b227/20170531213327082801.json b/misp_lib_stix2/test/v21/stix2_data/relationship/relationship--0e55ee98-0c6d-43d4-b424-b18a0036b227/20170531213327082801.json similarity index 100% rename from stix2/test/v21/stix2_data/relationship/relationship--0e55ee98-0c6d-43d4-b424-b18a0036b227/20170531213327082801.json rename to misp_lib_stix2/test/v21/stix2_data/relationship/relationship--0e55ee98-0c6d-43d4-b424-b18a0036b227/20170531213327082801.json diff --git a/stix2/test/v21/stix2_data/relationship/relationship--1e91cd45-a725-4965-abe3-700694374432/20170531213327018782.json b/misp_lib_stix2/test/v21/stix2_data/relationship/relationship--1e91cd45-a725-4965-abe3-700694374432/20170531213327018782.json similarity index 100% rename from stix2/test/v21/stix2_data/relationship/relationship--1e91cd45-a725-4965-abe3-700694374432/20170531213327018782.json rename to misp_lib_stix2/test/v21/stix2_data/relationship/relationship--1e91cd45-a725-4965-abe3-700694374432/20170531213327018782.json diff --git a/stix2/test/v21/stix2_data/relationship/relationship--3a3084f9-0302-4fd5-9b8a-e0db10f5345e/20170531213327100701.json b/misp_lib_stix2/test/v21/stix2_data/relationship/relationship--3a3084f9-0302-4fd5-9b8a-e0db10f5345e/20170531213327100701.json similarity index 100% rename from stix2/test/v21/stix2_data/relationship/relationship--3a3084f9-0302-4fd5-9b8a-e0db10f5345e/20170531213327100701.json rename to misp_lib_stix2/test/v21/stix2_data/relationship/relationship--3a3084f9-0302-4fd5-9b8a-e0db10f5345e/20170531213327100701.json diff --git a/stix2/test/v21/stix2_data/relationship/relationship--3a3ed0b2-0c38-441f-ac40-53b873e545d1/20170531213327143973.json b/misp_lib_stix2/test/v21/stix2_data/relationship/relationship--3a3ed0b2-0c38-441f-ac40-53b873e545d1/20170531213327143973.json similarity index 100% rename from stix2/test/v21/stix2_data/relationship/relationship--3a3ed0b2-0c38-441f-ac40-53b873e545d1/20170531213327143973.json rename to misp_lib_stix2/test/v21/stix2_data/relationship/relationship--3a3ed0b2-0c38-441f-ac40-53b873e545d1/20170531213327143973.json diff --git a/stix2/test/v21/stix2_data/relationship/relationship--592d0c31-e61f-495e-a60e-70d7be59a719/20170531213327021562.json b/misp_lib_stix2/test/v21/stix2_data/relationship/relationship--592d0c31-e61f-495e-a60e-70d7be59a719/20170531213327021562.json similarity index 100% rename from stix2/test/v21/stix2_data/relationship/relationship--592d0c31-e61f-495e-a60e-70d7be59a719/20170531213327021562.json rename to misp_lib_stix2/test/v21/stix2_data/relationship/relationship--592d0c31-e61f-495e-a60e-70d7be59a719/20170531213327021562.json diff --git a/stix2/test/v21/stix2_data/relationship/relationship--70dc6b5c-c524-429e-a6ab-0dd40f0482c1/20170531213327044387.json b/misp_lib_stix2/test/v21/stix2_data/relationship/relationship--70dc6b5c-c524-429e-a6ab-0dd40f0482c1/20170531213327044387.json similarity index 100% rename from stix2/test/v21/stix2_data/relationship/relationship--70dc6b5c-c524-429e-a6ab-0dd40f0482c1/20170531213327044387.json rename to misp_lib_stix2/test/v21/stix2_data/relationship/relationship--70dc6b5c-c524-429e-a6ab-0dd40f0482c1/20170531213327044387.json diff --git a/stix2/test/v21/stix2_data/relationship/relationship--8797579b-e3be-4209-a71b-255a4d08243d/20170531213327051532.json b/misp_lib_stix2/test/v21/stix2_data/relationship/relationship--8797579b-e3be-4209-a71b-255a4d08243d/20170531213327051532.json similarity index 100% rename from stix2/test/v21/stix2_data/relationship/relationship--8797579b-e3be-4209-a71b-255a4d08243d/20170531213327051532.json rename to misp_lib_stix2/test/v21/stix2_data/relationship/relationship--8797579b-e3be-4209-a71b-255a4d08243d/20170531213327051532.json diff --git a/stix2/test/v21/stix2_data/tool/tool--03342581-f790-4f03-ba41-e82e67392e23/20170531213231601148.json b/misp_lib_stix2/test/v21/stix2_data/tool/tool--03342581-f790-4f03-ba41-e82e67392e23/20170531213231601148.json similarity index 100% rename from stix2/test/v21/stix2_data/tool/tool--03342581-f790-4f03-ba41-e82e67392e23/20170531213231601148.json rename to misp_lib_stix2/test/v21/stix2_data/tool/tool--03342581-f790-4f03-ba41-e82e67392e23/20170531213231601148.json diff --git a/stix2/test/v21/stix2_data/tool/tool--242f3da3-4425-4d11-8f5c-b842886da966/20170531213212684914.json b/misp_lib_stix2/test/v21/stix2_data/tool/tool--242f3da3-4425-4d11-8f5c-b842886da966/20170531213212684914.json similarity index 100% rename from stix2/test/v21/stix2_data/tool/tool--242f3da3-4425-4d11-8f5c-b842886da966/20170531213212684914.json rename to misp_lib_stix2/test/v21/stix2_data/tool/tool--242f3da3-4425-4d11-8f5c-b842886da966/20170531213212684914.json diff --git a/stix2/test/v21/test_attack_pattern.py b/misp_lib_stix2/test/v21/test_attack_pattern.py similarity index 87% rename from stix2/test/v21/test_attack_pattern.py rename to misp_lib_stix2/test/v21/test_attack_pattern.py index 96a28693..3be6cca3 100644 --- a/stix2/test/v21/test_attack_pattern.py +++ b/misp_lib_stix2/test/v21/test_attack_pattern.py @@ -3,8 +3,8 @@ import pytest import pytz -import stix2 -import stix2.exceptions +import misp_lib_stix2 +import misp_lib_stix2.exceptions from .constants import ATTACK_PATTERN_ID @@ -26,7 +26,7 @@ def test_attack_pattern_example(): - ap = stix2.v21.AttackPattern( + ap = misp_lib_stix2.v21.AttackPattern( id=ATTACK_PATTERN_ID, created="2016-05-12T08:17:27.000Z", modified="2016-05-12T08:17:27.000Z", @@ -62,7 +62,7 @@ def test_attack_pattern_example(): ], ) def test_parse_attack_pattern(data): - ap = stix2.parse(data, version="2.1") + ap = misp_lib_stix2.parse(data, version="2.1") assert ap.type == 'attack-pattern' assert ap.spec_version == '2.1' @@ -76,8 +76,8 @@ def test_parse_attack_pattern(data): def test_attack_pattern_invalid_labels(): - with pytest.raises(stix2.exceptions.InvalidValueError): - stix2.v21.AttackPattern( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError): + misp_lib_stix2.v21.AttackPattern( id=ATTACK_PATTERN_ID, created="2016-05-12T08:17:27Z", modified="2016-05-12T08:17:27Z", @@ -87,8 +87,8 @@ def test_attack_pattern_invalid_labels(): def test_overly_precise_timestamps(): - with pytest.raises(stix2.exceptions.InvalidValueError): - stix2.v21.AttackPattern( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError): + misp_lib_stix2.v21.AttackPattern( id=ATTACK_PATTERN_ID, created="2016-05-12T08:17:27.000000342Z", modified="2016-05-12T08:17:27.000000287Z", @@ -102,7 +102,7 @@ def test_overly_precise_timestamps(): def test_less_precise_timestamps(): - ap = stix2.v21.AttackPattern( + ap = misp_lib_stix2.v21.AttackPattern( id=ATTACK_PATTERN_ID, created="2016-05-12T08:17:27.00Z", modified="2016-05-12T08:17:27.0Z", diff --git a/stix2/test/v21/test_base.py b/misp_lib_stix2/test/v21/test_base.py similarity index 86% rename from stix2/test/v21/test_base.py rename to misp_lib_stix2/test/v21/test_base.py index 325cf4bc..7c665441 100644 --- a/stix2/test/v21/test_base.py +++ b/misp_lib_stix2/test/v21/test_base.py @@ -5,8 +5,8 @@ import pytest import pytz -import stix2 -from stix2.base import STIXJSONEncoder +import misp_lib_stix2 +from misp_lib_stix2.base import STIXJSONEncoder def test_encode_json_datetime(): @@ -29,7 +29,7 @@ def test_encode_json_object(): def test_deterministic_id_unicode(): mutex = {'name': u'D*Fl#Ed*\u00a3\u00a8', 'type': 'mutex'} - obs = stix2.parse(mutex, version="2.1") + obs = misp_lib_stix2.parse(mutex, version="2.1") dd_idx = obs.id.index("--") id_uuid = uuid.UUID(obs.id[dd_idx+2:]) diff --git a/stix2/test/v21/test_bundle.py b/misp_lib_stix2/test/v21/test_bundle.py similarity index 83% rename from stix2/test/v21/test_bundle.py rename to misp_lib_stix2/test/v21/test_bundle.py index 35dd52c4..b467f715 100644 --- a/stix2/test/v21/test_bundle.py +++ b/misp_lib_stix2/test/v21/test_bundle.py @@ -3,7 +3,7 @@ import pytest -import stix2 +import misp_lib_stix2 from ...exceptions import InvalidValueError from .constants import IDENTITY_ID @@ -96,7 +96,7 @@ def test_empty_bundle(): - bundle = stix2.v21.Bundle() + bundle = misp_lib_stix2.v21.Bundle() assert bundle.type == "bundle" assert bundle.id.startswith("bundle--") @@ -105,27 +105,27 @@ def test_empty_bundle(): def test_bundle_with_wrong_type(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Bundle(type="not-a-bundle") + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Bundle(type="not-a-bundle") - assert excinfo.value.cls == stix2.v21.Bundle + assert excinfo.value.cls == misp_lib_stix2.v21.Bundle assert excinfo.value.prop_name == "type" assert excinfo.value.reason == "must equal 'bundle'." assert str(excinfo.value) == "Invalid value for Bundle 'type': must equal 'bundle'." def test_bundle_id_must_start_with_bundle(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Bundle(id='my-prefix--') + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Bundle(id='my-prefix--') - assert excinfo.value.cls == stix2.v21.Bundle + assert excinfo.value.cls == misp_lib_stix2.v21.Bundle assert excinfo.value.prop_name == "id" assert excinfo.value.reason == "must start with 'bundle--'." assert str(excinfo.value) == "Invalid value for Bundle 'id': must start with 'bundle--'." def test_create_bundle_fp_serialize_pretty(indicator, malware, relationship): - bundle = stix2.v21.Bundle(objects=[indicator, malware, relationship]) + bundle = misp_lib_stix2.v21.Bundle(objects=[indicator, malware, relationship]) buffer = io.StringIO() bundle.fp_serialize(buffer, pretty=True) @@ -135,7 +135,7 @@ def test_create_bundle_fp_serialize_pretty(indicator, malware, relationship): def test_create_bundle_fp_serialize_nonpretty(indicator, malware, relationship): - bundle = stix2.v21.Bundle(objects=[indicator, malware, relationship]) + bundle = misp_lib_stix2.v21.Bundle(objects=[indicator, malware, relationship]) buffer = io.StringIO() bundle.fp_serialize(buffer, sort_keys=True) @@ -145,69 +145,69 @@ def test_create_bundle_fp_serialize_nonpretty(indicator, malware, relationship): def test_create_bundle1(indicator, malware, relationship): - bundle = stix2.v21.Bundle(objects=[indicator, malware, relationship]) + bundle = misp_lib_stix2.v21.Bundle(objects=[indicator, malware, relationship]) assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE def test_create_bundle2(indicator, malware, relationship): - bundle = stix2.v21.Bundle(objects=[indicator, malware, relationship]) + bundle = misp_lib_stix2.v21.Bundle(objects=[indicator, malware, relationship]) assert json.loads(bundle.serialize()) == EXPECTED_BUNDLE_DICT def test_create_bundle_with_positional_args(indicator, malware, relationship): - bundle = stix2.v21.Bundle(indicator, malware, relationship) + bundle = misp_lib_stix2.v21.Bundle(indicator, malware, relationship) assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE def test_create_bundle_with_positional_listarg(indicator, malware, relationship): - bundle = stix2.v21.Bundle([indicator, malware, relationship]) + bundle = misp_lib_stix2.v21.Bundle([indicator, malware, relationship]) assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE def test_create_bundle_with_listarg_and_positional_arg(indicator, malware, relationship): - bundle = stix2.v21.Bundle([indicator, malware], relationship) + bundle = misp_lib_stix2.v21.Bundle([indicator, malware], relationship) assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE def test_create_bundle_with_listarg_and_kwarg(indicator, malware, relationship): - bundle = stix2.v21.Bundle([indicator, malware], objects=[relationship]) + bundle = misp_lib_stix2.v21.Bundle([indicator, malware], objects=[relationship]) assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE def test_create_bundle_with_arg_listarg_and_kwarg(indicator, malware, relationship): - bundle = stix2.v21.Bundle([indicator], malware, objects=[relationship]) + bundle = misp_lib_stix2.v21.Bundle([indicator], malware, objects=[relationship]) assert bundle.serialize(pretty=True) == EXPECTED_BUNDLE def test_create_bundle_invalid(indicator, malware, relationship): with pytest.raises(InvalidValueError) as excinfo: - stix2.v21.Bundle(objects=[1]) + misp_lib_stix2.v21.Bundle(objects=[1]) assert excinfo.value.reason == "This property may only contain a dictionary or object" with pytest.raises(InvalidValueError) as excinfo: - stix2.v21.Bundle(objects=[{}]) + misp_lib_stix2.v21.Bundle(objects=[{}]) assert excinfo.value.reason == "This property may only contain a non-empty dictionary or object" with pytest.raises(InvalidValueError) as excinfo: - stix2.v21.Bundle(objects=[{'type': 'bundle'}]) + misp_lib_stix2.v21.Bundle(objects=[{'type': 'bundle'}]) assert excinfo.value.reason == 'This property may not contain a Bundle object' @pytest.mark.parametrize("version", ["2.1"]) def test_parse_bundle(version): - bundle = stix2.parse(EXPECTED_BUNDLE, version=version) + bundle = misp_lib_stix2.parse(EXPECTED_BUNDLE, version=version) assert bundle.type == "bundle" assert bundle.id.startswith("bundle--") - assert isinstance(bundle.objects[0], stix2.v21.Indicator) + assert isinstance(bundle.objects[0], misp_lib_stix2.v21.Indicator) assert bundle.objects[0].type == 'indicator' assert bundle.objects[1].type == 'malware' assert bundle.objects[2].type == 'relationship' @@ -225,20 +225,20 @@ def test_parse_unknown_type(): "name": "Green Group Attacks Against Finance", } - with pytest.raises(stix2.exceptions.ParseError) as excinfo: - stix2.parse(unknown, version="2.1") + with pytest.raises(misp_lib_stix2.exceptions.ParseError) as excinfo: + misp_lib_stix2.parse(unknown, version="2.1") assert str(excinfo.value) == "Can't parse unknown object type 'other'! For custom types, use the CustomObject decorator." def test_stix_object_property(): - prop = stix2.properties.STIXObjectProperty(spec_version='2.1') + prop = misp_lib_stix2.properties.STIXObjectProperty(spec_version='2.1') - identity = stix2.v21.Identity(name="test", identity_class="individual") + identity = misp_lib_stix2.v21.Identity(name="test", identity_class="individual") assert prop.clean(identity, False) == (identity, False) def test_bundle_obj_id_found(): - bundle = stix2.parse(EXPECTED_BUNDLE) + bundle = misp_lib_stix2.parse(EXPECTED_BUNDLE) mal_list = bundle.get_obj("malware--00000000-0000-4000-8000-000000000003") assert bundle.objects[1] == mal_list[0] @@ -301,7 +301,7 @@ def test_bundle_obj_id_found(): }], ) def test_bundle_objs_ids_found(bundle_data): - bundle = stix2.parse(bundle_data) + bundle = misp_lib_stix2.parse(bundle_data) mal_list = bundle.get_obj("malware--00000000-0000-4000-8000-000000000003") assert bundle.objects[1] == mal_list[0] @@ -310,14 +310,14 @@ def test_bundle_objs_ids_found(bundle_data): def test_bundle_getitem_overload_property_found(): - bundle = stix2.parse(EXPECTED_BUNDLE) + bundle = misp_lib_stix2.parse(EXPECTED_BUNDLE) assert bundle.type == "bundle" assert bundle['type'] == "bundle" def test_bundle_getitem_overload_obj_id_found(): - bundle = stix2.parse(EXPECTED_BUNDLE) + bundle = misp_lib_stix2.parse(EXPECTED_BUNDLE) mal_list = bundle["malware--00000000-0000-4000-8000-000000000003"] assert bundle.objects[1] == mal_list[0] @@ -325,7 +325,7 @@ def test_bundle_getitem_overload_obj_id_found(): def test_bundle_obj_id_not_found(): - bundle = stix2.parse(EXPECTED_BUNDLE) + bundle = misp_lib_stix2.parse(EXPECTED_BUNDLE) with pytest.raises(KeyError) as excinfo: bundle.get_obj('non existent') @@ -333,7 +333,7 @@ def test_bundle_obj_id_not_found(): def test_bundle_getitem_overload_obj_id_not_found(): - bundle = stix2.parse(EXPECTED_BUNDLE) + bundle = misp_lib_stix2.parse(EXPECTED_BUNDLE) with pytest.raises(KeyError) as excinfo: bundle['non existent'] diff --git a/stix2/test/v21/test_campaign.py b/misp_lib_stix2/test/v21/test_campaign.py similarity index 93% rename from stix2/test/v21/test_campaign.py rename to misp_lib_stix2/test/v21/test_campaign.py index edc7d777..1d5df4b6 100644 --- a/stix2/test/v21/test_campaign.py +++ b/misp_lib_stix2/test/v21/test_campaign.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import CAMPAIGN_ID, CAMPAIGN_MORE_KWARGS, IDENTITY_ID @@ -20,7 +20,7 @@ def test_campaign_example(): - campaign = stix2.v21.Campaign( + campaign = misp_lib_stix2.v21.Campaign( **CAMPAIGN_MORE_KWARGS ) @@ -43,7 +43,7 @@ def test_campaign_example(): ], ) def test_parse_campaign(data): - cmpn = stix2.parse(data, version="2.1") + cmpn = misp_lib_stix2.parse(data, version="2.1") assert cmpn.type == 'campaign' assert cmpn.spec_version == '2.1' diff --git a/stix2/test/v21/test_confidence.py b/misp_lib_stix2/test/v21/test_confidence.py similarity index 99% rename from stix2/test/v21/test_confidence.py rename to misp_lib_stix2/test/v21/test_confidence.py index dda16709..10f8eef7 100644 --- a/stix2/test/v21/test_confidence.py +++ b/misp_lib_stix2/test/v21/test_confidence.py @@ -1,6 +1,6 @@ import pytest -from stix2.confidence.scales import ( +from misp_lib_stix2.confidence.scales import ( admiralty_credibility_to_value, dni_to_value, none_low_med_high_to_value, value_to_admiralty_credibility, value_to_dni, value_to_none_low_medium_high, value_to_wep, value_to_zero_ten, diff --git a/stix2/test/v21/test_course_of_action.py b/misp_lib_stix2/test/v21/test_course_of_action.py similarity index 88% rename from stix2/test/v21/test_course_of_action.py rename to misp_lib_stix2/test/v21/test_course_of_action.py index 964a5565..ee2a8cb6 100644 --- a/stix2/test/v21/test_course_of_action.py +++ b/misp_lib_stix2/test/v21/test_course_of_action.py @@ -2,9 +2,9 @@ import pytest -import stix2 -import stix2.exceptions -import stix2.utils +import misp_lib_stix2 +import misp_lib_stix2.exceptions +import misp_lib_stix2.utils COA_WITH_BIN_JSON = """{ "type": "course-of-action", @@ -41,7 +41,7 @@ ], ) def test_course_of_action_example(sdo_json, sdo_dict): - coa = stix2.v21.CourseOfAction(**sdo_dict) + coa = misp_lib_stix2.v21.CourseOfAction(**sdo_dict) assert coa.serialize(pretty=True) == sdo_json @@ -57,11 +57,11 @@ def test_parse_course_of_action(sdo_json, sdo_dict): ts_attrs = {"created", "modified"} for data in (sdo_json, sdo_dict): - coa = stix2.parse(data, version="2.1") + coa = misp_lib_stix2.parse(data, version="2.1") # sdo_dict is handy as a source of attribute names/values to check for attr_name, attr_value in sdo_dict.items(): - cmp_value = stix2.utils.parse_into_datetime(attr_value) \ + cmp_value = misp_lib_stix2.utils.parse_into_datetime(attr_value) \ if attr_name in ts_attrs else attr_value assert getattr(coa, attr_name) == cmp_value diff --git a/stix2/test/v21/test_custom.py b/misp_lib_stix2/test/v21/test_custom.py similarity index 76% rename from stix2/test/v21/test_custom.py rename to misp_lib_stix2/test/v21/test_custom.py index 03a8357b..734f2d8e 100644 --- a/stix2/test/v21/test_custom.py +++ b/misp_lib_stix2/test/v21/test_custom.py @@ -3,11 +3,11 @@ import pytest -import stix2 -import stix2.base -import stix2.registration -import stix2.registry -import stix2.v21 +import misp_lib_stix2 +import misp_lib_stix2.base +import misp_lib_stix2.registration +import misp_lib_stix2.registry +import misp_lib_stix2.v21 from ...exceptions import ( DuplicateRegistrationError, InvalidValueError, MissingPropertiesError, @@ -16,7 +16,7 @@ # Custom Properties in SDOs -IDENTITY_CUSTOM_PROP = stix2.v21.Identity( +IDENTITY_CUSTOM_PROP = misp_lib_stix2.v21.Identity( name="John Smith", identity_class="individual", x_foo="bar", @@ -39,7 +39,7 @@ def _register_extension(ext, props): ext_def_id = "extension-definition--" + str(uuid.uuid4()) - stix2.v21.CustomExtension( + misp_lib_stix2.v21.CustomExtension( ext_def_id, props, )(ext) @@ -48,11 +48,11 @@ def _register_extension(ext, props): yield ext_def_id finally: # "unregister" the extension - del stix2.registry.STIX2_OBJ_MAPS["2.1"]["extensions"][ext_def_id] + del misp_lib_stix2.registry.STIX2_OBJ_MAPS["2.1"]["extensions"][ext_def_id] def test_identity_custom_property(): - identity = stix2.v21.Identity( + identity = misp_lib_stix2.v21.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11Z", modified="2015-12-21T19:59:11Z", @@ -65,7 +65,7 @@ def test_identity_custom_property(): assert identity.foo == "bar" with pytest.raises(ValueError) as excinfo: - stix2.v21.Identity( + misp_lib_stix2.v21.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11Z", modified="2015-12-21T19:59:11Z", @@ -75,8 +75,8 @@ def test_identity_custom_property(): ) assert str(excinfo.value) == "'custom_properties' must be a dictionary" - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v21.Identity( + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v21.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11Z", modified="2015-12-21T19:59:11Z", @@ -91,8 +91,8 @@ def test_identity_custom_property(): # leading numeric character is illegal in 2.1 - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Identity( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11Z", modified="2015-12-21T19:59:11Z", @@ -106,8 +106,8 @@ def test_identity_custom_property(): # leading "_" is illegal in 2.1 - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Identity( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11Z", modified="2015-12-21T19:59:11Z", @@ -119,8 +119,8 @@ def test_identity_custom_property(): ) assert "must begin with an alpha character." in str(excinfo.value) - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - identity = stix2.v21.Identity( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + identity = misp_lib_stix2.v21.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11Z", modified="2015-12-21T19:59:11Z", @@ -133,8 +133,8 @@ def test_identity_custom_property(): def test_identity_custom_property_invalid(): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v21.Identity( + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v21.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11Z", modified="2015-12-21T19:59:11Z", @@ -142,13 +142,13 @@ def test_identity_custom_property_invalid(): identity_class="individual", x_foo="bar", ) - assert excinfo.value.cls == stix2.v21.Identity + assert excinfo.value.cls == misp_lib_stix2.v21.Identity assert excinfo.value.properties == ['x_foo'] assert "Unexpected properties for" in str(excinfo.value) def test_identity_custom_property_allowed(): - identity = stix2.v21.Identity( + identity = misp_lib_stix2.v21.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11Z", modified="2015-12-21T19:59:11Z", @@ -175,32 +175,32 @@ def test_identity_custom_property_allowed(): ], ) def test_parse_identity_custom_property(data): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.parse(data, version="2.1") - assert issubclass(excinfo.value.cls, stix2.v21.Identity) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.parse(data, version="2.1") + assert issubclass(excinfo.value.cls, misp_lib_stix2.v21.Identity) assert excinfo.value.properties == ['foo'] assert "Unexpected properties for" in str(excinfo.value) - identity = stix2.parse(data, version="2.1", allow_custom=True) + identity = misp_lib_stix2.parse(data, version="2.1", allow_custom=True) assert identity.foo == "bar" def test_custom_property_object_in_bundled_object(): - bundle = stix2.v21.Bundle(IDENTITY_CUSTOM_PROP, allow_custom=True) + bundle = misp_lib_stix2.v21.Bundle(IDENTITY_CUSTOM_PROP, allow_custom=True) assert bundle.objects[0].x_foo == "bar" assert '"x_foo": "bar"' in str(bundle) def test_custom_properties_object_in_bundled_object(): - obj = stix2.v21.Identity( + obj = misp_lib_stix2.v21.Identity( name="John Smith", identity_class="individual", custom_properties={ "x_foo": "bar", }, ) - bundle = stix2.v21.Bundle(obj, allow_custom=True) + bundle = misp_lib_stix2.v21.Bundle(obj, allow_custom=True) assert bundle.objects[0].x_foo == "bar" assert '"x_foo": "bar"' in str(bundle) @@ -217,9 +217,9 @@ def test_custom_property_dict_in_bundled_object(): 'x_foo': 'bar', } with pytest.raises(InvalidValueError): - stix2.v21.Bundle(custom_identity) + misp_lib_stix2.v21.Bundle(custom_identity) - bundle = stix2.v21.Bundle(custom_identity, allow_custom=True) + bundle = misp_lib_stix2.v21.Bundle(custom_identity, allow_custom=True) assert bundle.objects[0].x_foo == "bar" assert '"x_foo": "bar"' in str(bundle) @@ -237,9 +237,9 @@ def test_custom_properties_dict_in_bundled_object(): }, } with pytest.raises(InvalidValueError): - stix2.v21.Bundle(custom_identity) + misp_lib_stix2.v21.Bundle(custom_identity) - bundle = stix2.v21.Bundle(custom_identity, allow_custom=True) + bundle = misp_lib_stix2.v21.Bundle(custom_identity, allow_custom=True) assert bundle.objects[0].x_foo == "bar" assert '"x_foo": "bar"' in str(bundle) @@ -247,12 +247,12 @@ def test_custom_properties_dict_in_bundled_object(): def test_custom_property_in_observed_data(): - artifact = stix2.v21.File( + artifact = misp_lib_stix2.v21.File( allow_custom=True, name='test', x_foo='bar', ) - observed_data = stix2.v21.ObservedData( + observed_data = misp_lib_stix2.v21.ObservedData( allow_custom=True, first_observed="2015-12-21T19:00:00Z", last_observed="2015-12-21T19:00:00Z", @@ -265,8 +265,8 @@ def test_custom_property_in_observed_data(): def test_invalid_custom_property_in_observed_data(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.File( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.File( custom_properties={"8foo": 1}, allow_custom=True, name='test', @@ -277,17 +277,17 @@ def test_invalid_custom_property_in_observed_data(): def test_custom_property_object_in_observable_extension(): - ntfs = stix2.v21.NTFSExt( + ntfs = misp_lib_stix2.v21.NTFSExt( allow_custom=True, sid=1, x_foo='bar', ) - artifact = stix2.v21.File( + artifact = misp_lib_stix2.v21.File( allow_custom=True, name='test', extensions={'ntfs-ext': ntfs}, ) - observed_data = stix2.v21.ObservedData( + observed_data = misp_lib_stix2.v21.ObservedData( allow_custom=True, first_observed="2015-12-21T19:00:00Z", last_observed="2015-12-21T19:00:00Z", @@ -301,7 +301,7 @@ def test_custom_property_object_in_observable_extension(): def test_custom_property_dict_in_observable_extension(): with pytest.raises(InvalidValueError): - stix2.v21.File( + misp_lib_stix2.v21.File( name='test', extensions={ 'ntfs-ext': { @@ -311,7 +311,7 @@ def test_custom_property_dict_in_observable_extension(): }, ) - artifact = stix2.v21.File( + artifact = misp_lib_stix2.v21.File( allow_custom=True, name='test', extensions={ @@ -321,7 +321,7 @@ def test_custom_property_dict_in_observable_extension(): }, }, ) - observed_data = stix2.v21.ObservedData( + observed_data = misp_lib_stix2.v21.ObservedData( allow_custom=True, first_observed="2015-12-21T19:00:00Z", last_observed="2015-12-21T19:00:00Z", @@ -341,15 +341,15 @@ def test_identity_custom_property_revoke(): def test_identity_custom_property_edit_markings(): - marking_obj = stix2.v21.MarkingDefinition( + marking_obj = misp_lib_stix2.v21.MarkingDefinition( id=MARKING_DEFINITION_ID, definition_type="statement", - definition=stix2.v21.StatementMarking(statement="Copyright 2016, Example Corp"), + definition=misp_lib_stix2.v21.StatementMarking(statement="Copyright 2016, Example Corp"), ) - marking_obj2 = stix2.v21.MarkingDefinition( + marking_obj2 = misp_lib_stix2.v21.MarkingDefinition( id=MARKING_DEFINITION_ID, definition_type="statement", - definition=stix2.v21.StatementMarking(statement="Another one"), + definition=misp_lib_stix2.v21.StatementMarking(statement="Another one"), ) # None of the following should throw exceptions @@ -363,9 +363,9 @@ def test_identity_custom_property_edit_markings(): def test_invalid_custom_property_in_marking(): with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomMarking( + @misp_lib_stix2.v21.CustomMarking( 'x-new-obj', [ - ('9property1', stix2.properties.StringProperty(required=True)), + ('9property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj(): @@ -375,9 +375,9 @@ class NewObj(): def test_custom_marking_no_init_1(): - @stix2.v21.CustomMarking( + @misp_lib_stix2.v21.CustomMarking( 'x-new-obj', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj(): @@ -388,9 +388,9 @@ class NewObj(): def test_custom_marking_no_init_2(): - @stix2.v21.CustomMarking( + @misp_lib_stix2.v21.CustomMarking( 'x-new-obj2', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj2(object): @@ -402,9 +402,9 @@ class NewObj2(object): def test_custom_marking_invalid_type_name(): with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomMarking( + @misp_lib_stix2.v21.CustomMarking( 'x', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj(object): @@ -412,9 +412,9 @@ class NewObj(object): assert "Invalid type name 'x': " in str(excinfo.value) with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomMarking( + @misp_lib_stix2.v21.CustomMarking( 'x_new_marking', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj2(object): @@ -422,9 +422,9 @@ class NewObj2(object): assert "Invalid type name 'x_new_marking':" in str(excinfo.value) with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomMarking( + @misp_lib_stix2.v21.CustomMarking( '7x-new-marking', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj3(object): @@ -434,9 +434,9 @@ class NewObj3(object): def test_register_duplicate_marking(): with pytest.raises(DuplicateRegistrationError) as excinfo: - @stix2.v21.CustomMarking( + @misp_lib_stix2.v21.CustomMarking( 'x-new-obj', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj2(): @@ -446,10 +446,10 @@ class NewObj2(): # Custom Objects -@stix2.v21.CustomObject( +@misp_lib_stix2.v21.CustomObject( 'x-new-type', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewType(object): @@ -471,7 +471,7 @@ def test_custom_object_type(): nt = NewType(property1='something') assert nt.property1 == 'something' - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: NewType(property2=42) assert "No values for required properties" in str(excinfo.value) @@ -481,9 +481,9 @@ def test_custom_object_type(): def test_custom_object_no_init_1(): - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x-new-obj', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj(): @@ -494,9 +494,9 @@ class NewObj(): def test_custom_object_no_init_2(): - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x-new-obj2', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj2(object): @@ -508,9 +508,9 @@ class NewObj2(object): def test_custom_object_invalid_type_name(): with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj(object): @@ -518,9 +518,9 @@ class NewObj(object): assert "Invalid type name 'x': " in str(excinfo.value) with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x_new_object', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj2(object): @@ -528,9 +528,9 @@ class NewObj2(object): assert "Invalid type name 'x_new_object':" in str(excinfo.value) with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( '7x-new-object', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj3(object): @@ -539,9 +539,9 @@ class NewObj3(object): def test_custom_object_ref_property_containing_identifier(): - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x-new-obj-with-ref', [ - ('property_ref', stix2.properties.ReferenceProperty(invalid_types=[])), + ('property_ref', misp_lib_stix2.properties.ReferenceProperty(invalid_types=[])), ], ) class NewObs(): @@ -549,9 +549,9 @@ class NewObs(): def test_custom_object_refs_property_containing_identifiers(): - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x-new-obj-with-refs', [ - ('property_refs', stix2.properties.ListProperty(stix2.properties.ReferenceProperty(invalid_types=[]))), + ('property_refs', misp_lib_stix2.properties.ListProperty(misp_lib_stix2.properties.ReferenceProperty(invalid_types=[]))), ], ) class NewObs(): @@ -560,9 +560,9 @@ class NewObs(): def test_custom_object_ref_property_containing_objectref(): with pytest.raises(ValueError, match=r"not a subclass of 'ReferenceProperty"): - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x-new-obj-with-objref', [ - ('property_ref', stix2.properties.ObjectReferenceProperty()), + ('property_ref', misp_lib_stix2.properties.ObjectReferenceProperty()), ], ) class NewObs(): @@ -571,9 +571,9 @@ class NewObs(): def test_custom_object_refs_property_containing_objectrefs(): with pytest.raises(ValueError, match=r"not a 'ListProperty' containing a subclass of 'ReferenceProperty"): - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x-new-obj-with-objrefs', [ - ('property_refs', stix2.properties.ListProperty(stix2.properties.ObjectReferenceProperty())), + ('property_refs', misp_lib_stix2.properties.ListProperty(misp_lib_stix2.properties.ObjectReferenceProperty())), ], ) class NewObs(): @@ -582,9 +582,9 @@ class NewObs(): def test_custom_object_invalid_ref_property(): with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x-new-obj', [ - ('property_ref', stix2.properties.StringProperty()), + ('property_ref', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs(): @@ -594,9 +594,9 @@ class NewObs(): def test_custom_object_invalid_refs_property(): with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x-new-obj', [ - ('property_refs', stix2.properties.StringProperty()), + ('property_refs', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs(): @@ -606,9 +606,9 @@ class NewObs(): def test_custom_object_invalid_refs_list_property(): with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x-new-obj', [ - ('property_refs', stix2.properties.ListProperty(stix2.properties.StringProperty)), + ('property_refs', misp_lib_stix2.properties.ListProperty(misp_lib_stix2.properties.StringProperty)), ], ) class NewObs(): @@ -631,16 +631,16 @@ def test_custom_subobject_dict(): ], } - obj = stix2.parse(obj_dict, allow_custom=True) + obj = misp_lib_stix2.parse(obj_dict, allow_custom=True) assert obj["objects"][0]["x_foo"] == 123 assert obj.has_custom with pytest.raises(InvalidValueError): - stix2.parse(obj_dict, allow_custom=False) + misp_lib_stix2.parse(obj_dict, allow_custom=False) def test_custom_subobject_obj(): - ident = stix2.v21.Identity( + ident = misp_lib_stix2.v21.Identity( name="alice", identity_class=123, x_foo=123, allow_custom=True, ) @@ -650,12 +650,12 @@ def test_custom_subobject_obj(): "objects": [ident], } - obj = stix2.parse(obj_dict, allow_custom=True) + obj = misp_lib_stix2.parse(obj_dict, allow_custom=True) assert obj["objects"][0]["x_foo"] == 123 assert obj.has_custom with pytest.raises(InvalidValueError): - stix2.parse(obj_dict, allow_custom=False) + misp_lib_stix2.parse(obj_dict, allow_custom=False) def test_parse_custom_object_type(): @@ -665,7 +665,7 @@ def test_parse_custom_object_type(): "property1": "something" }""" - nt = stix2.parse(nt_string, allow_custom=True) + nt = misp_lib_stix2.parse(nt_string, allow_custom=True) assert nt["property1"] == 'something' @@ -676,8 +676,8 @@ def test_parse_unregistered_custom_object_type(): "property1": "something" }""" - with pytest.raises(stix2.exceptions.ParseError) as excinfo: - stix2.parse(nt_string, version="2.1") + with pytest.raises(misp_lib_stix2.exceptions.ParseError) as excinfo: + misp_lib_stix2.parse(nt_string, version="2.1") assert "Can't parse unknown object type" in str(excinfo.value) assert "use the CustomObject decorator." in str(excinfo.value) @@ -692,17 +692,17 @@ def test_parse_unregistered_custom_object_type_w_allow_custom(): "property1": "something" }""" - custom_obj = stix2.parse(nt_string, version="2.1", allow_custom=True) + custom_obj = misp_lib_stix2.parse(nt_string, version="2.1", allow_custom=True) assert custom_obj["type"] == "x-foobar-observable" # Custom SCOs -@stix2.v21.CustomObservable( +@misp_lib_stix2.v21.CustomObservable( 'x-new-observable', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), - ('x_property3', stix2.properties.BooleanProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), + ('x_property3', misp_lib_stix2.properties.BooleanProperty()), ], ) class NewObservable(): @@ -719,7 +719,7 @@ def test_custom_observable_object_1(): def test_custom_observable_object_2(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: NewObservable(property2=42) assert excinfo.value.properties == ['property1'] assert "No values for required properties" in str(excinfo.value) @@ -739,9 +739,9 @@ def test_custom_observable_raises_exception(): def test_custom_observable_object_no_init_1(): - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x-new-observable-2', [ - ('property1', stix2.properties.StringProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs(): @@ -752,9 +752,9 @@ class NewObs(): def test_custom_observable_object_no_init_2(): - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x-new-obs2', [ - ('property1', stix2.properties.StringProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs2(object): @@ -766,9 +766,9 @@ class NewObs2(object): def test_invalid_custom_property_in_custom_observable_object(): with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x-new-sco', [ - ('5property1', stix2.properties.StringProperty()), + ('5property1', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs(object): @@ -778,9 +778,9 @@ class NewObs(object): def test_custom_observable_object_invalid_type_name(): with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x', [ - ('property1', stix2.properties.StringProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs(object): @@ -788,9 +788,9 @@ class NewObs(object): assert "Invalid type name 'x':" in str(excinfo.value) with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x_new_obs', [ - ('property1', stix2.properties.StringProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs2(object): @@ -798,9 +798,9 @@ class NewObs2(object): assert "Invalid type name 'x_new_obs':" in str(excinfo.value) with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( '7x-new-obs', [ - ('property1', stix2.properties.StringProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs3(object): @@ -809,9 +809,9 @@ class NewObs3(object): def test_custom_observable_object_ref_property_as_identifier(): - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x-new-obs-with-ref', [ - ('property_ref', stix2.properties.ReferenceProperty(invalid_types=[])), + ('property_ref', misp_lib_stix2.properties.ReferenceProperty(invalid_types=[])), ], ) class NewObs(): @@ -819,9 +819,9 @@ class NewObs(): def test_custom_observable_object_refs_property_containing_identifiers(): - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x-new-obs-with-refs', [ - ('property_refs', stix2.properties.ListProperty(stix2.properties.ReferenceProperty(invalid_types=[]))), + ('property_refs', misp_lib_stix2.properties.ListProperty(misp_lib_stix2.properties.ReferenceProperty(invalid_types=[]))), ], ) class NewObs(): @@ -830,9 +830,9 @@ class NewObs(): def test_custom_observable_object_ref_property_as_objectref(): with pytest.raises(ValueError, match=r"not a subclass of 'ReferenceProperty"): - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x-new-obs-with-objref', [ - ('property_ref', stix2.properties.ObjectReferenceProperty()), + ('property_ref', misp_lib_stix2.properties.ObjectReferenceProperty()), ], ) class NewObs(): @@ -841,9 +841,9 @@ class NewObs(): def test_custom_observable_object_refs_property_containing_objectrefs(): with pytest.raises(ValueError, match=r"not a 'ListProperty' containing a subclass of 'ReferenceProperty"): - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x-new-obs-with-objrefs', [ - ('property_refs', stix2.properties.ListProperty(stix2.properties.ObjectReferenceProperty())), + ('property_refs', misp_lib_stix2.properties.ListProperty(misp_lib_stix2.properties.ObjectReferenceProperty())), ], ) class NewObs(): @@ -852,9 +852,9 @@ class NewObs(): def test_custom_observable_object_invalid_ref_property(): with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x-new-obs', [ - ('property_ref', stix2.properties.StringProperty()), + ('property_ref', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs(): @@ -864,9 +864,9 @@ class NewObs(): def test_custom_observable_object_invalid_refs_property(): with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x-new-obs', [ - ('property_refs', stix2.properties.StringProperty()), + ('property_refs', misp_lib_stix2.properties.StringProperty()), ], ) class NewObs(): @@ -876,9 +876,9 @@ class NewObs(): def test_custom_observable_object_invalid_refs_list_property(): with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x-new-obs', [ - ('property_refs', stix2.properties.ListProperty(stix2.properties.StringProperty)), + ('property_refs', misp_lib_stix2.properties.ListProperty(misp_lib_stix2.properties.StringProperty)), ], ) class NewObs(): @@ -889,7 +889,7 @@ class NewObs(): def test_custom_no_properties_raises_exception(): with pytest.raises(TypeError): - @stix2.v21.CustomObject('x-new-object-type') + @misp_lib_stix2.v21.CustomObject('x-new-object-type') class NewObject1(object): pass @@ -897,7 +897,7 @@ class NewObject1(object): def test_custom_wrong_properties_arg_raises_exception(): with pytest.raises(ValueError): - @stix2.v21.CustomObservable('x-new-object-type', (("prop", stix2.properties.BooleanProperty()))) + @misp_lib_stix2.v21.CustomObservable('x-new-object-type', (("prop", misp_lib_stix2.properties.BooleanProperty()))) class NewObject2(object): pass @@ -907,8 +907,8 @@ def test_parse_custom_observable_object(): "type": "x-new-observable", "property1": "something" }""" - nt = stix2.parse(nt_string, [], version='2.1') - assert isinstance(nt, stix2.base._STIXBase) + nt = misp_lib_stix2.parse(nt_string, [], version='2.1') + assert isinstance(nt, misp_lib_stix2.base._STIXBase) assert nt.property1 == 'something' @@ -918,14 +918,14 @@ def test_parse_unregistered_custom_observable_object(): "property1": "something" }""" - with pytest.raises(stix2.exceptions.ParseError) as excinfo: - stix2.parse(nt_string, version='2.1') + with pytest.raises(misp_lib_stix2.exceptions.ParseError) as excinfo: + misp_lib_stix2.parse(nt_string, version='2.1') assert "Can't parse unknown object type" in str(excinfo.value) - parsed_custom = stix2.parse(nt_string, allow_custom=True, version='2.1') + parsed_custom = misp_lib_stix2.parse(nt_string, allow_custom=True, version='2.1') assert parsed_custom['property1'] == 'something' with pytest.raises(AttributeError) as excinfo: assert parsed_custom.property1 == 'something' - assert not isinstance(parsed_custom, stix2.base._STIXBase) + assert not isinstance(parsed_custom, misp_lib_stix2.base._STIXBase) def test_parse_unregistered_custom_observable_object_with_no_type(): @@ -933,8 +933,8 @@ def test_parse_unregistered_custom_observable_object_with_no_type(): "property1": "something" }""" - with pytest.raises(stix2.exceptions.ParseError) as excinfo: - stix2.parse(nt_string, allow_custom=True, version='2.1') + with pytest.raises(misp_lib_stix2.exceptions.ParseError) as excinfo: + misp_lib_stix2.parse(nt_string, allow_custom=True, version='2.1') assert "Can't parse object with no 'type' property" in str(excinfo.value) @@ -954,7 +954,7 @@ def test_parse_observed_data_with_custom_observable(): } } }""" - parsed = stix2.parse(input_str, version="2.1", allow_custom=True) + parsed = misp_lib_stix2.parse(input_str, version="2.1", allow_custom=True) assert parsed.objects['0']['property1'] == 'something' @@ -963,8 +963,8 @@ def test_parse_invalid_custom_observable_object(): "property1": "something" }""" - with pytest.raises(stix2.exceptions.ParseError) as excinfo: - stix2.parse(nt_string, version='2.1') + with pytest.raises(misp_lib_stix2.exceptions.ParseError) as excinfo: + misp_lib_stix2.parse(nt_string, version='2.1') assert "Can't parse object with no 'type' property" in str(excinfo.value) @@ -986,7 +986,7 @@ def test_observable_custom_property(): def test_observable_custom_property_invalid(): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: NewObservable( property1='something', x_foo="bar", @@ -1006,7 +1006,7 @@ def test_observable_custom_property_allowed(): def test_observed_data_with_custom_observable_object(): no = NewObservable(property1='something') - ob_data = stix2.v21.ObservedData( + ob_data = misp_lib_stix2.v21.ObservedData( first_observed=FAKE_TIME, last_observed=FAKE_TIME, number_observed=1, @@ -1017,10 +1017,10 @@ def test_observed_data_with_custom_observable_object(): def test_custom_observable_object_det_id_1(): - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x-det-id-observable-1', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], [ 'property1', ], @@ -1045,10 +1045,10 @@ class DetIdObs1(): def test_custom_observable_object_det_id_2(): - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x-det-id-observable-2', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], [ 'property1', 'property2', ], @@ -1071,9 +1071,9 @@ class DetIdObs2(): def test_custom_observable_object_no_id_contrib_props(): - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x-det-id-observable-3', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class DetIdObs3(): @@ -1088,10 +1088,10 @@ class DetIdObs3(): # Custom Extensions -@stix2.v21.CustomExtension( +@misp_lib_stix2.v21.CustomExtension( 'x-new-ext', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewExtension(): @@ -1113,7 +1113,7 @@ def test_custom_extension(): ext = NewExtension(property1='something') assert ext.property1 == 'something' - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: NewExtension(property2=42) assert excinfo.value.properties == ['property1'] assert str(excinfo.value) == "No values for required properties for NewExtension: (property1)." @@ -1127,7 +1127,7 @@ def test_custom_extension_wrong_observable_type(): # NewExtension is an extension of DomainName, not File ext = NewExtension(property1='something') with pytest.raises(InvalidValueError) as excinfo: - stix2.v21.File( + misp_lib_stix2.v21.File( name="abc.txt", extensions={ "ntfs-ext": ext, @@ -1150,9 +1150,9 @@ def test_custom_extension_wrong_observable_type(): ], ) def test_custom_extension_with_list_and_dict_properties_observable_type(data): - @stix2.v21.CustomExtension( + @misp_lib_stix2.v21.CustomExtension( 'x-some-extension-ext', [ - ('keys', stix2.properties.ListProperty(stix2.properties.DictionaryProperty, required=True)), + ('keys', misp_lib_stix2.properties.ListProperty(misp_lib_stix2.properties.DictionaryProperty, required=True)), ], ) class SomeCustomExtension: @@ -1164,9 +1164,9 @@ class SomeCustomExtension: def test_custom_extension_invalid_type_name(): with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomExtension( + @misp_lib_stix2.v21.CustomExtension( 'x', { - 'property1': stix2.properties.StringProperty(required=True), + 'property1': misp_lib_stix2.properties.StringProperty(required=True), }, ) class FooExtension(): @@ -1174,9 +1174,9 @@ class FooExtension(): assert "Invalid type name 'x':" in str(excinfo.value) with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomExtension( + @misp_lib_stix2.v21.CustomExtension( 'x_new_ext', { - 'property1': stix2.properties.StringProperty(required=True), + 'property1': misp_lib_stix2.properties.StringProperty(required=True), }, ) class BlaExtension(): @@ -1184,9 +1184,9 @@ class BlaExtension(): assert "Invalid type name 'x_new_ext':" in str(excinfo.value) with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomExtension( + @misp_lib_stix2.v21.CustomExtension( '7x-new-ext', { - 'property1': stix2.properties.StringProperty(required=True), + 'property1': misp_lib_stix2.properties.StringProperty(required=True), }, ) class Bla2Extension(): @@ -1196,29 +1196,29 @@ class Bla2Extension(): def test_custom_extension_no_properties(): with pytest.raises(ValueError): - @stix2.v21.CustomExtension('x-new2-ext', None) + @misp_lib_stix2.v21.CustomExtension('x-new2-ext', None) class BarExtension(): pass def test_custom_extension_empty_properties(): with pytest.raises(ValueError): - @stix2.v21.CustomExtension('x-new2-ext', []) + @misp_lib_stix2.v21.CustomExtension('x-new2-ext', []) class BarExtension(): pass def test_custom_extension_dict_properties(): with pytest.raises(ValueError): - @stix2.v21.CustomExtension('x-new2-ext', {}) + @misp_lib_stix2.v21.CustomExtension('x-new2-ext', {}) class BarExtension(): pass def test_custom_extension_no_init_1(): - @stix2.v21.CustomExtension( + @misp_lib_stix2.v21.CustomExtension( 'x-new-extension-ext', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewExt(): @@ -1229,9 +1229,9 @@ class NewExt(): def test_custom_extension_no_init_2(): - @stix2.v21.CustomExtension( + @misp_lib_stix2.v21.CustomExtension( 'x-new2-ext', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewExt2(object): @@ -1243,9 +1243,9 @@ class NewExt2(object): def test_invalid_custom_property_in_extension(): with pytest.raises(ValueError) as excinfo: - @stix2.v21.CustomExtension( + @misp_lib_stix2.v21.CustomExtension( 'x-new3-ext', [ - ('6property1', stix2.properties.StringProperty(required=True)), + ('6property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewExt(): @@ -1265,7 +1265,7 @@ def test_parse_observable_with_custom_extension(): } } }""" - parsed = stix2.parse(input_str, version='2.1') + parsed = misp_lib_stix2.parse(input_str, version='2.1') assert parsed.extensions['x-new-ext'].property2 == 12 @@ -1292,12 +1292,12 @@ def test_parse_observable_with_custom_extension_property(): } }""" - parsed = stix2.parse(input_str, version='2.1', allow_custom=True) + parsed = misp_lib_stix2.parse(input_str, version='2.1', allow_custom=True) assert parsed.has_custom assert parsed["objects"]["0"]["extensions"]["raster-image-ext"]["x-foo"] is False with pytest.raises(InvalidValueError): - stix2.parse(input_str, version="2.1", allow_custom=False) + misp_lib_stix2.parse(input_str, version="2.1", allow_custom=False) def test_custom_and_spec_extension_mix(): @@ -1306,7 +1306,7 @@ def test_custom_and_spec_extension_mix(): extension doesn't result in a completely uncleaned extensions property. """ - file_obs = stix2.v21.File( + file_obs = misp_lib_stix2.v21.File( name="my_file.dat", extensions={ "x-custom1-ext": { @@ -1336,10 +1336,10 @@ def test_custom_and_spec_extension_mix(): # Both of these should have been converted to objects, not left as dicts. assert isinstance( - file_obs.extensions["raster-image-ext"], stix2.v21.RasterImageExt, + file_obs.extensions["raster-image-ext"], misp_lib_stix2.v21.RasterImageExt, ) assert isinstance( - file_obs.extensions["ntfs-ext"], stix2.v21.NTFSExt, + file_obs.extensions["ntfs-ext"], misp_lib_stix2.v21.NTFSExt, ) @@ -1371,11 +1371,11 @@ def test_custom_and_spec_extension_mix(): ) def test_parse_observable_with_unregistered_custom_extension(data): with pytest.raises(InvalidValueError) as excinfo: - stix2.parse(data, version='2.1') + misp_lib_stix2.parse(data, version='2.1') assert "Can't parse unknown extension type" in str(excinfo.value) - parsed_ob = stix2.parse(data, allow_custom=True, version='2.1') + parsed_ob = misp_lib_stix2.parse(data, allow_custom=True, version='2.1') assert parsed_ob['extensions']['x-foobar-ext']['property1'] == 'foo' - assert not isinstance(parsed_ob['extensions']['x-foobar-ext'], stix2.base._STIXBase) + assert not isinstance(parsed_ob['extensions']['x-foobar-ext'], misp_lib_stix2.base._STIXBase) def test_unregistered_new_style_extension(): @@ -1392,7 +1392,7 @@ def test_unregistered_new_style_extension(): }, } - f = stix2.parse(f_dict, allow_custom=False) + f = misp_lib_stix2.parse(f_dict, allow_custom=False) assert f.extensions[ "extension-definition--31adb724-a9a4-44b6-8ec2-fd4b181c9507" @@ -1402,7 +1402,7 @@ def test_unregistered_new_style_extension(): ]["b"] assert not f.has_custom - f = stix2.parse(f_dict, allow_custom=True) + f = misp_lib_stix2.parse(f_dict, allow_custom=True) assert f.extensions[ "extension-definition--31adb724-a9a4-44b6-8ec2-fd4b181c9507" @@ -1419,13 +1419,13 @@ class CustomObject2(object): _type = 'awesome-object' with pytest.raises(ValueError) as excinfo: - stix2.registration._register_object(CustomObject2, version="2.1") + misp_lib_stix2.registration._register_object(CustomObject2, version="2.1") assert '@CustomObject decorator' in str(excinfo) def test_extension_property_location(): - assert 'extensions' in stix2.v21.OBJ_MAP_OBSERVABLE['x-new-observable']._properties - assert 'extensions' not in stix2.v21.EXT_MAP['x-new-ext']._properties + assert 'extensions' in misp_lib_stix2.v21.OBJ_MAP_OBSERVABLE['x-new-observable']._properties + assert 'extensions' not in misp_lib_stix2.v21.EXT_MAP['x-new-ext']._properties @pytest.mark.parametrize( @@ -1446,9 +1446,9 @@ def test_extension_property_location(): ], ) def test_custom_object_nested_dictionary(data): - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x-example', [ - ('dictionary', stix2.properties.DictionaryProperty()), + ('dictionary', misp_lib_stix2.properties.DictionaryProperty()), ], ) class Example(object): @@ -1465,10 +1465,10 @@ def __init__(self, **kwargs): assert data == example.serialize(pretty=True) -@stix2.v21.CustomObject( +@misp_lib_stix2.v21.CustomObject( 'x-new-type-2', [ - ('property1', stix2.properties.StringProperty()), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewType3(object): @@ -1482,18 +1482,18 @@ def test_register_custom_object_with_version(): "spec_version": "2.1", } - cust_obj_1 = stix2.parsing.dict_to_stix2(custom_obj_1, version='2.1') + cust_obj_1 = misp_lib_stix2.parsing.dict_to_stix2(custom_obj_1, version='2.1') - assert cust_obj_1.type in stix2.registry.STIX2_OBJ_MAPS['2.1']['objects'] + assert cust_obj_1.type in misp_lib_stix2.registry.STIX2_OBJ_MAPS['2.1']['objects'] assert cust_obj_1.spec_version == "2.1" def test_register_duplicate_object_with_version(): with pytest.raises(DuplicateRegistrationError) as excinfo: - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x-new-type-2', [ - ('property1', stix2.properties.StringProperty()), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewType2(object): @@ -1501,9 +1501,9 @@ class NewType2(object): assert "cannot be registered again" in str(excinfo.value) -@stix2.v21.CustomObservable( +@misp_lib_stix2.v21.CustomObservable( 'x-new-observable-3', [ - ('property1', stix2.properties.StringProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), ], ) class NewObservable3(object): @@ -1513,14 +1513,14 @@ class NewObservable3(object): def test_register_observable(): custom_obs = NewObservable3(property1="Test Observable") - assert custom_obs.type in stix2.registry.STIX2_OBJ_MAPS['2.1']['observables'] + assert custom_obs.type in misp_lib_stix2.registry.STIX2_OBJ_MAPS['2.1']['observables'] def test_register_duplicate_observable(): with pytest.raises(DuplicateRegistrationError) as excinfo: - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'x-new-observable-2', [ - ('property1', stix2.properties.StringProperty()), + ('property1', misp_lib_stix2.properties.StringProperty()), ], ) class NewObservable2(object): @@ -1529,10 +1529,10 @@ class NewObservable2(object): def test_register_observable_custom_extension(): - @stix2.v21.CustomExtension( + @misp_lib_stix2.v21.CustomExtension( 'x-new-2-ext', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewExtension2(): @@ -1540,16 +1540,16 @@ class NewExtension2(): example = NewExtension2(property1="Hi there") - assert 'domain-name' in stix2.registry.STIX2_OBJ_MAPS['2.1']['observables'] - assert example._type in stix2.registry.STIX2_OBJ_MAPS['2.1']['extensions'] + assert 'domain-name' in misp_lib_stix2.registry.STIX2_OBJ_MAPS['2.1']['observables'] + assert example._type in misp_lib_stix2.registry.STIX2_OBJ_MAPS['2.1']['extensions'] def test_register_duplicate_observable_extension(): with pytest.raises(DuplicateRegistrationError) as excinfo: - @stix2.v21.CustomExtension( + @misp_lib_stix2.v21.CustomExtension( 'x-new-2-ext', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewExtension2(): @@ -1558,7 +1558,7 @@ class NewExtension2(): def test_unregistered_top_level_extension_passes_with_allow_custom_false(): - indicator = stix2.v21.Indicator( + indicator = misp_lib_stix2.v21.Indicator( id='indicator--e97bfccf-8970-4a3c-9cd1-5b5b97ed5d0c', created='2014-02-20T09:16:08.989000Z', modified='2014-02-20T09:16:08.989000Z', @@ -1586,7 +1586,7 @@ def test_unregistered_top_level_extension_passes_with_allow_custom_false(): def test_unregistered_embedded_extension_passes_with_allow_custom_false(): - indicator = stix2.v21.Indicator( + indicator = misp_lib_stix2.v21.Indicator( id='indicator--e97bfccf-8970-4a3c-9cd1-5b5b97ed5d0c', created='2014-02-20T09:16:08.989000Z', modified='2014-02-20T09:16:08.989000Z', @@ -1614,16 +1614,16 @@ def test_unregistered_embedded_extension_passes_with_allow_custom_false(): def test_registered_top_level_extension_passes_with_allow_custom_false(): - @stix2.v21.CustomExtension( + @misp_lib_stix2.v21.CustomExtension( 'extension-definition--d83fce45-ef58-4c6c-a3f4-1fbc32e98c6e', [ - ('rank', stix2.properties.IntegerProperty(required=True)), - ('toxicity', stix2.properties.IntegerProperty(required=True)), + ('rank', misp_lib_stix2.properties.IntegerProperty(required=True)), + ('toxicity', misp_lib_stix2.properties.IntegerProperty(required=True)), ], ) class ExtensionFoo1: extension_type = 'toplevel-property-extension' - indicator = stix2.v21.Indicator( + indicator = misp_lib_stix2.v21.Indicator( id='indicator--e97bfccf-8970-4a3c-9cd1-5b5b97ed5d0c', created='2014-02-20T09:16:08.989000Z', modified='2014-02-20T09:16:08.989000Z', @@ -1651,16 +1651,16 @@ class ExtensionFoo1: def test_registered_embedded_extension_passes_with_allow_custom_false(): - @stix2.v21.CustomExtension( + @misp_lib_stix2.v21.CustomExtension( 'extension-definition--d83fce45-ef58-4c6c-a3ff-1fbc32e98c6e', [ - ('rank', stix2.properties.IntegerProperty(required=True)), - ('toxicity', stix2.properties.IntegerProperty(required=True)), + ('rank', misp_lib_stix2.properties.IntegerProperty(required=True)), + ('toxicity', misp_lib_stix2.properties.IntegerProperty(required=True)), ], ) class ExtensionFoo1: extension_type = "property-extension" - indicator = stix2.v21.Indicator( + indicator = misp_lib_stix2.v21.Indicator( id='indicator--e97bfccf-8970-4a3c-9cd1-5b5b97ed5d0c', created='2014-02-20T09:16:08.989000Z', modified='2014-02-20T09:16:08.989000Z', @@ -1688,11 +1688,11 @@ class ExtensionFoo1: def test_registered_new_extension_sdo_allow_custom_false(): - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'my-favorite-sdo', [ - ('name', stix2.properties.StringProperty(required=True)), - ('some_property_name1', stix2.properties.StringProperty(required=True)), - ('some_property_name2', stix2.properties.StringProperty()), + ('name', misp_lib_stix2.properties.StringProperty(required=True)), + ('some_property_name1', misp_lib_stix2.properties.StringProperty(required=True)), + ('some_property_name2', misp_lib_stix2.properties.StringProperty()), ], 'extension-definition--d83fce45-ef58-4c6c-a3f4-1fbc32e9999', ) class MyFavSDO: @@ -1711,11 +1711,11 @@ class MyFavSDO: # 'extension-definition--d83fce45-ef58-4c6c-a3f4-1fbc32e9999': ExtensionDefinitiond83fce45ef584c6ca3f41fbc32e98c6e() # } } - sdo_object = stix2.parse(my_favorite_sdo) + sdo_object = misp_lib_stix2.parse(my_favorite_sdo) assert isinstance(sdo_object, MyFavSDO) assert isinstance( sdo_object.extensions['extension-definition--d83fce45-ef58-4c6c-a3f4-1fbc32e9999'], - stix2.v21.EXT_MAP['extension-definition--d83fce45-ef58-4c6c-a3f4-1fbc32e9999'], + misp_lib_stix2.v21.EXT_MAP['extension-definition--d83fce45-ef58-4c6c-a3f4-1fbc32e9999'], ) sdo_serialized = sdo_object.serialize() @@ -1723,11 +1723,11 @@ class MyFavSDO: def test_registered_new_extension_sro_allow_custom_false(): - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'my-favorite-sro', [ - ('name', stix2.properties.StringProperty(required=True)), - ('some_property_name1', stix2.properties.StringProperty(required=True)), - ('some_property_name2', stix2.properties.StringProperty()), + ('name', misp_lib_stix2.properties.StringProperty(required=True)), + ('some_property_name1', misp_lib_stix2.properties.StringProperty(required=True)), + ('some_property_name2', misp_lib_stix2.properties.StringProperty()), ], 'extension-definition--e96690a5-dc13-4f27-99dd-0f2188ad74ce', False, ) class MyFavSRO: @@ -1746,11 +1746,11 @@ class MyFavSRO: # 'extension-definition--e96690a5-dc13-4f27-99dd-0f2188ad74ce': ExtensionDefinitiond83fce45ef584c6ca3f41fbc32e98c6e() # } } - sro_object = stix2.parse(my_favorite_sro) + sro_object = misp_lib_stix2.parse(my_favorite_sro) assert isinstance(sro_object, MyFavSRO) assert isinstance( sro_object.extensions['extension-definition--e96690a5-dc13-4f27-99dd-0f2188ad74ce'], - stix2.v21.EXT_MAP['extension-definition--e96690a5-dc13-4f27-99dd-0f2188ad74ce'], + misp_lib_stix2.v21.EXT_MAP['extension-definition--e96690a5-dc13-4f27-99dd-0f2188ad74ce'], ) sdo_serialized = sro_object.serialize() @@ -1758,10 +1758,10 @@ class MyFavSRO: def test_registered_new_extension_sco_allow_custom_false(): - @stix2.v21.CustomObservable( + @misp_lib_stix2.v21.CustomObservable( 'my-favorite-sco', [ - ('name', stix2.properties.StringProperty(required=True)), - ('some_network_protocol_field', stix2.properties.StringProperty(required=True)), + ('name', misp_lib_stix2.properties.StringProperty(required=True)), + ('some_network_protocol_field', misp_lib_stix2.properties.StringProperty(required=True)), ], ['name', 'some_network_protocol_field'], 'extension-definition--a932fcc6-e032-177c-126f-cb970a5a1fff', ) class MyFavSCO: @@ -1780,11 +1780,11 @@ class MyFavSCO: # } } - sco_object = stix2.parse(my_favorite_sco) + sco_object = misp_lib_stix2.parse(my_favorite_sco) assert isinstance(sco_object, MyFavSCO) assert isinstance( sco_object.extensions['extension-definition--a932fcc6-e032-177c-126f-cb970a5a1fff'], - stix2.v21.EXT_MAP['extension-definition--a932fcc6-e032-177c-126f-cb970a5a1fff'], + misp_lib_stix2.v21.EXT_MAP['extension-definition--a932fcc6-e032-177c-126f-cb970a5a1fff'], ) sco_serialized = sco_object.serialize() @@ -1797,7 +1797,7 @@ class MyFavMarking: extension_type = "property-extension" props = { - 'some_marking_field': stix2.properties.StringProperty(required=True), + 'some_marking_field': misp_lib_stix2.properties.StringProperty(required=True), } with _register_extension(MyFavMarking, props) as ext_def_id: @@ -1815,11 +1815,11 @@ class MyFavMarking: }, } - marking_object = stix2.parse(my_favorite_marking) - assert isinstance(marking_object, stix2.v21.MarkingDefinition) + marking_object = misp_lib_stix2.parse(my_favorite_marking) + assert isinstance(marking_object, misp_lib_stix2.v21.MarkingDefinition) assert isinstance( marking_object.extensions[ext_def_id], - stix2.v21.EXT_MAP[ext_def_id], + misp_lib_stix2.v21.EXT_MAP[ext_def_id], ) marking_serialized = marking_object.serialize(sort_keys=True) @@ -1832,7 +1832,7 @@ class CustomMarking: extension_type = "toplevel-property-extension" props = { - "foo": stix2.properties.StringProperty(required=True), + "foo": misp_lib_stix2.properties.StringProperty(required=True), } with _register_extension(CustomMarking, props) as ext_def_id: @@ -1848,7 +1848,7 @@ class CustomMarking: }, } - marking = stix2.parse(marking_dict) + marking = misp_lib_stix2.parse(marking_dict) assert marking.foo == "hello" @@ -1858,15 +1858,15 @@ class TestExt: extension_type = "property-extension" props = { - "intprop": stix2.properties.IntegerProperty(required=True), - "strprop": stix2.properties.StringProperty( + "intprop": misp_lib_stix2.properties.IntegerProperty(required=True), + "strprop": misp_lib_stix2.properties.StringProperty( required=False, default=lambda: "foo", ), } with _register_extension(TestExt, props) as ext_def_id: - obj = stix2.v21.Identity( + obj = misp_lib_stix2.v21.Identity( name="test", extensions={ ext_def_id: { @@ -1881,7 +1881,7 @@ class TestExt: assert obj.extensions[ext_def_id].intprop == 1 assert obj.extensions[ext_def_id].strprop == "2" - obj = stix2.v21.Identity( + obj = misp_lib_stix2.v21.Identity( name="test", extensions={ ext_def_id: { @@ -1895,7 +1895,7 @@ class TestExt: assert obj.extensions[ext_def_id].strprop == "foo" with pytest.raises(InvalidValueError): - stix2.v21.Identity( + misp_lib_stix2.v21.Identity( name="test", extensions={ ext_def_id: { @@ -1907,7 +1907,7 @@ class TestExt: ) with pytest.raises(InvalidValueError): - stix2.v21.Identity( + misp_lib_stix2.v21.Identity( name="test", extensions={ ext_def_id: { @@ -1919,7 +1919,7 @@ class TestExt: ) with pytest.raises(InvalidValueError): - stix2.v21.Identity( + misp_lib_stix2.v21.Identity( name="test", extensions={ ext_def_id: { @@ -1932,7 +1932,7 @@ class TestExt: ) with pytest.raises(InvalidValueError): - stix2.v21.Identity( + misp_lib_stix2.v21.Identity( name="test", extensions={ ext_def_id: { @@ -1951,15 +1951,15 @@ class TestExt: extension_type = "toplevel-property-extension" props = { - "intprop": stix2.properties.IntegerProperty(required=True), - "strprop": stix2.properties.StringProperty( + "intprop": misp_lib_stix2.properties.IntegerProperty(required=True), + "strprop": misp_lib_stix2.properties.StringProperty( required=False, default=lambda: "foo", ), } with _register_extension(TestExt, props) as ext_def_id: - obj = stix2.v21.Identity( + obj = misp_lib_stix2.v21.Identity( name="test", intprop="1", strprop=2, @@ -1974,7 +1974,7 @@ class TestExt: assert obj.intprop == 1 assert obj.strprop == "2" - obj = stix2.v21.Identity( + obj = misp_lib_stix2.v21.Identity( name="test", intprop=1, extensions={ @@ -1988,7 +1988,7 @@ class TestExt: assert obj.strprop == "foo" with pytest.raises(InvalidValueError): - stix2.v21.Identity( + misp_lib_stix2.v21.Identity( name="test", intprop="foo", # wrong value type extensions={ @@ -1999,7 +1999,7 @@ class TestExt: ) with pytest.raises(InvalidValueError): - stix2.v21.Identity( + misp_lib_stix2.v21.Identity( name="test", intprop=1, extensions={ @@ -2012,7 +2012,7 @@ class TestExt: ) with pytest.raises(InvalidValueError): - stix2.v21.Identity( + misp_lib_stix2.v21.Identity( name="test", intprop=1, extensions={ @@ -2026,7 +2026,7 @@ class TestExt: ) with pytest.raises(MissingPropertiesError): - stix2.v21.Identity( + misp_lib_stix2.v21.Identity( name="test", strprop="foo", # missing required property extensions={ @@ -2048,7 +2048,7 @@ class ExtensionsExtension: extension_type = "toplevel-property-extension" ext_props = { - "extensions": stix2.properties.ExtensionsProperty(spec_version="2.1"), + "extensions": misp_lib_stix2.properties.ExtensionsProperty(spec_version="2.1"), } with _register_extension(ExtensionsExtension, ext_props) as ext_id: @@ -2069,26 +2069,26 @@ class ExtensionsExtension: }, } - stix2.parse(obj_dict) + misp_lib_stix2.parse(obj_dict) def test_invalid_extension_prop_name(): with pytest.raises(ValueError): - @stix2.v21.common.CustomExtension( + @misp_lib_stix2.v21.common.CustomExtension( "extension-definition--0530fdbd-0fa3-42ab-90cf-660e0abad370", [ - ("7foo", stix2.properties.StringProperty()), + ("7foo", misp_lib_stix2.properties.StringProperty()), ], ) class CustomExt: extension_type = "property-extension" with pytest.raises(ValueError): - @stix2.v21.common.CustomExtension( + @misp_lib_stix2.v21.common.CustomExtension( "extension-definition--0530fdbd-0fa3-42ab-90cf-660e0abad370", [ - ("7foo", stix2.properties.StringProperty()), + ("7foo", misp_lib_stix2.properties.StringProperty()), ], ) class CustomExt: # noqa: F811 @@ -2119,4 +2119,4 @@ def test_allow_custom_propagation(): # allow_custom=False at the top level should catch the custom property way # down in the SCO extension. with pytest.raises(InvalidValueError): - stix2.parse(obj_dict, allow_custom=False) + misp_lib_stix2.parse(obj_dict, allow_custom=False) diff --git a/stix2/test/v20/test_datastore.py b/misp_lib_stix2/test/v21/test_datastore.py similarity index 98% rename from stix2/test/v20/test_datastore.py rename to misp_lib_stix2/test/v21/test_datastore.py index 8bb5494c..a0238a5a 100644 --- a/stix2/test/v20/test_datastore.py +++ b/misp_lib_stix2/test/v21/test_datastore.py @@ -1,9 +1,9 @@ import pytest -from stix2.datastore import ( +from misp_lib_stix2.datastore import ( CompositeDataSource, DataSink, DataSource, DataStoreMixin, ) -from stix2.datastore.filters import Filter +from misp_lib_stix2.datastore.filters import Filter from .constants import CAMPAIGN_MORE_KWARGS diff --git a/stix2/test/v21/test_datastore_composite.py b/misp_lib_stix2/test/v21/test_datastore_composite.py similarity index 94% rename from stix2/test/v21/test_datastore_composite.py rename to misp_lib_stix2/test/v21/test_datastore_composite.py index c6128e52..ca5d1b83 100644 --- a/stix2/test/v21/test_datastore_composite.py +++ b/misp_lib_stix2/test/v21/test_datastore_composite.py @@ -1,10 +1,10 @@ import pytest -from stix2.datastore import CompositeDataSource, make_id -from stix2.datastore.filters import Filter -from stix2.datastore.memory import MemorySink, MemorySource, MemoryStore -from stix2.utils import parse_into_datetime -from stix2.v21.common import TLP_GREEN +from misp_lib_stix2.datastore import CompositeDataSource, make_id +from misp_lib_stix2.datastore.filters import Filter +from misp_lib_stix2.datastore.memory import MemorySink, MemorySource, MemoryStore +from misp_lib_stix2.utils import parse_into_datetime +from misp_lib_stix2.v21.common import TLP_GREEN def test_add_remove_composite_datasource(): diff --git a/stix2/test/v21/test_datastore_filesystem.py b/misp_lib_stix2/test/v21/test_datastore_filesystem.py similarity index 87% rename from stix2/test/v21/test_datastore_filesystem.py rename to misp_lib_stix2/test/v21/test_datastore_filesystem.py index 3eb20b5f..f22f986e 100644 --- a/stix2/test/v21/test_datastore_filesystem.py +++ b/misp_lib_stix2/test/v21/test_datastore_filesystem.py @@ -8,12 +8,12 @@ import pytest import pytz -import stix2 -from stix2.datastore.filesystem import ( +import misp_lib_stix2 +from misp_lib_stix2.datastore.filesystem import ( AuthSet, _find_search_optimizations, _get_matching_dir_entries, _timestamp2filename, ) -from stix2.exceptions import STIXError +from misp_lib_stix2.exceptions import STIXError from .constants import ( CAMPAIGN_ID, CAMPAIGN_KWARGS, IDENTITY_ID, IDENTITY_KWARGS, INDICATOR_ID, @@ -26,7 +26,7 @@ @pytest.fixture def fs_store(): # create - yield stix2.FileSystemStore(FS_PATH) + yield misp_lib_stix2.FileSystemStore(FS_PATH) # remove campaign dir shutil.rmtree(os.path.join(FS_PATH, "campaign"), True) @@ -35,7 +35,7 @@ def fs_store(): @pytest.fixture def fs_source(): # create - fs = stix2.FileSystemSource(FS_PATH) + fs = misp_lib_stix2.FileSystemSource(FS_PATH) assert fs.stix_dir == FS_PATH yield fs @@ -46,7 +46,7 @@ def fs_source(): @pytest.fixture def fs_sink(): # create - fs = stix2.FileSystemSink(FS_PATH) + fs = misp_lib_stix2.FileSystemSink(FS_PATH) assert fs.stix_dir == FS_PATH yield fs @@ -91,15 +91,15 @@ def bad_stix_files(): @pytest.fixture(scope='module') def rel_fs_store(): - cam = stix2.v21.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) - idy = stix2.v21.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) - ind = stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) - mal = stix2.v21.Malware(id=MALWARE_ID, **MALWARE_KWARGS) - rel1 = stix2.v21.Relationship(ind, 'indicates', mal, id=RELATIONSHIP_IDS[0]) - rel2 = stix2.v21.Relationship(mal, 'targets', idy, id=RELATIONSHIP_IDS[1]) - rel3 = stix2.v21.Relationship(cam, 'uses', mal, id=RELATIONSHIP_IDS[2]) + cam = misp_lib_stix2.v21.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) + idy = misp_lib_stix2.v21.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) + ind = misp_lib_stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) + mal = misp_lib_stix2.v21.Malware(id=MALWARE_ID, **MALWARE_KWARGS) + rel1 = misp_lib_stix2.v21.Relationship(ind, 'indicates', mal, id=RELATIONSHIP_IDS[0]) + rel2 = misp_lib_stix2.v21.Relationship(mal, 'targets', idy, id=RELATIONSHIP_IDS[1]) + rel3 = misp_lib_stix2.v21.Relationship(cam, 'uses', mal, id=RELATIONSHIP_IDS[2]) stix_objs = [cam, idy, ind, mal, rel1, rel2, rel3] - fs = stix2.FileSystemStore(FS_PATH) + fs = misp_lib_stix2.FileSystemStore(FS_PATH) for o in stix_objs: fs.add(o) yield fs @@ -125,12 +125,12 @@ def rel_fs_store(): def test_filesystem_source_nonexistent_folder(): with pytest.raises(ValueError): - stix2.FileSystemSource('nonexistent-folder') + misp_lib_stix2.FileSystemSource('nonexistent-folder') def test_filesystem_sink_nonexistent_folder(): with pytest.raises(ValueError): - stix2.FileSystemSink('nonexistent-folder') + misp_lib_stix2.FileSystemSink('nonexistent-folder') def test_filesystem_source_bad_json_file(fs_source, bad_json_files): @@ -183,7 +183,7 @@ def test_filesystem_source_all_versions(fs_source): def test_filesystem_source_query_single(fs_source): # query2 - is_2 = fs_source.query([stix2.Filter("external_references.external_id", '=', "T1027")]) + is_2 = fs_source.query([misp_lib_stix2.Filter("external_references.external_id", '=', "T1027")]) assert len(is_2) == 1 is_2 = is_2[0] @@ -193,7 +193,7 @@ def test_filesystem_source_query_single(fs_source): def test_filesystem_source_query_multiple(fs_source): # query - intrusion_sets = fs_source.query([stix2.Filter("type", '=', "intrusion-set")]) + intrusion_sets = fs_source.query([misp_lib_stix2.Filter("type", '=', "intrusion-set")]) assert len(intrusion_sets) == 2 assert "intrusion-set--a653431d-6a5e-4600-8ad3-609b5af57064" in [is_.id for is_ in intrusion_sets] assert "intrusion-set--f3bdec95-3d62-42d9-a840-29630f6cdc1a" in [is_.id for is_ in intrusion_sets] @@ -208,9 +208,9 @@ def test_filesystem_source_backward_compatible(fs_source): # it. modified = datetime.datetime(2018, 11, 16, 22, 54, 20, 390000, pytz.utc) results = fs_source.query([ - stix2.Filter("type", "=", "malware"), - stix2.Filter("id", "=", "malware--6b616fc1-1505-48e3-8b2c-0d19337bff38"), - stix2.Filter("modified", "=", modified), + misp_lib_stix2.Filter("type", "=", "malware"), + misp_lib_stix2.Filter("id", "=", "malware--6b616fc1-1505-48e3-8b2c-0d19337bff38"), + misp_lib_stix2.Filter("modified", "=", modified), ]) assert len(results) == 1 @@ -222,7 +222,7 @@ def test_filesystem_source_backward_compatible(fs_source): def test_filesystem_source_sco(fs_source): - results = fs_source.query([stix2.Filter("type", "=", "directory")]) + results = fs_source.query([misp_lib_stix2.Filter("type", "=", "directory")]) assert len(results) == 1 result = results[0] @@ -233,7 +233,7 @@ def test_filesystem_source_sco(fs_source): def test_filesystem_sink_add_python_stix_object(fs_sink, fs_source): # add python stix object - camp1 = stix2.v21.Campaign( + camp1 = misp_lib_stix2.v21.Campaign( name="Hannibal", objective="Targeting Italian and Spanish Diplomat internet accounts", aliases=["War Elephant"], @@ -275,7 +275,7 @@ def test_filesystem_sink_add_stix_object_dict(fs_sink, fs_source): # as what's in the dict, since the parsing process can enforce a precision # constraint (e.g. truncate to milliseconds), which results in a slightly # different name. - camp2obj = stix2.parse(camp2) + camp2obj = misp_lib_stix2.parse(camp2) filepath = os.path.join( FS_PATH, "campaign", camp2obj["id"], _timestamp2filename(camp2obj["modified"]) + ".json", @@ -311,7 +311,7 @@ def test_filesystem_sink_add_stix_bundle_dict(fs_sink, fs_source): fs_sink.add(bund) - camp_obj = stix2.parse(bund["objects"][0]) + camp_obj = misp_lib_stix2.parse(bund["objects"][0]) filepath = os.path.join( FS_PATH, "campaign", camp_obj["id"], _timestamp2filename(camp_obj["modified"]) + ".json", @@ -336,7 +336,7 @@ def test_filesystem_sink_add_json_stix_object(fs_sink, fs_source): fs_sink.add(camp4) - camp4obj = stix2.parse(camp4) + camp4obj = misp_lib_stix2.parse(camp4) filepath = os.path.join( FS_PATH, "campaign", "campaign--6a6ca372-ba07-42cc-81ef-9840fc1f963d", @@ -361,7 +361,7 @@ def test_filesystem_sink_json_stix_bundle(fs_sink, fs_source): ' "name": "Spartacus", "objective": "Oppressive regimes of Africa and Middle East"}]}' fs_sink.add(bund2) - bund2obj = stix2.parse(bund2) + bund2obj = misp_lib_stix2.parse(bund2) camp_obj = bund2obj["objects"][0] filepath = os.path.join( @@ -381,7 +381,7 @@ def test_filesystem_sink_json_stix_bundle(fs_sink, fs_source): def test_filesystem_sink_add_objects_list(fs_sink, fs_source): # add list of objects - camp6 = stix2.v21.Campaign( + camp6 = misp_lib_stix2.v21.Campaign( name="Comanche", objective="US Midwest manufacturing firms, oil refineries, and businesses", aliases=["Horse Warrior"], @@ -399,7 +399,7 @@ def test_filesystem_sink_add_objects_list(fs_sink, fs_source): fs_sink.add([camp6, camp7]) - camp7obj = stix2.parse(camp7) + camp7obj = misp_lib_stix2.parse(camp7) camp6filepath = os.path.join( FS_PATH, "campaign", camp6.id, @@ -428,11 +428,11 @@ def test_filesystem_sink_add_objects_list(fs_sink, fs_source): def test_filesystem_sink_marking(fs_sink): - marking = stix2.v21.MarkingDefinition( + marking = misp_lib_stix2.v21.MarkingDefinition( id="marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da", created="2017-01-20T00:00:00.000Z", definition_type="tlp", - definition=stix2.v21.TLPMarking(tlp="green"), + definition=misp_lib_stix2.v21.TLPMarking(tlp="green"), ) fs_sink.add(marking) @@ -485,14 +485,14 @@ def test_filesystem_store_all_versions(fs_store): def test_filesystem_store_query(fs_store): # query() - tools = fs_store.query([stix2.Filter("tool_types", "in", "tool")]) + tools = fs_store.query([misp_lib_stix2.Filter("tool_types", "in", "tool")]) assert len(tools) == 2 assert "tool--242f3da3-4425-4d11-8f5c-b842886da966" in [tool.id for tool in tools] assert "tool--03342581-f790-4f03-ba41-e82e67392e23" in [tool.id for tool in tools] def test_filesystem_store_query_single_filter(fs_store): - query = stix2.Filter("tool_types", "in", "tool") + query = misp_lib_stix2.Filter("tool_types", "in", "tool") tools = fs_store.query(query) assert len(tools) == 2 assert "tool--242f3da3-4425-4d11-8f5c-b842886da966" in [tool.id for tool in tools] @@ -508,20 +508,20 @@ def test_filesystem_store_empty_query(fs_store): def test_filesystem_store_query_multiple_filters(fs_store): - fs_store.source.filters.add(stix2.Filter("tool_types", "in", "tool")) - tools = fs_store.query(stix2.Filter("id", "=", "tool--242f3da3-4425-4d11-8f5c-b842886da966")) + fs_store.source.filters.add(misp_lib_stix2.Filter("tool_types", "in", "tool")) + tools = fs_store.query(misp_lib_stix2.Filter("id", "=", "tool--242f3da3-4425-4d11-8f5c-b842886da966")) assert len(tools) == 1 assert tools[0].id == "tool--242f3da3-4425-4d11-8f5c-b842886da966" def test_filesystem_store_query_dont_include_type_folder(fs_store): - results = fs_store.query(stix2.Filter("type", "!=", "tool")) + results = fs_store.query(misp_lib_stix2.Filter("type", "!=", "tool")) assert len(results) == 29 def test_filesystem_store_add(fs_store): # add() - camp1 = stix2.v21.Campaign( + camp1 = misp_lib_stix2.v21.Campaign( name="Great Heathen Army", objective="Targeting the government of United Kingdom and insitutions affiliated with the Church Of England", aliases=["Ragnar"], @@ -542,9 +542,9 @@ def test_filesystem_store_add(fs_store): def test_filesystem_store_add_as_bundle(): - fs_store = stix2.FileSystemStore(FS_PATH, bundlify=True) + fs_store = misp_lib_stix2.FileSystemStore(FS_PATH, bundlify=True) - camp1 = stix2.v21.Campaign( + camp1 = misp_lib_stix2.v21.Campaign( name="Great Heathen Army", objective="Targeting the government of United Kingdom and insitutions affiliated with the Church Of England", aliases=["Ragnar"], @@ -567,7 +567,7 @@ def test_filesystem_store_add_as_bundle(): def test_filesystem_add_bundle_object(fs_store): - bundle = stix2.v21.Bundle() + bundle = misp_lib_stix2.v21.Bundle() fs_store.add(bundle) @@ -582,11 +582,11 @@ def test_filesystem_store_add_invalid_object(fs_store): def test_filesystem_store_add_marking(fs_store): - marking = stix2.v21.MarkingDefinition( + marking = misp_lib_stix2.v21.MarkingDefinition( id="marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da", created="2017-01-20T00:00:00.000Z", definition_type="tlp", - definition=stix2.v21.TLPMarking(tlp="green"), + definition=misp_lib_stix2.v21.TLPMarking(tlp="green"), ) fs_store.add(marking) @@ -604,7 +604,7 @@ def test_filesystem_store_add_marking(fs_store): def test_filesystem_store_add_sco(fs_store): - sco = stix2.v21.EmailAddress( + sco = misp_lib_stix2.v21.EmailAddress( value="jdoe@example.com", ) @@ -624,7 +624,7 @@ def test_filesystem_store_add_sco(fs_store): def test_filesystem_object_with_custom_property(fs_store): - camp = stix2.v21.Campaign( + camp = misp_lib_stix2.v21.Campaign( name="Scipio Africanus", objective="Defeat the Carthaginians", x_empire="Roman", @@ -639,14 +639,14 @@ def test_filesystem_object_with_custom_property(fs_store): def test_filesystem_object_with_custom_property_in_bundle(fs_store): - camp = stix2.v21.Campaign( + camp = misp_lib_stix2.v21.Campaign( name="Scipio Africanus", objective="Defeat the Carthaginians", x_empire="Roman", allow_custom=True, ) - bundle = stix2.v21.Bundle(camp, allow_custom=True) + bundle = misp_lib_stix2.v21.Bundle(camp, allow_custom=True) fs_store.add(bundle) camp_r = fs_store.get(camp.id) @@ -676,9 +676,9 @@ def test_filesystem_custom_object_dict(fs_store): def test_filesystem_custom_object(fs_store): - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x-new-obj-2', [ - ('property1', stix2.properties.StringProperty(required=True)), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), ], ) class NewObj(): @@ -797,7 +797,7 @@ def test_auth_set_black1(): def test_optimize_types1(): filters = [ - stix2.Filter("type", "=", "foo"), + misp_lib_stix2.Filter("type", "=", "foo"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -810,8 +810,8 @@ def test_optimize_types1(): def test_optimize_types2(): filters = [ - stix2.Filter("type", "=", "foo"), - stix2.Filter("type", "=", "bar"), + misp_lib_stix2.Filter("type", "=", "foo"), + misp_lib_stix2.Filter("type", "=", "bar"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -824,8 +824,8 @@ def test_optimize_types2(): def test_optimize_types3(): filters = [ - stix2.Filter("type", "in", ["A", "B", "C"]), - stix2.Filter("type", "in", ["B", "C", "D"]), + misp_lib_stix2.Filter("type", "in", ["A", "B", "C"]), + misp_lib_stix2.Filter("type", "in", ["B", "C", "D"]), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -838,8 +838,8 @@ def test_optimize_types3(): def test_optimize_types4(): filters = [ - stix2.Filter("type", "in", ["A", "B", "C"]), - stix2.Filter("type", "in", ["D", "E", "F"]), + misp_lib_stix2.Filter("type", "in", ["A", "B", "C"]), + misp_lib_stix2.Filter("type", "in", ["D", "E", "F"]), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -852,8 +852,8 @@ def test_optimize_types4(): def test_optimize_types5(): filters = [ - stix2.Filter("type", "in", ["foo", "bar"]), - stix2.Filter("type", "!=", "bar"), + misp_lib_stix2.Filter("type", "in", ["foo", "bar"]), + misp_lib_stix2.Filter("type", "!=", "bar"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -866,8 +866,8 @@ def test_optimize_types5(): def test_optimize_types6(): filters = [ - stix2.Filter("type", "!=", "foo"), - stix2.Filter("type", "!=", "bar"), + misp_lib_stix2.Filter("type", "!=", "foo"), + misp_lib_stix2.Filter("type", "!=", "bar"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -880,8 +880,8 @@ def test_optimize_types6(): def test_optimize_types7(): filters = [ - stix2.Filter("type", "=", "foo"), - stix2.Filter("type", "!=", "foo"), + misp_lib_stix2.Filter("type", "=", "foo"), + misp_lib_stix2.Filter("type", "!=", "foo"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -905,8 +905,8 @@ def test_optimize_types8(): def test_optimize_types_ids1(): filters = [ - stix2.Filter("type", "in", ["foo", "bar"]), - stix2.Filter("id", "=", "foo--00000000-0000-0000-0000-000000000000"), + misp_lib_stix2.Filter("type", "in", ["foo", "bar"]), + misp_lib_stix2.Filter("id", "=", "foo--00000000-0000-0000-0000-000000000000"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -919,8 +919,8 @@ def test_optimize_types_ids1(): def test_optimize_types_ids2(): filters = [ - stix2.Filter("type", "=", "foo"), - stix2.Filter("id", "=", "bar--00000000-0000-0000-0000-000000000000"), + misp_lib_stix2.Filter("type", "=", "foo"), + misp_lib_stix2.Filter("id", "=", "bar--00000000-0000-0000-0000-000000000000"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -933,8 +933,8 @@ def test_optimize_types_ids2(): def test_optimize_types_ids3(): filters = [ - stix2.Filter("type", "in", ["foo", "bar"]), - stix2.Filter("id", "!=", "bar--00000000-0000-0000-0000-000000000000"), + misp_lib_stix2.Filter("type", "in", ["foo", "bar"]), + misp_lib_stix2.Filter("id", "!=", "bar--00000000-0000-0000-0000-000000000000"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -947,8 +947,8 @@ def test_optimize_types_ids3(): def test_optimize_types_ids4(): filters = [ - stix2.Filter("type", "in", ["A", "B", "C"]), - stix2.Filter( + misp_lib_stix2.Filter("type", "in", ["A", "B", "C"]), + misp_lib_stix2.Filter( "id", "in", [ "B--00000000-0000-0000-0000-000000000000", "C--00000000-0000-0000-0000-000000000000", @@ -970,16 +970,16 @@ def test_optimize_types_ids4(): def test_optimize_types_ids5(): filters = [ - stix2.Filter("type", "in", ["A", "B", "C"]), - stix2.Filter("type", "!=", "C"), - stix2.Filter( + misp_lib_stix2.Filter("type", "in", ["A", "B", "C"]), + misp_lib_stix2.Filter("type", "!=", "C"), + misp_lib_stix2.Filter( "id", "in", [ "B--00000000-0000-0000-0000-000000000000", "C--00000000-0000-0000-0000-000000000000", "D--00000000-0000-0000-0000-000000000000", ], ), - stix2.Filter("id", "!=", "D--00000000-0000-0000-0000-000000000000"), + misp_lib_stix2.Filter("id", "!=", "D--00000000-0000-0000-0000-000000000000"), ] auth_types, auth_ids = _find_search_optimizations(filters) @@ -992,7 +992,7 @@ def test_optimize_types_ids5(): def test_optimize_types_ids6(): filters = [ - stix2.Filter("id", "=", "A--00000000-0000-0000-0000-000000000000"), + misp_lib_stix2.Filter("id", "=", "A--00000000-0000-0000-0000-000000000000"), ] auth_types, auth_ids = _find_search_optimizations(filters) diff --git a/stix2/test/v21/test_datastore_filters.py b/misp_lib_stix2/test/v21/test_datastore_filters.py similarity index 99% rename from stix2/test/v21/test_datastore_filters.py rename to misp_lib_stix2/test/v21/test_datastore_filters.py index 0e531fdb..9404ade0 100644 --- a/stix2/test/v21/test_datastore_filters.py +++ b/misp_lib_stix2/test/v21/test_datastore_filters.py @@ -1,8 +1,8 @@ import pytest -from stix2 import parse -from stix2.datastore.filters import Filter, apply_common_filters -from stix2.utils import STIXdatetime, parse_into_datetime +from misp_lib_stix2 import parse +from misp_lib_stix2.datastore.filters import Filter, apply_common_filters +from misp_lib_stix2.utils import STIXdatetime, parse_into_datetime from .constants import OBSERVED_DATA_ID diff --git a/stix2/test/v21/test_datastore_memory.py b/misp_lib_stix2/test/v21/test_datastore_memory.py similarity index 98% rename from stix2/test/v21/test_datastore_memory.py rename to misp_lib_stix2/test/v21/test_datastore_memory.py index f2c9a8c1..3f4376e4 100644 --- a/stix2/test/v21/test_datastore_memory.py +++ b/misp_lib_stix2/test/v21/test_datastore_memory.py @@ -3,10 +3,10 @@ import pytest -from stix2 import Filter, MemorySource, MemoryStore, properties -from stix2.datastore import make_id -from stix2.utils import parse_into_datetime -from stix2.v21 import ( +from misp_lib_stix2 import Filter, MemorySource, MemoryStore, properties +from misp_lib_stix2.datastore import make_id +from misp_lib_stix2.utils import parse_into_datetime +from misp_lib_stix2.v21 import ( Bundle, Campaign, CustomObject, Identity, Indicator, Malware, Relationship, ) diff --git a/stix2/test/v21/test_datastore_taxii.py b/misp_lib_stix2/test/v21/test_datastore_taxii.py similarity index 87% rename from stix2/test/v21/test_datastore_taxii.py rename to misp_lib_stix2/test/v21/test_datastore_taxii.py index 62ddadc3..264d861d 100644 --- a/stix2/test/v21/test_datastore_taxii.py +++ b/misp_lib_stix2/test/v21/test_datastore_taxii.py @@ -6,10 +6,10 @@ from taxii2client.common import _filter_kwargs_to_query_params from taxii2client.v21 import Collection -import stix2 -from stix2.datastore import DataSourceError -from stix2.datastore.filters import Filter -from stix2.utils import get_timestamp +import misp_lib_stix2 +from misp_lib_stix2.datastore import DataSourceError +from misp_lib_stix2.datastore.filters import Filter +from misp_lib_stix2.utils import get_timestamp COLLECTION_URL = 'https://example.com/api1/collections/91a7b528-80eb-42ed-a74d-c6fbd5a26116/' @@ -129,15 +129,15 @@ def collection_no_rw_access(stix_objs1, stix_objs1_manifests): def test_ds_taxii(collection): - ds = stix2.TAXIICollectionSource(collection) + ds = misp_lib_stix2.TAXIICollectionSource(collection) assert ds.collection is not None def test_add_stix2_object(collection): - tc_sink = stix2.TAXIICollectionSink(collection) + tc_sink = misp_lib_stix2.TAXIICollectionSink(collection) # create new STIX threat-actor - ta = stix2.v21.ThreatActor( + ta = misp_lib_stix2.v21.ThreatActor( name="Teddy Bear", threat_actor_types=["nation-state"], sophistication="innovator", @@ -152,10 +152,10 @@ def test_add_stix2_object(collection): def test_add_stix2_with_custom_object(collection): - tc_sink = stix2.TAXIICollectionStore(collection, allow_custom=True) + tc_sink = misp_lib_stix2.TAXIICollectionStore(collection, allow_custom=True) # create new STIX threat-actor - ta = stix2.v21.ThreatActor( + ta = misp_lib_stix2.v21.ThreatActor( name="Teddy Bear", threat_actor_types=["nation-state"], sophistication="innovator", @@ -172,10 +172,10 @@ def test_add_stix2_with_custom_object(collection): def test_add_list_object(collection, indicator): - tc_sink = stix2.TAXIICollectionSink(collection) + tc_sink = misp_lib_stix2.TAXIICollectionSink(collection) # create new STIX threat-actor - ta = stix2.v21.ThreatActor( + ta = misp_lib_stix2.v21.ThreatActor( name="Teddy Bear", threat_actor_types=["nation-state"], sophistication="innovator", @@ -190,24 +190,24 @@ def test_add_list_object(collection, indicator): def test_get_object_found(collection): - tc_source = stix2.TAXIICollectionSource(collection) + tc_source = misp_lib_stix2.TAXIICollectionSource(collection) result = tc_source.query([ - stix2.Filter("id", "=", "indicator--00000000-0000-4000-8000-000000000001"), + misp_lib_stix2.Filter("id", "=", "indicator--00000000-0000-4000-8000-000000000001"), ]) assert result def test_get_object_not_found(collection): - tc_source = stix2.TAXIICollectionSource(collection) + tc_source = misp_lib_stix2.TAXIICollectionSource(collection) result = tc_source.get("indicator--00000000-0000-4000-8000-000000000012") assert result is None def test_add_stix2_bundle_object(collection): - tc_sink = stix2.TAXIICollectionSink(collection) + tc_sink = misp_lib_stix2.TAXIICollectionSink(collection) # create new STIX threat-actor - ta = stix2.v21.ThreatActor( + ta = misp_lib_stix2.v21.ThreatActor( name="Teddy Bear", threat_actor_types=["nation-state"], sophistication="innovator", @@ -218,11 +218,11 @@ def test_add_stix2_bundle_object(collection): ], ) - tc_sink.add(stix2.v21.Bundle(objects=[ta])) + tc_sink.add(misp_lib_stix2.v21.Bundle(objects=[ta])) def test_add_str_object(collection): - tc_sink = stix2.TAXIICollectionSink(collection) + tc_sink = misp_lib_stix2.TAXIICollectionSink(collection) # create new STIX threat-actor ta = """{ @@ -247,7 +247,7 @@ def test_add_str_object(collection): def test_add_dict_object(collection): - tc_sink = stix2.TAXIICollectionSink(collection) + tc_sink = misp_lib_stix2.TAXIICollectionSink(collection) ta = { "type": "threat-actor", @@ -271,7 +271,7 @@ def test_add_dict_object(collection): def test_add_dict_bundle_object(collection): - tc_sink = stix2.TAXIICollectionSink(collection) + tc_sink = misp_lib_stix2.TAXIICollectionSink(collection) ta = { "type": "bundle", @@ -301,7 +301,7 @@ def test_add_dict_bundle_object(collection): def test_get_stix2_object(collection): - tc_sink = stix2.TAXIICollectionSource(collection) + tc_sink = misp_lib_stix2.TAXIICollectionSource(collection) objects = tc_sink.get("indicator--00000000-0000-4000-8000-000000000001") @@ -324,7 +324,7 @@ def test_parse_taxii_filters(collection): Filter("version", "=", "first"), ] - ds = stix2.TAXIICollectionSource(collection) + ds = misp_lib_stix2.TAXIICollectionSource(collection) taxii_filters = ds._parse_taxii_filters(query) @@ -332,7 +332,7 @@ def test_parse_taxii_filters(collection): def test_add_get_remove_filter(collection): - ds = stix2.TAXIICollectionSource(collection) + ds = misp_lib_stix2.TAXIICollectionSource(collection) # First 3 filters are valid, remaining properties are erroneous in some way valid_filters = [ @@ -368,7 +368,7 @@ def test_add_get_remove_filter(collection): def test_get_all_versions(collection): - ds = stix2.TAXIICollectionStore(collection) + ds = misp_lib_stix2.TAXIICollectionStore(collection) indicators = ds.all_versions('indicator--00000000-0000-4000-8000-000000000001') # There are 3 indicators but 2 share the same 'modified' timestamp @@ -380,7 +380,7 @@ def test_can_read_error(collection_no_rw_access): instance that does not have read access, check ValueError exception is raised""" with pytest.raises(DataSourceError) as excinfo: - stix2.TAXIICollectionSource(collection_no_rw_access) + misp_lib_stix2.TAXIICollectionSource(collection_no_rw_access) assert "Collection object provided does not have read access" in str(excinfo.value) @@ -389,7 +389,7 @@ def test_can_write_error(collection_no_rw_access): instance that does not have write access, check ValueError exception is raised""" with pytest.raises(DataSourceError) as excinfo: - stix2.TAXIICollectionSink(collection_no_rw_access) + misp_lib_stix2.TAXIICollectionSink(collection_no_rw_access) assert "Collection object provided does not have write access" in str(excinfo.value) @@ -410,7 +410,7 @@ def get_object(self, id, version=None): resp.status_code = 404 resp.raise_for_status() - ds = stix2.TAXIICollectionSource(TAXIICollection404()) + ds = misp_lib_stix2.TAXIICollectionSource(TAXIICollection404()) # this will raise 404 from mock TAXII Client but TAXIICollectionStore # should handle gracefully and return None @@ -422,7 +422,7 @@ def test_all_versions_404(collection): """ a TAXIICollectionSource.all_version() call that recieves an HTTP 404 response code from the taxii2client should be returned as an exception""" - ds = stix2.TAXIICollectionStore(collection) + ds = misp_lib_stix2.TAXIICollectionStore(collection) with pytest.raises(DataSourceError) as excinfo: ds.all_versions("indicator--1") @@ -434,7 +434,7 @@ def test_query_404(collection): """ a TAXIICollectionSource.query() call that recieves an HTTP 404 response code from the taxii2client should be returned as an exception""" - ds = stix2.TAXIICollectionStore(collection) + ds = misp_lib_stix2.TAXIICollectionStore(collection) query = [Filter("type", "=", "malware")] with pytest.raises(DataSourceError) as excinfo: diff --git a/stix2/test/v21/test_deterministic_ids.py b/misp_lib_stix2/test/v21/test_deterministic_ids.py similarity index 81% rename from stix2/test/v21/test_deterministic_ids.py rename to misp_lib_stix2/test/v21/test_deterministic_ids.py index 710ee7a8..b2c03563 100644 --- a/stix2/test/v21/test_deterministic_ids.py +++ b/misp_lib_stix2/test/v21/test_deterministic_ids.py @@ -4,17 +4,17 @@ import pytest -import stix2.base -import stix2.canonicalization.Canonicalize -import stix2.exceptions -from stix2.properties import ( +import misp_lib_stix2.base +import misp_lib_stix2.canonicalization.Canonicalize +import misp_lib_stix2.exceptions +from misp_lib_stix2.properties import ( BooleanProperty, DictionaryProperty, EmbeddedObjectProperty, ExtensionsProperty, FloatProperty, HashesProperty, IDProperty, IntegerProperty, ListProperty, StringProperty, TimestampProperty, TypeProperty, ) -import stix2.v21 -from stix2.v21.vocab import HASHING_ALGORITHM +import misp_lib_stix2.v21 +from misp_lib_stix2.v21.vocab import HASHING_ALGORITHM SCO_DET_ID_NAMESPACE = uuid.UUID("00abedb4-aa42-466c-9c01-fed23315a9b7") @@ -38,7 +38,7 @@ def _make_uuid5(name): def test_no_contrib_props_defined(): - class SomeSCO(stix2.v21._Observable): + class SomeSCO(misp_lib_stix2.v21._Observable): _type = "some-sco" _properties = OrderedDict(( ('type', TypeProperty(_type, spec_version='2.1')), @@ -55,7 +55,7 @@ class SomeSCO(stix2.v21._Observable): def test_json_compatible_prop_values(): - class SomeSCO(stix2.v21._Observable): + class SomeSCO(misp_lib_stix2.v21._Observable): _type = "some-sco" _properties = OrderedDict(( ('type', TypeProperty(_type, spec_version='2.1')), @@ -83,7 +83,7 @@ class SomeSCO(stix2.v21._Observable): sco = SomeSCO(**obj) - can_json = stix2.canonicalization.Canonicalize.canonicalize(obj, utf8=False) + can_json = misp_lib_stix2.canonicalization.Canonicalize.canonicalize(obj, utf8=False) expected_uuid5 = _make_uuid5(can_json) actual_uuid5 = _uuid_from_id(sco["id"]) @@ -91,7 +91,7 @@ class SomeSCO(stix2.v21._Observable): def test_json_incompatible_timestamp_value(): - class SomeSCO(stix2.v21._Observable): + class SomeSCO(misp_lib_stix2.v21._Observable): _type = "some-sco" _properties = OrderedDict(( ('type', TypeProperty(_type, spec_version='2.1')), @@ -109,7 +109,7 @@ class SomeSCO(stix2.v21._Observable): "timestamp": "1987-01-02T03:04:05.6789Z", } - can_json = stix2.canonicalization.Canonicalize.canonicalize(obj, utf8=False) + can_json = misp_lib_stix2.canonicalization.Canonicalize.canonicalize(obj, utf8=False) expected_uuid5 = _make_uuid5(can_json) actual_uuid5 = _uuid_from_id(sco["id"]) @@ -117,13 +117,13 @@ class SomeSCO(stix2.v21._Observable): def test_embedded_object(): - class SubObj(stix2.base._STIXBase): + class SubObj(misp_lib_stix2.base._STIXBase): _type = "sub-object" _properties = OrderedDict(( ('value', StringProperty()), )) - class SomeSCO(stix2.v21._Observable): + class SomeSCO(misp_lib_stix2.v21._Observable): _type = "some-sco" _properties = OrderedDict(( ('type', TypeProperty(_type, spec_version='2.1')), @@ -142,7 +142,7 @@ class SomeSCO(stix2.v21._Observable): }, } - can_json = stix2.canonicalization.Canonicalize.canonicalize(obj, utf8=False) + can_json = misp_lib_stix2.canonicalization.Canonicalize.canonicalize(obj, utf8=False) expected_uuid5 = _make_uuid5(can_json) actual_uuid5 = _uuid_from_id(sco["id"]) @@ -150,7 +150,7 @@ class SomeSCO(stix2.v21._Observable): def test_empty_hash(): - class SomeSCO(stix2.v21._Observable): + class SomeSCO(misp_lib_stix2.v21._Observable): _type = "some-sco" _properties = OrderedDict(( ('type', TypeProperty(_type, spec_version='2.1')), @@ -160,7 +160,7 @@ class SomeSCO(stix2.v21._Observable): )) _id_contributing_properties = ['hashes'] - with pytest.raises(stix2.exceptions.InvalidValueError): + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError): SomeSCO(hashes={}) @@ -175,22 +175,22 @@ class SomeSCO(stix2.v21._Observable): ], ) def test_json_unescaping(json_escaped, expected_unescaped): - actual_unescaped = stix2.base._un_json_escape(json_escaped) + actual_unescaped = misp_lib_stix2.base._un_json_escape(json_escaped) assert actual_unescaped == expected_unescaped def test_json_unescaping_bad_escape(): with pytest.raises(ValueError): - stix2.base._un_json_escape(r"\x") + misp_lib_stix2.base._un_json_escape(r"\x") def test_deterministic_id_same_extra_prop_vals(): - email_addr_1 = stix2.v21.EmailAddress( + email_addr_1 = misp_lib_stix2.v21.EmailAddress( value="john@example.com", display_name="Johnny Doe", ) - email_addr_2 = stix2.v21.EmailAddress( + email_addr_2 = misp_lib_stix2.v21.EmailAddress( value="john@example.com", display_name="Johnny Doe", ) @@ -207,12 +207,12 @@ def test_deterministic_id_same_extra_prop_vals(): def test_deterministic_id_diff_extra_prop_vals(): - email_addr_1 = stix2.v21.EmailAddress( + email_addr_1 = misp_lib_stix2.v21.EmailAddress( value="john@example.com", display_name="Johnny Doe", ) - email_addr_2 = stix2.v21.EmailAddress( + email_addr_2 = misp_lib_stix2.v21.EmailAddress( value="john@example.com", display_name="Janey Doe", ) @@ -229,12 +229,12 @@ def test_deterministic_id_diff_extra_prop_vals(): def test_deterministic_id_diff_contributing_prop_vals(): - email_addr_1 = stix2.v21.EmailAddress( + email_addr_1 = misp_lib_stix2.v21.EmailAddress( value="john@example.com", display_name="Johnny Doe", ) - email_addr_2 = stix2.v21.EmailAddress( + email_addr_2 = misp_lib_stix2.v21.EmailAddress( value="jane@example.com", display_name="Janey Doe", ) @@ -251,11 +251,11 @@ def test_deterministic_id_diff_contributing_prop_vals(): def test_deterministic_id_no_contributing_props(): - email_msg_1 = stix2.v21.EmailMessage( + email_msg_1 = misp_lib_stix2.v21.EmailMessage( is_multipart=False, ) - email_msg_2 = stix2.v21.EmailMessage( + email_msg_2 = misp_lib_stix2.v21.EmailMessage( is_multipart=False, ) @@ -271,7 +271,7 @@ def test_deterministic_id_no_contributing_props(): def test_id_gen_recursive_dict_conversion_1(): - file_observable = stix2.v21.File( + file_observable = misp_lib_stix2.v21.File( name="example.exe", size=68 * 1000, magic_number_hex="50000000", @@ -279,11 +279,11 @@ def test_id_gen_recursive_dict_conversion_1(): "SHA-256": "841a8921140aba50671ebb0770fecc4ee308c4952cfeff8de154ab14eeef4649", }, extensions={ - "windows-pebinary-ext": stix2.v21.WindowsPEBinaryExt( + "windows-pebinary-ext": misp_lib_stix2.v21.WindowsPEBinaryExt( pe_type="exe", machine_hex="014c", sections=[ - stix2.v21.WindowsPESection( + misp_lib_stix2.v21.WindowsPESection( name=".data", size=4096, entropy=7.980693, @@ -298,13 +298,13 @@ def test_id_gen_recursive_dict_conversion_1(): def test_id_gen_recursive_dict_conversion_2(): - wrko = stix2.v21.WindowsRegistryKey( + wrko = misp_lib_stix2.v21.WindowsRegistryKey( values=[ - stix2.v21.WindowsRegistryValueType( + misp_lib_stix2.v21.WindowsRegistryValueType( name="Foo", data="qwerty", ), - stix2.v21.WindowsRegistryValueType( + misp_lib_stix2.v21.WindowsRegistryValueType( name="Bar", data="42", ), diff --git a/stix2/test/v21/test_environment.py b/misp_lib_stix2/test/v21/test_environment.py similarity index 64% rename from stix2/test/v21/test_environment.py rename to misp_lib_stix2/test/v21/test_environment.py index 883ff012..29027a5c 100644 --- a/stix2/test/v21/test_environment.py +++ b/misp_lib_stix2/test/v21/test_environment.py @@ -3,11 +3,11 @@ import pytest -import stix2 -import stix2.environment -import stix2.equivalence.graph -import stix2.equivalence.object -import stix2.exceptions +import misp_lib_stix2 +import misp_lib_stix2.environment +import misp_lib_stix2.equivalence.graph +import misp_lib_stix2.equivalence.object +import misp_lib_stix2.exceptions from .constants import ( ATTACK_PATTERN_ID, ATTACK_PATTERN_KWARGS, CAMPAIGN_ID, CAMPAIGN_KWARGS, @@ -22,26 +22,26 @@ @pytest.fixture def ds(): - cam = stix2.v21.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) - idy = stix2.v21.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) - ind = stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) - mal = stix2.v21.Malware(id=MALWARE_ID, **MALWARE_KWARGS) - rel1 = stix2.v21.Relationship(ind, 'indicates', mal, id=RELATIONSHIP_IDS[0]) - rel2 = stix2.v21.Relationship(mal, 'targets', idy, id=RELATIONSHIP_IDS[1]) - rel3 = stix2.v21.Relationship(cam, 'uses', mal, id=RELATIONSHIP_IDS[2]) - reprt = stix2.v21.Report( + cam = misp_lib_stix2.v21.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) + idy = misp_lib_stix2.v21.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) + ind = misp_lib_stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) + mal = misp_lib_stix2.v21.Malware(id=MALWARE_ID, **MALWARE_KWARGS) + rel1 = misp_lib_stix2.v21.Relationship(ind, 'indicates', mal, id=RELATIONSHIP_IDS[0]) + rel2 = misp_lib_stix2.v21.Relationship(mal, 'targets', idy, id=RELATIONSHIP_IDS[1]) + rel3 = misp_lib_stix2.v21.Relationship(cam, 'uses', mal, id=RELATIONSHIP_IDS[2]) + reprt = misp_lib_stix2.v21.Report( name="Malware Report", published="2021-05-09T08:22:22Z", object_refs=[mal.id, rel1.id, ind.id], ) stix_objs = [cam, idy, ind, mal, rel1, rel2, rel3, reprt] - yield stix2.MemoryStore(stix_objs) + yield misp_lib_stix2.MemoryStore(stix_objs) @pytest.fixture def ds2_objects(): - cam = stix2.v21.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) - idy = stix2.v21.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) - ind = stix2.v21.Indicator(id=INDICATOR_ID, created_by_ref=idy.id, **INDICATOR_KWARGS) + cam = misp_lib_stix2.v21.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) + idy = misp_lib_stix2.v21.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) + ind = misp_lib_stix2.v21.Indicator(id=INDICATOR_ID, created_by_ref=idy.id, **INDICATOR_KWARGS) indv2 = ind.new_version( external_references=[ { @@ -49,9 +49,9 @@ def ds2_objects(): "url": "https://examplewebsite.com/", }, ], - object_marking_refs=[stix2.v21.TLP_WHITE], + object_marking_refs=[misp_lib_stix2.v21.TLP_WHITE], ) - mal = stix2.v21.Malware(id=MALWARE_ID, created_by_ref=idy.id, **MALWARE_KWARGS) + mal = misp_lib_stix2.v21.Malware(id=MALWARE_ID, created_by_ref=idy.id, **MALWARE_KWARGS) malv2 = mal.new_version( external_references=[ { @@ -60,11 +60,11 @@ def ds2_objects(): }, ], ) - rel1 = stix2.v21.Relationship(ind, 'indicates', mal, id=RELATIONSHIP_IDS[0]) - rel2 = stix2.v21.Relationship(mal, 'targets', idy, id=RELATIONSHIP_IDS[1]) - rel3 = stix2.v21.Relationship(cam, 'uses', mal, id=RELATIONSHIP_IDS[2]) + rel1 = misp_lib_stix2.v21.Relationship(ind, 'indicates', mal, id=RELATIONSHIP_IDS[0]) + rel2 = misp_lib_stix2.v21.Relationship(mal, 'targets', idy, id=RELATIONSHIP_IDS[1]) + rel3 = misp_lib_stix2.v21.Relationship(cam, 'uses', mal, id=RELATIONSHIP_IDS[2]) stix_objs = [cam, idy, ind, indv2, mal, malv2, rel1, rel2, rel3] - reprt = stix2.v21.Report( + reprt = misp_lib_stix2.v21.Report( created_by_ref=idy.id, name="example", published="2021-04-09T08:22:22Z", object_refs=stix_objs, ) @@ -74,115 +74,115 @@ def ds2_objects(): @pytest.fixture def ds2(ds2_objects): - yield stix2.MemoryStore(ds2_objects) + yield misp_lib_stix2.MemoryStore(ds2_objects) @pytest.fixture def fs(): - yield stix2.FileSystemSource(FS_PATH) + yield misp_lib_stix2.FileSystemSource(FS_PATH) def test_object_factory_created_by_ref_str(): - factory = stix2.ObjectFactory(created_by_ref=IDENTITY_ID) - ind = factory.create(stix2.v21.Indicator, **INDICATOR_KWARGS) + factory = misp_lib_stix2.ObjectFactory(created_by_ref=IDENTITY_ID) + ind = factory.create(misp_lib_stix2.v21.Indicator, **INDICATOR_KWARGS) assert ind.created_by_ref == IDENTITY_ID def test_object_factory_created_by_ref_obj(): - id_obj = stix2.v21.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) - factory = stix2.ObjectFactory(created_by_ref=id_obj) - ind = factory.create(stix2.v21.Indicator, **INDICATOR_KWARGS) + id_obj = misp_lib_stix2.v21.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) + factory = misp_lib_stix2.ObjectFactory(created_by_ref=id_obj) + ind = factory.create(misp_lib_stix2.v21.Indicator, **INDICATOR_KWARGS) assert ind.created_by_ref == IDENTITY_ID def test_object_factory_override_default(): - factory = stix2.ObjectFactory(created_by_ref=IDENTITY_ID) + factory = misp_lib_stix2.ObjectFactory(created_by_ref=IDENTITY_ID) new_id = "identity--983b3172-44fe-4a80-8091-eb8098841fe8" - ind = factory.create(stix2.v21.Indicator, created_by_ref=new_id, **INDICATOR_KWARGS) + ind = factory.create(misp_lib_stix2.v21.Indicator, created_by_ref=new_id, **INDICATOR_KWARGS) assert ind.created_by_ref == new_id def test_object_factory_created(): - factory = stix2.ObjectFactory(created=FAKE_TIME) - ind = factory.create(stix2.v21.Indicator, **INDICATOR_KWARGS) + factory = misp_lib_stix2.ObjectFactory(created=FAKE_TIME) + ind = factory.create(misp_lib_stix2.v21.Indicator, **INDICATOR_KWARGS) assert ind.created == FAKE_TIME assert ind.modified == FAKE_TIME def test_object_factory_external_reference(): - ext_ref = stix2.v21.ExternalReference( + ext_ref = misp_lib_stix2.v21.ExternalReference( source_name="ACME Threat Intel", description="Threat report", ) - factory = stix2.ObjectFactory(external_references=ext_ref) - ind = factory.create(stix2.v21.Indicator, **INDICATOR_KWARGS) + factory = misp_lib_stix2.ObjectFactory(external_references=ext_ref) + ind = factory.create(misp_lib_stix2.v21.Indicator, **INDICATOR_KWARGS) assert ind.external_references[0].source_name == "ACME Threat Intel" assert ind.external_references[0].description == "Threat report" - ind2 = factory.create(stix2.v21.Indicator, external_references=None, **INDICATOR_KWARGS) + ind2 = factory.create(misp_lib_stix2.v21.Indicator, external_references=None, **INDICATOR_KWARGS) assert 'external_references' not in ind2 def test_object_factory_obj_markings(): - stmt_marking = stix2.v21.StatementMarking("Copyright 2016, Example Corp") - mark_def = stix2.v21.MarkingDefinition( + stmt_marking = misp_lib_stix2.v21.StatementMarking("Copyright 2016, Example Corp") + mark_def = misp_lib_stix2.v21.MarkingDefinition( definition_type="statement", definition=stmt_marking, ) - factory = stix2.ObjectFactory(object_marking_refs=[mark_def, stix2.v21.TLP_AMBER]) - ind = factory.create(stix2.v21.Indicator, **INDICATOR_KWARGS) + factory = misp_lib_stix2.ObjectFactory(object_marking_refs=[mark_def, misp_lib_stix2.v21.TLP_AMBER]) + ind = factory.create(misp_lib_stix2.v21.Indicator, **INDICATOR_KWARGS) assert mark_def.id in ind.object_marking_refs - assert stix2.v21.TLP_AMBER.id in ind.object_marking_refs + assert misp_lib_stix2.v21.TLP_AMBER.id in ind.object_marking_refs - factory = stix2.ObjectFactory(object_marking_refs=stix2.v21.TLP_RED) - ind = factory.create(stix2.v21.Indicator, **INDICATOR_KWARGS) - assert stix2.v21.TLP_RED.id in ind.object_marking_refs + factory = misp_lib_stix2.ObjectFactory(object_marking_refs=misp_lib_stix2.v21.TLP_RED) + ind = factory.create(misp_lib_stix2.v21.Indicator, **INDICATOR_KWARGS) + assert misp_lib_stix2.v21.TLP_RED.id in ind.object_marking_refs def test_object_factory_list_append(): - ext_ref = stix2.v21.ExternalReference( + ext_ref = misp_lib_stix2.v21.ExternalReference( source_name="ACME Threat Intel", description="Threat report from ACME", ) - ext_ref2 = stix2.v21.ExternalReference( + ext_ref2 = misp_lib_stix2.v21.ExternalReference( source_name="Yet Another Threat Report", description="Threat report from YATR", ) - ext_ref3 = stix2.v21.ExternalReference( + ext_ref3 = misp_lib_stix2.v21.ExternalReference( source_name="Threat Report #3", description="One more threat report", ) - factory = stix2.ObjectFactory(external_references=ext_ref) - ind = factory.create(stix2.v21.Indicator, external_references=ext_ref2, **INDICATOR_KWARGS) + factory = misp_lib_stix2.ObjectFactory(external_references=ext_ref) + ind = factory.create(misp_lib_stix2.v21.Indicator, external_references=ext_ref2, **INDICATOR_KWARGS) assert ind.external_references[1].source_name == "Yet Another Threat Report" - ind = factory.create(stix2.v21.Indicator, external_references=[ext_ref2, ext_ref3], **INDICATOR_KWARGS) + ind = factory.create(misp_lib_stix2.v21.Indicator, external_references=[ext_ref2, ext_ref3], **INDICATOR_KWARGS) assert ind.external_references[2].source_name == "Threat Report #3" def test_object_factory_list_replace(): - ext_ref = stix2.v21.ExternalReference( + ext_ref = misp_lib_stix2.v21.ExternalReference( source_name="ACME Threat Intel", description="Threat report from ACME", ) - ext_ref2 = stix2.v21.ExternalReference( + ext_ref2 = misp_lib_stix2.v21.ExternalReference( source_name="Yet Another Threat Report", description="Threat report from YATR", ) - factory = stix2.ObjectFactory(external_references=ext_ref, list_append=False) - ind = factory.create(stix2.v21.Indicator, external_references=ext_ref2, **INDICATOR_KWARGS) + factory = misp_lib_stix2.ObjectFactory(external_references=ext_ref, list_append=False) + ind = factory.create(misp_lib_stix2.v21.Indicator, external_references=ext_ref2, **INDICATOR_KWARGS) assert len(ind.external_references) == 1 assert ind.external_references[0].source_name == "Yet Another Threat Report" def test_environment_functions(): - env = stix2.Environment( - stix2.ObjectFactory(created_by_ref=IDENTITY_ID), - stix2.MemoryStore(), + env = misp_lib_stix2.Environment( + misp_lib_stix2.ObjectFactory(created_by_ref=IDENTITY_ID), + misp_lib_stix2.MemoryStore(), ) # Create a STIX object - ind = env.create(stix2.v21.Indicator, id=INDICATOR_ID, **INDICATOR_KWARGS) + ind = env.create(misp_lib_stix2.v21.Indicator, id=INDICATOR_ID, **INDICATOR_KWARGS) assert ind.created_by_ref == IDENTITY_ID # Add objects to datastore @@ -198,40 +198,40 @@ def test_environment_functions(): assert resp['labels'][0] == 'benign' # Search on something other than id - query = [stix2.Filter('type', '=', 'vulnerability')] + query = [misp_lib_stix2.Filter('type', '=', 'vulnerability')] resp = env.query(query) assert len(resp) == 0 # See different results after adding filters to the environment env.add_filters([ - stix2.Filter('type', '=', 'indicator'), - stix2.Filter('created_by_ref', '=', IDENTITY_ID), + misp_lib_stix2.Filter('type', '=', 'indicator'), + misp_lib_stix2.Filter('created_by_ref', '=', IDENTITY_ID), ]) - env.add_filter(stix2.Filter('labels', '=', 'benign')) # should be 'malicious-activity' + env.add_filter(misp_lib_stix2.Filter('labels', '=', 'benign')) # should be 'malicious-activity' resp = env.get(INDICATOR_ID) assert resp['labels'][0] == 'benign' # should be 'malicious-activity' def test_environment_source_and_sink(): - ind = stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) - env = stix2.Environment(source=stix2.MemorySource([ind]), sink=stix2.MemorySink([ind])) + ind = misp_lib_stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) + env = misp_lib_stix2.Environment(source=misp_lib_stix2.MemorySource([ind]), sink=misp_lib_stix2.MemorySink([ind])) assert env.get(INDICATOR_ID).indicator_types[0] == 'malicious-activity' def test_environment_datastore_and_sink(): with pytest.raises(ValueError) as excinfo: - stix2.Environment( - factory=stix2.ObjectFactory(), - store=stix2.MemoryStore(), sink=stix2.MemorySink, + misp_lib_stix2.Environment( + factory=misp_lib_stix2.ObjectFactory(), + store=misp_lib_stix2.MemoryStore(), sink=misp_lib_stix2.MemorySink, ) assert 'Data store already provided' in str(excinfo.value) def test_environment_no_datastore(): - env = stix2.Environment(factory=stix2.ObjectFactory()) + env = misp_lib_stix2.Environment(factory=misp_lib_stix2.ObjectFactory()) with pytest.raises(AttributeError) as excinfo: - env.add(stix2.v21.Indicator(**INDICATOR_KWARGS)) + env.add(misp_lib_stix2.v21.Indicator(**INDICATOR_KWARGS)) assert 'Environment has no data sink to put objects in' in str(excinfo.value) with pytest.raises(AttributeError) as excinfo: @@ -256,20 +256,20 @@ def test_environment_no_datastore(): def test_environment_add_filters(): - env = stix2.Environment(factory=stix2.ObjectFactory()) + env = misp_lib_stix2.Environment(factory=misp_lib_stix2.ObjectFactory()) env.add_filters([INDICATOR_ID]) env.add_filter(INDICATOR_ID) def test_environment_datastore_and_no_object_factory(): # Uses a default object factory - env = stix2.Environment(store=stix2.MemoryStore()) - ind = env.create(stix2.v21.Indicator, id=INDICATOR_ID, **INDICATOR_KWARGS) + env = misp_lib_stix2.Environment(store=misp_lib_stix2.MemoryStore()) + ind = env.create(misp_lib_stix2.v21.Indicator, id=INDICATOR_ID, **INDICATOR_KWARGS) assert ind.id == INDICATOR_ID def test_parse_malware(): - env = stix2.Environment() + env = misp_lib_stix2.Environment() data = """{ "type": "malware", "spec_version": "2.1", @@ -295,46 +295,46 @@ def test_parse_malware(): def test_creator_of(): - identity = stix2.v21.Identity(**IDENTITY_KWARGS) - factory = stix2.ObjectFactory(created_by_ref=identity.id) - env = stix2.Environment(store=stix2.MemoryStore(), factory=factory) + identity = misp_lib_stix2.v21.Identity(**IDENTITY_KWARGS) + factory = misp_lib_stix2.ObjectFactory(created_by_ref=identity.id) + env = misp_lib_stix2.Environment(store=misp_lib_stix2.MemoryStore(), factory=factory) env.add(identity) - ind = env.create(stix2.v21.Indicator, **INDICATOR_KWARGS) + ind = env.create(misp_lib_stix2.v21.Indicator, **INDICATOR_KWARGS) creator = env.creator_of(ind) assert creator is identity def test_creator_of_no_datasource(): - identity = stix2.v21.Identity(**IDENTITY_KWARGS) - factory = stix2.ObjectFactory(created_by_ref=identity.id) - env = stix2.Environment(factory=factory) + identity = misp_lib_stix2.v21.Identity(**IDENTITY_KWARGS) + factory = misp_lib_stix2.ObjectFactory(created_by_ref=identity.id) + env = misp_lib_stix2.Environment(factory=factory) - ind = env.create(stix2.v21.Indicator, **INDICATOR_KWARGS) + ind = env.create(misp_lib_stix2.v21.Indicator, **INDICATOR_KWARGS) with pytest.raises(AttributeError) as excinfo: env.creator_of(ind) assert 'Environment has no data source' in str(excinfo.value) def test_creator_of_not_found(): - identity = stix2.v21.Identity(**IDENTITY_KWARGS) - factory = stix2.ObjectFactory(created_by_ref=identity.id) - env = stix2.Environment(store=stix2.MemoryStore(), factory=factory) + identity = misp_lib_stix2.v21.Identity(**IDENTITY_KWARGS) + factory = misp_lib_stix2.ObjectFactory(created_by_ref=identity.id) + env = misp_lib_stix2.Environment(store=misp_lib_stix2.MemoryStore(), factory=factory) - ind = env.create(stix2.v21.Indicator, **INDICATOR_KWARGS) + ind = env.create(misp_lib_stix2.v21.Indicator, **INDICATOR_KWARGS) creator = env.creator_of(ind) assert creator is None def test_creator_of_no_created_by_ref(): - env = stix2.Environment(store=stix2.MemoryStore()) - ind = env.create(stix2.v21.Indicator, **INDICATOR_KWARGS) + env = misp_lib_stix2.Environment(store=misp_lib_stix2.MemoryStore()) + ind = env.create(misp_lib_stix2.v21.Indicator, **INDICATOR_KWARGS) creator = env.creator_of(ind) assert creator is None def test_relationships(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) mal = env.get(MALWARE_ID) resp = env.relationships(mal) @@ -345,7 +345,7 @@ def test_relationships(ds): def test_relationships_no_id(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) mal = { "type": "malware", "name": "some variant", @@ -356,7 +356,7 @@ def test_relationships_no_id(ds): def test_relationships_by_type(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) mal = env.get(MALWARE_ID) resp = env.relationships(mal, relationship_type='indicates') @@ -365,7 +365,7 @@ def test_relationships_by_type(ds): def test_relationships_by_source(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) resp = env.relationships(MALWARE_ID, source_only=True) assert len(resp) == 1 @@ -373,7 +373,7 @@ def test_relationships_by_source(ds): def test_relationships_by_target(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) resp = env.relationships(MALWARE_ID, target_only=True) assert len(resp) == 2 @@ -382,7 +382,7 @@ def test_relationships_by_target(ds): def test_relationships_by_target_and_type(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) resp = env.relationships(MALWARE_ID, relationship_type='uses', target_only=True) assert len(resp) == 1 @@ -390,7 +390,7 @@ def test_relationships_by_target_and_type(ds): def test_relationships_by_target_and_source(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) with pytest.raises(ValueError) as excinfo: env.relationships(MALWARE_ID, target_only=True, source_only=True) @@ -398,7 +398,7 @@ def test_relationships_by_target_and_source(ds): def test_related_to(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) mal = env.get(MALWARE_ID) resp = env.related_to(mal) @@ -409,7 +409,7 @@ def test_related_to(ds): def test_related_to_no_id(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) mal = { "type": "malware", "name": "some variant", @@ -421,7 +421,7 @@ def test_related_to_no_id(ds): def test_related_to_by_source(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) resp = env.related_to(MALWARE_ID, source_only=True) assert len(resp) == 1 @@ -429,7 +429,7 @@ def test_related_to_by_source(ds): def test_related_to_by_target(ds): - env = stix2.Environment(store=ds) + env = misp_lib_stix2.Environment(store=ds) resp = env.related_to(MALWARE_ID, target_only=True) assert len(resp) == 2 @@ -438,9 +438,9 @@ def test_related_to_by_target(ds): def test_object_similarity_on_same_attack_pattern1(): - ap1 = stix2.v21.AttackPattern(id=ATTACK_PATTERN_ID, **ATTACK_PATTERN_KWARGS) - ap2 = stix2.v21.AttackPattern(id=ATTACK_PATTERN_ID, **ATTACK_PATTERN_KWARGS) - env = stix2.Environment().object_similarity(ap1, ap2) + ap1 = misp_lib_stix2.v21.AttackPattern(id=ATTACK_PATTERN_ID, **ATTACK_PATTERN_KWARGS) + ap2 = misp_lib_stix2.v21.AttackPattern(id=ATTACK_PATTERN_ID, **ATTACK_PATTERN_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(ap1, ap2) assert round(env) == 100 @@ -454,16 +454,16 @@ def test_object_similarity_on_same_attack_pattern2(): }, ], ) - ap1 = stix2.v21.AttackPattern(id=ATTACK_PATTERN_ID, **ATTACK_KWARGS) - ap2 = stix2.v21.AttackPattern(id=ATTACK_PATTERN_ID, **ATTACK_KWARGS) - env = stix2.Environment().object_similarity(ap1, ap2) + ap1 = misp_lib_stix2.v21.AttackPattern(id=ATTACK_PATTERN_ID, **ATTACK_KWARGS) + ap2 = misp_lib_stix2.v21.AttackPattern(id=ATTACK_PATTERN_ID, **ATTACK_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(ap1, ap2) assert round(env) == 100 def test_object_similarity_on_same_campaign1(): - camp1 = stix2.v21.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) - camp2 = stix2.v21.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) - env = stix2.Environment().object_similarity(camp1, camp2) + camp1 = misp_lib_stix2.v21.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) + camp2 = misp_lib_stix2.v21.Campaign(id=CAMPAIGN_ID, **CAMPAIGN_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(camp1, camp2) assert round(env) == 100 @@ -473,16 +473,16 @@ def test_object_similarity_on_same_campaign2(): description="Campaign by Green Group against a series of targets in the financial services sector.", aliases=["super-green", "some-green"], ) - camp1 = stix2.v21.Campaign(id=CAMPAIGN_ID, **CAMP_KWARGS) - camp2 = stix2.v21.Campaign(id=CAMPAIGN_ID, **CAMP_KWARGS) - env = stix2.Environment().object_similarity(camp1, camp2) + camp1 = misp_lib_stix2.v21.Campaign(id=CAMPAIGN_ID, **CAMP_KWARGS) + camp2 = misp_lib_stix2.v21.Campaign(id=CAMPAIGN_ID, **CAMP_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(camp1, camp2) assert round(env) == 100 def test_object_similarity_on_same_identity1(): - iden1 = stix2.v21.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) - iden2 = stix2.v21.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) - env = stix2.Environment().object_similarity(iden1, iden2) + iden1 = misp_lib_stix2.v21.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) + iden2 = misp_lib_stix2.v21.Identity(id=IDENTITY_ID, **IDENTITY_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(iden1, iden2) assert round(env) == 100 @@ -492,24 +492,24 @@ def test_object_similarity_on_same_identity2(): identity_class="individual", sectors=["government", "infrastructure"], ) - iden1 = stix2.v21.Identity(id=IDENTITY_ID, **IDEN_KWARGS) - iden2 = stix2.v21.Identity(id=IDENTITY_ID, **IDEN_KWARGS) - env = stix2.Environment().object_similarity(iden1, iden2) + iden1 = misp_lib_stix2.v21.Identity(id=IDENTITY_ID, **IDEN_KWARGS) + iden2 = misp_lib_stix2.v21.Identity(id=IDENTITY_ID, **IDEN_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(iden1, iden2) assert round(env) == 100 def test_object_similarity_on_same_indicator(): - ind1 = stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) - ind2 = stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) - env = stix2.Environment().object_similarity(ind1, ind2) + ind1 = misp_lib_stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) + ind2 = misp_lib_stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(ind1, ind2) assert round(env) == 100 def test_object_similarity_on_same_location1(): location_kwargs = dict(latitude=45, longitude=179) - loc1 = stix2.v21.Location(id=LOCATION_ID, **location_kwargs) - loc2 = stix2.v21.Location(id=LOCATION_ID, **location_kwargs) - env = stix2.Environment().object_similarity(loc1, loc2) + loc1 = misp_lib_stix2.v21.Location(id=LOCATION_ID, **location_kwargs) + loc2 = misp_lib_stix2.v21.Location(id=LOCATION_ID, **location_kwargs) + env = misp_lib_stix2.Environment().object_similarity(loc1, loc2) assert round(env) == 100 @@ -520,31 +520,31 @@ def test_object_similarity_on_same_location2(): region="northern-america", country="us", ) - loc1 = stix2.v21.Location(id=LOCATION_ID, **location_kwargs) - loc2 = stix2.v21.Location(id=LOCATION_ID, **location_kwargs) - env = stix2.Environment().object_similarity(loc1, loc2) + loc1 = misp_lib_stix2.v21.Location(id=LOCATION_ID, **location_kwargs) + loc2 = misp_lib_stix2.v21.Location(id=LOCATION_ID, **location_kwargs) + env = misp_lib_stix2.Environment().object_similarity(loc1, loc2) assert round(env) == 100 def test_object_similarity_location_with_no_latlong(): loc_kwargs = dict(country="US", administrative_area="US-DC") - loc1 = stix2.v21.Location(id=LOCATION_ID, **LOCATION_KWARGS) - loc2 = stix2.v21.Location(id=LOCATION_ID, **loc_kwargs) - env = stix2.Environment().object_similarity(loc1, loc2) + loc1 = misp_lib_stix2.v21.Location(id=LOCATION_ID, **LOCATION_KWARGS) + loc2 = misp_lib_stix2.v21.Location(id=LOCATION_ID, **loc_kwargs) + env = misp_lib_stix2.Environment().object_similarity(loc1, loc2) assert round(env) != 100 def test_object_similarity_on_same_malware(): - malw1 = stix2.v21.Malware(id=MALWARE_ID, **MALWARE_KWARGS) - malw2 = stix2.v21.Malware(id=MALWARE_ID, **MALWARE_KWARGS) - env = stix2.Environment().object_similarity(malw1, malw2) + malw1 = misp_lib_stix2.v21.Malware(id=MALWARE_ID, **MALWARE_KWARGS) + malw2 = misp_lib_stix2.v21.Malware(id=MALWARE_ID, **MALWARE_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(malw1, malw2) assert round(env) == 100 def test_object_similarity_on_same_threat_actor1(): - ta1 = stix2.v21.ThreatActor(id=THREAT_ACTOR_ID, **THREAT_ACTOR_KWARGS) - ta2 = stix2.v21.ThreatActor(id=THREAT_ACTOR_ID, **THREAT_ACTOR_KWARGS) - env = stix2.Environment().object_similarity(ta1, ta2) + ta1 = misp_lib_stix2.v21.ThreatActor(id=THREAT_ACTOR_ID, **THREAT_ACTOR_KWARGS) + ta2 = misp_lib_stix2.v21.ThreatActor(id=THREAT_ACTOR_ID, **THREAT_ACTOR_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(ta1, ta2) assert round(env) == 100 @@ -554,34 +554,34 @@ def test_object_similarity_on_same_threat_actor2(): aliases=["super-evil"], name="Evil Org", ) - ta1 = stix2.v21.ThreatActor(id=THREAT_ACTOR_ID, **THREAT_KWARGS) - ta2 = stix2.v21.ThreatActor(id=THREAT_ACTOR_ID, **THREAT_KWARGS) - env = stix2.Environment().object_similarity(ta1, ta2) + ta1 = misp_lib_stix2.v21.ThreatActor(id=THREAT_ACTOR_ID, **THREAT_KWARGS) + ta2 = misp_lib_stix2.v21.ThreatActor(id=THREAT_ACTOR_ID, **THREAT_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(ta1, ta2) assert round(env) == 100 def test_object_similarity_on_same_tool(): - tool1 = stix2.v21.Tool(id=TOOL_ID, **TOOL_KWARGS) - tool2 = stix2.v21.Tool(id=TOOL_ID, **TOOL_KWARGS) - env = stix2.Environment().object_similarity(tool1, tool2) + tool1 = misp_lib_stix2.v21.Tool(id=TOOL_ID, **TOOL_KWARGS) + tool2 = misp_lib_stix2.v21.Tool(id=TOOL_ID, **TOOL_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(tool1, tool2) assert round(env) == 100 def test_object_similarity_on_same_vulnerability1(): - vul1 = stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULNERABILITY_KWARGS) - vul2 = stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULNERABILITY_KWARGS) + vul1 = misp_lib_stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULNERABILITY_KWARGS) + vul2 = misp_lib_stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULNERABILITY_KWARGS) prop_scores = {} - env = stix2.Environment().object_similarity(vul1, vul2, prop_scores) + env = misp_lib_stix2.Environment().object_similarity(vul1, vul2, prop_scores) assert round(env) == 100 assert round(prop_scores["matching_score"]) == 30 assert round(prop_scores["sum_weights"]) == 30 def test_object_equivalence_on_same_vulnerability1(): - vul1 = stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULNERABILITY_KWARGS) - vul2 = stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULNERABILITY_KWARGS) + vul1 = misp_lib_stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULNERABILITY_KWARGS) + vul2 = misp_lib_stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULNERABILITY_KWARGS) prop_scores = {} - env = stix2.Environment().object_equivalence(vul1, vul2, prop_scores) + env = misp_lib_stix2.Environment().object_equivalence(vul1, vul2, prop_scores) assert env is True assert round(prop_scores["matching_score"]) == 30 assert round(prop_scores["sum_weights"]) == 30 @@ -606,10 +606,10 @@ def test_object_similarity_on_same_vulnerability2(): }, ], ) - vul1 = stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULN_KWARGS1) - vul2 = stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULN_KWARGS2) + vul1 = misp_lib_stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULN_KWARGS1) + vul2 = misp_lib_stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULN_KWARGS2) prop_scores = {} - env = stix2.Environment().object_similarity(vul1, vul2, prop_scores) + env = misp_lib_stix2.Environment().object_similarity(vul1, vul2, prop_scores) assert round(env) == 0.0 assert round(prop_scores["matching_score"]) == 0 assert round(prop_scores["sum_weights"]) == 100 @@ -634,10 +634,10 @@ def test_object_equivalence_on_same_vulnerability2(): }, ], ) - vul1 = stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULN_KWARGS1) - vul2 = stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULN_KWARGS2) + vul1 = misp_lib_stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULN_KWARGS1) + vul2 = misp_lib_stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULN_KWARGS2) prop_scores = {} - env = stix2.Environment().object_equivalence(vul1, vul2, prop_scores) + env = misp_lib_stix2.Environment().object_equivalence(vul1, vul2, prop_scores) assert env is False assert round(prop_scores["matching_score"]) == 0 assert round(prop_scores["sum_weights"]) == 100 @@ -670,17 +670,17 @@ def test_object_similarity_on_unknown_object(): def _x_foobar_checks(obj1, obj2, **weights): matching_score = 0.0 sum_weights = 0.0 - if stix2.equivalence.object.check_property_present("external_references", obj1, obj2): + if misp_lib_stix2.equivalence.object.check_property_present("external_references", obj1, obj2): w = weights["external_references"] sum_weights += w - matching_score += w * stix2.equivalence.object.partial_external_reference_based( + matching_score += w * misp_lib_stix2.equivalence.object.partial_external_reference_based( obj1["external_references"], obj2["external_references"], ) - if stix2.equivalence.object.check_property_present("name", obj1, obj2): + if misp_lib_stix2.equivalence.object.check_property_present("name", obj1, obj2): w = weights["name"] sum_weights += w - matching_score += w * stix2.equivalence.object.partial_string_based(obj1["name"], obj2["name"]) + matching_score += w * misp_lib_stix2.equivalence.object.partial_string_based(obj1["name"], obj2["name"]) return matching_score, sum_weights weights = { @@ -693,17 +693,17 @@ def _x_foobar_checks(obj1, obj2, **weights): "ignore_spec_version": False, }, } - cust1 = stix2.parse(CUSTOM_KWARGS1, allow_custom=True) - cust2 = stix2.parse(CUSTOM_KWARGS2, allow_custom=True) - env = stix2.Environment().object_similarity(cust1, cust2, **weights) + cust1 = misp_lib_stix2.parse(CUSTOM_KWARGS1, allow_custom=True) + cust2 = misp_lib_stix2.parse(CUSTOM_KWARGS2, allow_custom=True) + env = misp_lib_stix2.Environment().object_similarity(cust1, cust2, **weights) assert round(env) == 0 def test_object_similarity_different_type_raises(): with pytest.raises(ValueError) as excinfo: - vul1 = stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULNERABILITY_KWARGS) - ind1 = stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) - stix2.Environment().object_similarity(vul1, ind1) + vul1 = misp_lib_stix2.v21.Vulnerability(id=VULNERABILITY_ID, **VULNERABILITY_KWARGS) + ind1 = misp_lib_stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) + misp_lib_stix2.Environment().object_similarity(vul1, ind1) assert str(excinfo.value) == "The objects to compare must be of the same type!" @@ -714,9 +714,9 @@ def test_object_similarity_different_spec_version_raises(): labels=['malicious-activity'], pattern="[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']", ) - ind1 = stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) - ind2 = stix2.v20.Indicator(id=INDICATOR_ID, **V20_KWARGS) - stix2.Environment().object_similarity(ind1, ind2) + ind1 = misp_lib_stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) + ind2 = misp_lib_stix2.v20.Indicator(id=INDICATOR_ID, **V20_KWARGS) + misp_lib_stix2.Environment().object_similarity(ind1, ind2) assert str(excinfo.value) == "The objects to compare must be of the same spec version!" @@ -731,20 +731,20 @@ def test_object_similarity_zero_match(): ) weights = { "indicator": { - "indicator_types": (15, stix2.equivalence.object.partial_list_based), - "pattern": (80, stix2.equivalence.object.custom_pattern_based), - "valid_from": (5, stix2.equivalence.object.partial_timestamp_based), + "indicator_types": (15, misp_lib_stix2.equivalence.object.partial_list_based), + "pattern": (80, misp_lib_stix2.equivalence.object.custom_pattern_based), + "valid_from": (5, misp_lib_stix2.equivalence.object.partial_timestamp_based), "tdelta": 1, # One day interval }, "_internal": { "ignore_spec_version": False, }, } - ind1 = stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) - ind2 = stix2.v21.Indicator(id=INDICATOR_ID, **IND_KWARGS) - env = stix2.Environment().object_similarity(ind1, ind2, **weights) + ind1 = misp_lib_stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) + ind2 = misp_lib_stix2.v21.Indicator(id=INDICATOR_ID, **IND_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(ind1, ind2, **weights) assert round(env) == 0 - env = stix2.Environment().object_similarity(ind2, ind1, **weights) + env = misp_lib_stix2.Environment().object_similarity(ind2, ind1, **weights) assert round(env) == 0 @@ -755,18 +755,18 @@ def test_object_similarity_different_spec_version(): ) weights = { "indicator": { - "indicator_types": (15, stix2.equivalence.object.partial_list_based), - "pattern": (80, stix2.equivalence.object.custom_pattern_based), - "valid_from": (5, stix2.equivalence.object.partial_timestamp_based), + "indicator_types": (15, misp_lib_stix2.equivalence.object.partial_list_based), + "pattern": (80, misp_lib_stix2.equivalence.object.custom_pattern_based), + "valid_from": (5, misp_lib_stix2.equivalence.object.partial_timestamp_based), "tdelta": 1, # One day interval }, } - ind1 = stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) - ind2 = stix2.v20.Indicator(id=INDICATOR_ID, **IND_KWARGS) - env = stix2.Environment().object_similarity(ind1, ind2, ignore_spec_version=True, **weights) + ind1 = misp_lib_stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS) + ind2 = misp_lib_stix2.v20.Indicator(id=INDICATOR_ID, **IND_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(ind1, ind2, ignore_spec_version=True, **weights) assert round(env) == 0 - env = stix2.Environment().object_similarity(ind2, ind1, ignore_spec_version=True, **weights) + env = misp_lib_stix2.Environment().object_similarity(ind2, ind1, ignore_spec_version=True, **weights) assert round(env) == 0 @@ -839,27 +839,27 @@ def test_object_similarity_different_spec_version(): ], ) def test_object_similarity_external_references(refs1, refs2, ret_val): - value = stix2.equivalence.object.partial_external_reference_based(refs1, refs2) + value = misp_lib_stix2.equivalence.object.partial_external_reference_based(refs1, refs2) assert value == ret_val def test_object_similarity_timestamp(): t1 = "2018-10-17T00:14:20.652Z" t2 = "2018-10-17T12:14:20.652Z" - assert stix2.equivalence.object.partial_timestamp_based(t1, t2, 1) == 0.5 + assert misp_lib_stix2.equivalence.object.partial_timestamp_based(t1, t2, 1) == 0.5 def test_object_similarity_exact_match(): t1 = "2018-10-17T00:14:20.652Z" t2 = "2018-10-17T12:14:20.652Z" - assert stix2.equivalence.object.exact_match(t1, t2) == 0.0 + assert misp_lib_stix2.equivalence.object.exact_match(t1, t2) == 0.0 def test_no_datastore_fallsback_list_based_check_for_refs_check(): - r1 = stix2.v21.Report(id=REPORT_ID, **REPORT_KWARGS) - r2 = stix2.v21.Report(id=REPORT_ID, **REPORT_KWARGS) + r1 = misp_lib_stix2.v21.Report(id=REPORT_ID, **REPORT_KWARGS) + r2 = misp_lib_stix2.v21.Report(id=REPORT_ID, **REPORT_KWARGS) prop_scores = {} - assert stix2.Environment().object_similarity(r1, r2, prop_scores) == 100.0 + assert misp_lib_stix2.Environment().object_similarity(r1, r2, prop_scores) == 100.0 assert prop_scores["object_refs"]["check_type"] == "partial_list_based" @@ -876,15 +876,15 @@ def test_object_similarity_method_provided(): weights = { "tool": { - "tool_types": (20, stix2.equivalence.object.partial_list_based), - "name": (80, stix2.equivalence.object.partial_string_based), + "tool_types": (20, misp_lib_stix2.equivalence.object.partial_list_based), + "name": (80, misp_lib_stix2.equivalence.object.partial_string_based), "method": custom_semantic_equivalence_method, }, } - tool1 = stix2.v21.Tool(id=TOOL_ID, **TOOL_KWARGS) - tool2 = stix2.v21.Tool(id=TOOL_ID, **TOOL2_KWARGS) - env = stix2.Environment().object_similarity(tool1, tool2, **weights) + tool1 = misp_lib_stix2.v21.Tool(id=TOOL_ID, **TOOL_KWARGS) + tool2 = misp_lib_stix2.v21.Tool(id=TOOL_ID, **TOOL2_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(tool1, tool2, **weights) assert round(env) == 96 @@ -896,9 +896,9 @@ def test_object_similarity_prop_scores(): prop_scores = {} - tool1 = stix2.v21.Tool(id=TOOL_ID, **TOOL_KWARGS) - tool2 = stix2.v21.Tool(id=TOOL_ID, **TOOL2_KWARGS) - stix2.Environment().object_similarity(tool1, tool2, prop_scores) + tool1 = misp_lib_stix2.v21.Tool(id=TOOL_ID, **TOOL_KWARGS) + tool2 = misp_lib_stix2.v21.Tool(id=TOOL_ID, **TOOL2_KWARGS) + misp_lib_stix2.Environment().object_similarity(tool1, tool2, prop_scores) assert len(prop_scores) == 4 assert round(prop_scores["matching_score"], 1) == 8.9 assert round(prop_scores["sum_weights"], 1) == 100.0 @@ -926,9 +926,9 @@ def test_object_similarity_prop_scores_method_provided(): prop_scores = {} - tool1 = stix2.v21.Tool(id=TOOL_ID, **TOOL_KWARGS) - tool2 = stix2.v21.Tool(id=TOOL_ID, **TOOL2_KWARGS) - env = stix2.Environment().object_similarity(tool1, tool2, prop_scores, **weights) + tool1 = misp_lib_stix2.v21.Tool(id=TOOL_ID, **TOOL_KWARGS) + tool2 = misp_lib_stix2.v21.Tool(id=TOOL_ID, **TOOL2_KWARGS) + env = misp_lib_stix2.Environment().object_similarity(tool1, tool2, prop_scores, **weights) assert round(env) == 96 assert len(prop_scores) == 2 assert prop_scores["matching_score"] == 96.0 @@ -937,7 +937,7 @@ def test_object_similarity_prop_scores_method_provided(): def test_versioned_checks(ds, ds2): # Testing internal method - weights = stix2.equivalence.graph.WEIGHTS.copy() + weights = misp_lib_stix2.equivalence.graph.WEIGHTS.copy() weights.update({ "_internal": { "ignore_spec_version": True, @@ -945,12 +945,12 @@ def test_versioned_checks(ds, ds2): "max_depth": 1, }, }) - score = stix2.equivalence.object._versioned_checks(INDICATOR_ID, INDICATOR_ID, ds, ds2, **weights) + score = misp_lib_stix2.equivalence.object._versioned_checks(INDICATOR_ID, INDICATOR_ID, ds, ds2, **weights) assert round(score) == 100 def test_semantic_check_with_versioning(ds, ds2): - weights = stix2.equivalence.graph.WEIGHTS.copy() + weights = misp_lib_stix2.equivalence.graph.WEIGHTS.copy() weights.update({ "_internal": { "ignore_spec_version": False, @@ -960,7 +960,7 @@ def test_semantic_check_with_versioning(ds, ds2): "max_depth": 1, }, }) - ind = stix2.v21.Indicator( + ind = misp_lib_stix2.v21.Indicator( **dict( indicator_types=["malicious-activity"], pattern_type="stix", @@ -972,16 +972,16 @@ def test_semantic_check_with_versioning(ds, ds2): "url": "https://examplewebsite2.com/", }, ], - object_marking_refs=[stix2.v21.TLP_WHITE], + object_marking_refs=[misp_lib_stix2.v21.TLP_WHITE], ) ) ds.add(ind) - score = stix2.equivalence.object.reference_check(ind.id, INDICATOR_ID, ds, ds2, **weights) + score = misp_lib_stix2.equivalence.object.reference_check(ind.id, INDICATOR_ID, ds, ds2, **weights) assert round(score) == 0 # Since pattern is different score is really low def test_list_semantic_check(ds, ds2): - weights = stix2.equivalence.graph.WEIGHTS.copy() + weights = misp_lib_stix2.equivalence.graph.WEIGHTS.copy() weights.update({ "_internal": { "ignore_spec_version": False, @@ -1007,7 +1007,7 @@ def test_list_semantic_check(ds, ds2): "relationship--a0cbb21c-8daf-4a7f-96aa-7155a4ef8f70", ] - score = stix2.equivalence.object.list_reference_check( + score = misp_lib_stix2.equivalence.object.list_reference_check( object_refs1, object_refs2, ds, @@ -1016,7 +1016,7 @@ def test_list_semantic_check(ds, ds2): ) assert round(score) == 1 - score = stix2.equivalence.object.list_reference_check( + score = misp_lib_stix2.equivalence.object.list_reference_check( object_refs2, object_refs1, ds2, @@ -1029,12 +1029,12 @@ def test_list_semantic_check(ds, ds2): def test_graph_similarity_raises_value_error(ds): with pytest.raises(ValueError): prop_scores1 = {} - stix2.Environment().graph_similarity(ds, ds2, prop_scores1, max_depth=-1) + misp_lib_stix2.Environment().graph_similarity(ds, ds2, prop_scores1, max_depth=-1) def test_graph_similarity_with_filesystem_source(ds, fs): prop_scores1 = {} - env1 = stix2.Environment().graph_similarity( + env1 = misp_lib_stix2.Environment().graph_similarity( fs, ds, prop_scores1, ignore_spec_version=True, versioning_checks=False, @@ -1043,7 +1043,7 @@ def test_graph_similarity_with_filesystem_source(ds, fs): # Switching parameters prop_scores2 = {} - env2 = stix2.Environment().graph_similarity( + env2 = misp_lib_stix2.Environment().graph_similarity( ds, fs, prop_scores2, ignore_spec_version=True, versioning_checks=False, @@ -1134,18 +1134,18 @@ def test_depth_limiting(): }, ] - mem_store1 = stix2.MemorySource(g1) - mem_store2 = stix2.MemorySource(g2) + mem_store1 = misp_lib_stix2.MemorySource(g1) + mem_store2 = misp_lib_stix2.MemorySource(g2) custom_weights = { "foo": { - "some1_ref": (33, stix2.equivalence.object.reference_check), - "some2_ref": (33, stix2.equivalence.object.reference_check), - "name": (34, stix2.equivalence.object.partial_string_based), + "some1_ref": (33, misp_lib_stix2.equivalence.object.reference_check), + "some2_ref": (33, misp_lib_stix2.equivalence.object.reference_check), + "name": (34, misp_lib_stix2.equivalence.object.partial_string_based), }, } prop_scores1 = {} - env1 = stix2.equivalence.graph.graph_similarity( + env1 = misp_lib_stix2.equivalence.graph.graph_similarity( mem_store1, mem_store2, prop_scores1, **custom_weights ) @@ -1158,7 +1158,7 @@ def test_depth_limiting(): # Switching parameters prop_scores2 = {} - env2 = stix2.equivalence.graph.graph_similarity( + env2 = misp_lib_stix2.equivalence.graph.graph_similarity( mem_store2, mem_store1, prop_scores2, **custom_weights ) @@ -1172,7 +1172,7 @@ def test_depth_limiting(): def test_graph_similarity_with_duplicate_graph(ds): prop_scores = {} - env = stix2.Environment().graph_similarity(ds, ds, prop_scores) + env = misp_lib_stix2.Environment().graph_similarity(ds, ds, prop_scores) assert round(env) == 100 assert round(prop_scores["matching_score"]) == 800 assert round(prop_scores["len_pairs"]) == 8 @@ -1180,14 +1180,14 @@ def test_graph_similarity_with_duplicate_graph(ds): def test_graph_similarity_with_versioning_check_on(ds2, ds): prop_scores1 = {} - env1 = stix2.Environment().graph_similarity(ds, ds2, prop_scores1, versioning_checks=True) + env1 = misp_lib_stix2.Environment().graph_similarity(ds, ds2, prop_scores1, versioning_checks=True) assert round(env1) == 88 assert round(prop_scores1["matching_score"]) == 789 assert round(prop_scores1["len_pairs"]) == 9 # Switching parameters prop_scores2 = {} - env2 = stix2.Environment().graph_similarity(ds2, ds, prop_scores2, versioning_checks=True) + env2 = misp_lib_stix2.Environment().graph_similarity(ds2, ds, prop_scores2, versioning_checks=True) assert round(env2) == 88 assert round(prop_scores2["matching_score"]) == 789 assert round(prop_scores2["len_pairs"]) == 9 @@ -1199,14 +1199,14 @@ def test_graph_similarity_with_versioning_check_on(ds2, ds): def test_graph_similarity_with_versioning_check_off(ds2, ds): prop_scores1 = {} - env1 = stix2.Environment().graph_similarity(ds, ds2, prop_scores1) + env1 = misp_lib_stix2.Environment().graph_similarity(ds, ds2, prop_scores1) assert round(env1) == 88 assert round(prop_scores1["matching_score"]) == 789 assert round(prop_scores1["len_pairs"]) == 9 # Switching parameters prop_scores2 = {} - env2 = stix2.Environment().graph_similarity(ds2, ds, prop_scores2) + env2 = misp_lib_stix2.Environment().graph_similarity(ds2, ds, prop_scores2) assert round(env2) == 88 assert round(prop_scores2["matching_score"]) == 789 assert round(prop_scores2["len_pairs"]) == 9 @@ -1218,11 +1218,11 @@ def test_graph_similarity_with_versioning_check_off(ds2, ds): def test_graph_equivalence_with_filesystem_source(ds, fs): prop_scores1 = {} - env1 = stix2.Environment().graph_equivalence(fs, ds, prop_scores1, ignore_spec_version=True) + env1 = misp_lib_stix2.Environment().graph_equivalence(fs, ds, prop_scores1, ignore_spec_version=True) # Switching parameters prop_scores2 = {} - env2 = stix2.Environment().graph_equivalence(ds, fs, prop_scores2, ignore_spec_version=True) + env2 = misp_lib_stix2.Environment().graph_equivalence(ds, fs, prop_scores2, ignore_spec_version=True) assert env1 is False assert round(prop_scores1["matching_score"]) == 411 @@ -1239,7 +1239,7 @@ def test_graph_equivalence_with_filesystem_source(ds, fs): def test_graph_equivalence_with_duplicate_graph(ds): prop_scores = {} - env = stix2.Environment().graph_equivalence(ds, ds, prop_scores) + env = misp_lib_stix2.Environment().graph_equivalence(ds, ds, prop_scores) assert env is True assert round(prop_scores["matching_score"]) == 800 assert round(prop_scores["len_pairs"]) == 8 @@ -1247,11 +1247,11 @@ def test_graph_equivalence_with_duplicate_graph(ds): def test_graph_equivalence_with_versioning_check_on(ds2, ds): prop_scores1 = {} - env1 = stix2.Environment().graph_equivalence(ds, ds2, prop_scores1, versioning_checks=True) + env1 = misp_lib_stix2.Environment().graph_equivalence(ds, ds2, prop_scores1, versioning_checks=True) # Switching parameters prop_scores2 = {} - env2 = stix2.Environment().graph_equivalence(ds2, ds, prop_scores2, versioning_checks=True) + env2 = misp_lib_stix2.Environment().graph_equivalence(ds2, ds, prop_scores2, versioning_checks=True) assert env1 is True assert round(prop_scores1["matching_score"]) == 789 @@ -1268,11 +1268,11 @@ def test_graph_equivalence_with_versioning_check_on(ds2, ds): def test_graph_equivalence_with_versioning_check_off(ds2, ds): prop_scores1 = {} - env1 = stix2.Environment().graph_equivalence(ds, ds2, prop_scores1) + env1 = misp_lib_stix2.Environment().graph_equivalence(ds, ds2, prop_scores1) # Switching parameters prop_scores2 = {} - env2 = stix2.Environment().graph_equivalence(ds2, ds, prop_scores2) + env2 = misp_lib_stix2.Environment().graph_equivalence(ds2, ds, prop_scores2) assert env1 is True assert round(prop_scores1["matching_score"]) == 789 diff --git a/stix2/test/v21/test_extension_definition.py b/misp_lib_stix2/test/v21/test_extension_definition.py similarity index 92% rename from stix2/test/v21/test_extension_definition.py rename to misp_lib_stix2/test/v21/test_extension_definition.py index af13425d..81ee9ca7 100644 --- a/stix2/test/v21/test_extension_definition.py +++ b/misp_lib_stix2/test/v21/test_extension_definition.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import EXTENSION_DEFINITION_IDS @@ -25,7 +25,7 @@ def test_extension_definition_example(): - extension_definition = stix2.v21.ExtensionDefinition( + extension_definition = misp_lib_stix2.v21.ExtensionDefinition( id=EXTENSION_DEFINITION_IDS[0], created_by_ref="identity--11b76a96-5d2b-45e0-8a5a-f6994f370731", created="2014-02-20T09:16:08.000Z", @@ -59,7 +59,7 @@ def test_extension_definition_example(): ], ) def test_parse_extension_definition(data): - extension_definition = stix2.parse(data, version="2.1") + extension_definition = misp_lib_stix2.parse(data, version="2.1") assert extension_definition.type == 'extension-definition' assert extension_definition.spec_version == '2.1' @@ -74,8 +74,8 @@ def test_parse_extension_definition(data): def test_parse_no_type(): - with pytest.raises(stix2.exceptions.ParseError): - stix2.parse( + with pytest.raises(misp_lib_stix2.exceptions.ParseError): + misp_lib_stix2.parse( """{ "id": "{EXTENSION_DEFINITION_IDS[0]}", "spec_version": "2.1", @@ -92,7 +92,7 @@ def test_parse_no_type(): def test_extension_definition_with_custom(): - extension_definition = stix2.v21.ExtensionDefinition( + extension_definition = misp_lib_stix2.v21.ExtensionDefinition( created_by_ref="identity--11b76a96-5d2b-45e0-8a5a-f6994f370731", created="2014-02-20T09:16:08.000Z", modified="2014-02-20T09:16:08.000Z", diff --git a/stix2/test/v21/test_external_reference.py b/misp_lib_stix2/test/v21/test_external_reference.py similarity index 83% rename from stix2/test/v21/test_external_reference.py rename to misp_lib_stix2/test/v21/test_external_reference.py index 93168572..8738f71b 100644 --- a/stix2/test/v21/test_external_reference.py +++ b/misp_lib_stix2/test/v21/test_external_reference.py @@ -4,7 +4,7 @@ import pytest -import stix2 +import misp_lib_stix2 VERIS = """{ "source_name": "veris", @@ -17,7 +17,7 @@ def test_external_reference_veris(): - ref = stix2.v21.ExternalReference( + ref = misp_lib_stix2.v21.ExternalReference( source_name="veris", external_id="0001AA7F-C601-424A-B2B8-BE6C9F5164E7", hashes={ @@ -36,7 +36,7 @@ def test_external_reference_veris(): def test_external_reference_capec(): - ref = stix2.v21.ExternalReference( + ref = misp_lib_stix2.v21.ExternalReference( source_name="capec", external_id="CAPEC-550", ) @@ -53,7 +53,7 @@ def test_external_reference_capec(): def test_external_reference_capec_url(): - ref = stix2.v21.ExternalReference( + ref = misp_lib_stix2.v21.ExternalReference( source_name="capec", external_id="CAPEC-550", url="http://capec.mitre.org/data/definitions/550.html", @@ -70,7 +70,7 @@ def test_external_reference_capec_url(): def test_external_reference_threat_report(): - ref = stix2.v21.ExternalReference( + ref = misp_lib_stix2.v21.ExternalReference( source_name="ACME Threat Intel", description="Threat report", url="http://www.example.com/threat-report.pdf", @@ -87,7 +87,7 @@ def test_external_reference_threat_report(): def test_external_reference_bugzilla(): - ref = stix2.v21.ExternalReference( + ref = misp_lib_stix2.v21.ExternalReference( source_name="ACME Bugzilla", external_id="1370", url="https://www.example.com/bugs/1370", @@ -103,7 +103,7 @@ def test_external_reference_bugzilla(): def test_external_reference_offline(): - ref = stix2.v21.ExternalReference( + ref = misp_lib_stix2.v21.ExternalReference( source_name="ACME Threat Intel", description="Threat report", ) @@ -115,16 +115,16 @@ def test_external_reference_offline(): def test_external_reference_source_required(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v21.ExternalReference() + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v21.ExternalReference() - assert excinfo.value.cls == stix2.v21.ExternalReference + assert excinfo.value.cls == misp_lib_stix2.v21.ExternalReference assert excinfo.value.properties == ["source_name"] def test_external_reference_bad_hash(): - with pytest.raises(stix2.exceptions.InvalidValueError): - stix2.v21.ExternalReference( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError): + misp_lib_stix2.v21.ExternalReference( source_name="ACME Threat Intel", description="Threat report", hashes={ diff --git a/stix2/test/v20/test_fixtures.py b/misp_lib_stix2/test/v21/test_fixtures.py similarity index 93% rename from stix2/test/v20/test_fixtures.py rename to misp_lib_stix2/test/v21/test_fixtures.py index 23ad8a4e..48305eb0 100644 --- a/stix2/test/v20/test_fixtures.py +++ b/misp_lib_stix2/test/v21/test_fixtures.py @@ -1,6 +1,6 @@ import uuid -from stix2 import utils +from misp_lib_stix2 import utils from .constants import FAKE_TIME diff --git a/stix2/test/v21/test_granular_markings.py b/misp_lib_stix2/test/v21/test_granular_markings.py similarity index 99% rename from stix2/test/v21/test_granular_markings.py rename to misp_lib_stix2/test/v21/test_granular_markings.py index ff8fe26d..4afc6bce 100644 --- a/stix2/test/v21/test_granular_markings.py +++ b/misp_lib_stix2/test/v21/test_granular_markings.py @@ -1,8 +1,8 @@ import pytest -from stix2 import markings -from stix2.exceptions import InvalidSelectorError, MarkingNotFoundError -from stix2.v21 import TLP_RED, Malware +from misp_lib_stix2 import markings +from misp_lib_stix2.exceptions import InvalidSelectorError, MarkingNotFoundError +from misp_lib_stix2.v21 import TLP_RED, Malware from .constants import MALWARE_MORE_KWARGS as MALWARE_KWARGS_CONST from .constants import MARKING_IDS, MARKING_LANGS diff --git a/stix2/test/v21/test_grouping.py b/misp_lib_stix2/test/v21/test_grouping.py similarity index 78% rename from stix2/test/v21/test_grouping.py rename to misp_lib_stix2/test/v21/test_grouping.py index e495888c..090b4644 100644 --- a/stix2/test/v21/test_grouping.py +++ b/misp_lib_stix2/test/v21/test_grouping.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import FAKE_TIME, GROUPING_ID, GROUPING_KWARGS @@ -25,7 +25,7 @@ def test_grouping_with_all_required_properties(): now = dt.datetime(2017, 1, 1, 12, 34, 56, tzinfo=pytz.utc) - grp = stix2.v21.Grouping( + grp = misp_lib_stix2.v21.Grouping( type="grouping", id=GROUPING_ID, created=now, @@ -58,38 +58,38 @@ def test_grouping_autogenerated_properties(grouping): def test_grouping_type_must_be_grouping(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Grouping(type='xxx', **GROUPING_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Grouping(type='xxx', **GROUPING_KWARGS) - assert excinfo.value.cls == stix2.v21.Grouping + assert excinfo.value.cls == misp_lib_stix2.v21.Grouping assert excinfo.value.prop_name == "type" assert excinfo.value.reason == "must equal 'grouping'." assert str(excinfo.value) == "Invalid value for Grouping 'type': must equal 'grouping'." def test_grouping_id_must_start_with_grouping(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Grouping(id='my-prefix--', **GROUPING_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Grouping(id='my-prefix--', **GROUPING_KWARGS) - assert excinfo.value.cls == stix2.v21.Grouping + assert excinfo.value.cls == misp_lib_stix2.v21.Grouping assert excinfo.value.prop_name == "id" assert excinfo.value.reason == "must start with 'grouping--'." assert str(excinfo.value) == "Invalid value for Grouping 'id': must start with 'grouping--'." def test_grouping_required_properties(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v21.Grouping() + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v21.Grouping() - assert excinfo.value.cls == stix2.v21.Grouping + assert excinfo.value.cls == misp_lib_stix2.v21.Grouping assert excinfo.value.properties == ["context", "object_refs"] def test_invalid_kwarg_to_grouping(): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v21.Grouping(my_custom_property="foo", **GROUPING_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v21.Grouping(my_custom_property="foo", **GROUPING_KWARGS) - assert excinfo.value.cls == stix2.v21.Grouping + assert excinfo.value.cls == misp_lib_stix2.v21.Grouping assert excinfo.value.properties == ['my_custom_property'] assert str(excinfo.value) == "Unexpected properties for Grouping: (my_custom_property)." @@ -113,7 +113,7 @@ def test_invalid_kwarg_to_grouping(): ], ) def test_parse_grouping(data): - grp = stix2.parse(data) + grp = misp_lib_stix2.parse(data) assert grp.type == 'grouping' assert grp.spec_version == '2.1' diff --git a/stix2/test/v21/test_identity.py b/misp_lib_stix2/test/v21/test_identity.py similarity index 88% rename from stix2/test/v21/test_identity.py rename to misp_lib_stix2/test/v21/test_identity.py index 2f8747ce..7c2345d9 100644 --- a/stix2/test/v21/test_identity.py +++ b/misp_lib_stix2/test/v21/test_identity.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import IDENTITY_ID @@ -19,7 +19,7 @@ def test_identity_example(): - identity = stix2.v21.Identity( + identity = misp_lib_stix2.v21.Identity( id=IDENTITY_ID, created="2015-12-21T19:59:11.000Z", modified="2015-12-21T19:59:11.000Z", @@ -45,7 +45,7 @@ def test_identity_example(): ], ) def test_parse_identity(data): - identity = stix2.parse(data, version="2.1") + identity = misp_lib_stix2.parse(data, version="2.1") assert identity.type == 'identity' assert identity.spec_version == '2.1' @@ -56,8 +56,8 @@ def test_parse_identity(data): def test_parse_no_type(): - with pytest.raises(stix2.exceptions.ParseError): - stix2.parse( + with pytest.raises(misp_lib_stix2.exceptions.ParseError): + misp_lib_stix2.parse( """ { "id": "identity--311b2d2d-f010-4473-83ec-1edf84858f4c", @@ -70,7 +70,7 @@ def test_parse_no_type(): def test_identity_with_custom(): - identity = stix2.v21.Identity( + identity = misp_lib_stix2.v21.Identity( name="John Smith", identity_class="individual", custom_properties={'x_foo': 'bar'}, diff --git a/stix2/test/v21/test_incident.py b/misp_lib_stix2/test/v21/test_incident.py similarity index 89% rename from stix2/test/v21/test_incident.py rename to misp_lib_stix2/test/v21/test_incident.py index fac92380..5b4b8971 100644 --- a/stix2/test/v21/test_incident.py +++ b/misp_lib_stix2/test/v21/test_incident.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import INCIDENT_ID @@ -19,7 +19,7 @@ def test_incident_example(): - incident = stix2.v21.Incident( + incident = misp_lib_stix2.v21.Incident( id=INCIDENT_ID, created="2015-12-21T19:59:11.000Z", modified="2015-12-21T19:59:11.000Z", @@ -45,7 +45,7 @@ def test_incident_example(): ], ) def test_parse_incident(data): - incident = stix2.parse(data, version="2.1") + incident = misp_lib_stix2.parse(data, version="2.1") assert incident.type == 'incident' assert incident.spec_version == '2.1' @@ -57,8 +57,8 @@ def test_parse_incident(data): def test_parse_no_type(): - with pytest.raises(stix2.exceptions.ParseError): - stix2.parse( + with pytest.raises(misp_lib_stix2.exceptions.ParseError): + misp_lib_stix2.parse( """ { "id": "incident--40fc3b35-0dc4-4afd-9927-288d44bfce20", @@ -71,7 +71,7 @@ def test_parse_no_type(): def test_incident_with_custom(): - incident = stix2.v21.Incident( + incident = misp_lib_stix2.v21.Incident( name="Breach of Cyber Tech Dynamics", description="Intrusion into enterprise network", custom_properties={'x_foo': 'bar'}, diff --git a/stix2/test/v21/test_indicator.py b/misp_lib_stix2/test/v21/test_indicator.py similarity index 74% rename from stix2/test/v21/test_indicator.py rename to misp_lib_stix2/test/v21/test_indicator.py index 6175948f..bf921674 100644 --- a/stix2/test/v21/test_indicator.py +++ b/misp_lib_stix2/test/v21/test_indicator.py @@ -4,7 +4,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import FAKE_TIME, INDICATOR_ID, INDICATOR_KWARGS @@ -40,7 +40,7 @@ def test_indicator_with_all_required_properties(): now = dt.datetime(2017, 1, 1, 0, 0, 1, tzinfo=pytz.utc) epoch = dt.datetime(1970, 1, 1, 0, 0, 1, tzinfo=pytz.utc) - ind = stix2.v21.Indicator( + ind = misp_lib_stix2.v21.Indicator( type="indicator", id=INDICATOR_ID, created=now, @@ -77,78 +77,78 @@ def test_indicator_autogenerated_properties(indicator): def test_indicator_type_must_be_indicator(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Indicator(type='xxx', **INDICATOR_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Indicator(type='xxx', **INDICATOR_KWARGS) - assert excinfo.value.cls == stix2.v21.Indicator + assert excinfo.value.cls == misp_lib_stix2.v21.Indicator assert excinfo.value.prop_name == "type" assert excinfo.value.reason == "must equal 'indicator'." assert str(excinfo.value) == "Invalid value for Indicator 'type': must equal 'indicator'." def test_indicator_id_must_start_with_indicator(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Indicator(id='my-prefix--', **INDICATOR_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Indicator(id='my-prefix--', **INDICATOR_KWARGS) - assert excinfo.value.cls == stix2.v21.Indicator + assert excinfo.value.cls == misp_lib_stix2.v21.Indicator assert excinfo.value.prop_name == "id" assert excinfo.value.reason == "must start with 'indicator--'." assert str(excinfo.value) == "Invalid value for Indicator 'id': must start with 'indicator--'." def test_indicator_required_properties(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v21.Indicator() + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v21.Indicator() - assert excinfo.value.cls == stix2.v21.Indicator + assert excinfo.value.cls == misp_lib_stix2.v21.Indicator assert excinfo.value.properties == ["pattern", "pattern_type"] assert str(excinfo.value) == "No values for required properties for Indicator: (pattern, pattern_type)." def test_indicator_required_property_pattern(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v21.Indicator(indicator_types=['malicious-activity']) + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v21.Indicator(indicator_types=['malicious-activity']) - assert excinfo.value.cls == stix2.v21.Indicator + assert excinfo.value.cls == misp_lib_stix2.v21.Indicator assert excinfo.value.properties == ["pattern", "pattern_type"] def test_indicator_created_ref_invalid_format(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Indicator(created_by_ref='myprefix--12345678', **INDICATOR_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Indicator(created_by_ref='myprefix--12345678', **INDICATOR_KWARGS) - assert excinfo.value.cls == stix2.v21.Indicator + assert excinfo.value.cls == misp_lib_stix2.v21.Indicator assert excinfo.value.prop_name == "created_by_ref" def test_indicator_revoked_invalid(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Indicator(revoked='no', **INDICATOR_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Indicator(revoked='no', **INDICATOR_KWARGS) - assert excinfo.value.cls == stix2.v21.Indicator + assert excinfo.value.cls == misp_lib_stix2.v21.Indicator assert excinfo.value.prop_name == "revoked" assert excinfo.value.reason == "must be a boolean value." def test_cannot_assign_to_indicator_attributes(indicator): - with pytest.raises(stix2.exceptions.ImmutableError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.ImmutableError) as excinfo: indicator.valid_from = dt.datetime.now() assert str(excinfo.value) == "Cannot modify 'valid_from' property in 'Indicator' after creation." def test_invalid_kwarg_to_indicator(): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v21.Indicator(my_custom_property="foo", **INDICATOR_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v21.Indicator(my_custom_property="foo", **INDICATOR_KWARGS) - assert excinfo.value.cls == stix2.v21.Indicator + assert excinfo.value.cls == misp_lib_stix2.v21.Indicator assert excinfo.value.properties == ['my_custom_property'] assert str(excinfo.value) == "Unexpected properties for Indicator: (my_custom_property)." def test_created_modified_time_are_identical_by_default(): """By default, the created and modified times should be the same.""" - ind = stix2.v21.Indicator(**INDICATOR_KWARGS) + ind = misp_lib_stix2.v21.Indicator(**INDICATOR_KWARGS) assert ind.created == ind.modified @@ -168,7 +168,7 @@ def test_created_modified_time_are_identical_by_default(): ], ) def test_parse_indicator(data): - idctr = stix2.parse(data, version="2.1") + idctr = misp_lib_stix2.parse(data, version="2.1") assert idctr.type == 'indicator' assert idctr.spec_version == '2.1' @@ -180,25 +180,25 @@ def test_parse_indicator(data): def test_invalid_indicator_pattern(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Indicator( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Indicator( indicator_types=['malicious-activity'], pattern="file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e'", pattern_type="stix", valid_from="2017-01-01T12:34:56Z", ) - assert excinfo.value.cls == stix2.v21.Indicator + assert excinfo.value.cls == misp_lib_stix2.v21.Indicator assert excinfo.value.prop_name == 'pattern' assert 'input is missing square brackets' in excinfo.value.reason - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Indicator( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Indicator( indicator_types=['malicious-activity'], pattern='[file:hashes.MD5 = "d41d8cd98f00b204e9800998ecf8427e"]', pattern_type="stix", valid_from="2017-01-01T12:34:56Z", ) - assert excinfo.value.cls == stix2.v21.Indicator + assert excinfo.value.cls == misp_lib_stix2.v21.Indicator assert excinfo.value.prop_name == 'pattern' assert 'mismatched input' in excinfo.value.reason @@ -207,14 +207,14 @@ def test_indicator_with_custom_embedded_objs(): now = dt.datetime(2017, 1, 1, 0, 0, 1, tzinfo=pytz.utc) epoch = dt.datetime(1970, 1, 1, 0, 0, 1, tzinfo=pytz.utc) - ext_ref = stix2.v21.ExternalReference( + ext_ref = misp_lib_stix2.v21.ExternalReference( source_name="Test", description="Example Custom Ext Ref", random_custom_prop="This is a custom property", allow_custom=True, ) - ind = stix2.v21.Indicator( + ind = misp_lib_stix2.v21.Indicator( type="indicator", id=INDICATOR_ID, created=now, @@ -233,17 +233,17 @@ def test_indicator_with_custom_embedded_objs(): def test_indicator_with_custom_embed_objs_extra_props_error(): - ext_ref = stix2.v21.ExternalReference( + ext_ref = misp_lib_stix2.v21.ExternalReference( source_name="Test", description="Example Custom Ext Ref", random_custom_prop="This is a custom property", allow_custom=True, ) - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v21.Indicator(external_references=[ext_ref], bad_custom_prop="shouldn't be here", **INDICATOR_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v21.Indicator(external_references=[ext_ref], bad_custom_prop="shouldn't be here", **INDICATOR_KWARGS) - assert excinfo.value.cls == stix2.v21.Indicator + assert excinfo.value.cls == misp_lib_stix2.v21.Indicator assert excinfo.value.properties == ['bad_custom_prop'] assert str(excinfo.value) == "Unexpected properties for Indicator: (bad_custom_prop)." @@ -253,8 +253,8 @@ def test_indicator_stix20_invalid_pattern(): epoch = dt.datetime(1970, 1, 1, 0, 0, 1, tzinfo=pytz.utc) patrn = "[win-registry-key:key = 'hkey_local_machine\\\\foo\\\\bar'] WITHIN 5 SECONDS WITHIN 6 SECONDS" - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Indicator( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Indicator( type="indicator", id=INDICATOR_ID, created=now, @@ -265,10 +265,10 @@ def test_indicator_stix20_invalid_pattern(): indicator_types=['malicious-activity'], ) - assert excinfo.value.cls == stix2.v21.Indicator + assert excinfo.value.cls == misp_lib_stix2.v21.Indicator assert "FAIL: Duplicate qualifier type encountered: WITHIN" in str(excinfo.value) - ind = stix2.v21.Indicator( + ind = misp_lib_stix2.v21.Indicator( type="indicator", id=INDICATOR_ID, created=now, diff --git a/stix2/test/v21/test_infrastructure.py b/misp_lib_stix2/test/v21/test_infrastructure.py similarity index 73% rename from stix2/test/v21/test_infrastructure.py rename to misp_lib_stix2/test/v21/test_infrastructure.py index 2beb6aab..762a6fe5 100644 --- a/stix2/test/v21/test_infrastructure.py +++ b/misp_lib_stix2/test/v21/test_infrastructure.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import FAKE_TIME, INFRASTRUCTURE_ID, INFRASTRUCTURE_KWARGS @@ -20,7 +20,7 @@ def test_infrastructure_with_all_required_properties(): now = dt.datetime(2017, 1, 1, 12, 34, 56, tzinfo=pytz.utc) - infra = stix2.v21.Infrastructure( + infra = misp_lib_stix2.v21.Infrastructure( type="infrastructure", id=INFRASTRUCTURE_ID, created=now, @@ -48,46 +48,46 @@ def test_infrastructure_autogenerated_properties(infrastructure): def test_infrastructure_type_must_be_infrastructure(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Infrastructure(type='xxx', **INFRASTRUCTURE_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Infrastructure(type='xxx', **INFRASTRUCTURE_KWARGS) - assert excinfo.value.cls == stix2.v21.Infrastructure + assert excinfo.value.cls == misp_lib_stix2.v21.Infrastructure assert excinfo.value.prop_name == "type" assert excinfo.value.reason == "must equal 'infrastructure'." assert str(excinfo.value) == "Invalid value for Infrastructure 'type': must equal 'infrastructure'." def test_infrastructure_id_must_start_with_infrastructure(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Infrastructure(id='my-prefix--', **INFRASTRUCTURE_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Infrastructure(id='my-prefix--', **INFRASTRUCTURE_KWARGS) - assert excinfo.value.cls == stix2.v21.Infrastructure + assert excinfo.value.cls == misp_lib_stix2.v21.Infrastructure assert excinfo.value.prop_name == "id" assert excinfo.value.reason == "must start with 'infrastructure--'." assert str(excinfo.value) == "Invalid value for Infrastructure 'id': must start with 'infrastructure--'." def test_infrastructure_required_properties(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v21.Infrastructure() + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v21.Infrastructure() - assert excinfo.value.cls == stix2.v21.Infrastructure + assert excinfo.value.cls == misp_lib_stix2.v21.Infrastructure assert excinfo.value.properties == ["name"] def test_infrastructure_required_property_name(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v21.Infrastructure(infrastructure_types=['command-and-control']) + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v21.Infrastructure(infrastructure_types=['command-and-control']) - assert excinfo.value.cls == stix2.v21.Infrastructure + assert excinfo.value.cls == misp_lib_stix2.v21.Infrastructure assert excinfo.value.properties == ["name"] def test_invalid_kwarg_to_infrastructure(): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v21.Infrastructure(my_custom_property="foo", **INFRASTRUCTURE_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v21.Infrastructure(my_custom_property="foo", **INFRASTRUCTURE_KWARGS) - assert excinfo.value.cls == stix2.v21.Infrastructure + assert excinfo.value.cls == misp_lib_stix2.v21.Infrastructure assert excinfo.value.properties == ['my_custom_property'] assert str(excinfo.value) == "Unexpected properties for Infrastructure: (my_custom_property)." @@ -106,7 +106,7 @@ def test_invalid_kwarg_to_infrastructure(): ], ) def test_parse_infrastructure(data): - infra = stix2.parse(data) + infra = misp_lib_stix2.parse(data) assert infra.type == 'infrastructure' assert infra.spec_version == '2.1' @@ -125,7 +125,7 @@ def test_parse_infrastructure_kill_chain_phases(): } ]""" data = EXPECTED_INFRASTRUCTURE.replace('infrastructure"', 'infrastructure",%s' % kill_chain) - infra = stix2.parse(data, version="2.1") + infra = misp_lib_stix2.parse(data, version="2.1") assert infra.kill_chain_phases[0].kill_chain_name == "lockheed-martin-cyber-kill-chain" assert infra.kill_chain_phases[0].phase_name == "reconnaissance" assert infra['kill_chain_phases'][0]['kill_chain_name'] == "lockheed-martin-cyber-kill-chain" @@ -141,12 +141,12 @@ def test_parse_infrastructure_clean_kill_chain_phases(): } ]""" data = EXPECTED_INFRASTRUCTURE.replace('2.1"', '2.1",%s' % kill_chain) - infra = stix2.parse(data, version="2.1") + infra = misp_lib_stix2.parse(data, version="2.1") assert infra['kill_chain_phases'][0]['phase_name'] == "1" def test_infrastructure_invalid_last_before_first(): with pytest.raises(ValueError) as excinfo: - stix2.v21.Infrastructure(first_seen="2017-01-01T12:34:56.000Z", last_seen="2017-01-01T12:33:56.000Z", **INFRASTRUCTURE_KWARGS) + misp_lib_stix2.v21.Infrastructure(first_seen="2017-01-01T12:34:56.000Z", last_seen="2017-01-01T12:33:56.000Z", **INFRASTRUCTURE_KWARGS) assert "'last_seen' must be greater than or equal to 'first_seen'" in str(excinfo.value) diff --git a/stix2/test/v21/test_interoperability.py b/misp_lib_stix2/test/v21/test_interoperability.py similarity index 78% rename from stix2/test/v21/test_interoperability.py rename to misp_lib_stix2/test/v21/test_interoperability.py index 37256446..7afa723a 100644 --- a/stix2/test/v21/test_interoperability.py +++ b/misp_lib_stix2/test/v21/test_interoperability.py @@ -2,7 +2,7 @@ import pytz -import stix2 +import misp_lib_stix2 FAKE_TIME = datetime.datetime(2017, 1, 1, 12, 34, 56, tzinfo=pytz.utc) @@ -176,22 +176,22 @@ if __name__ == '__main__': - attack_pattern = stix2.v21.AttackPattern(**ATTACK_PATTERN_KWARGS, interoperability=True) - campaign = stix2.v21.Campaign(**CAMPAIGN_KWARGS, interoperability=True) - course_of_action = stix2.v21.CourseOfAction(**COURSE_OF_ACTION_KWARGS, interoperability=True) - identity = stix2.v21.Identity(**IDENTITY_KWARGS, interoperability=True) - indicator = stix2.v21.Indicator(**INDICATOR_KWARGS, interoperability=True) - intrusion_set = stix2.v21.IntrusionSet(**INTRUSION_SET_KWARGS, interoperability=True) - malware = stix2.v21.Malware(**MALWARE_KWARGS, interoperability=True) - marking_definition = stix2.v21.MarkingDefinition(**MARKING_DEFINITION_KWARGS, interoperability=True) - observed_data = stix2.v21.ObservedData(**OBSERVED_DATA_KWARGS, interoperability=True) - relationship = stix2.v21.Relationship(**RELATIONSHIP_KWARGS, interoperability=True) - sighting = stix2.v21.Sighting(**SIGHTING_KWARGS, interoperability=True) - threat_actor = stix2.v21.ThreatActor(**THREAT_ACTOR_KWARGS, interoperability=True) - tool = stix2.v21.Tool(**TOOL_KWARGS) - vulnerability = stix2.v21.Vulnerability(**VULNERABILITY_KWARGS, interoperability=True) - report = stix2.v21.Report(**REPORT_KWARGS, interoperability=True) - bundle = stix2.v21.Bundle( + attack_pattern = misp_lib_stix2.v21.AttackPattern(**ATTACK_PATTERN_KWARGS, interoperability=True) + campaign = misp_lib_stix2.v21.Campaign(**CAMPAIGN_KWARGS, interoperability=True) + course_of_action = misp_lib_stix2.v21.CourseOfAction(**COURSE_OF_ACTION_KWARGS, interoperability=True) + identity = misp_lib_stix2.v21.Identity(**IDENTITY_KWARGS, interoperability=True) + indicator = misp_lib_stix2.v21.Indicator(**INDICATOR_KWARGS, interoperability=True) + intrusion_set = misp_lib_stix2.v21.IntrusionSet(**INTRUSION_SET_KWARGS, interoperability=True) + malware = misp_lib_stix2.v21.Malware(**MALWARE_KWARGS, interoperability=True) + marking_definition = misp_lib_stix2.v21.MarkingDefinition(**MARKING_DEFINITION_KWARGS, interoperability=True) + observed_data = misp_lib_stix2.v21.ObservedData(**OBSERVED_DATA_KWARGS, interoperability=True) + relationship = misp_lib_stix2.v21.Relationship(**RELATIONSHIP_KWARGS, interoperability=True) + sighting = misp_lib_stix2.v21.Sighting(**SIGHTING_KWARGS, interoperability=True) + threat_actor = misp_lib_stix2.v21.ThreatActor(**THREAT_ACTOR_KWARGS, interoperability=True) + tool = misp_lib_stix2.v21.Tool(**TOOL_KWARGS) + vulnerability = misp_lib_stix2.v21.Vulnerability(**VULNERABILITY_KWARGS, interoperability=True) + report = misp_lib_stix2.v21.Report(**REPORT_KWARGS, interoperability=True) + bundle = misp_lib_stix2.v21.Bundle( **BUNDLE_KWARGS, interoperability=True, objects=[ attack_pattern, campaign, course_of_action, identity, indicator, @@ -199,5 +199,5 @@ relationship, sighting, threat_actor, vulnerability, report, ] ) - stix2.parse(dict(bundle), interoperability=True) + misp_lib_stix2.parse(dict(bundle), interoperability=True) print("All interoperability tests passed !") diff --git a/stix2/test/v21/test_intrusion_set.py b/misp_lib_stix2/test/v21/test_intrusion_set.py similarity index 95% rename from stix2/test/v21/test_intrusion_set.py rename to misp_lib_stix2/test/v21/test_intrusion_set.py index 2b2dc0c9..5f62bea3 100644 --- a/stix2/test/v21/test_intrusion_set.py +++ b/misp_lib_stix2/test/v21/test_intrusion_set.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import IDENTITY_ID, INTRUSION_SET_ID @@ -28,7 +28,7 @@ def test_intrusion_set_example(): - intrusion_set = stix2.v21.IntrusionSet( + intrusion_set = misp_lib_stix2.v21.IntrusionSet( id=INTRUSION_SET_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T20:03:48.000Z", @@ -66,7 +66,7 @@ def test_intrusion_set_example(): ], ) def test_parse_intrusion_set(data): - intset = stix2.parse(data) + intset = misp_lib_stix2.parse(data) assert intset.type == "intrusion-set" assert intset.spec_version == '2.1' diff --git a/stix2/test/v20/test_kill_chain_phases.py b/misp_lib_stix2/test/v21/test_kill_chain_phases.py similarity index 55% rename from stix2/test/v20/test_kill_chain_phases.py rename to misp_lib_stix2/test/v21/test_kill_chain_phases.py index 7f65f00a..c47c82d0 100644 --- a/stix2/test/v20/test_kill_chain_phases.py +++ b/misp_lib_stix2/test/v21/test_kill_chain_phases.py @@ -2,7 +2,7 @@ import pytest -import stix2 +import misp_lib_stix2 LMCO_RECON = """{ "kill_chain_name": "lockheed-martin-cyber-kill-chain", @@ -11,7 +11,7 @@ def test_lockheed_martin_cyber_kill_chain(): - recon = stix2.v20.KillChainPhase( + recon = misp_lib_stix2.v21.KillChainPhase( kill_chain_name="lockheed-martin-cyber-kill-chain", phase_name="reconnaissance", ) @@ -26,7 +26,7 @@ def test_lockheed_martin_cyber_kill_chain(): def test_kill_chain_example(): - preattack = stix2.v20.KillChainPhase( + preattack = misp_lib_stix2.v21.KillChainPhase( kill_chain_name="foo", phase_name="pre-attack", ) @@ -36,26 +36,26 @@ def test_kill_chain_example(): def test_kill_chain_required_properties(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v20.KillChainPhase() + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v21.KillChainPhase() - assert excinfo.value.cls == stix2.v20.KillChainPhase + assert excinfo.value.cls == misp_lib_stix2.v21.KillChainPhase assert excinfo.value.properties == ["kill_chain_name", "phase_name"] def test_kill_chain_required_property_chain_name(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v20.KillChainPhase(phase_name="weaponization") + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v21.KillChainPhase(phase_name="weaponization") - assert excinfo.value.cls == stix2.v20.KillChainPhase + assert excinfo.value.cls == misp_lib_stix2.v21.KillChainPhase assert excinfo.value.properties == ["kill_chain_name"] def test_kill_chain_required_property_phase_name(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v20.KillChainPhase(kill_chain_name="lockheed-martin-cyber-kill-chain") + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v21.KillChainPhase(kill_chain_name="lockheed-martin-cyber-kill-chain") - assert excinfo.value.cls == stix2.v20.KillChainPhase + assert excinfo.value.cls == misp_lib_stix2.v21.KillChainPhase assert excinfo.value.properties == ["phase_name"] diff --git a/stix2/test/v21/test_language_content.py b/misp_lib_stix2/test/v21/test_language_content.py similarity index 93% rename from stix2/test/v21/test_language_content.py rename to misp_lib_stix2/test/v21/test_language_content.py index 95adebc3..99909c5f 100644 --- a/stix2/test/v21/test_language_content.py +++ b/misp_lib_stix2/test/v21/test_language_content.py @@ -4,7 +4,7 @@ import pytz -import stix2 +import misp_lib_stix2 CAMPAIGN_ID = "campaign--12a111f0-b824-4baf-a224-83b80237a094" @@ -45,7 +45,7 @@ def test_language_content_campaign(): now = dt.datetime(2017, 2, 8, 21, 31, 22, microsecond=7000, tzinfo=pytz.utc) - lc = stix2.v21.LanguageContent( + lc = misp_lib_stix2.v21.LanguageContent( type='language-content', id=LANGUAGE_CONTENT_ID, created=now, @@ -64,7 +64,7 @@ def test_language_content_campaign(): }, ) - camp = stix2.parse(TEST_CAMPAIGN, version='2.1') + camp = misp_lib_stix2.parse(TEST_CAMPAIGN, version='2.1') # In order to provide the same representation, we need to disable escaping # in json.dumps(). https://docs.python.org/3/library/json.html#json.dumps @@ -78,7 +78,7 @@ def test_object_modified_optional(): object_modified is now optional in STIX 2.1. """ - stix2.v21.LanguageContent( + misp_lib_stix2.v21.LanguageContent( object_ref=CAMPAIGN_ID, contents={ "en": { diff --git a/stix2/test/v21/test_location.py b/misp_lib_stix2/test/v21/test_location.py similarity index 89% rename from stix2/test/v21/test_location.py rename to misp_lib_stix2/test/v21/test_location.py index 5d3eab8a..0fc31abd 100644 --- a/stix2/test/v21/test_location.py +++ b/misp_lib_stix2/test/v21/test_location.py @@ -4,8 +4,8 @@ import pytest import pytz -import stix2 -import stix2.exceptions +import misp_lib_stix2 +import misp_lib_stix2.exceptions from .constants import LOCATION_ID @@ -56,7 +56,7 @@ def test_location_with_some_required_properties(): now = dt.datetime(2016, 4, 6, 20, 3, 0, tzinfo=pytz.utc) - location = stix2.v21.Location( + location = misp_lib_stix2.v21.Location( id=LOCATION_ID, created=now, modified=now, @@ -83,7 +83,7 @@ def test_location_with_some_required_properties(): ], ) def test_parse_location(data): - location = stix2.parse(data, version="2.1") + location = misp_lib_stix2.parse(data, version="2.1") assert location.type == 'location' assert location.spec_version == '2.1' @@ -118,8 +118,8 @@ def test_parse_location(data): ], ) def test_location_bad_latitude(data): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.parse(data) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.parse(data) assert "Invalid value for Location 'latitude'" in str(excinfo.value) @@ -147,8 +147,8 @@ def test_location_bad_latitude(data): ], ) def test_location_bad_longitude(data): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.parse(data) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.parse(data) assert "Invalid value for Location 'longitude'" in str(excinfo.value) @@ -176,8 +176,8 @@ def test_location_bad_longitude(data): ], ) def test_location_properties_missing_when_precision_is_present(data): - with pytest.raises(stix2.exceptions.DependentPropertiesError) as excinfo: - stix2.parse(data) + with pytest.raises(misp_lib_stix2.exceptions.DependentPropertiesError) as excinfo: + misp_lib_stix2.parse(data) assert any(x in str(excinfo.value) for x in ("(latitude, precision)", "(longitude, precision)")) @@ -197,8 +197,8 @@ def test_location_properties_missing_when_precision_is_present(data): ], ) def test_location_negative_precision(data): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.parse(data) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.parse(data) assert "Invalid value for Location 'precision'" in str(excinfo.value) @@ -232,8 +232,8 @@ def test_location_negative_precision(data): ], ) def test_location_latitude_dependency_missing(data, msg): - with pytest.raises(stix2.exceptions.DependentPropertiesError) as excinfo: - stix2.parse(data) + with pytest.raises(misp_lib_stix2.exceptions.DependentPropertiesError) as excinfo: + misp_lib_stix2.parse(data) assert msg in str(excinfo.value) @@ -265,15 +265,15 @@ def test_location_latitude_dependency_missing(data, msg): ], ) def test_location_lat_or_lon_dependency_missing(data, msg): - with pytest.raises(stix2.exceptions.DependentPropertiesError) as excinfo: - stix2.parse(data) + with pytest.raises(misp_lib_stix2.exceptions.DependentPropertiesError) as excinfo: + misp_lib_stix2.parse(data) assert msg in str(excinfo.value) def test_location_complex_presence_constraint(): - with pytest.raises(stix2.exceptions.PropertyPresenceError): - stix2.parse({ + with pytest.raises(misp_lib_stix2.exceptions.PropertyPresenceError): + misp_lib_stix2.parse({ "type": "location", "spec_version": "2.1", "id": LOCATION_ID, @@ -283,7 +283,7 @@ def test_location_complex_presence_constraint(): def test_google_map_url_long_lat_provided(): expected_url = "https://www.google.com/maps/search/?api=1&query=41.862401%2C-87.616001" - loc = stix2.v21.Location( + loc = misp_lib_stix2.v21.Location( latitude=41.862401, longitude=-87.616001, ) @@ -296,7 +296,7 @@ def test_google_map_url_multiple_props_no_long_lat_provided(): expected_url = "https://www.google.com/maps/search/?api=1&query=1410+Museum+Campus+Drive%2C+Chicago%2C+IL+60605%2CUnited+States+of+America%2CNorth+America" now = dt.datetime(2019, 2, 7, 12, 34, 56, tzinfo=pytz.utc) - loc = stix2.v21.Location( + loc = misp_lib_stix2.v21.Location( type="location", id=LOCATION_ID, created=now, @@ -314,7 +314,7 @@ def test_google_map_url_multiple_props_no_long_lat_provided(): def test_google_map_url_multiple_props_and_long_lat_provided(): expected_url = "https://www.google.com/maps/search/?api=1&query=41.862401%2C-87.616001" - loc = stix2.v21.Location( + loc = misp_lib_stix2.v21.Location( region="northern-america", country="United States of America", street_address="1410 Museum Campus Drive, Chicago, IL 60605", @@ -327,7 +327,7 @@ def test_google_map_url_multiple_props_and_long_lat_provided(): def test_map_url_invalid_map_engine_provided(): - loc = stix2.v21.Location( + loc = misp_lib_stix2.v21.Location( latitude=41.862401, longitude=-87.616001, ) @@ -341,7 +341,7 @@ def test_map_url_invalid_map_engine_provided(): def test_bing_map_url_long_lat_provided(): expected_url = "https://bing.com/maps/default.aspx?where1=41.862401%2C-87.616001&lvl=16" - loc = stix2.v21.Location( + loc = misp_lib_stix2.v21.Location( latitude=41.862401, longitude=-87.616001, ) @@ -353,7 +353,7 @@ def test_bing_map_url_long_lat_provided(): def test_bing_map_url_multiple_props_no_long_lat_provided(): expected_url = "https://bing.com/maps/default.aspx?where1=1410+Museum+Campus+Drive%2C+Chicago%2C+IL+60605%2CUnited+States+of+America%2CNorth+America&lvl=16" - loc = stix2.v21.Location( + loc = misp_lib_stix2.v21.Location( region="North America", country="United States of America", street_address="1410 Museum Campus Drive, Chicago, IL 60605", @@ -367,7 +367,7 @@ def test_bing_map_url_multiple_props_no_long_lat_provided(): def test_bing_map_url_multiple_props_and_long_lat_provided(): expected_url = "https://bing.com/maps/default.aspx?where1=41.862401%2C-87.616001&lvl=16" - loc = stix2.v21.Location( + loc = misp_lib_stix2.v21.Location( region="northern-america", country="United States of America", street_address="1410 Museum Campus Drive, Chicago, IL 60605", diff --git a/stix2/test/v21/test_malware.py b/misp_lib_stix2/test/v21/test_malware.py similarity index 77% rename from stix2/test/v21/test_malware.py rename to misp_lib_stix2/test/v21/test_malware.py index 3c8b39cd..0afbad8e 100644 --- a/stix2/test/v21/test_malware.py +++ b/misp_lib_stix2/test/v21/test_malware.py @@ -4,7 +4,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from ...exceptions import InvalidValueError, PropertyPresenceError from .constants import FAKE_TIME, MALWARE_ID, MALWARE_KWARGS @@ -23,7 +23,7 @@ def test_malware_with_all_required_properties(): now = dt.datetime(2016, 5, 12, 8, 17, 27, tzinfo=pytz.utc) - malware = stix2.v21.Malware( + malware = misp_lib_stix2.v21.Malware( type="malware", id=MALWARE_ID, created=now, @@ -52,53 +52,53 @@ def test_malware_autogenerated_properties(malware): def test_malware_type_must_be_malware(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Malware(type='xxx', **MALWARE_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Malware(type='xxx', **MALWARE_KWARGS) - assert excinfo.value.cls == stix2.v21.Malware + assert excinfo.value.cls == misp_lib_stix2.v21.Malware assert excinfo.value.prop_name == "type" assert excinfo.value.reason == "must equal 'malware'." assert str(excinfo.value) == "Invalid value for Malware 'type': must equal 'malware'." def test_malware_id_must_start_with_malware(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Malware(id='my-prefix--', **MALWARE_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Malware(id='my-prefix--', **MALWARE_KWARGS) - assert excinfo.value.cls == stix2.v21.Malware + assert excinfo.value.cls == misp_lib_stix2.v21.Malware assert excinfo.value.prop_name == "id" assert excinfo.value.reason == "must start with 'malware--'." assert str(excinfo.value) == "Invalid value for Malware 'id': must start with 'malware--'." def test_malware_required_properties(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v21.Malware() + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v21.Malware() - assert excinfo.value.cls == stix2.v21.Malware + assert excinfo.value.cls == misp_lib_stix2.v21.Malware assert excinfo.value.properties == ["is_family"] def test_malware_required_property_name(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v21.Malware(malware_types=['ransomware']) + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v21.Malware(malware_types=['ransomware']) - assert excinfo.value.cls == stix2.v21.Malware + assert excinfo.value.cls == misp_lib_stix2.v21.Malware assert excinfo.value.properties == ["is_family"] def test_cannot_assign_to_malware_attributes(malware): - with pytest.raises(stix2.exceptions.ImmutableError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.ImmutableError) as excinfo: malware.name = "Cryptolocker II" assert str(excinfo.value) == "Cannot modify 'name' property in 'Malware' after creation." def test_invalid_kwarg_to_malware(): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v21.Malware(my_custom_property="foo", **MALWARE_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v21.Malware(my_custom_property="foo", **MALWARE_KWARGS) - assert excinfo.value.cls == stix2.v21.Malware + assert excinfo.value.cls == misp_lib_stix2.v21.Malware assert excinfo.value.properties == ['my_custom_property'] assert str(excinfo.value) == "Unexpected properties for Malware: (my_custom_property)." @@ -118,7 +118,7 @@ def test_invalid_kwarg_to_malware(): ], ) def test_parse_malware(data): - mal = stix2.parse(data) + mal = misp_lib_stix2.parse(data) assert mal.type == 'malware' assert mal.spec_version == '2.1' @@ -134,7 +134,7 @@ def test_parse_malware_invalid_types(): data["malware_types"] = 1 # Oops, not a list data = json.dumps(data) with pytest.raises(InvalidValueError) as excinfo: - stix2.parse(data) + misp_lib_stix2.parse(data) assert "Invalid value for Malware 'malware_types'" in str(excinfo.value) @@ -147,7 +147,7 @@ def test_parse_malware_kill_chain_phases(): } ]""" data = EXPECTED_MALWARE.replace('malware"', 'malware",%s' % kill_chain) - mal = stix2.parse(data, version="2.1") + mal = misp_lib_stix2.parse(data, version="2.1") assert mal.kill_chain_phases[0].kill_chain_name == "lockheed-martin-cyber-kill-chain" assert mal.kill_chain_phases[0].phase_name == "reconnaissance" assert mal['kill_chain_phases'][0]['kill_chain_name'] == "lockheed-martin-cyber-kill-chain" @@ -163,20 +163,20 @@ def test_parse_malware_clean_kill_chain_phases(): } ]""" data = EXPECTED_MALWARE.replace('2.1"', '2.1",%s' % kill_chain) - mal = stix2.parse(data, version="2.1") + mal = misp_lib_stix2.parse(data, version="2.1") assert mal['kill_chain_phases'][0]['phase_name'] == "1" def test_malware_invalid_last_before_first(): with pytest.raises(ValueError) as excinfo: - stix2.v21.Malware(first_seen="2017-01-01T12:34:56.000Z", last_seen="2017-01-01T12:33:56.000Z", **MALWARE_KWARGS) + misp_lib_stix2.v21.Malware(first_seen="2017-01-01T12:34:56.000Z", last_seen="2017-01-01T12:33:56.000Z", **MALWARE_KWARGS) assert "'last_seen' must be greater than or equal to 'first_seen'" in str(excinfo.value) def test_malware_family_no_name(): with pytest.raises(PropertyPresenceError): - stix2.parse({ + misp_lib_stix2.parse({ "type": "malware", "id": MALWARE_ID, "spec_version": "2.1", @@ -186,7 +186,7 @@ def test_malware_family_no_name(): def test_malware_non_family_no_name(): - stix2.parse({ + misp_lib_stix2.parse({ "type": "malware", "id": MALWARE_ID, "spec_version": "2.1", @@ -196,13 +196,13 @@ def test_malware_non_family_no_name(): def test_malware_with_os_refs(): - software = stix2.parse({ + software = misp_lib_stix2.parse({ "type": "software", "name": "SuperOS", "spec_version": "2.1", }) - malware = stix2.parse({ + malware = misp_lib_stix2.parse({ "type": "malware", "id": MALWARE_ID, "spec_version": "2.1", diff --git a/stix2/test/v21/test_malware_analysis.py b/misp_lib_stix2/test/v21/test_malware_analysis.py similarity index 82% rename from stix2/test/v21/test_malware_analysis.py rename to misp_lib_stix2/test/v21/test_malware_analysis.py index c0e4ca22..cf4e5f78 100644 --- a/stix2/test/v21/test_malware_analysis.py +++ b/misp_lib_stix2/test/v21/test_malware_analysis.py @@ -2,9 +2,9 @@ import pytest -import stix2.exceptions -import stix2.utils -import stix2.v21 +import misp_lib_stix2.exceptions +import misp_lib_stix2.utils +import misp_lib_stix2.v21 MALWARE_ANALYSIS_JSON = """{ "type": "malware-analysis", @@ -48,7 +48,7 @@ def test_malware_analysis_example(): - malware_analysis = stix2.v21.MalwareAnalysis(**MALWARE_ANALYSIS_DICT) + malware_analysis = misp_lib_stix2.v21.MalwareAnalysis(**MALWARE_ANALYSIS_DICT) assert malware_analysis.serialize(pretty=True) == MALWARE_ANALYSIS_JSON @@ -60,7 +60,7 @@ def test_malware_analysis_example(): ], ) def test_parse_malware_analysis(data): - ma = stix2.parse(data, version="2.1") + ma = misp_lib_stix2.parse(data, version="2.1") # timestamp-valued attributes whose values (from JSON) can't be compared # directly, since stix2 internally converts them to datetime objects. @@ -73,21 +73,21 @@ def test_parse_malware_analysis(data): } for attr_name, attr_value in MALWARE_ANALYSIS_DICT.items(): - cmp_value = stix2.utils.parse_into_datetime(attr_value) \ + cmp_value = misp_lib_stix2.utils.parse_into_datetime(attr_value) \ if attr_name in ts_attrs else attr_value assert getattr(ma, attr_name) == cmp_value def test_malware_analysis_constraint(): - with pytest.raises(stix2.exceptions.AtLeastOnePropertyError): - stix2.v21.MalwareAnalysis( + with pytest.raises(misp_lib_stix2.exceptions.AtLeastOnePropertyError): + misp_lib_stix2.v21.MalwareAnalysis( product="Acme Malware Analyzer", ) def test_malware_analysis_custom_sco_refs(): - ma = stix2.v21.MalwareAnalysis( + ma = misp_lib_stix2.v21.MalwareAnalysis( product="super scanner", analysis_sco_refs=[ "file--6e8c78cf-4bcc-4729-9265-86a97bfc91ba", @@ -100,8 +100,8 @@ def test_malware_analysis_custom_sco_refs(): ma["analysis_sco_refs"] assert ma.has_custom - with pytest.raises(stix2.exceptions.InvalidValueError): - stix2.v21.MalwareAnalysis( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError): + misp_lib_stix2.v21.MalwareAnalysis( product="super scanner", analysis_sco_refs=[ "file--6e8c78cf-4bcc-4729-9265-86a97bfc91ba", @@ -109,8 +109,8 @@ def test_malware_analysis_custom_sco_refs(): ], ) - with pytest.raises(stix2.exceptions.InvalidValueError): - stix2.v21.MalwareAnalysis( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError): + misp_lib_stix2.v21.MalwareAnalysis( product="super scanner", analysis_sco_refs=[ "file--6e8c78cf-4bcc-4729-9265-86a97bfc91ba", diff --git a/stix2/test/v21/test_marking_definition.py b/misp_lib_stix2/test/v21/test_marking_definition.py similarity index 98% rename from stix2/test/v21/test_marking_definition.py rename to misp_lib_stix2/test/v21/test_marking_definition.py index 7fe32a85..6529d38b 100644 --- a/stix2/test/v21/test_marking_definition.py +++ b/misp_lib_stix2/test/v21/test_marking_definition.py @@ -1,8 +1,8 @@ import pytest -from stix2 import exceptions, parse -from stix2.v21 import ( +from misp_lib_stix2 import exceptions, parse +from misp_lib_stix2.v21 import ( TLP_AMBER, TLP_GREEN, TLP_RED, TLP_WHITE, MarkingDefinition, TLPMarking, ) diff --git a/stix2/test/v21/test_markings.py b/misp_lib_stix2/test/v21/test_markings.py similarity index 85% rename from stix2/test/v21/test_markings.py rename to misp_lib_stix2/test/v21/test_markings.py index d3fd11bb..a0c35ded 100644 --- a/stix2/test/v21/test_markings.py +++ b/misp_lib_stix2/test/v21/test_markings.py @@ -5,8 +5,8 @@ import pytest import pytz -import stix2 -from stix2.v21 import TLP_WHITE +import misp_lib_stix2 +from misp_lib_stix2.v21 import TLP_WHITE from .constants import IDENTITY_ID, MARKING_DEFINITION_ID @@ -103,11 +103,11 @@ def test_marking_def_example_with_tlp(): def test_marking_def_example_with_statement_positional_argument(): - marking_definition = stix2.v21.MarkingDefinition( + marking_definition = misp_lib_stix2.v21.MarkingDefinition( id=MARKING_DEFINITION_ID, created="2017-01-20T00:00:00.000Z", definition_type="statement", - definition=stix2.StatementMarking(statement="Copyright 2016, Example Corp"), + definition=misp_lib_stix2.StatementMarking(statement="Copyright 2016, Example Corp"), ) assert marking_definition.serialize(pretty=True) == EXPECTED_STATEMENT_MARKING_DEFINITION @@ -115,11 +115,11 @@ def test_marking_def_example_with_statement_positional_argument(): def test_marking_def_example_with_kwargs_statement(): kwargs = dict(statement="Copyright 2016, Example Corp") - marking_definition = stix2.v21.MarkingDefinition( + marking_definition = misp_lib_stix2.v21.MarkingDefinition( id=MARKING_DEFINITION_ID, created="2017-01-20T00:00:00.000Z", definition_type="statement", - definition=stix2.StatementMarking(**kwargs), + definition=misp_lib_stix2.StatementMarking(**kwargs), ) assert marking_definition.serialize(pretty=True) == EXPECTED_STATEMENT_MARKING_DEFINITION @@ -127,16 +127,16 @@ def test_marking_def_example_with_kwargs_statement(): def test_marking_def_invalid_type(): with pytest.raises(ValueError): - stix2.v21.MarkingDefinition( + misp_lib_stix2.v21.MarkingDefinition( id=MARKING_DEFINITION_ID, created="2017-01-20T00:00:00.000Z", definition_type="my-definition-type", - definition=stix2.StatementMarking("Copyright 2016, Example Corp"), + definition=misp_lib_stix2.StatementMarking("Copyright 2016, Example Corp"), ) def test_campaign_with_markings_example(): - campaign = stix2.v21.Campaign( + campaign = misp_lib_stix2.v21.Campaign( id="campaign--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f", created_by_ref=IDENTITY_ID, created="2016-04-06T20:03:00Z", @@ -149,7 +149,7 @@ def test_campaign_with_markings_example(): def test_granular_example(): - granular_marking = stix2.v21.GranularMarking( + granular_marking = misp_lib_stix2.v21.GranularMarking( marking_ref=MARKING_DEFINITION_ID, selectors=["abc", "abc.[23]", "abc.def", "abc.[2].efg"], ) @@ -158,20 +158,20 @@ def test_granular_example(): def test_granular_example_with_bad_selector(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.GranularMarking( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.GranularMarking( marking_ref=MARKING_DEFINITION_ID, selectors=["abc[0]"], # missing "." ) - assert excinfo.value.cls == stix2.v21.GranularMarking + assert excinfo.value.cls == misp_lib_stix2.v21.GranularMarking assert excinfo.value.prop_name == "selectors" assert excinfo.value.reason == "must adhere to selector syntax." assert str(excinfo.value) == "Invalid value for GranularMarking 'selectors': must adhere to selector syntax." def test_campaign_with_granular_markings_example(): - campaign = stix2.v21.Campaign( + campaign = misp_lib_stix2.v21.Campaign( id="campaign--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f", created_by_ref=IDENTITY_ID, created="2016-04-06T20:03:00Z", @@ -179,7 +179,7 @@ def test_campaign_with_granular_markings_example(): name="Green Group Attacks Against Finance", description="Campaign by Green Group against a series of targets in the financial services sector.", granular_markings=[ - stix2.v21.GranularMarking( + misp_lib_stix2.v21.GranularMarking( marking_ref=MARKING_DEFINITION_ID, selectors=["description"], ), @@ -204,7 +204,7 @@ def test_campaign_with_granular_markings_example(): ], ) def test_parse_marking_definition(data): - gm = stix2.parse(data, version="2.1") + gm = misp_lib_stix2.parse(data, version="2.1") assert gm.type == 'marking-definition' assert gm.spec_version == '2.1' @@ -214,10 +214,10 @@ def test_parse_marking_definition(data): assert gm.definition_type == "tlp" -@stix2.v21.CustomMarking( +@misp_lib_stix2.v21.CustomMarking( 'x-new-marking-type', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewMarking(object): @@ -229,7 +229,7 @@ def __init__(self, property2=None, **kwargs): def test_registered_custom_marking(): nm = NewMarking(property1='something', property2=55) - marking_def = stix2.v21.MarkingDefinition( + marking_def = misp_lib_stix2.v21.MarkingDefinition( id="marking-definition--00000000-0000-4000-8000-000000000012", created="2017-01-22T00:00:00.000Z", definition_type="x-new-marking-type", @@ -254,10 +254,10 @@ def test_registered_custom_marking_raises_exception(): def test_not_registered_marking_raises_exception(): with pytest.raises(ValueError) as excinfo: # Used custom object on purpose to demonstrate a not-registered marking - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x-new-marking-type2', [ - ('property1', stix2.properties.StringProperty(required=True)), - ('property2', stix2.properties.IntegerProperty()), + ('property1', misp_lib_stix2.properties.StringProperty(required=True)), + ('property2', misp_lib_stix2.properties.IntegerProperty()), ], ) class NewObject2(object): @@ -266,7 +266,7 @@ def __init__(self, property2=None, **kwargs): no = NewObject2(property1='something', property2=55) - stix2.v21.MarkingDefinition( + misp_lib_stix2.v21.MarkingDefinition( id="marking-definition--00000000-0000-4000-8000-000000000012", created="2017-01-22T00:00:00.000Z", definition_type="x-new-marking-type2", @@ -279,13 +279,13 @@ def __init__(self, property2=None, **kwargs): def test_marking_wrong_type_construction(): with pytest.raises(ValueError): # Test passing wrong type for properties. - @stix2.v21.CustomMarking('x-new-marking-type2', ("a", "b")) + @misp_lib_stix2.v21.CustomMarking('x-new-marking-type2', ("a", "b")) class NewObject3(object): pass def test_campaign_add_markings(): - campaign = stix2.v21.Campaign( + campaign = misp_lib_stix2.v21.Campaign( id="campaign--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f", created_by_ref=IDENTITY_ID, created="2016-04-06T20:03:00Z", @@ -298,7 +298,7 @@ def test_campaign_add_markings(): def test_campaign_with_granular_lang_markings_example(): - campaign = stix2.v21.Campaign( + campaign = misp_lib_stix2.v21.Campaign( id="campaign--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f", created_by_ref=IDENTITY_ID, created="2016-04-06T20:03:00Z", @@ -307,7 +307,7 @@ def test_campaign_with_granular_lang_markings_example(): lang="en", description="Weitere Informationen über Banküberfall", granular_markings=[ - stix2.v21.GranularMarking( + misp_lib_stix2.v21.GranularMarking( lang="de", selectors=["description"], ), diff --git a/stix2/test/v21/test_note.py b/misp_lib_stix2/test/v21/test_note.py similarity index 96% rename from stix2/test/v21/test_note.py rename to misp_lib_stix2/test/v21/test_note.py index ca1fc6d6..66ddae21 100644 --- a/stix2/test/v21/test_note.py +++ b/misp_lib_stix2/test/v21/test_note.py @@ -4,7 +4,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import CAMPAIGN_ID, NOTE_ID @@ -57,7 +57,7 @@ def test_note_with_required_properties(): now = dt.datetime(2016, 5, 12, 8, 17, 27, tzinfo=pytz.utc) - note = stix2.v21.Note( + note = misp_lib_stix2.v21.Note( type='note', id=NOTE_ID, created=now, @@ -106,7 +106,7 @@ def test_note_with_required_properties(): ], ) def test_parse_note(data): - note = stix2.parse(data, version="2.1") + note = misp_lib_stix2.parse(data, version="2.1") assert note.type == 'note' assert note.spec_version == '2.1' diff --git a/stix2/test/v21/test_object_markings.py b/misp_lib_stix2/test/v21/test_object_markings.py similarity index 99% rename from stix2/test/v21/test_object_markings.py rename to misp_lib_stix2/test/v21/test_object_markings.py index bb1c4ab0..356084d5 100644 --- a/stix2/test/v21/test_object_markings.py +++ b/misp_lib_stix2/test/v21/test_object_markings.py @@ -1,7 +1,7 @@ import pytest -from stix2 import exceptions, markings -from stix2.v21 import TLP_AMBER, Malware +from misp_lib_stix2 import exceptions, markings +from misp_lib_stix2.v21 import TLP_AMBER, Malware from ...exceptions import MarkingNotFoundError from .constants import FAKE_TIME, MALWARE_ID diff --git a/stix2/test/v21/test_observed_data.py b/misp_lib_stix2/test/v21/test_observed_data.py similarity index 86% rename from stix2/test/v21/test_observed_data.py rename to misp_lib_stix2/test/v21/test_observed_data.py index d2ccec49..3058bf3f 100644 --- a/stix2/test/v21/test_observed_data.py +++ b/misp_lib_stix2/test/v21/test_observed_data.py @@ -4,8 +4,8 @@ import pytest import pytz -import stix2 -import stix2.exceptions +import misp_lib_stix2 +import misp_lib_stix2.exceptions from .constants import IDENTITY_ID, OBSERVED_DATA_ID @@ -34,7 +34,7 @@ def test_observed_data_example(): - observed_data = stix2.v21.ObservedData( + observed_data = misp_lib_stix2.v21.ObservedData( id=OBSERVED_DATA_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T19:58:16.000Z", @@ -56,7 +56,7 @@ def test_observed_data_example(): assert observed_data.created == observed_data.modified == dt.datetime(2016, 4, 6, 19, 58, 16, tzinfo=pytz.utc) assert observed_data.first_observed == observed_data.last_observed == dt.datetime(2015, 12, 21, 19, 00, 00, tzinfo=pytz.utc) assert observed_data.number_observed == 50 - assert observed_data.objects['0'] == stix2.v21.File(name="foo.exe") + assert observed_data.objects['0'] == misp_lib_stix2.v21.File(name="foo.exe") EXPECTED_WITH_REF = """{ @@ -90,7 +90,7 @@ def test_observed_data_example(): def test_observed_data_example_with_refs(): - observed_data = stix2.v21.ObservedData( + observed_data = misp_lib_stix2.v21.ObservedData( id=OBSERVED_DATA_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T19:58:16.000Z", @@ -117,8 +117,8 @@ def test_observed_data_example_with_refs(): assert observed_data.created == observed_data.modified == dt.datetime(2016, 4, 6, 19, 58, 16, tzinfo=pytz.utc) assert observed_data.first_observed == observed_data.last_observed == dt.datetime(2015, 12, 21, 19, 00, 00, tzinfo=pytz.utc) assert observed_data.number_observed == 50 - assert observed_data.objects['0'] == stix2.v21.File(name="foo.exe") - assert observed_data.objects['1'] == stix2.v21.Directory(path="/usr/home", contains_refs=["file--5956efbb-a7b0-566d-a7f9-a202eb05c70f"]) + assert observed_data.objects['0'] == misp_lib_stix2.v21.File(name="foo.exe") + assert observed_data.objects['1'] == misp_lib_stix2.v21.Directory(path="/usr/home", contains_refs=["file--5956efbb-a7b0-566d-a7f9-a202eb05c70f"]) EXPECTED_OBJECT_REFS = """{ @@ -140,7 +140,7 @@ def test_observed_data_example_with_refs(): def test_observed_data_example_with_object_refs(): - observed_data = stix2.v21.ObservedData( + observed_data = misp_lib_stix2.v21.ObservedData( id="observed-data--b67d30ff-02ac-498a-92f9-32f845f448cf", created_by_ref="identity--f431f809-377b-45e0-aa1c-6a4751cae5ff", created="2016-04-06T19:58:16.000Z", @@ -159,8 +159,8 @@ def test_observed_data_example_with_object_refs(): def test_observed_data_object_constraint(): - with pytest.raises(stix2.exceptions.MutuallyExclusivePropertiesError): - stix2.v21.ObservedData( + with pytest.raises(misp_lib_stix2.exceptions.MutuallyExclusivePropertiesError): + misp_lib_stix2.v21.ObservedData( id="observed-data--b67d30ff-02ac-498a-92f9-32f845f448cf", created_by_ref="identity--f431f809-377b-45e0-aa1c-6a4751cae5ff", created="2016-04-06T19:58:16.000Z", @@ -183,8 +183,8 @@ def test_observed_data_object_constraint(): def test_observed_data_example_with_bad_refs(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.ObservedData( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.ObservedData( id=OBSERVED_DATA_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T19:58:16.000Z", @@ -206,14 +206,14 @@ def test_observed_data_example_with_bad_refs(): }, ) - assert excinfo.value.cls == stix2.v21.Directory + assert excinfo.value.cls == misp_lib_stix2.v21.Directory assert excinfo.value.prop_name == "contains_refs" assert "The type-specifying prefix 'monkey' for this property is not" in excinfo.value.reason def test_observed_data_example_with_non_dictionary(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.ObservedData( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.ObservedData( id=OBSERVED_DATA_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T19:58:16.000Z", @@ -224,14 +224,14 @@ def test_observed_data_example_with_non_dictionary(): objects="file: foo.exe", ) - assert excinfo.value.cls == stix2.v21.ObservedData + assert excinfo.value.cls == misp_lib_stix2.v21.ObservedData assert excinfo.value.prop_name == "objects" assert 'must contain a dictionary' in excinfo.value.reason def test_observed_data_example_with_empty_dictionary(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.ObservedData( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.ObservedData( id=OBSERVED_DATA_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T19:58:16.000Z", @@ -242,7 +242,7 @@ def test_observed_data_example_with_empty_dictionary(): objects={}, ) - assert excinfo.value.cls == stix2.v21.ObservedData + assert excinfo.value.cls == misp_lib_stix2.v21.ObservedData assert excinfo.value.prop_name == "objects" assert 'must contain a non-empty dictionary' in excinfo.value.reason @@ -271,7 +271,7 @@ def test_observed_data_example_with_empty_dictionary(): ], ) def test_parse_observed_data(data): - odata = stix2.parse(data, version="2.1") + odata = misp_lib_stix2.parse(data, version="2.1") assert odata.type == 'observed-data' assert odata.spec_version == '2.1' @@ -303,7 +303,7 @@ def test_parse_observed_data(data): ) def test_parse_artifact_valid(data): odata_str = OBJECTS_REGEX.sub('"objects": { %s }' % data, EXPECTED) - odata = stix2.parse(odata_str, version="2.1") + odata = misp_lib_stix2.parse(odata_str, version="2.1") assert odata.objects["0"].type == "artifact" @@ -326,13 +326,13 @@ def test_parse_artifact_valid(data): ) def test_parse_artifact_invalid(data): odata_str = OBJECTS_REGEX.sub('"objects": { %s }' % data, EXPECTED) - with pytest.raises(stix2.exceptions.InvalidValueError): - stix2.parse(odata_str, version="2.1") + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError): + misp_lib_stix2.parse(odata_str, version="2.1") def test_artifact_example_dependency_error(): - with pytest.raises(stix2.exceptions.DependentPropertiesError) as excinfo: - stix2.v21.Artifact(url="http://example.com/sirvizio.exe") + with pytest.raises(misp_lib_stix2.exceptions.DependentPropertiesError) as excinfo: + misp_lib_stix2.v21.Artifact(url="http://example.com/sirvizio.exe") assert excinfo.value.dependencies == [("hashes", "url")] assert str(excinfo.value) == "The property dependencies for Artifact: (hashes, url) are not met." @@ -350,7 +350,7 @@ def test_artifact_example_dependency_error(): ) def test_parse_autonomous_system_valid(data): odata_str = OBJECTS_REGEX.sub('"objects": { %s }' % data, EXPECTED) - odata = stix2.parse(odata_str, version="2.1") + odata = misp_lib_stix2.parse(odata_str, version="2.1") assert odata.objects["0"].type == "autonomous-system" assert odata.objects["0"].number == 15139 assert odata.objects["0"].name == "Slime Industries" @@ -368,7 +368,7 @@ def test_parse_autonomous_system_valid(data): ], ) def test_parse_email_address(data): - odata = stix2.parse(data, version='2.1') + odata = misp_lib_stix2.parse(data, version='2.1') assert odata.type == "email-addr" odata_str = re.compile( @@ -376,8 +376,8 @@ def test_parse_email_address(data): ).sub( '"belongs_to_ref": "mutex--9be6365f-b89c-48c0-9340-6953f6595718"', data, ) - with pytest.raises(stix2.exceptions.InvalidValueError): - stix2.parse(odata_str, version='2.1') + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError): + misp_lib_stix2.parse(odata_str, version='2.1') @pytest.mark.parametrize( @@ -423,7 +423,7 @@ def test_parse_email_address(data): ], ) def test_parse_email_message(data): - odata = stix2.parse(data, version='2.1') + odata = misp_lib_stix2.parse(data, version='2.1') assert odata.type == "email-message" assert odata.body_multipart[0].content_disposition == "inline" @@ -444,10 +444,10 @@ def test_parse_email_message(data): ], ) def test_parse_email_message_not_multipart(data): - with pytest.raises(stix2.exceptions.DependentPropertiesError) as excinfo: - stix2.parse(data, version='2.1') + with pytest.raises(misp_lib_stix2.exceptions.DependentPropertiesError) as excinfo: + misp_lib_stix2.parse(data, version='2.1') - assert excinfo.value.cls == stix2.v21.EmailMessage + assert excinfo.value.cls == misp_lib_stix2.v21.EmailMessage assert excinfo.value.dependencies == [("is_multipart", "body")] @@ -495,7 +495,7 @@ def test_parse_email_message_not_multipart(data): ) def test_parse_file_archive(data): odata_str = OBJECTS_REGEX.sub('"objects": { %s }' % data, EXPECTED) - odata = stix2.parse(odata_str, version="2.1") + odata = misp_lib_stix2.parse(odata_str, version="2.1") assert all( x in odata.objects["3"].extensions['archive-ext'].contains_refs for x in [ @@ -548,10 +548,10 @@ def test_parse_file_archive(data): ], ) def test_parse_email_message_with_at_least_one_error(data): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.parse(data, version='2.1') + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.parse(data, version='2.1') - assert excinfo.value.cls == stix2.v21.EmailMessage + assert excinfo.value.cls == misp_lib_stix2.v21.EmailMessage assert "At least one of the" in str(excinfo.value) assert "must be populated" in str(excinfo.value) @@ -571,7 +571,7 @@ def test_parse_email_message_with_at_least_one_error(data): ], ) def test_parse_basic_tcp_traffic(data): - odata = stix2.parse( + odata = misp_lib_stix2.parse( data, version='2.1', ) @@ -602,10 +602,10 @@ def test_parse_basic_tcp_traffic(data): ], ) def test_parse_basic_tcp_traffic_with_error(data): - with pytest.raises(stix2.exceptions.AtLeastOnePropertyError) as excinfo: - stix2.parse(data, version='2.1') + with pytest.raises(misp_lib_stix2.exceptions.AtLeastOnePropertyError) as excinfo: + misp_lib_stix2.parse(data, version='2.1') - assert excinfo.value.cls == stix2.v21.NetworkTraffic + assert excinfo.value.cls == misp_lib_stix2.v21.NetworkTraffic assert excinfo.value.properties == ["dst_ref", "src_ref"] @@ -638,7 +638,7 @@ def test_parse_basic_tcp_traffic_with_error(data): def test_observed_data_with_process_example(): - observed_data = stix2.v21.ObservedData( + observed_data = misp_lib_stix2.v21.ObservedData( id=OBSERVED_DATA_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T19:58:16.000Z", @@ -675,7 +675,7 @@ def test_observed_data_with_process_example(): # creating cyber observables directly def test_artifact_example(): - art = stix2.v21.Artifact( + art = misp_lib_stix2.v21.Artifact( mime_type="image/jpeg", url="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg", hashes={ @@ -688,8 +688,8 @@ def test_artifact_example(): def test_artifact_mutual_exclusion_error(): - with pytest.raises(stix2.exceptions.MutuallyExclusivePropertiesError) as excinfo: - stix2.v21.Artifact( + with pytest.raises(misp_lib_stix2.exceptions.MutuallyExclusivePropertiesError) as excinfo: + misp_lib_stix2.v21.Artifact( mime_type="image/jpeg", url="https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg", hashes={ @@ -698,17 +698,17 @@ def test_artifact_mutual_exclusion_error(): payload_bin="VBORw0KGgoAAAANSUhEUgAAADI==", ) - assert excinfo.value.cls == stix2.v21.Artifact + assert excinfo.value.cls == misp_lib_stix2.v21.Artifact assert excinfo.value.properties == ["payload_bin", "url"] assert 'are mutually exclusive' in str(excinfo.value) def test_directory_example(): - f = stix2.v21.File( + f = misp_lib_stix2.v21.File( name="penguin.exe", ) - dir1 = stix2.v21.Directory( + dir1 = misp_lib_stix2.v21.Directory( path='/usr/lib', ctime="2015-12-21T19:00:00Z", mtime="2015-12-24T19:00:00Z", @@ -724,8 +724,8 @@ def test_directory_example(): def test_directory_example_ref_error(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Directory( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Directory( path='/usr/lib', ctime="2015-12-21T19:00:00Z", mtime="2015-12-24T19:00:00Z", @@ -733,16 +733,16 @@ def test_directory_example_ref_error(): contains_refs=["domain-name--02af94ea-7e38-5718-87c3-5cc023e3d49d"], ) - assert excinfo.value.cls == stix2.v21.Directory + assert excinfo.value.cls == misp_lib_stix2.v21.Directory assert excinfo.value.prop_name == "contains_refs" def test_domain_name_example(): - dn1 = stix2.v21.DomainName( + dn1 = misp_lib_stix2.v21.DomainName( value="mitre.org", ) - dn2 = stix2.v21.DomainName( + dn2 = misp_lib_stix2.v21.DomainName( value="example.com", resolves_to_refs=[str(dn1.id)], ) @@ -752,18 +752,18 @@ def test_domain_name_example(): def test_domain_name_example_invalid_ref_type(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.DomainName( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.DomainName( value="example.com", resolves_to_refs=["file--44a431e6-764b-5556-a3f5-bf655930a581"], ) - assert excinfo.value.cls == stix2.v21.DomainName + assert excinfo.value.cls == misp_lib_stix2.v21.DomainName assert excinfo.value.prop_name == "resolves_to_refs" def test_file_example(): - f = stix2.v21.File( + f = misp_lib_stix2.v21.File( name="qwerty.dll", hashes={ "SHA-256": "ceafbfd424be2ca4a5f0402cae090dda2fb0526cf521b60b60077c0f622b285a", @@ -787,7 +787,7 @@ def test_file_example(): def test_file_ssdeep_example(): - f = stix2.v21.File( + f = misp_lib_stix2.v21.File( name="example.dll", hashes={ "SHA-256": "ceafbfd424be2ca4a5f0402cae090dda2fb0526cf521b60b60077c0f622b285a", @@ -803,7 +803,7 @@ def test_file_ssdeep_example(): def test_file_example_with_NTFSExt(): - f = stix2.v21.File( + f = misp_lib_stix2.v21.File( name="abc.txt", extensions={ "ntfs-ext": { @@ -822,19 +822,19 @@ def test_file_example_with_NTFSExt(): def test_file_example_with_empty_NTFSExt(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.File( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.File( name="abc.txt", extensions={ "ntfs-ext": {}, }, ) - assert excinfo.value.cls == stix2.v21.File + assert excinfo.value.cls == misp_lib_stix2.v21.File def test_file_example_with_PDFExt(): - f = stix2.v21.File( + f = misp_lib_stix2.v21.File( name="qwerty.dll", extensions={ "pdf-ext": { @@ -858,10 +858,10 @@ def test_file_example_with_PDFExt(): def test_file_example_with_PDFExt_Object(): - f = stix2.v21.File( + f = misp_lib_stix2.v21.File( name="qwerty.dll", extensions={ - "pdf-ext": stix2.v21.PDFExt( + "pdf-ext": misp_lib_stix2.v21.PDFExt( version="1.7", document_info_dict={ "Title": "Sample document", @@ -882,7 +882,7 @@ def test_file_example_with_PDFExt_Object(): def test_file_example_with_RasterImageExt_Object(): - f = stix2.v21.File( + f = misp_lib_stix2.v21.File( name="qwerty.jpeg", extensions={ "raster-image-ext": { @@ -902,15 +902,15 @@ def test_file_example_with_RasterImageExt_Object(): def test_file_with_archive_ext_object(): - ad = stix2.v21.Directory(path="archived/path") - f_obj = stix2.v21.File( + ad = misp_lib_stix2.v21.Directory(path="archived/path") + f_obj = misp_lib_stix2.v21.File( name="foo", extensions={ "archive-ext": { "contains_refs": [ad], }, }, ) - f_ref = stix2.v21.File( + f_ref = misp_lib_stix2.v21.File( name="foo", extensions={ "archive-ext": { "contains_refs": [ad.id], @@ -959,17 +959,17 @@ def test_file_with_archive_ext_object(): def test_raster_image_ext_parse(): - obj = stix2.parse(RASTER_IMAGE_EXT, version="2.1") + obj = misp_lib_stix2.parse(RASTER_IMAGE_EXT, version="2.1") assert obj.objects["0"].extensions['raster-image-ext'].image_width == 1024 def test_raster_images_ext_create(): - ext = stix2.v21.RasterImageExt(image_width=1024) + ext = misp_lib_stix2.v21.RasterImageExt(image_width=1024) assert "image_width" in str(ext) def test_file_example_with_WindowsPEBinaryExt(): - f = stix2.v21.File( + f = misp_lib_stix2.v21.File( name="qwerty.dll", extensions={ "windows-pebinary-ext": { @@ -1039,15 +1039,15 @@ def test_file_example_with_WindowsPEBinaryExt(): def test_file_example_encryption_error(): - with pytest.raises(stix2.exceptions.AtLeastOnePropertyError) as excinfo: - stix2.v21.File(magic_number_hex="010b") + with pytest.raises(misp_lib_stix2.exceptions.AtLeastOnePropertyError) as excinfo: + misp_lib_stix2.v21.File(magic_number_hex="010b") - assert excinfo.value.cls == stix2.v21.File + assert excinfo.value.cls == misp_lib_stix2.v21.File assert "At least one of the (hashes, name)" in str(excinfo.value) def test_ipv4_address_example(): - ip4 = stix2.v21.IPv4Address( + ip4 = misp_lib_stix2.v21.IPv4Address( value="198.51.100.3", resolves_to_refs=["mac-addr--a85820f7-d9b7-567a-a3a6-dedc34139342", "mac-addr--9a59b496-fdeb-510f-97b5-7137210bc699"], ) @@ -1057,14 +1057,14 @@ def test_ipv4_address_example(): def test_ipv4_address_valid_refs(): - mac1 = stix2.v21.MACAddress( + mac1 = misp_lib_stix2.v21.MACAddress( value="a1:b2:c3:d4:e5:f6", ) - mac2 = stix2.v21.MACAddress( + mac2 = misp_lib_stix2.v21.MACAddress( value="a7:b8:c9:d0:e1:f2", ) - ip4 = stix2.v21.IPv4Address( + ip4 = misp_lib_stix2.v21.IPv4Address( value="177.60.40.7", resolves_to_refs=[str(mac1.id), str(mac2.id)], ) @@ -1074,25 +1074,25 @@ def test_ipv4_address_valid_refs(): def test_ipv4_address_example_cidr(): - ip4 = stix2.v21.IPv4Address(value="198.51.100.0/24") + ip4 = misp_lib_stix2.v21.IPv4Address(value="198.51.100.0/24") assert ip4.value == "198.51.100.0/24" def test_ipv6_address_example(): - ip6 = stix2.v21.IPv6Address(value="2001:0db8:85a3:0000:0000:8a2e:0370:7334") + ip6 = misp_lib_stix2.v21.IPv6Address(value="2001:0db8:85a3:0000:0000:8a2e:0370:7334") assert ip6.value == "2001:0db8:85a3:0000:0000:8a2e:0370:7334" def test_mac_address_example(): - ip6 = stix2.v21.MACAddress(value="d2:fb:49:24:37:18") + ip6 = misp_lib_stix2.v21.MACAddress(value="d2:fb:49:24:37:18") assert ip6.value == "d2:fb:49:24:37:18" def test_network_traffic_example(): - nt = stix2.v21.NetworkTraffic( + nt = misp_lib_stix2.v21.NetworkTraffic( protocols=["tcp"], src_ref="ipv4-addr--29a591d9-533a-5ecd-a5a1-cadee4411e88", dst_ref="ipv4-addr--6d39dd0b-1f74-5faf-8d76-d8762c2a57cb", @@ -1103,7 +1103,7 @@ def test_network_traffic_example(): def test_network_traffic_http_request_example(): - h = stix2.v21.HTTPRequestExt( + h = misp_lib_stix2.v21.HTTPRequestExt( request_method="get", request_value="/download.html", request_version="http/1.1", @@ -1113,7 +1113,7 @@ def test_network_traffic_http_request_example(): "Host": "www.example.com", }, ) - nt = stix2.v21.NetworkTraffic( + nt = misp_lib_stix2.v21.NetworkTraffic( protocols=["tcp"], src_ref="ipv4-addr--29a591d9-533a-5ecd-a5a1-cadee4411e88", extensions={'http-request-ext': h}, @@ -1127,8 +1127,8 @@ def test_network_traffic_http_request_example(): def test_network_traffic_icmp_example(): - h = stix2.v21.ICMPExt(icmp_type_hex="08", icmp_code_hex="00") - nt = stix2.v21.NetworkTraffic( + h = misp_lib_stix2.v21.ICMPExt(icmp_type_hex="08", icmp_code_hex="00") + nt = misp_lib_stix2.v21.NetworkTraffic( protocols=["tcp"], src_ref="ipv4-addr--29a591d9-533a-5ecd-a5a1-cadee4411e88", extensions={'icmp-ext': h}, @@ -1138,12 +1138,12 @@ def test_network_traffic_icmp_example(): def test_network_traffic_socket_example(): - h = stix2.v21.SocketExt( + h = misp_lib_stix2.v21.SocketExt( is_listening=True, address_family="AF_INET", socket_type="SOCK_STREAM", ) - nt = stix2.v21.NetworkTraffic( + nt = misp_lib_stix2.v21.NetworkTraffic( protocols=["tcp"], src_ref="ipv4-addr--29a591d9-533a-5ecd-a5a1-cadee4411e88", extensions={'socket-ext': h}, @@ -1154,7 +1154,7 @@ def test_network_traffic_socket_example(): def test_correct_socket_options(): - se1 = stix2.v21.SocketExt( + se1 = misp_lib_stix2.v21.SocketExt( is_listening=True, address_family="AF_INET", socket_type="SOCK_STREAM", @@ -1168,7 +1168,7 @@ def test_correct_socket_options(): def test_incorrect_socket_options(): with pytest.raises(ValueError) as excinfo: - stix2.v21.SocketExt( + misp_lib_stix2.v21.SocketExt( is_listening=True, address_family="AF_INET", socket_type="SOCK_STREAM", @@ -1177,7 +1177,7 @@ def test_incorrect_socket_options(): assert "Incorrect options key" == str(excinfo.value) with pytest.raises(ValueError) as excinfo: - stix2.v21.SocketExt( + misp_lib_stix2.v21.SocketExt( is_listening=True, address_family="AF_INET", socket_type="SOCK_STREAM", @@ -1187,8 +1187,8 @@ def test_incorrect_socket_options(): def test_network_traffic_tcp_example(): - h = stix2.v21.TCPExt(src_flags_hex="00000002") - nt = stix2.v21.NetworkTraffic( + h = misp_lib_stix2.v21.TCPExt(src_flags_hex="00000002") + nt = misp_lib_stix2.v21.NetworkTraffic( protocols=["tcp"], src_ref="ipv4-addr--29a591d9-533a-5ecd-a5a1-cadee4411e88", extensions={'tcp-ext': h}, @@ -1197,13 +1197,13 @@ def test_network_traffic_tcp_example(): def test_mutex_example(): - m = stix2.v21.Mutex(name="barney") + m = misp_lib_stix2.v21.Mutex(name="barney") assert m.name == "barney" def test_process_example(): - p = stix2.v21.Process( + p = misp_lib_stix2.v21.Process( pid=1221, created_time="2016-01-20T14:11:25.55Z", command_line="./gedit-bin --new-window", @@ -1214,34 +1214,34 @@ def test_process_example(): def test_process_example_empty_error(): - with pytest.raises(stix2.exceptions.AtLeastOnePropertyError) as excinfo: - stix2.v21.Process() + with pytest.raises(misp_lib_stix2.exceptions.AtLeastOnePropertyError) as excinfo: + misp_lib_stix2.v21.Process() - assert excinfo.value.cls == stix2.v21.Process - properties_of_process = stix2.v21.Process._properties.keys() + assert excinfo.value.cls == misp_lib_stix2.v21.Process + properties_of_process = misp_lib_stix2.v21.Process._properties.keys() properties_of_process -= {"type", "id", "defanged", "spec_version", "extensions"} assert excinfo.value.properties == sorted(properties_of_process) msg = "At least one of the ({1}) properties for {0} must be populated." msg = msg.format( - stix2.v21.Process.__name__, + misp_lib_stix2.v21.Process.__name__, ", ".join(sorted(properties_of_process)), ) assert str(excinfo.value) == msg def test_process_example_empty_with_extensions(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Process( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Process( extensions={ "windows-process-ext": {}, }, ) - assert excinfo.value.cls == stix2.v21.Process + assert excinfo.value.cls == misp_lib_stix2.v21.Process def test_process_example_windows_process_ext(): - proc = stix2.v21.Process( + proc = misp_lib_stix2.v21.Process( pid=314, extensions={ "windows-process-ext": { @@ -1259,19 +1259,19 @@ def test_process_example_windows_process_ext(): def test_process_example_windows_process_ext_empty(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Process( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Process( pid=1221, extensions={ "windows-process-ext": {}, }, ) - assert excinfo.value.cls == stix2.v21.Process + assert excinfo.value.cls == misp_lib_stix2.v21.Process def test_process_example_extensions_empty(): - proc = stix2.v21.Process( + proc = misp_lib_stix2.v21.Process( pid=314, extensions={}, ) @@ -1280,9 +1280,9 @@ def test_process_example_extensions_empty(): def test_process_example_with_WindowsProcessExt_Object(): - p = stix2.v21.Process( + p = misp_lib_stix2.v21.Process( extensions={ - "windows-process-ext": stix2.v21.WindowsProcessExt( + "windows-process-ext": misp_lib_stix2.v21.WindowsProcessExt( aslr_enabled=True, dep_enabled=True, priority="HIGH_PRIORITY_CLASS", @@ -1296,7 +1296,7 @@ def test_process_example_with_WindowsProcessExt_Object(): def test_process_example_with_WindowsServiceExt(): - p = stix2.v21.Process( + p = misp_lib_stix2.v21.Process( extensions={ "windows-service-ext": { "service_name": "sirvizio", @@ -1313,7 +1313,7 @@ def test_process_example_with_WindowsServiceExt(): def test_process_example_with_WindowsProcessServiceExt(): - p = stix2.v21.Process( + p = misp_lib_stix2.v21.Process( extensions={ "windows-service-ext": { "service_name": "sirvizio", @@ -1338,7 +1338,7 @@ def test_process_example_with_WindowsProcessServiceExt(): def test_software_example(): - s = stix2.v21.Software( + s = misp_lib_stix2.v21.Software( name="Word", cpe="cpe:2.3:a:microsoft:word:2000:*:*:*:*:*:*:*", swid="com.acme.rms-ce-v4-1-5-0", @@ -1353,14 +1353,14 @@ def test_software_example(): def test_url_example(): - s = stix2.v21.URL(value="https://example.com/research/index.html") + s = misp_lib_stix2.v21.URL(value="https://example.com/research/index.html") assert s.type == "url" assert s.value == "https://example.com/research/index.html" def test_user_account_example(): - a = stix2.v21.UserAccount( + a = misp_lib_stix2.v21.UserAccount( user_id="1001", account_login="jdoe", account_type="unix", @@ -1388,13 +1388,13 @@ def test_user_account_example(): def test_user_account_unix_account_ext_example(): - u = stix2.v21.UNIXAccountExt( + u = misp_lib_stix2.v21.UNIXAccountExt( gid=1001, groups=["wheel"], home_dir="/home/jdoe", shell="/bin/bash", ) - a = stix2.v21.UserAccount( + a = misp_lib_stix2.v21.UserAccount( user_id="1001", account_login="jdoe", account_type="unix", @@ -1407,19 +1407,19 @@ def test_user_account_unix_account_ext_example(): def test_windows_registry_key_example(): - with pytest.raises(stix2.exceptions.InvalidValueError): - stix2.v21.WindowsRegistryValueType( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError): + misp_lib_stix2.v21.WindowsRegistryValueType( name="Foo", data="qwerty", data_type="string", ) - v = stix2.v21.WindowsRegistryValueType( + v = misp_lib_stix2.v21.WindowsRegistryValueType( name="Foo", data="qwerty", data_type="REG_SZ", ) - w = stix2.v21.WindowsRegistryKey( + w = misp_lib_stix2.v21.WindowsRegistryKey( key="hkey_local_machine\\system\\bar\\foo", values=[v], ) @@ -1432,7 +1432,7 @@ def test_windows_registry_key_example(): def test_x509_certificate_example(): - x509 = stix2.v21.X509Certificate( + x509 = misp_lib_stix2.v21.X509Certificate( issuer="C=ZA, ST=Western Cape, L=Cape Town, O=Thawte Consulting cc, OU=Certification Services Division, CN=Thawte Server CA/emailAddress=server-certs@thawte.com", # noqa validity_not_before="2016-03-12T12:00:00Z", validity_not_after="2016-08-21T12:00:00Z", @@ -1446,18 +1446,18 @@ def test_x509_certificate_example(): def test_x509_certificate_error(): - with pytest.raises(stix2.exceptions.PropertyPresenceError) as excinfo: - stix2.v21.X509Certificate( + with pytest.raises(misp_lib_stix2.exceptions.PropertyPresenceError) as excinfo: + misp_lib_stix2.v21.X509Certificate( defanged=True, ) - assert excinfo.value.cls == stix2.v21.X509Certificate + assert excinfo.value.cls == misp_lib_stix2.v21.X509Certificate assert "At least one of the" in str(excinfo.value) assert "properties for X509Certificate must be populated." in str(excinfo.value) def test_new_version_with_related_objects(): - data = stix2.v21.ObservedData( + data = misp_lib_stix2.v21.ObservedData( first_observed="2016-03-12T12:00:00Z", last_observed="2016-03-12T12:00:00Z", number_observed=1, @@ -1481,9 +1481,9 @@ def test_new_version_with_related_objects(): def test_objects_deprecation(): - with pytest.warns(stix2.exceptions.STIXDeprecationWarning): + with pytest.warns(misp_lib_stix2.exceptions.STIXDeprecationWarning): - stix2.v21.ObservedData( + misp_lib_stix2.v21.ObservedData( first_observed="2016-03-12T12:00:00Z", last_observed="2016-03-12T12:00:00Z", number_observed=1, diff --git a/stix2/test/v21/test_opinion.py b/misp_lib_stix2/test/v21/test_opinion.py similarity index 96% rename from stix2/test/v21/test_opinion.py rename to misp_lib_stix2/test/v21/test_opinion.py index 31cd0af7..7016c357 100644 --- a/stix2/test/v21/test_opinion.py +++ b/misp_lib_stix2/test/v21/test_opinion.py @@ -4,7 +4,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import OPINION_ID @@ -47,7 +47,7 @@ def test_opinion_with_required_properties(): now = dt.datetime(2016, 5, 12, 8, 17, 27, tzinfo=pytz.utc) - opi = stix2.v21.Opinion( + opi = misp_lib_stix2.v21.Opinion( type='opinion', id=OPINION_ID, created=now, @@ -80,7 +80,7 @@ def test_opinion_with_required_properties(): ], ) def test_parse_opinion(data): - opinion = stix2.parse(data, version="2.1") + opinion = misp_lib_stix2.parse(data, version="2.1") assert opinion.type == 'opinion' assert opinion.spec_version == '2.1' diff --git a/stix2/test/v21/test_parsing.py b/misp_lib_stix2/test/v21/test_parsing.py similarity index 97% rename from stix2/test/v21/test_parsing.py rename to misp_lib_stix2/test/v21/test_parsing.py index f23eb7d0..da9db6cf 100644 --- a/stix2/test/v21/test_parsing.py +++ b/misp_lib_stix2/test/v21/test_parsing.py @@ -2,7 +2,7 @@ import pytest -from stix2 import DEFAULT_VERSION, exceptions, parsing, registration, registry +from misp_lib_stix2 import DEFAULT_VERSION, exceptions, parsing, registration, registry BUNDLE = { "type": "bundle", diff --git a/stix2/test/v21/test_pattern_equivalence.py b/misp_lib_stix2/test/v21/test_pattern_equivalence.py similarity index 95% rename from stix2/test/v21/test_pattern_equivalence.py rename to misp_lib_stix2/test/v21/test_pattern_equivalence.py index 5f6b707c..fde88a74 100644 --- a/stix2/test/v21/test_pattern_equivalence.py +++ b/misp_lib_stix2/test/v21/test_pattern_equivalence.py @@ -4,7 +4,7 @@ import pytest -from stix2.equivalence.pattern import equivalent_patterns +from misp_lib_stix2.equivalence.pattern import equivalent_patterns @pytest.mark.parametrize( diff --git a/stix2/test/v21/test_pattern_expressions.py b/misp_lib_stix2/test/v21/test_pattern_expressions.py similarity index 65% rename from stix2/test/v21/test_pattern_expressions.py rename to misp_lib_stix2/test/v21/test_pattern_expressions.py index d171879e..7936d274 100644 --- a/stix2/test/v21/test_pattern_expressions.py +++ b/misp_lib_stix2/test/v21/test_pattern_expressions.py @@ -4,10 +4,10 @@ import pytz from stix2patterns.exceptions import ParseException -import stix2 -from stix2.pattern_visitor import create_pattern_object -import stix2.patterns -import stix2.utils +import misp_lib_stix2 +from misp_lib_stix2.pattern_visitor import create_pattern_object +import misp_lib_stix2.patterns +import misp_lib_stix2.utils # flake8 does not approve of star imports. # flake8: noqa: F405 @@ -15,139 +15,139 @@ def test_create_comparison_expression(): - exp = stix2.EqualityComparisonExpression( + exp = misp_lib_stix2.EqualityComparisonExpression( "file:hashes.'SHA-256'", - stix2.HashConstant("aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f", "SHA-256"), + misp_lib_stix2.HashConstant("aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f", "SHA-256"), ) # noqa assert str(exp) == "file:hashes.'SHA-256' = 'aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f'" def test_boolean_expression(): - exp1 = stix2.MatchesComparisonExpression( + exp1 = misp_lib_stix2.MatchesComparisonExpression( "email-message:from_ref.value", - stix2.StringConstant(".+\\@example\\.com$"), + misp_lib_stix2.StringConstant(".+\\@example\\.com$"), ) - exp2 = stix2.MatchesComparisonExpression( + exp2 = misp_lib_stix2.MatchesComparisonExpression( "email-message:body_multipart[*].body_raw_ref.name", - stix2.StringConstant("^Final Report.+\\.exe$"), + misp_lib_stix2.StringConstant("^Final Report.+\\.exe$"), ) - exp = stix2.AndBooleanExpression([exp1, exp2]) + exp = misp_lib_stix2.AndBooleanExpression([exp1, exp2]) assert str(exp) == "email-message:from_ref.value MATCHES '.+\\\\@example\\\\.com$' AND email-message:body_multipart[*].body_raw_ref.name MATCHES '^Final Report.+\\\\.exe$'" # noqa def test_boolean_expression_with_parentheses(): - exp1 = stix2.MatchesComparisonExpression( - stix2.ObjectPath( + exp1 = misp_lib_stix2.MatchesComparisonExpression( + misp_lib_stix2.ObjectPath( "email-message", [ - stix2.ReferenceObjectPathComponent("from_ref"), - stix2.BasicObjectPathComponent("value", False), + misp_lib_stix2.ReferenceObjectPathComponent("from_ref"), + misp_lib_stix2.BasicObjectPathComponent("value", False), ], ), - stix2.StringConstant(".+\\@example\\.com$"), + misp_lib_stix2.StringConstant(".+\\@example\\.com$"), ) - exp2 = stix2.MatchesComparisonExpression( + exp2 = misp_lib_stix2.MatchesComparisonExpression( "email-message:body_multipart[*].body_raw_ref.name", - stix2.StringConstant("^Final Report.+\\.exe$"), + misp_lib_stix2.StringConstant("^Final Report.+\\.exe$"), ) - exp = stix2.ParentheticalExpression(stix2.AndBooleanExpression([exp1, exp2])) + exp = misp_lib_stix2.ParentheticalExpression(misp_lib_stix2.AndBooleanExpression([exp1, exp2])) assert str(exp) == "(email-message:from_ref.value MATCHES '.+\\\\@example\\\\.com$' AND email-message:body_multipart[*].body_raw_ref.name MATCHES '^Final Report.+\\\\.exe$')" # noqa def test_hash_followed_by_registryKey_expression_python_constant(): - hash_exp = stix2.EqualityComparisonExpression( + hash_exp = misp_lib_stix2.EqualityComparisonExpression( "file:hashes.MD5", - stix2.HashConstant("79054025255fb1a26e4bc422aef54eb4", "MD5"), - ) - o_exp1 = stix2.ObservationExpression(hash_exp) - reg_exp = stix2.EqualityComparisonExpression( - stix2.ObjectPath("windows-registry-key", ["key"]), - stix2.StringConstant("HKEY_LOCAL_MACHINE\\foo\\bar"), - ) - o_exp2 = stix2.ObservationExpression(reg_exp) - fb_exp = stix2.FollowedByObservationExpression([o_exp1, o_exp2]) - para_exp = stix2.ParentheticalExpression(fb_exp) - qual_exp = stix2.WithinQualifier(300) - exp = stix2.QualifiedObservationExpression(para_exp, qual_exp) + misp_lib_stix2.HashConstant("79054025255fb1a26e4bc422aef54eb4", "MD5"), + ) + o_exp1 = misp_lib_stix2.ObservationExpression(hash_exp) + reg_exp = misp_lib_stix2.EqualityComparisonExpression( + misp_lib_stix2.ObjectPath("windows-registry-key", ["key"]), + misp_lib_stix2.StringConstant("HKEY_LOCAL_MACHINE\\foo\\bar"), + ) + o_exp2 = misp_lib_stix2.ObservationExpression(reg_exp) + fb_exp = misp_lib_stix2.FollowedByObservationExpression([o_exp1, o_exp2]) + para_exp = misp_lib_stix2.ParentheticalExpression(fb_exp) + qual_exp = misp_lib_stix2.WithinQualifier(300) + exp = misp_lib_stix2.QualifiedObservationExpression(para_exp, qual_exp) assert str(exp) == "([file:hashes.MD5 = '79054025255fb1a26e4bc422aef54eb4'] FOLLOWEDBY [windows-registry-key:key = 'HKEY_LOCAL_MACHINE\\\\foo\\\\bar']) WITHIN 300 SECONDS" # noqa def test_hash_followed_by_registryKey_expression(): - hash_exp = stix2.EqualityComparisonExpression( + hash_exp = misp_lib_stix2.EqualityComparisonExpression( "file:hashes.MD5", - stix2.HashConstant("79054025255fb1a26e4bc422aef54eb4", "MD5"), - ) - o_exp1 = stix2.ObservationExpression(hash_exp) - reg_exp = stix2.EqualityComparisonExpression( - stix2.ObjectPath("windows-registry-key", ["key"]), - stix2.StringConstant("HKEY_LOCAL_MACHINE\\foo\\bar"), - ) - o_exp2 = stix2.ObservationExpression(reg_exp) - fb_exp = stix2.FollowedByObservationExpression([o_exp1, o_exp2]) - para_exp = stix2.ParentheticalExpression(fb_exp) - qual_exp = stix2.WithinQualifier(stix2.IntegerConstant(300)) - exp = stix2.QualifiedObservationExpression(para_exp, qual_exp) + misp_lib_stix2.HashConstant("79054025255fb1a26e4bc422aef54eb4", "MD5"), + ) + o_exp1 = misp_lib_stix2.ObservationExpression(hash_exp) + reg_exp = misp_lib_stix2.EqualityComparisonExpression( + misp_lib_stix2.ObjectPath("windows-registry-key", ["key"]), + misp_lib_stix2.StringConstant("HKEY_LOCAL_MACHINE\\foo\\bar"), + ) + o_exp2 = misp_lib_stix2.ObservationExpression(reg_exp) + fb_exp = misp_lib_stix2.FollowedByObservationExpression([o_exp1, o_exp2]) + para_exp = misp_lib_stix2.ParentheticalExpression(fb_exp) + qual_exp = misp_lib_stix2.WithinQualifier(misp_lib_stix2.IntegerConstant(300)) + exp = misp_lib_stix2.QualifiedObservationExpression(para_exp, qual_exp) assert str(exp) == "([file:hashes.MD5 = '79054025255fb1a26e4bc422aef54eb4'] FOLLOWEDBY [windows-registry-key:key = 'HKEY_LOCAL_MACHINE\\\\foo\\\\bar']) WITHIN 300 SECONDS" # noqa def test_file_observable_expression(): - exp1 = stix2.EqualityComparisonExpression( + exp1 = misp_lib_stix2.EqualityComparisonExpression( "file:hashes.'SHA-256'", - stix2.HashConstant( + misp_lib_stix2.HashConstant( "aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f", 'SHA-256', ), ) - exp2 = stix2.EqualityComparisonExpression("file:mime_type", stix2.StringConstant("application/x-pdf")) - bool_exp = stix2.ObservationExpression(stix2.AndBooleanExpression([exp1, exp2])) + exp2 = misp_lib_stix2.EqualityComparisonExpression("file:mime_type", misp_lib_stix2.StringConstant("application/x-pdf")) + bool_exp = misp_lib_stix2.ObservationExpression(misp_lib_stix2.AndBooleanExpression([exp1, exp2])) assert str(bool_exp) == "[file:hashes.'SHA-256' = 'aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f' AND file:mime_type = 'application/x-pdf']" # noqa @pytest.mark.parametrize( "observation_class, op", [ - (stix2.AndObservationExpression, 'AND'), - (stix2.OrObservationExpression, 'OR'), + (misp_lib_stix2.AndObservationExpression, 'AND'), + (misp_lib_stix2.OrObservationExpression, 'OR'), ], ) def test_multiple_file_observable_expression(observation_class, op): - exp1 = stix2.EqualityComparisonExpression( + exp1 = misp_lib_stix2.EqualityComparisonExpression( "file:hashes.'SHA-256'", - stix2.HashConstant( + misp_lib_stix2.HashConstant( "bf07a7fbb825fc0aae7bf4a1177b2b31fcf8a3feeaf7092761e18c859ee52a9c", 'SHA-256', ), ) - exp2 = stix2.EqualityComparisonExpression( + exp2 = misp_lib_stix2.EqualityComparisonExpression( "file:hashes.MD5", - stix2.HashConstant("cead3f77f6cda6ec00f57d76c9a6879f", "MD5"), + misp_lib_stix2.HashConstant("cead3f77f6cda6ec00f57d76c9a6879f", "MD5"), ) - bool1_exp = stix2.OrBooleanExpression([exp1, exp2]) - exp3 = stix2.EqualityComparisonExpression( + bool1_exp = misp_lib_stix2.OrBooleanExpression([exp1, exp2]) + exp3 = misp_lib_stix2.EqualityComparisonExpression( "file:hashes.'SHA-256'", - stix2.HashConstant( + misp_lib_stix2.HashConstant( "aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f", 'SHA-256', ), ) - op1_exp = stix2.ObservationExpression(bool1_exp) - op2_exp = stix2.ObservationExpression(exp3) + op1_exp = misp_lib_stix2.ObservationExpression(bool1_exp) + op2_exp = misp_lib_stix2.ObservationExpression(exp3) exp = observation_class([op1_exp, op2_exp]) assert str(exp) == "[file:hashes.'SHA-256' = 'bf07a7fbb825fc0aae7bf4a1177b2b31fcf8a3feeaf7092761e18c859ee52a9c' OR file:hashes.MD5 = 'cead3f77f6cda6ec00f57d76c9a6879f'] {} [file:hashes.'SHA-256' = 'aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f']".format(op) # noqa def test_root_types(): - ast = stix2.ObservationExpression( - stix2.AndBooleanExpression( + ast = misp_lib_stix2.ObservationExpression( + misp_lib_stix2.AndBooleanExpression( [ - stix2.ParentheticalExpression( - stix2.OrBooleanExpression([ - stix2.EqualityComparisonExpression("a:b", stix2.StringConstant("1")), - stix2.EqualityComparisonExpression("b:c", stix2.StringConstant("2")), + misp_lib_stix2.ParentheticalExpression( + misp_lib_stix2.OrBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression("a:b", misp_lib_stix2.StringConstant("1")), + misp_lib_stix2.EqualityComparisonExpression("b:c", misp_lib_stix2.StringConstant("2")), ]), ), - stix2.EqualityComparisonExpression(u"b:d", stix2.StringConstant("3")), + misp_lib_stix2.EqualityComparisonExpression(u"b:d", misp_lib_stix2.StringConstant("3")), ], ), ) @@ -155,30 +155,30 @@ def test_root_types(): def test_artifact_payload(): - exp1 = stix2.EqualityComparisonExpression( + exp1 = misp_lib_stix2.EqualityComparisonExpression( "artifact:mime_type", "application/vnd.tcpdump.pcap", ) - exp2 = stix2.MatchesComparisonExpression( + exp2 = misp_lib_stix2.MatchesComparisonExpression( "artifact:payload_bin", - stix2.StringConstant("\\xd4\\xc3\\xb2\\xa1\\x02\\x00\\x04\\x00"), + misp_lib_stix2.StringConstant("\\xd4\\xc3\\xb2\\xa1\\x02\\x00\\x04\\x00"), ) - and_exp = stix2.ObservationExpression(stix2.AndBooleanExpression([exp1, exp2])) + and_exp = misp_lib_stix2.ObservationExpression(misp_lib_stix2.AndBooleanExpression([exp1, exp2])) assert str(and_exp) == "[artifact:mime_type = 'application/vnd.tcpdump.pcap' AND artifact:payload_bin MATCHES '\\\\xd4\\\\xc3\\\\xb2\\\\xa1\\\\x02\\\\x00\\\\x04\\\\x00']" # noqa def test_greater_than_python_constant(): - exp1 = stix2.GreaterThanComparisonExpression("file:extensions.'windows-pebinary-ext'.sections[*].entropy", 7.0) - exp = stix2.ObservationExpression(exp1) + exp1 = misp_lib_stix2.GreaterThanComparisonExpression("file:extensions.'windows-pebinary-ext'.sections[*].entropy", 7.0) + exp = misp_lib_stix2.ObservationExpression(exp1) assert str(exp) == "[file:extensions.'windows-pebinary-ext'.sections[*].entropy > 7.0]" def test_greater_than(): - exp1 = stix2.GreaterThanComparisonExpression( + exp1 = misp_lib_stix2.GreaterThanComparisonExpression( "file:extensions.'windows-pebinary-ext'.sections[*].entropy", - stix2.FloatConstant(7.0), + misp_lib_stix2.FloatConstant(7.0), ) - exp = stix2.ObservationExpression(exp1) + exp = misp_lib_stix2.ObservationExpression(exp1) assert str(exp) == "[file:extensions.'windows-pebinary-ext'.sections[*].entropy > 7.0]" @@ -188,7 +188,7 @@ def test_parsing_greater_than(): def test_less_than(): - exp = stix2.LessThanComparisonExpression("file:size", 1024) + exp = misp_lib_stix2.LessThanComparisonExpression("file:size", 1024) assert str(exp) == "file:size < 1024" @@ -198,7 +198,7 @@ def test_parsing_less_than(): def test_greater_than_or_equal(): - exp = stix2.GreaterThanEqualComparisonExpression( + exp = misp_lib_stix2.GreaterThanEqualComparisonExpression( "file:size", 1024, ) @@ -211,7 +211,7 @@ def test_parsing_greater_than_or_equal(): def test_less_than_or_equal(): - exp = stix2.LessThanEqualComparisonExpression( + exp = misp_lib_stix2.LessThanEqualComparisonExpression( "file:size", 1024, ) @@ -249,7 +249,7 @@ def test_parsing_followed_by(): def test_not(): - exp = stix2.LessThanComparisonExpression( + exp = misp_lib_stix2.LessThanComparisonExpression( "file:size", 1024, negated=True, @@ -258,52 +258,52 @@ def test_not(): def test_and_observable_expression(): - exp1 = stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + exp1 = misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_type", "unix", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:user_id", - stix2.StringConstant("1007"), + misp_lib_stix2.StringConstant("1007"), ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_login", "Peter", ), ]) - exp2 = stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + exp2 = misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_type", "unix", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:user_id", - stix2.StringConstant("1008"), + misp_lib_stix2.StringConstant("1008"), ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_login", "Paul", ), ]) - exp3 = stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + exp3 = misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_type", "unix", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:user_id", - stix2.StringConstant("1009"), + misp_lib_stix2.StringConstant("1009"), ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_login", "Mary", ), ]) - exp = stix2.AndObservationExpression([ - stix2.ObservationExpression(exp1), - stix2.ObservationExpression(exp2), - stix2.ObservationExpression(exp3), + exp = misp_lib_stix2.AndObservationExpression([ + misp_lib_stix2.ObservationExpression(exp1), + misp_lib_stix2.ObservationExpression(exp2), + misp_lib_stix2.ObservationExpression(exp3), ]) assert str(exp) == "[user-account:account_type = 'unix' AND user-account:user_id = '1007' AND user-account:account_login = 'Peter'] AND [user-account:account_type = 'unix' AND user-account:user_id = '1008' AND user-account:account_login = 'Paul'] AND [user-account:account_type = 'unix' AND user-account:user_id = '1009' AND user-account:account_login = 'Mary']" # noqa @@ -314,52 +314,52 @@ def test_parsing_and_observable_expression(): def test_or_observable_expression(): - exp1 = stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + exp1 = misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_type", "unix", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:user_id", - stix2.StringConstant("1007"), + misp_lib_stix2.StringConstant("1007"), ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_login", "Peter", ), ]) - exp2 = stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + exp2 = misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_type", "unix", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:user_id", - stix2.StringConstant("1008"), + misp_lib_stix2.StringConstant("1008"), ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_login", "Paul", ), ]) - exp3 = stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + exp3 = misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_type", "unix", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:user_id", - stix2.StringConstant("1009"), + misp_lib_stix2.StringConstant("1009"), ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "user-account:account_login", "Mary", ), ]) - exp = stix2.OrObservationExpression([ - stix2.ObservationExpression(exp1), - stix2.ObservationExpression(exp2), - stix2.ObservationExpression(exp3), + exp = misp_lib_stix2.OrObservationExpression([ + misp_lib_stix2.ObservationExpression(exp1), + misp_lib_stix2.ObservationExpression(exp2), + misp_lib_stix2.ObservationExpression(exp3), ]) assert str(exp) == "[user-account:account_type = 'unix' AND user-account:user_id = '1007' AND user-account:account_login = 'Peter'] OR [user-account:account_type = 'unix' AND user-account:user_id = '1008' AND user-account:account_login = 'Paul'] OR [user-account:account_type = 'unix' AND user-account:user_id = '1009' AND user-account:account_login = 'Mary']" # noqa @@ -371,14 +371,14 @@ def test_parsing_or_observable_expression(): def test_invalid_and_comparison_expression(): with pytest.raises(ValueError): - stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "user-account:display_name", "admin", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "email-addr:display_name", - stix2.StringConstant("admin"), + misp_lib_stix2.StringConstant("admin"), ), ]) @@ -411,17 +411,17 @@ def test_comparison_expression_root_types_error(pattern): def test_hex(): - exp_and = stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + exp_and = misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "file:mime_type", "image/bmp", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "file:magic_number_hex", - stix2.HexConstant("ffd8"), + misp_lib_stix2.HexConstant("ffd8"), ), ]) - exp = stix2.ObservationExpression(exp_and) + exp = misp_lib_stix2.ObservationExpression(exp_and) assert str(exp) == "[file:mime_type = 'image/bmp' AND file:magic_number_hex = h'ffd8']" @@ -431,26 +431,26 @@ def test_parsing_hex(): def test_multiple_qualifiers(): - exp_and = stix2.AndBooleanExpression([ - stix2.EqualityComparisonExpression( + exp_and = misp_lib_stix2.AndBooleanExpression([ + misp_lib_stix2.EqualityComparisonExpression( "network-traffic:dst_ref.type", "domain-name", ), - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "network-traffic:dst_ref.value", "example.com", ), ]) - exp_ob = stix2.ObservationExpression(exp_and) - qual_rep = stix2.RepeatQualifier(5) - qual_within = stix2.WithinQualifier(stix2.IntegerConstant(1800)) - exp = stix2.QualifiedObservationExpression(stix2.QualifiedObservationExpression(exp_ob, qual_rep), qual_within) + exp_ob = misp_lib_stix2.ObservationExpression(exp_and) + qual_rep = misp_lib_stix2.RepeatQualifier(5) + qual_within = misp_lib_stix2.WithinQualifier(misp_lib_stix2.IntegerConstant(1800)) + exp = misp_lib_stix2.QualifiedObservationExpression(misp_lib_stix2.QualifiedObservationExpression(exp_ob, qual_rep), qual_within) assert str(exp) == "[network-traffic:dst_ref.type = 'domain-name' AND network-traffic:dst_ref.value = 'example.com'] REPEATS 5 TIMES WITHIN 1800 SECONDS" # noqa def test_set_op(): - exp = stix2.ObservationExpression( - stix2.IsSubsetComparisonExpression( + exp = misp_lib_stix2.ObservationExpression( + misp_lib_stix2.IsSubsetComparisonExpression( "network-traffic:dst_ref.value", "2001:0db8:dead:beef:0000:0000:0000:0000/64", ), @@ -459,12 +459,12 @@ def test_set_op(): def test_timestamp(): - ts = stix2.TimestampConstant('2014-01-13T07:03:17Z') + ts = misp_lib_stix2.TimestampConstant('2014-01-13T07:03:17Z') assert str(ts) == "t'2014-01-13T07:03:17Z'" def test_boolean(): - exp = stix2.EqualityComparisonExpression( + exp = misp_lib_stix2.EqualityComparisonExpression( "email-message:is_multipart", True, ) @@ -472,8 +472,8 @@ def test_boolean(): def test_binary(): - const = stix2.BinaryConstant("dGhpcyBpcyBhIHRlc3Q=") - exp = stix2.EqualityComparisonExpression( + const = misp_lib_stix2.BinaryConstant("dGhpcyBpcyBhIHRlc3Q=") + exp = misp_lib_stix2.EqualityComparisonExpression( "artifact:payload_bin", const, ) @@ -486,7 +486,7 @@ def test_parsing_binary(): def test_list(): - exp = stix2.InComparisonExpression( + exp = misp_lib_stix2.InComparisonExpression( "process:name", ['proccy', 'proximus', 'badproc'], ) @@ -495,7 +495,7 @@ def test_list(): def test_list2(): # alternate way to construct an "IN" Comparison Expression - exp = stix2.EqualityComparisonExpression( + exp = misp_lib_stix2.EqualityComparisonExpression( "process:name", ['proccy', 'proximus', 'badproc'], ) @@ -504,7 +504,7 @@ def test_list2(): def test_invalid_constant_type(): with pytest.raises(ValueError): - stix2.EqualityComparisonExpression( + misp_lib_stix2.EqualityComparisonExpression( "artifact:payload_bin", {'foo': 'bar'}, ) @@ -512,17 +512,17 @@ def test_invalid_constant_type(): def test_invalid_integer_constant(): with pytest.raises(ValueError): - stix2.IntegerConstant('foo') + misp_lib_stix2.IntegerConstant('foo') def test_invalid_timestamp_constant(): with pytest.raises(ValueError): - stix2.TimestampConstant('foo') + misp_lib_stix2.TimestampConstant('foo') def test_invalid_float_constant(): with pytest.raises(ValueError): - stix2.FloatConstant('foo') + misp_lib_stix2.FloatConstant('foo') @pytest.mark.parametrize( @@ -542,13 +542,13 @@ def test_invalid_float_constant(): ], ) def test_boolean_constant(data, result): - boolean = stix2.BooleanConstant(data) + boolean = misp_lib_stix2.BooleanConstant(data) assert boolean.value == result def test_invalid_boolean_constant(): with pytest.raises(ValueError): - stix2.BooleanConstant('foo') + misp_lib_stix2.BooleanConstant('foo') @pytest.mark.parametrize( @@ -559,21 +559,21 @@ def test_invalid_boolean_constant(): ) def test_invalid_hash_constant(hashtype, data): with pytest.raises(ValueError): - stix2.HashConstant(data, hashtype) + misp_lib_stix2.HashConstant(data, hashtype) def test_invalid_hex_constant(): with pytest.raises(ValueError): - stix2.HexConstant('mm') + misp_lib_stix2.HexConstant('mm') def test_invalid_binary_constant(): with pytest.raises(ValueError): - stix2.BinaryConstant('foo') + misp_lib_stix2.BinaryConstant('foo') def test_escape_quotes_and_backslashes(): - exp = stix2.MatchesComparisonExpression( + exp = misp_lib_stix2.MatchesComparisonExpression( "file:name", "^Final Report.+\\.exe$", ) @@ -581,7 +581,7 @@ def test_escape_quotes_and_backslashes(): def test_like(): - exp = stix2.LikeComparisonExpression( + exp = misp_lib_stix2.LikeComparisonExpression( "directory:path", "C:\\Windows\\%\\foo", ) @@ -589,7 +589,7 @@ def test_like(): def test_issuperset(): - exp = stix2.IsSupersetComparisonExpression( + exp = misp_lib_stix2.IsSupersetComparisonExpression( "ipv4-addr:value", "198.51.100.0/24", ) @@ -597,43 +597,43 @@ def test_issuperset(): def test_repeat_qualifier(): - qual = stix2.RepeatQualifier(stix2.IntegerConstant(5)) + qual = misp_lib_stix2.RepeatQualifier(misp_lib_stix2.IntegerConstant(5)) assert str(qual) == 'REPEATS 5 TIMES' def test_invalid_repeat_qualifier(): with pytest.raises(ValueError): - stix2.RepeatQualifier('foo') + misp_lib_stix2.RepeatQualifier('foo') def test_invalid_within_qualifier(): with pytest.raises(ValueError): - stix2.WithinQualifier('foo') + misp_lib_stix2.WithinQualifier('foo') def test_startstop_qualifier(): - qual = stix2.StartStopQualifier( - stix2.TimestampConstant('2016-06-01T00:00:00Z'), + qual = misp_lib_stix2.StartStopQualifier( + misp_lib_stix2.TimestampConstant('2016-06-01T00:00:00Z'), datetime.datetime(2017, 3, 12, 8, 30, 0), ) assert str(qual) == "START t'2016-06-01T00:00:00Z' STOP t'2017-03-12T08:30:00Z'" - qual2 = stix2.StartStopQualifier( + qual2 = misp_lib_stix2.StartStopQualifier( datetime.date(2016, 6, 1), - stix2.TimestampConstant('2016-07-01T00:00:00Z'), + misp_lib_stix2.TimestampConstant('2016-07-01T00:00:00Z'), ) assert str(qual2) == "START t'2016-06-01T00:00:00Z' STOP t'2016-07-01T00:00:00Z'" def test_invalid_startstop_qualifier(): with pytest.raises(ValueError): - stix2.StartStopQualifier( + misp_lib_stix2.StartStopQualifier( 'foo', - stix2.TimestampConstant('2016-06-01T00:00:00Z'), + misp_lib_stix2.TimestampConstant('2016-06-01T00:00:00Z'), ) with pytest.raises(ValueError): - stix2.StartStopQualifier( + misp_lib_stix2.StartStopQualifier( datetime.date(2016, 6, 1), 'foo', ) @@ -641,34 +641,34 @@ def test_invalid_startstop_qualifier(): @pytest.mark.parametrize( "input_, expected_class, expected_value", [ - (1, stix2.patterns.IntegerConstant, 1), - (1.5, stix2.patterns.FloatConstant, 1.5), - ("abc", stix2.patterns.StringConstant, "abc"), - (True, stix2.patterns.BooleanConstant, True), + (1, misp_lib_stix2.patterns.IntegerConstant, 1), + (1.5, misp_lib_stix2.patterns.FloatConstant, 1.5), + ("abc", misp_lib_stix2.patterns.StringConstant, "abc"), + (True, misp_lib_stix2.patterns.BooleanConstant, True), ( - "2001-02-10T21:36:15Z", stix2.patterns.TimestampConstant, - stix2.utils.STIXdatetime(2001, 2, 10, 21, 36, 15, tzinfo=pytz.utc), + "2001-02-10T21:36:15Z", misp_lib_stix2.patterns.TimestampConstant, + misp_lib_stix2.utils.STIXdatetime(2001, 2, 10, 21, 36, 15, tzinfo=pytz.utc), ), ( datetime.datetime(2001, 2, 10, 21, 36, 15, tzinfo=pytz.utc), - stix2.patterns.TimestampConstant, - stix2.utils.STIXdatetime(2001, 2, 10, 21, 36, 15, tzinfo=pytz.utc), + misp_lib_stix2.patterns.TimestampConstant, + misp_lib_stix2.utils.STIXdatetime(2001, 2, 10, 21, 36, 15, tzinfo=pytz.utc), ), ], ) def test_make_constant_simple(input_, expected_class, expected_value): - const = stix2.patterns.make_constant(input_) + const = misp_lib_stix2.patterns.make_constant(input_) assert isinstance(const, expected_class) assert const.value == expected_value def test_make_constant_list(): - list_const = stix2.patterns.make_constant([1, 2, 3]) + list_const = misp_lib_stix2.patterns.make_constant([1, 2, 3]) - assert isinstance(list_const, stix2.patterns.ListConstant) + assert isinstance(list_const, misp_lib_stix2.patterns.ListConstant) assert all( - isinstance(elt, stix2.patterns.IntegerConstant) + isinstance(elt, misp_lib_stix2.patterns.IntegerConstant) for elt in list_const.value ) assert all( @@ -678,8 +678,8 @@ def test_make_constant_list(): def test_make_constant_already_a_constant(): - str_const = stix2.StringConstant('Foo') - result = stix2.patterns.make_constant(str_const) + str_const = misp_lib_stix2.StringConstant('Foo') + result = misp_lib_stix2.patterns.make_constant(str_const) assert result is str_const @@ -760,7 +760,7 @@ def test_ast_class_override_comp_equals(): version="2.1", ) - assert isinstance(patt_ast, stix2.patterns.ObservationExpression) + assert isinstance(patt_ast, misp_lib_stix2.patterns.ObservationExpression) assert isinstance(patt_ast.operand, EqualityComparisonExpressionForTesting) assert str(patt_ast) == "[a:b = 1]" @@ -772,9 +772,9 @@ def test_ast_class_override_string_constant(): version="2.1", ) - assert isinstance(patt_ast, stix2.patterns.ObservationExpression) + assert isinstance(patt_ast, misp_lib_stix2.patterns.ObservationExpression) assert isinstance( - patt_ast.operand, stix2.patterns.LessThanComparisonExpression, + patt_ast.operand, misp_lib_stix2.patterns.LessThanComparisonExpression, ) assert isinstance( patt_ast.operand.lhs.property_path[0].property_name, @@ -795,9 +795,9 @@ def test_ast_class_override_startstop_qualifier(): "Testing", "stix2.test.v21.pattern_ast_overrides", version="2.1", ) - assert isinstance(patt_ast, stix2.patterns.QualifiedObservationExpression) + assert isinstance(patt_ast, misp_lib_stix2.patterns.QualifiedObservationExpression) assert isinstance( - patt_ast.observation_expression, stix2.patterns.ObservationExpression, + patt_ast.observation_expression, misp_lib_stix2.patterns.ObservationExpression, ) assert isinstance( patt_ast.observation_expression.operand, diff --git a/stix2/test/v20/test_pickle.py b/misp_lib_stix2/test/v21/test_pickle.py similarity index 82% rename from stix2/test/v20/test_pickle.py rename to misp_lib_stix2/test/v21/test_pickle.py index 36e43379..3f2470d3 100644 --- a/stix2/test/v20/test_pickle.py +++ b/misp_lib_stix2/test/v21/test_pickle.py @@ -1,6 +1,6 @@ import pickle -import stix2 +import misp_lib_stix2 from .constants import IDENTITY_ID @@ -9,7 +9,7 @@ def test_pickling(): """ Ensure a pickle/unpickle cycle works okay. """ - identity = stix2.v20.Identity( + identity = misp_lib_stix2.v21.Identity( id=IDENTITY_ID, name="alice", description="this is a pickle test", diff --git a/stix2/test/v21/test_properties.py b/misp_lib_stix2/test/v21/test_properties.py similarity index 92% rename from stix2/test/v21/test_properties.py rename to misp_lib_stix2/test/v21/test_properties.py index 4fb84ec0..6ddd46f3 100644 --- a/stix2/test/v21/test_properties.py +++ b/misp_lib_stix2/test/v21/test_properties.py @@ -1,16 +1,16 @@ import pytest -import stix2 -from stix2.exceptions import ( +import misp_lib_stix2 +from misp_lib_stix2.exceptions import ( AtLeastOnePropertyError, CustomContentError, DictionaryKeyError, ExtraPropertiesError, ParseError, ) -from stix2.properties import ( +from misp_lib_stix2.properties import ( DictionaryProperty, EmbeddedObjectProperty, ExtensionsProperty, HashesProperty, IDProperty, ListProperty, ObservableProperty, ReferenceProperty, STIXObjectProperty, StringProperty, ) -from stix2.v21.common import MarkingProperty +from misp_lib_stix2.v21.common import MarkingProperty from . import constants @@ -376,7 +376,7 @@ def test_dictionary_property_invalid(d): def test_property_list_of_dictionary(): - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( 'x-new-obj-4', [ ('property1', ListProperty(DictionaryProperty(spec_version='2.1'), required=True)), ], @@ -415,8 +415,8 @@ def test_hash_property_invalid_key(key): def test_embedded_property(): - emb_prop = EmbeddedObjectProperty(type=stix2.v21.EmailMIMEComponent) - mime = stix2.v21.EmailMIMEComponent( + emb_prop = EmbeddedObjectProperty(type=misp_lib_stix2.v21.EmailMIMEComponent) + mime = misp_lib_stix2.v21.EmailMIMEComponent( content_type="text/plain; charset=utf-8", content_disposition="inline", body="Cats are funny!", @@ -432,7 +432,7 @@ def test_embedded_property(): def test_embedded_property_dict(): - emb_prop = EmbeddedObjectProperty(type=stix2.v21.EmailMIMEComponent) + emb_prop = EmbeddedObjectProperty(type=misp_lib_stix2.v21.EmailMIMEComponent) mime = { "content_type": "text/plain; charset=utf-8", "content_disposition": "inline", @@ -440,19 +440,19 @@ def test_embedded_property_dict(): } result = emb_prop.clean(mime, False) - assert isinstance(result[0], stix2.v21.EmailMIMEComponent) + assert isinstance(result[0], misp_lib_stix2.v21.EmailMIMEComponent) assert result[0]["body"] == "Cats are funny!" assert not result[1] result = emb_prop.clean(mime, True) - assert isinstance(result[0], stix2.v21.EmailMIMEComponent) + assert isinstance(result[0], misp_lib_stix2.v21.EmailMIMEComponent) assert result[0]["body"] == "Cats are funny!" assert not result[1] def test_embedded_property_custom(): - emb_prop = EmbeddedObjectProperty(type=stix2.v21.EmailMIMEComponent) - mime = stix2.v21.EmailMIMEComponent( + emb_prop = EmbeddedObjectProperty(type=misp_lib_stix2.v21.EmailMIMEComponent) + mime = misp_lib_stix2.v21.EmailMIMEComponent( content_type="text/plain; charset=utf-8", content_disposition="inline", body="Cats are funny!", @@ -468,7 +468,7 @@ def test_embedded_property_custom(): def test_embedded_property_dict_custom(): - emb_prop = EmbeddedObjectProperty(type=stix2.v21.EmailMIMEComponent) + emb_prop = EmbeddedObjectProperty(type=misp_lib_stix2.v21.EmailMIMEComponent) mime = { "content_type": "text/plain; charset=utf-8", "content_disposition": "inline", @@ -480,7 +480,7 @@ def test_embedded_property_dict_custom(): emb_prop.clean(mime, False) result = emb_prop.clean(mime, True) - assert isinstance(result[0], stix2.v21.EmailMIMEComponent) + assert isinstance(result[0], misp_lib_stix2.v21.EmailMIMEComponent) assert result[0]["body"] == "Cats are funny!" assert result[1] @@ -496,7 +496,7 @@ def test_extension_property_valid(): ) assert isinstance( - result[0]["windows-pebinary-ext"], stix2.v21.WindowsPEBinaryExt, + result[0]["windows-pebinary-ext"], misp_lib_stix2.v21.WindowsPEBinaryExt, ) assert not result[1] @@ -509,7 +509,7 @@ def test_extension_property_valid(): ) assert isinstance( - result[0]["windows-pebinary-ext"], stix2.v21.WindowsPEBinaryExt, + result[0]["windows-pebinary-ext"], misp_lib_stix2.v21.WindowsPEBinaryExt, ) assert not result[1] @@ -565,7 +565,7 @@ def test_extension_property_invalid3(): ) assert isinstance( - result[0]["windows-pebinary-ext"], stix2.v21.WindowsPEBinaryExt, + result[0]["windows-pebinary-ext"], misp_lib_stix2.v21.WindowsPEBinaryExt, ) assert result[0]["windows-pebinary-ext"]["abc"] == 123 assert result[1] @@ -573,7 +573,7 @@ def test_extension_property_invalid3(): def test_extension_at_least_one_property_constraint(): with pytest.raises(AtLeastOnePropertyError): - stix2.v21.TCPExt() + misp_lib_stix2.v21.TCPExt() def test_marking_property_error(): @@ -588,7 +588,7 @@ def test_marking_property_error(): def test_observable_property_obj(): prop = ObservableProperty(spec_version="2.1") - obs = stix2.v21.File(name="data.dat") + obs = misp_lib_stix2.v21.File(name="data.dat") obs_dict = { "0": obs, } @@ -613,12 +613,12 @@ def test_observable_property_dict(): } result = prop.clean(obs_dict, False) - assert isinstance(result[0]["0"], stix2.v21.File) + assert isinstance(result[0]["0"], misp_lib_stix2.v21.File) assert result[0]["0"]["name"] == "data.dat" assert not result[1] result = prop.clean(obs_dict, True) - assert isinstance(result[0]["0"], stix2.v21.File) + assert isinstance(result[0]["0"], misp_lib_stix2.v21.File) assert result[0]["0"]["name"] == "data.dat" assert not result[1] @@ -626,7 +626,7 @@ def test_observable_property_dict(): def test_observable_property_obj_custom(): prop = ObservableProperty(spec_version="2.1") - obs = stix2.v21.File(name="data.dat", foo=True, allow_custom=True) + obs = misp_lib_stix2.v21.File(name="data.dat", foo=True, allow_custom=True) obs_dict = { "0": obs, } @@ -654,7 +654,7 @@ def test_observable_property_dict_custom(): prop.clean(obs_dict, False) result = prop.clean(obs_dict, True) - assert isinstance(result[0]["0"], stix2.v21.File) + assert isinstance(result[0]["0"], misp_lib_stix2.v21.File) assert result[0]["0"]["foo"] assert result[1] @@ -674,7 +674,7 @@ def test_stix_object_property_custom_prop(): prop.clean(obj_dict, False) result = prop.clean(obj_dict, True) - assert isinstance(result[0], stix2.v21.Identity) + assert isinstance(result[0], misp_lib_stix2.v21.Identity) assert result[0].has_custom assert result[0]["foo"] == "bar" assert result[1] diff --git a/stix2/test/v21/test_relationship.py b/misp_lib_stix2/test/v21/test_relationship.py similarity index 79% rename from stix2/test/v21/test_relationship.py rename to misp_lib_stix2/test/v21/test_relationship.py index 9f76d927..a40012dc 100644 --- a/stix2/test/v21/test_relationship.py +++ b/misp_lib_stix2/test/v21/test_relationship.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import ( FAKE_TIME, INDICATOR_ID, MALWARE_ID, RELATIONSHIP_ID, RELATIONSHIP_KWARGS, @@ -24,7 +24,7 @@ def test_relationship_all_required_properties(): now = dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc) - rel = stix2.v21.Relationship( + rel = misp_lib_stix2.v21.Relationship( type='relationship', id=RELATIONSHIP_ID, created=now, @@ -57,69 +57,69 @@ def test_relationship_autogenerated_properties(relationship): def test_relationship_type_must_be_relationship(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Relationship(type='xxx', **RELATIONSHIP_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Relationship(type='xxx', **RELATIONSHIP_KWARGS) - assert excinfo.value.cls == stix2.v21.Relationship + assert excinfo.value.cls == misp_lib_stix2.v21.Relationship assert excinfo.value.prop_name == "type" assert excinfo.value.reason == "must equal 'relationship'." assert str(excinfo.value) == "Invalid value for Relationship 'type': must equal 'relationship'." def test_relationship_id_must_start_with_relationship(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Relationship(id='my-prefix--', **RELATIONSHIP_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Relationship(id='my-prefix--', **RELATIONSHIP_KWARGS) - assert excinfo.value.cls == stix2.v21.Relationship + assert excinfo.value.cls == misp_lib_stix2.v21.Relationship assert excinfo.value.prop_name == "id" assert excinfo.value.reason == "must start with 'relationship--'." assert str(excinfo.value) == "Invalid value for Relationship 'id': must start with 'relationship--'." def test_relationship_required_property_relationship_type(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v21.Relationship() - assert excinfo.value.cls == stix2.v21.Relationship + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v21.Relationship() + assert excinfo.value.cls == misp_lib_stix2.v21.Relationship assert excinfo.value.properties == ["relationship_type", "source_ref", "target_ref"] def test_relationship_missing_some_required_properties(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v21.Relationship(relationship_type='indicates') + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v21.Relationship(relationship_type='indicates') - assert excinfo.value.cls == stix2.v21.Relationship + assert excinfo.value.cls == misp_lib_stix2.v21.Relationship assert excinfo.value.properties == ["source_ref", "target_ref"] def test_relationship_required_properties_target_ref(): - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: - stix2.v21.Relationship( + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: + misp_lib_stix2.v21.Relationship( relationship_type='indicates', source_ref=INDICATOR_ID, ) - assert excinfo.value.cls == stix2.v21.Relationship + assert excinfo.value.cls == misp_lib_stix2.v21.Relationship assert excinfo.value.properties == ["target_ref"] def test_cannot_assign_to_relationship_attributes(relationship): - with pytest.raises(stix2.exceptions.ImmutableError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.ImmutableError) as excinfo: relationship.relationship_type = "derived-from" assert str(excinfo.value) == "Cannot modify 'relationship_type' property in 'Relationship' after creation." def test_invalid_kwarg_to_relationship(): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v21.Relationship(my_custom_property="foo", **RELATIONSHIP_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v21.Relationship(my_custom_property="foo", **RELATIONSHIP_KWARGS) - assert excinfo.value.cls == stix2.v21.Relationship + assert excinfo.value.cls == misp_lib_stix2.v21.Relationship assert excinfo.value.properties == ['my_custom_property'] assert str(excinfo.value) == "Unexpected properties for Relationship: (my_custom_property)." def test_create_relationship_from_objects_rather_than_ids1(indicator, malware): - rel = stix2.v21.Relationship( + rel = misp_lib_stix2.v21.Relationship( relationship_type="indicates", source_ref=indicator, target_ref=malware, @@ -134,7 +134,7 @@ def test_create_relationship_from_objects_rather_than_ids1(indicator, malware): def test_create_relationship_from_objects_rather_than_ids2(indicator, malware): - rel = stix2.v21.Relationship( + rel = misp_lib_stix2.v21.Relationship( relationship_type="indicates", source_ref=indicator, target_ref=malware, @@ -149,7 +149,7 @@ def test_create_relationship_from_objects_rather_than_ids2(indicator, malware): def test_create_relationship_with_positional_args(indicator, malware): - rel = stix2.v21.Relationship(indicator, 'indicates', malware) + rel = misp_lib_stix2.v21.Relationship(indicator, 'indicates', malware) assert rel.relationship_type == 'indicates' assert rel.source_ref == 'indicator--00000000-0000-4000-8000-000000000001' @@ -173,7 +173,7 @@ def test_create_relationship_with_positional_args(indicator, malware): ], ) def test_parse_relationship(data): - rel = stix2.parse(data, version="2.1") + rel = misp_lib_stix2.parse(data, version="2.1") assert rel.type == 'relationship' assert rel.spec_version == '2.1' @@ -203,6 +203,6 @@ def test_parse_relationship(data): ) def test_parse_relationship_with_wrong_start_and_stop_time(data): with pytest.raises(ValueError) as excinfo: - stix2.parse(data) + misp_lib_stix2.parse(data) assert str(excinfo.value) == "{id} 'stop_time' must be later than 'start_time'".format(**data) diff --git a/stix2/test/v21/test_report.py b/misp_lib_stix2/test/v21/test_report.py similarity index 88% rename from stix2/test/v21/test_report.py rename to misp_lib_stix2/test/v21/test_report.py index d2854b62..57a1194d 100644 --- a/stix2/test/v21/test_report.py +++ b/misp_lib_stix2/test/v21/test_report.py @@ -3,8 +3,8 @@ import pytest import pytz -import stix2 -from stix2.exceptions import InvalidValueError +import misp_lib_stix2 +from misp_lib_stix2.exceptions import InvalidValueError from .constants import ( CAMPAIGN_ID, IDENTITY_ID, INDICATOR_ID, INDICATOR_KWARGS, RELATIONSHIP_ID, @@ -33,7 +33,7 @@ def test_report_example(): - report = stix2.v21.Report( + report = misp_lib_stix2.v21.Report( id=REPORT_ID, created_by_ref=IDENTITY_ID, created="2015-12-21T19:59:11.000Z", @@ -53,7 +53,7 @@ def test_report_example(): def test_report_example_objects_in_object_refs(): - report = stix2.v21.Report( + report = misp_lib_stix2.v21.Report( id=REPORT_ID, created_by_ref=IDENTITY_ID, created="2015-12-21T19:59:11.000Z", @@ -63,7 +63,7 @@ def test_report_example_objects_in_object_refs(): published="2016-01-20T17:00:00Z", report_types=["campaign"], object_refs=[ - stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS), + misp_lib_stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS), CAMPAIGN_ID, RELATIONSHIP_ID, ], @@ -73,8 +73,8 @@ def test_report_example_objects_in_object_refs(): def test_report_example_objects_in_object_refs_with_bad_id(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Report( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Report( id=REPORT_ID, created_by_ref=IDENTITY_ID, created="2015-12-21T19:59:11.000Z", @@ -84,13 +84,13 @@ def test_report_example_objects_in_object_refs_with_bad_id(): published="2016-01-20T17:00:00Z", report_types=["campaign"], object_refs=[ - stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS), + misp_lib_stix2.v21.Indicator(id=INDICATOR_ID, **INDICATOR_KWARGS), "campaign-83422c77-904c-4dc1-aff5-5c38f3a2c55c", # the "bad" id, missing a "-" RELATIONSHIP_ID, ], ) - assert excinfo.value.cls == stix2.v21.Report + assert excinfo.value.cls == misp_lib_stix2.v21.Report assert excinfo.value.prop_name == "object_refs" @@ -119,7 +119,7 @@ def test_report_example_objects_in_object_refs_with_bad_id(): ], ) def test_parse_report(data): - rept = stix2.parse(data, version="2.1") + rept = misp_lib_stix2.parse(data, version="2.1") assert rept.type == 'report' assert rept.spec_version == '2.1' @@ -139,7 +139,7 @@ def test_parse_report(data): def test_report_on_custom(): with pytest.raises(InvalidValueError): - stix2.v21.Report( + misp_lib_stix2.v21.Report( name="my report", published="2016-01-20T17:00:00Z", object_refs=[ @@ -148,7 +148,7 @@ def test_report_on_custom(): ], ) - report = stix2.v21.Report( + report = misp_lib_stix2.v21.Report( name="my report", published="2016-01-20T17:00:00Z", object_refs=[ diff --git a/stix2/test/v21/test_sighting.py b/misp_lib_stix2/test/v21/test_sighting.py similarity index 80% rename from stix2/test/v21/test_sighting.py rename to misp_lib_stix2/test/v21/test_sighting.py index e997d62a..56aff721 100644 --- a/stix2/test/v21/test_sighting.py +++ b/misp_lib_stix2/test/v21/test_sighting.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import ( IDENTITY_ID, INDICATOR_ID, LOCATION_ID, SIGHTING_ID, SIGHTING_KWARGS, @@ -38,7 +38,7 @@ def test_sighting_all_required_properties(): now = dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc) - sighting = stix2.v21.Sighting( + sighting = misp_lib_stix2.v21.Sighting( type='sighting', id=SIGHTING_ID, created=now, @@ -52,8 +52,8 @@ def test_sighting_all_required_properties(): def test_sighting_bad_where_sighted_refs(): now = dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc) - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Sighting( + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Sighting( type='sighting', id=SIGHTING_ID, created=now, @@ -62,31 +62,31 @@ def test_sighting_bad_where_sighted_refs(): where_sighted_refs=["malware--8cc7afd6-5455-4d2b-a736-e614ee631d99"], ) - assert excinfo.value.cls == stix2.v21.Sighting + assert excinfo.value.cls == misp_lib_stix2.v21.Sighting assert excinfo.value.prop_name == "where_sighted_refs" def test_sighting_type_must_be_sightings(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.v21.Sighting(type='xxx', **SIGHTING_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.v21.Sighting(type='xxx', **SIGHTING_KWARGS) - assert excinfo.value.cls == stix2.v21.Sighting + assert excinfo.value.cls == misp_lib_stix2.v21.Sighting assert excinfo.value.prop_name == "type" assert excinfo.value.reason == "must equal 'sighting'." assert str(excinfo.value) == "Invalid value for Sighting 'type': must equal 'sighting'." def test_invalid_kwarg_to_sighting(): - with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo: - stix2.v21.Sighting(my_custom_property="foo", **SIGHTING_KWARGS) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError) as excinfo: + misp_lib_stix2.v21.Sighting(my_custom_property="foo", **SIGHTING_KWARGS) - assert excinfo.value.cls == stix2.v21.Sighting + assert excinfo.value.cls == misp_lib_stix2.v21.Sighting assert excinfo.value.properties == ['my_custom_property'] assert str(excinfo.value) == "Unexpected properties for Sighting: (my_custom_property)." def test_create_sighting_from_objects_rather_than_ids(malware): # noqa: F811 - rel = stix2.v21.Sighting(sighting_of_ref=malware) + rel = misp_lib_stix2.v21.Sighting(sighting_of_ref=malware) assert rel.sighting_of_ref == 'malware--00000000-0000-4000-8000-000000000001' assert rel.id == 'sighting--00000000-0000-4000-8000-000000000003' @@ -110,7 +110,7 @@ def test_create_sighting_from_objects_rather_than_ids(malware): # noqa: F811 ], ) def test_parse_sighting(data): - sighting = stix2.parse(data, version="2.1") + sighting = misp_lib_stix2.parse(data, version="2.1") assert sighting.type == 'sighting' assert sighting.spec_version == '2.1' diff --git a/stix2/test/v21/test_threat_actor.py b/misp_lib_stix2/test/v21/test_threat_actor.py similarity index 91% rename from stix2/test/v21/test_threat_actor.py rename to misp_lib_stix2/test/v21/test_threat_actor.py index b53512f9..aef21105 100644 --- a/stix2/test/v21/test_threat_actor.py +++ b/misp_lib_stix2/test/v21/test_threat_actor.py @@ -3,8 +3,8 @@ import pytest import pytz -import stix2 -import stix2.v21 +import misp_lib_stix2 +import misp_lib_stix2.v21 from .constants import IDENTITY_ID, THREAT_ACTOR_ID @@ -24,7 +24,7 @@ def test_threat_actor_example(): - threat_actor = stix2.v21.ThreatActor( + threat_actor = misp_lib_stix2.v21.ThreatActor( id=THREAT_ACTOR_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T20:03:48.000Z", @@ -56,7 +56,7 @@ def test_threat_actor_example(): ], ) def test_parse_threat_actor(data): - actor = stix2.parse(data, version="2.1") + actor = misp_lib_stix2.parse(data, version="2.1") assert actor.type == 'threat-actor' assert actor.spec_version == '2.1' @@ -74,7 +74,7 @@ def test_seen_ordering_constraint(): Test first_seen/last_seen value co-constraint. """ with pytest.raises(ValueError): - stix2.v21.ThreatActor( + misp_lib_stix2.v21.ThreatActor( name="Bad Person", threat_actor_types=["hacker", "criminal"], first_seen="2010-04-21T09:31:11Z", @@ -82,7 +82,7 @@ def test_seen_ordering_constraint(): ) # equal timestamps is okay. - stix2.v21.ThreatActor( + misp_lib_stix2.v21.ThreatActor( name="Bad Person", threat_actor_types=["hacker", "criminal"], first_seen="2010-04-21T09:31:11Z", diff --git a/stix2/test/v21/test_timestamp_precision.py b/misp_lib_stix2/test/v21/test_timestamp_precision.py similarity index 98% rename from stix2/test/v21/test_timestamp_precision.py rename to misp_lib_stix2/test/v21/test_timestamp_precision.py index 831bd7a0..2c1e0699 100644 --- a/stix2/test/v21/test_timestamp_precision.py +++ b/misp_lib_stix2/test/v21/test_timestamp_precision.py @@ -3,8 +3,8 @@ import pytest -import stix2 -from stix2.utils import ( +import misp_lib_stix2 +from misp_lib_stix2.utils import ( Precision, PrecisionConstraint, STIXdatetime, format_datetime, parse_into_datetime, to_enum, ) @@ -145,7 +145,7 @@ def test_sdo_extra_precision(): "spec_version": "2.1", } - identity_obj = stix2.parse(identity_dict) + identity_obj = misp_lib_stix2.parse(identity_dict) assert identity_obj.modified.microsecond == 100 assert identity_obj.modified.precision is Precision.MILLISECOND assert identity_obj.modified.precision_constraint is PrecisionConstraint.MIN diff --git a/stix2/test/v21/test_tool.py b/misp_lib_stix2/test/v21/test_tool.py similarity index 91% rename from stix2/test/v21/test_tool.py rename to misp_lib_stix2/test/v21/test_tool.py index 427f8de9..7fbedea2 100644 --- a/stix2/test/v21/test_tool.py +++ b/misp_lib_stix2/test/v21/test_tool.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import IDENTITY_ID, TOOL_ID @@ -36,7 +36,7 @@ def test_tool_example(): - tool = stix2.v21.Tool( + tool = misp_lib_stix2.v21.Tool( id=TOOL_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T20:03:48.000Z", @@ -66,7 +66,7 @@ def test_tool_example(): ], ) def test_parse_tool(data): - tool = stix2.parse(data, version="2.1") + tool = misp_lib_stix2.parse(data, version="2.1") assert tool.type == 'tool' assert tool.spec_version == '2.1' @@ -79,13 +79,13 @@ def test_parse_tool(data): def test_tool_no_workbench_wrappers(): - tool = stix2.v21.Tool(name='VNC', tool_types=['remote-access']) + tool = misp_lib_stix2.v21.Tool(name='VNC', tool_types=['remote-access']) with pytest.raises(AttributeError): tool.created_by() def test_tool_serialize_with_defaults(): - tool = stix2.v21.Tool( + tool = misp_lib_stix2.v21.Tool( id=TOOL_ID, created_by_ref=IDENTITY_ID, created="2016-04-06T20:03:48.000Z", diff --git a/stix2/test/v21/test_utils.py b/misp_lib_stix2/test/v21/test_utils.py similarity index 89% rename from stix2/test/v21/test_utils.py rename to misp_lib_stix2/test/v21/test_utils.py index 33e7ea49..ea09cd64 100644 --- a/stix2/test/v21/test_utils.py +++ b/misp_lib_stix2/test/v21/test_utils.py @@ -6,8 +6,8 @@ import pytest import pytz -import stix2.serialization -import stix2.utils +import misp_lib_stix2.serialization +import misp_lib_stix2.utils from .constants import IDENTITY_ID @@ -23,12 +23,12 @@ (eastern.localize(dt.datetime(2017, 7, 1)), '2017-07-01T04:00:00Z'), (dt.datetime(2017, 7, 1), '2017-07-01T00:00:00Z'), (dt.datetime(2017, 7, 1, 0, 0, 0, 1), '2017-07-01T00:00:00.000001Z'), - (stix2.utils.STIXdatetime(2017, 7, 1, 0, 0, 0, 1, precision='millisecond'), '2017-07-01T00:00:00.000Z'), - (stix2.utils.STIXdatetime(2017, 7, 1, 0, 0, 0, 1, precision='second'), '2017-07-01T00:00:00Z'), + (misp_lib_stix2.utils.STIXdatetime(2017, 7, 1, 0, 0, 0, 1, precision='millisecond'), '2017-07-01T00:00:00.000Z'), + (misp_lib_stix2.utils.STIXdatetime(2017, 7, 1, 0, 0, 0, 1, precision='second'), '2017-07-01T00:00:00Z'), ], ) def test_timestamp_formatting(dttm, timestamp): - assert stix2.utils.format_datetime(dttm) == timestamp + assert misp_lib_stix2.utils.format_datetime(dttm) == timestamp @pytest.mark.parametrize( @@ -39,7 +39,7 @@ def test_timestamp_formatting(dttm, timestamp): ], ) def test_parse_datetime(timestamp, dttm): - assert stix2.utils.parse_into_datetime(timestamp) == dttm + assert misp_lib_stix2.utils.parse_into_datetime(timestamp) == dttm @pytest.mark.parametrize( @@ -52,7 +52,7 @@ def test_parse_datetime(timestamp, dttm): ], ) def test_parse_datetime_precision(timestamp, dttm, precision): - assert stix2.utils.parse_into_datetime(timestamp, precision) == dttm + assert misp_lib_stix2.utils.parse_into_datetime(timestamp, precision) == dttm @pytest.mark.parametrize( @@ -63,7 +63,7 @@ def test_parse_datetime_precision(timestamp, dttm, precision): ) def test_parse_datetime_invalid(ts): with pytest.raises(ValueError): - stix2.utils.parse_into_datetime('foobar') + misp_lib_stix2.utils.parse_into_datetime('foobar') @pytest.mark.parametrize( @@ -75,7 +75,7 @@ def test_parse_datetime_invalid(ts): ], ) def test_get_dict(data): - assert stix2.utils._get_dict(data) + assert misp_lib_stix2.utils._get_dict(data) @pytest.mark.parametrize( @@ -88,7 +88,7 @@ def test_get_dict(data): ) def test_get_dict_invalid(data): with pytest.raises(ValueError): - stix2.utils._get_dict(data) + misp_lib_stix2.utils._get_dict(data) @pytest.mark.parametrize( @@ -98,11 +98,11 @@ def test_get_dict_invalid(data): ], ) def test_get_type_from_id(stix_id, type): - assert stix2.utils.get_type_from_id(stix_id) == type + assert misp_lib_stix2.utils.get_type_from_id(stix_id) == type def test_deduplicate(stix_objs1): - unique = stix2.utils.deduplicate(stix_objs1) + unique = misp_lib_stix2.utils.deduplicate(stix_objs1) # Only 4 objects are unique # 3 id's vary @@ -123,7 +123,7 @@ def test_deduplicate(stix_objs1): @pytest.mark.parametrize( 'object, tuple_to_find, expected_index', [ ( - stix2.v21.ObservedData( + misp_lib_stix2.v21.ObservedData( id="observed-data--b67d30ff-02ac-498a-92f9-32f845f448cf", created_by_ref=IDENTITY_ID, created="2016-04-06T19:58:16.000Z", @@ -203,7 +203,7 @@ def test_deduplicate(stix_objs1): ], ) def test_find_property_index(object, tuple_to_find, expected_index): - assert stix2.serialization.find_property_index( + assert misp_lib_stix2.serialization.find_property_index( object, *tuple_to_find ) == expected_index @@ -240,7 +240,7 @@ def test_find_property_index(object, tuple_to_find, expected_index): ], ) def test_iterate_over_values(dict_value, tuple_to_find, expected_index): - assert stix2.serialization._find_property_in_seq(dict_value.values(), *tuple_to_find) == expected_index + assert misp_lib_stix2.serialization._find_property_in_seq(dict_value.values(), *tuple_to_find) == expected_index @pytest.mark.parametrize( @@ -272,7 +272,7 @@ def test_is_sdo_dict(type_): "type": type_, "spec_version": "2.1", } - assert stix2.utils.is_sdo(d, "2.1") + assert misp_lib_stix2.utils.is_sdo(d, "2.1") @pytest.mark.parametrize( @@ -292,7 +292,7 @@ def test_is_sdo_dict(type_): ], ) def test_is_not_sdo_dict(dict_): - assert not stix2.utils.is_sdo(dict_, "2.1") + assert not misp_lib_stix2.utils.is_sdo(dict_, "2.1") def test_is_sco_dict(): @@ -301,7 +301,7 @@ def test_is_sco_dict(): "spec_version": "2.1", } - assert stix2.utils.is_sco(d, "2.1") + assert misp_lib_stix2.utils.is_sco(d, "2.1") @pytest.mark.parametrize( @@ -321,7 +321,7 @@ def test_is_sco_dict(): ], ) def test_is_not_sco_dict(dict_): - assert not stix2.utils.is_sco(dict_, "2.1") + assert not misp_lib_stix2.utils.is_sco(dict_, "2.1") @pytest.mark.parametrize( @@ -331,7 +331,7 @@ def test_is_not_sco_dict(dict_): ], ) def test_is_sro_dict(dict_): - assert stix2.utils.is_sro(dict_, "2.1") + assert misp_lib_stix2.utils.is_sro(dict_, "2.1") @pytest.mark.parametrize( @@ -352,7 +352,7 @@ def test_is_sro_dict(dict_): ], ) def test_is_not_sro_dict(dict_): - assert not stix2.utils.is_sro(dict_, "2.1") + assert not misp_lib_stix2.utils.is_sro(dict_, "2.1") @pytest.mark.parametrize( @@ -374,7 +374,7 @@ def test_is_not_sro_dict(dict_): ], ) def test_is_object_dict(dict_): - assert stix2.utils.is_object(dict_, "2.1") + assert misp_lib_stix2.utils.is_object(dict_, "2.1") @pytest.mark.parametrize( @@ -390,4 +390,4 @@ def test_is_object_dict(dict_): ], ) def test_is_not_object_dict(dict_): - assert not stix2.utils.is_object(dict_, "2.1") + assert not misp_lib_stix2.utils.is_object(dict_, "2.1") diff --git a/stix2/test/v21/test_versioning.py b/misp_lib_stix2/test/v21/test_versioning.py similarity index 69% rename from stix2/test/v21/test_versioning.py rename to misp_lib_stix2/test/v21/test_versioning.py index c7b6f119..c55dcf07 100644 --- a/stix2/test/v21/test_versioning.py +++ b/misp_lib_stix2/test/v21/test_versioning.py @@ -2,18 +2,18 @@ import pytest -import stix2 -import stix2.exceptions -import stix2.properties -import stix2.utils -import stix2.v21 -import stix2.versioning +import misp_lib_stix2 +import misp_lib_stix2.exceptions +import misp_lib_stix2.properties +import misp_lib_stix2.utils +import misp_lib_stix2.v21 +import misp_lib_stix2.versioning from .constants import CAMPAIGN_MORE_KWARGS def test_making_new_version(): - campaign_v1 = stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) campaign_v2 = campaign_v1.new_version(name="fred") @@ -28,7 +28,7 @@ def test_making_new_version(): def test_making_new_version_with_unset(): - campaign_v1 = stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) campaign_v2 = campaign_v1.new_version(description=None) @@ -43,7 +43,7 @@ def test_making_new_version_with_unset(): def test_making_new_version_with_embedded_object(): - campaign_v1 = stix2.v21.Campaign( + campaign_v1 = misp_lib_stix2.v21.Campaign( external_references=[{ "source_name": "capec", "external_id": "CAPEC-163", @@ -69,7 +69,7 @@ def test_making_new_version_with_embedded_object(): def test_revoke(): - campaign_v1 = stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) campaign_v2 = campaign_v1.revoke() @@ -85,21 +85,21 @@ def test_revoke(): def test_versioning_error_invalid_property(): - campaign_v1 = stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) - with pytest.raises(stix2.exceptions.UnmodifiablePropertyError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.UnmodifiablePropertyError) as excinfo: campaign_v1.new_version(type="threat-actor") assert str(excinfo.value) == "These properties cannot be changed when making a new version: type." def test_versioning_error_bad_modified_value(): - campaign_v1 = stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: campaign_v1.new_version(modified="2015-04-06T20:03:00.000Z") - assert excinfo.value.cls == stix2.v21.Campaign + assert excinfo.value.cls == misp_lib_stix2.v21.Campaign assert excinfo.value.prop_name == "modified" assert excinfo.value.reason == ( "The new modified datetime cannot be before than or equal to the current modified datetime." @@ -109,7 +109,7 @@ def test_versioning_error_bad_modified_value(): msg = "Invalid value for {0} '{1}': {2}" msg = msg.format( - stix2.v21.Campaign.__name__, "modified", + misp_lib_stix2.v21.Campaign.__name__, "modified", "The new modified datetime cannot be before than or equal to the current modified datetime." "It cannot be equal, as according to STIX 2 specification, objects that are different " "but have the same id and modified timestamp do not have defined consumer behavior.", @@ -118,24 +118,24 @@ def test_versioning_error_bad_modified_value(): def test_versioning_error_usetting_required_property(): - campaign_v1 = stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) - with pytest.raises(stix2.exceptions.MissingPropertiesError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.MissingPropertiesError) as excinfo: campaign_v1.new_version(name=None) - assert excinfo.value.cls == stix2.v21.Campaign + assert excinfo.value.cls == misp_lib_stix2.v21.Campaign assert excinfo.value.properties == ["name"] msg = "No values for required properties for {0}: ({1})." - msg = msg.format(stix2.v21.Campaign.__name__, "name") + msg = msg.format(misp_lib_stix2.v21.Campaign.__name__, "name") assert str(excinfo.value) == msg def test_versioning_error_new_version_of_revoked(): - campaign_v1 = stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) campaign_v2 = campaign_v1.revoke() - with pytest.raises(stix2.exceptions.RevokeError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.RevokeError) as excinfo: campaign_v2.new_version(name="barney") assert str(excinfo.value) == "Cannot create a new version of a revoked object." @@ -144,10 +144,10 @@ def test_versioning_error_new_version_of_revoked(): def test_versioning_error_revoke_of_revoked(): - campaign_v1 = stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v1 = misp_lib_stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) campaign_v2 = campaign_v1.revoke() - with pytest.raises(stix2.exceptions.RevokeError) as excinfo: + with pytest.raises(misp_lib_stix2.exceptions.RevokeError) as excinfo: campaign_v2.revoke() assert str(excinfo.value) == "Cannot revoke an already revoked object." @@ -157,7 +157,7 @@ def test_versioning_error_revoke_of_revoked(): def test_making_new_version_dict(): campaign_v1 = CAMPAIGN_MORE_KWARGS - campaign_v2 = stix2.versioning.new_version(CAMPAIGN_MORE_KWARGS, name="fred") + campaign_v2 = misp_lib_stix2.versioning.new_version(CAMPAIGN_MORE_KWARGS, name="fred") assert campaign_v1['id'] == campaign_v2['id'] assert campaign_v1['spec_version'] == campaign_v2['spec_version'] @@ -166,12 +166,12 @@ def test_making_new_version_dict(): assert campaign_v1['name'] != campaign_v2['name'] assert campaign_v2['name'] == "fred" assert campaign_v1['description'] == campaign_v2['description'] - assert stix2.utils.parse_into_datetime(campaign_v1['modified'], precision='millisecond') < campaign_v2['modified'] + assert misp_lib_stix2.utils.parse_into_datetime(campaign_v1['modified'], precision='millisecond') < campaign_v2['modified'] def test_versioning_error_dict_bad_modified_value(): - with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: - stix2.versioning.new_version(CAMPAIGN_MORE_KWARGS, modified="2015-04-06T20:03:00.000Z") + with pytest.raises(misp_lib_stix2.exceptions.InvalidValueError) as excinfo: + misp_lib_stix2.versioning.new_version(CAMPAIGN_MORE_KWARGS, modified="2015-04-06T20:03:00.000Z") assert excinfo.value.cls == dict assert excinfo.value.prop_name == "modified" @@ -188,11 +188,11 @@ def test_versioning_dict_unregistered_no_modified(): "created": "1995-04-07T15:37:48.178Z", } - new_d = stix2.versioning.new_version(d) + new_d = misp_lib_stix2.versioning.new_version(d) assert "modified" in new_d - assert new_d["modified"] > stix2.utils.parse_into_datetime(d["created"]) + assert new_d["modified"] > misp_lib_stix2.utils.parse_into_datetime(d["created"]) - new_d = stix2.versioning.new_version(d, modified="1996-11-20T01:19:29.134Z") + new_d = misp_lib_stix2.versioning.new_version(d, modified="1996-11-20T01:19:29.134Z") assert new_d["modified"] == "1996-11-20T01:19:29.134Z" @@ -204,36 +204,36 @@ def test_versioning_dict_unregistered_unversionable(): "modified": "1995-04-07T15:37:48.178Z", } - with pytest.raises(stix2.exceptions.ObjectNotVersionableError): - stix2.versioning.new_version(d) + with pytest.raises(misp_lib_stix2.exceptions.ObjectNotVersionableError): + misp_lib_stix2.versioning.new_version(d) - with pytest.raises(stix2.exceptions.ObjectNotVersionableError): + with pytest.raises(misp_lib_stix2.exceptions.ObjectNotVersionableError): # should fail even if we provide a "created" kwarg. - stix2.versioning.new_version(d, created="1985-06-29T06:09:51.157Z") + misp_lib_stix2.versioning.new_version(d, created="1985-06-29T06:09:51.157Z") def test_versioning_custom_object(): - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( "x-versionable-all-optional-21", [ - ("created", stix2.properties.TimestampProperty()), - ("modified", stix2.properties.TimestampProperty()), - ("revoked", stix2.properties.BooleanProperty()), + ("created", misp_lib_stix2.properties.TimestampProperty()), + ("modified", misp_lib_stix2.properties.TimestampProperty()), + ("revoked", misp_lib_stix2.properties.BooleanProperty()), ], ) class CustomSDO: pass obj = CustomSDO(created="1990-12-18T17:56:11.346234Z") - new_obj = stix2.versioning.new_version(obj) + new_obj = misp_lib_stix2.versioning.new_version(obj) assert "modified" in new_obj assert new_obj["modified"] > new_obj["created"] obj = CustomSDO() - with pytest.raises(stix2.exceptions.ObjectNotVersionableError): + with pytest.raises(misp_lib_stix2.exceptions.ObjectNotVersionableError): # fails due to insufficient properties on the object, even though its # type supports versioning. - stix2.versioning.new_version(obj) + misp_lib_stix2.versioning.new_version(obj) def test_versioning_error_dict_no_modified_value(): @@ -243,22 +243,22 @@ def test_versioning_error_dict_no_modified_value(): 'created': "2016-04-06T20:03:00.000Z", 'name': "Green Group Attacks Against Finance", } - campaign_v2 = stix2.versioning.new_version(campaign_v1, modified="2017-04-06T20:03:00.000Z") + campaign_v2 = misp_lib_stix2.versioning.new_version(campaign_v1, modified="2017-04-06T20:03:00.000Z") assert str(campaign_v2['modified']) == "2017-04-06T20:03:00.000Z" def test_making_new_version_invalid_cls(): campaign_v1 = "This is a campaign." - with pytest.raises(stix2.exceptions.TypeNotVersionableError) as excinfo: - stix2.versioning.new_version(campaign_v1, name="fred") + with pytest.raises(misp_lib_stix2.exceptions.TypeNotVersionableError) as excinfo: + misp_lib_stix2.versioning.new_version(campaign_v1, name="fred") assert excinfo.value.object is campaign_v1 def test_revoke_dict(): campaign_v1 = CAMPAIGN_MORE_KWARGS - campaign_v2 = stix2.versioning.revoke(campaign_v1) + campaign_v2 = misp_lib_stix2.versioning.revoke(campaign_v1) assert campaign_v1['id'] == campaign_v2['id'] assert campaign_v1['spec_version'] == campaign_v2['spec_version'] @@ -266,23 +266,23 @@ def test_revoke_dict(): assert campaign_v1['created'] == campaign_v2['created'] assert campaign_v1['name'] == campaign_v2['name'] assert campaign_v1['description'] == campaign_v2['description'] - assert stix2.utils.parse_into_datetime(campaign_v1['modified'], precision='millisecond') < campaign_v2['modified'] + assert misp_lib_stix2.utils.parse_into_datetime(campaign_v1['modified'], precision='millisecond') < campaign_v2['modified'] assert campaign_v2['revoked'] def test_revoke_unversionable(): - sco = stix2.v21.File(name="data.txt") - with pytest.raises(stix2.exceptions.TypeNotVersionableError): + sco = misp_lib_stix2.v21.File(name="data.txt") + with pytest.raises(misp_lib_stix2.exceptions.TypeNotVersionableError): sco.revoke() def test_versioning_error_revoke_of_revoked_dict(): campaign_v1 = CAMPAIGN_MORE_KWARGS - campaign_v2 = stix2.versioning.revoke(campaign_v1) + campaign_v2 = misp_lib_stix2.versioning.revoke(campaign_v1) - with pytest.raises(stix2.exceptions.RevokeError) as excinfo: - stix2.versioning.revoke(campaign_v2) + with pytest.raises(misp_lib_stix2.exceptions.RevokeError) as excinfo: + misp_lib_stix2.versioning.revoke(campaign_v2) assert excinfo.value.called_by == "revoke" @@ -290,13 +290,13 @@ def test_versioning_error_revoke_of_revoked_dict(): def test_revoke_invalid_cls(): campaign_v1 = "This is a campaign." with pytest.raises(ValueError) as excinfo: - stix2.versioning.revoke(campaign_v1) + misp_lib_stix2.versioning.revoke(campaign_v1) assert 'cannot revoke object of this type' in str(excinfo.value) def test_remove_custom_stix_property(): - mal = stix2.v21.Malware( + mal = misp_lib_stix2.v21.Malware( name="ColePowers", malware_types=["rootkit"], x_custom="armada", @@ -304,17 +304,17 @@ def test_remove_custom_stix_property(): is_family=False, ) - mal_nc = stix2.versioning.remove_custom_stix(mal) + mal_nc = misp_lib_stix2.versioning.remove_custom_stix(mal) assert "x_custom" not in mal_nc assert mal["modified"] < mal_nc["modified"] def test_remove_custom_stix_object(): - @stix2.v21.CustomObject( + @misp_lib_stix2.v21.CustomObject( "x-animal", [ - ("species", stix2.properties.StringProperty(required=True)), - ("animal_class", stix2.properties.StringProperty()), + ("species", misp_lib_stix2.properties.StringProperty(required=True)), + ("animal_class", misp_lib_stix2.properties.StringProperty()), ], ) class Animal(object): @@ -322,14 +322,14 @@ class Animal(object): animal = Animal(species="lion", animal_class="mammal") - nc = stix2.versioning.remove_custom_stix(animal) + nc = misp_lib_stix2.versioning.remove_custom_stix(animal) assert nc is None def test_remove_custom_stix_no_custom(): - campaign_v1 = stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) - campaign_v2 = stix2.versioning.remove_custom_stix(campaign_v1) + campaign_v1 = misp_lib_stix2.v21.Campaign(**CAMPAIGN_MORE_KWARGS) + campaign_v2 = misp_lib_stix2.versioning.remove_custom_stix(campaign_v1) assert len(campaign_v1.keys()) == len(campaign_v2.keys()) assert campaign_v1.id == campaign_v2.id @@ -362,7 +362,7 @@ def test_fudge_modified(old, candidate_new, expected_new, use_stix21): expected_new, "%Y-%m-%dT%H:%M:%S.%fZ", ) - fudged = stix2.versioning._fudge_modified( + fudged = misp_lib_stix2.versioning._fudge_modified( old_dt, candidate_new_dt, use_stix21, ) assert fudged == expected_new_dt @@ -375,8 +375,8 @@ def test_version_unversionable_dict(): "name": "data.txt", } - with pytest.raises(stix2.exceptions.TypeNotVersionableError): - stix2.versioning.new_version(f) + with pytest.raises(misp_lib_stix2.exceptions.TypeNotVersionableError): + misp_lib_stix2.versioning.new_version(f) def test_version_sco_with_custom(): @@ -385,7 +385,7 @@ def test_version_sco_with_custom(): type which is otherwise unversionable, versioning should start working. """ - file_sco_obj = stix2.v21.File( + file_sco_obj = misp_lib_stix2.v21.File( name="data.txt", created="1973-11-23T02:31:37Z", modified="1991-05-13T19:24:57Z", @@ -393,13 +393,13 @@ def test_version_sco_with_custom(): allow_custom=True, ) - new_file_sco_obj = stix2.versioning.new_version( + new_file_sco_obj = misp_lib_stix2.versioning.new_version( file_sco_obj, size=1234, ) assert new_file_sco_obj.size == 1234 - revoked_obj = stix2.versioning.revoke(new_file_sco_obj) + revoked_obj = misp_lib_stix2.versioning.revoke(new_file_sco_obj) assert revoked_obj.revoked # Same thing with a dict @@ -413,15 +413,15 @@ def test_version_sco_with_custom(): "revoked": False, } - new_d = stix2.versioning.new_version(d, size=1234) + new_d = misp_lib_stix2.versioning.new_version(d, size=1234) assert new_d["size"] == 1234 - revoked_d = stix2.versioning.revoke(new_d) + revoked_d = misp_lib_stix2.versioning.revoke(new_d) assert revoked_d["revoked"] def test_version_sco_id_contributing_properties(): - file_sco_obj = stix2.v21.File( + file_sco_obj = misp_lib_stix2.v21.File( name="data.txt", created="1973-11-23T02:31:37Z", modified="1991-05-13T19:24:57Z", @@ -429,8 +429,8 @@ def test_version_sco_id_contributing_properties(): allow_custom=True, ) - with pytest.raises(stix2.exceptions.UnmodifiablePropertyError) as e: - stix2.versioning.new_version(file_sco_obj, name="foo.dat") + with pytest.raises(misp_lib_stix2.exceptions.UnmodifiablePropertyError) as e: + misp_lib_stix2.versioning.new_version(file_sco_obj, name="foo.dat") assert e.value.unchangable_properties == {"name"} @@ -446,22 +446,22 @@ def test_version_sco_id_contributing_properties_dict(): "revoked": False, } - with pytest.raises(stix2.exceptions.UnmodifiablePropertyError) as e: - stix2.versioning.new_version(file_sco_dict, name="foo.dat") + with pytest.raises(misp_lib_stix2.exceptions.UnmodifiablePropertyError) as e: + misp_lib_stix2.versioning.new_version(file_sco_dict, name="foo.dat") assert e.value.unchangable_properties == {"name"} def test_version_marking(): - m = stix2.v21.MarkingDefinition( + m = misp_lib_stix2.v21.MarkingDefinition( name="a name", created="1982-11-29T12:20:13.723Z", definition_type="statement", definition={"statement": "Copyright (c) 2000-2020 Acme Corp"}, ) - with pytest.raises(stix2.exceptions.TypeNotVersionableError): - stix2.versioning.new_version(m) + with pytest.raises(misp_lib_stix2.exceptions.TypeNotVersionableError): + misp_lib_stix2.versioning.new_version(m) m = { "type": "marking-definition", @@ -475,59 +475,59 @@ def test_version_marking(): }, } - with pytest.raises(stix2.exceptions.TypeNotVersionableError): - stix2.versioning.new_version(m) + with pytest.raises(misp_lib_stix2.exceptions.TypeNotVersionableError): + misp_lib_stix2.versioning.new_version(m) def test_version_disable_custom(): - m = stix2.v21.Malware( + m = misp_lib_stix2.v21.Malware( name="foo", description="Steals your identity!", is_family=False, x_custom=123, allow_custom=True, ) # Remove the custom property, and disallow custom properties in the # resulting object. - m2 = stix2.versioning.new_version(m, x_custom=None, allow_custom=False) + m2 = misp_lib_stix2.versioning.new_version(m, x_custom=None, allow_custom=False) assert "x_custom" not in m2 # Remove a regular property and leave the custom one, disallow custom # properties, and make sure we get an error. - with pytest.raises(stix2.exceptions.ExtraPropertiesError): - stix2.versioning.new_version(m, description=None, allow_custom=False) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError): + misp_lib_stix2.versioning.new_version(m, description=None, allow_custom=False) def test_version_enable_custom(): - m = stix2.v21.Malware( + m = misp_lib_stix2.v21.Malware( name="foo", description="Steals your identity!", is_family=False, ) # Add a custom property to an object for which it was previously disallowed - m2 = stix2.versioning.new_version(m, x_custom=123, allow_custom=True) + m2 = misp_lib_stix2.versioning.new_version(m, x_custom=123, allow_custom=True) assert "x_custom" in m2 # Add a custom property without enabling it, make sure we get an error - with pytest.raises(stix2.exceptions.ExtraPropertiesError): - stix2.versioning.new_version(m, x_custom=123, allow_custom=False) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError): + misp_lib_stix2.versioning.new_version(m, x_custom=123, allow_custom=False) def test_version_propagate_custom(): - m = stix2.v21.Malware( + m = misp_lib_stix2.v21.Malware( name="foo", is_family=False, ) # Remember custom-not-allowed setting from original; produce error - with pytest.raises(stix2.exceptions.ExtraPropertiesError): - stix2.versioning.new_version(m, x_custom=123) + with pytest.raises(misp_lib_stix2.exceptions.ExtraPropertiesError): + misp_lib_stix2.versioning.new_version(m, x_custom=123) - m2 = stix2.versioning.new_version(m, description="Steals your identity!") + m2 = misp_lib_stix2.versioning.new_version(m, description="Steals your identity!") assert "description" in m2 assert m2.description == "Steals your identity!" - m_custom = stix2.v21.Malware( + m_custom = misp_lib_stix2.v21.Malware( name="foo", is_family=False, x_custom=123, allow_custom=True, ) # Remember custom-allowed setting from original; should work - m2_custom = stix2.versioning.new_version(m_custom, x_other_custom="abc") + m2_custom = misp_lib_stix2.versioning.new_version(m_custom, x_other_custom="abc") assert "x_other_custom" in m2_custom assert m2_custom.x_other_custom == "abc" diff --git a/stix2/test/v21/test_vulnerability.py b/misp_lib_stix2/test/v21/test_vulnerability.py similarity index 91% rename from stix2/test/v21/test_vulnerability.py rename to misp_lib_stix2/test/v21/test_vulnerability.py index bcea913e..c2ab594a 100644 --- a/stix2/test/v21/test_vulnerability.py +++ b/misp_lib_stix2/test/v21/test_vulnerability.py @@ -3,7 +3,7 @@ import pytest import pytz -import stix2 +import misp_lib_stix2 from .constants import VULNERABILITY_ID @@ -24,13 +24,13 @@ def test_vulnerability_example(): - vulnerability = stix2.v21.Vulnerability( + vulnerability = misp_lib_stix2.v21.Vulnerability( id=VULNERABILITY_ID, created="2016-05-12T08:17:27.000Z", modified="2016-05-12T08:17:27.000Z", name="CVE-2016-1234", external_references=[ - stix2.ExternalReference( + misp_lib_stix2.ExternalReference( source_name='cve', external_id="CVE-2016-1234", ), @@ -60,7 +60,7 @@ def test_vulnerability_example(): ], ) def test_parse_vulnerability(data): - vuln = stix2.parse(data, version="2.1") + vuln = misp_lib_stix2.parse(data, version="2.1") assert vuln.type == 'vulnerability' assert vuln.spec_version == '2.1' diff --git a/stix2/utils.py b/misp_lib_stix2/utils.py similarity index 97% rename from stix2/utils.py rename to misp_lib_stix2/utils.py index 8f679d43..2c0c0c9f 100644 --- a/stix2/utils.py +++ b/misp_lib_stix2/utils.py @@ -8,8 +8,8 @@ import pytz -import stix2.registry as mappings -import stix2.version +import misp_lib_stix2.registry as mappings +import misp_lib_stix2.version # Sentinel value for properties that should be set to the current time. # We can't use the standard 'default' approach, since if there are multiple @@ -382,7 +382,7 @@ def _stix_type_of(value): return type_ -def is_sdo(value, stix_version=stix2.version.DEFAULT_VERSION): +def is_sdo(value, stix_version=misp_lib_stix2.version.DEFAULT_VERSION): """ Determine whether the given object, type, or ID is/is for an SDO of the given STIX version. If value is a type or ID, this just checks whether @@ -415,7 +415,7 @@ def is_sdo(value, stix_version=stix2.version.DEFAULT_VERSION): return result -def is_sco(value, stix_version=stix2.version.DEFAULT_VERSION): +def is_sco(value, stix_version=misp_lib_stix2.version.DEFAULT_VERSION): """ Determine whether the given object, type, or ID is/is for an SCO of the given STIX version. If value is a type or ID, this just checks whether @@ -445,7 +445,7 @@ def is_sco(value, stix_version=stix2.version.DEFAULT_VERSION): return result -def is_sro(value, stix_version=stix2.version.DEFAULT_VERSION): +def is_sro(value, stix_version=misp_lib_stix2.version.DEFAULT_VERSION): """ Determine whether the given object, type, or ID is/is for an SRO of the given STIX version. If value is a type or ID, this just checks whether @@ -475,7 +475,7 @@ def is_sro(value, stix_version=stix2.version.DEFAULT_VERSION): return result -def is_object(value, stix_version=stix2.version.DEFAULT_VERSION): +def is_object(value, stix_version=misp_lib_stix2.version.DEFAULT_VERSION): """ Determine whether an object, type, or ID is/is for any STIX object. This includes all SDOs, SCOs, meta-objects, and bundle. If value is a type or @@ -506,7 +506,7 @@ def is_object(value, stix_version=stix2.version.DEFAULT_VERSION): return result -def is_marking(value, stix_version=stix2.version.DEFAULT_VERSION): +def is_marking(value, stix_version=misp_lib_stix2.version.DEFAULT_VERSION): """ Determine whether the given object, type, or ID is/is for an marking definition of the given STIX version. If value is a type or ID, this just @@ -543,7 +543,7 @@ class STIXTypeClass(enum.Enum): SRO = 2 -def is_stix_type(value, stix_version=stix2.version.DEFAULT_VERSION, *types): +def is_stix_type(value, stix_version=misp_lib_stix2.version.DEFAULT_VERSION, *types): """ Determine whether the type of the given value satisfies the given constraints. 'types' must contain STIX types as strings, and/or the diff --git a/stix2/v20/__init__.py b/misp_lib_stix2/v20/__init__.py similarity index 100% rename from stix2/v20/__init__.py rename to misp_lib_stix2/v20/__init__.py diff --git a/stix2/v20/base.py b/misp_lib_stix2/v20/base.py similarity index 100% rename from stix2/v20/base.py rename to misp_lib_stix2/v20/base.py diff --git a/stix2/v20/bundle.py b/misp_lib_stix2/v20/bundle.py similarity index 100% rename from stix2/v20/bundle.py rename to misp_lib_stix2/v20/bundle.py diff --git a/stix2/v20/common.py b/misp_lib_stix2/v20/common.py similarity index 100% rename from stix2/v20/common.py rename to misp_lib_stix2/v20/common.py diff --git a/stix2/v20/observables.py b/misp_lib_stix2/v20/observables.py similarity index 100% rename from stix2/v20/observables.py rename to misp_lib_stix2/v20/observables.py diff --git a/stix2/v20/sdo.py b/misp_lib_stix2/v20/sdo.py similarity index 100% rename from stix2/v20/sdo.py rename to misp_lib_stix2/v20/sdo.py diff --git a/stix2/v20/sro.py b/misp_lib_stix2/v20/sro.py similarity index 100% rename from stix2/v20/sro.py rename to misp_lib_stix2/v20/sro.py diff --git a/stix2/v20/vocab.py b/misp_lib_stix2/v20/vocab.py similarity index 100% rename from stix2/v20/vocab.py rename to misp_lib_stix2/v20/vocab.py diff --git a/stix2/v21/__init__.py b/misp_lib_stix2/v21/__init__.py similarity index 100% rename from stix2/v21/__init__.py rename to misp_lib_stix2/v21/__init__.py diff --git a/stix2/v21/base.py b/misp_lib_stix2/v21/base.py similarity index 100% rename from stix2/v21/base.py rename to misp_lib_stix2/v21/base.py diff --git a/stix2/v21/bundle.py b/misp_lib_stix2/v21/bundle.py similarity index 100% rename from stix2/v21/bundle.py rename to misp_lib_stix2/v21/bundle.py diff --git a/stix2/v21/common.py b/misp_lib_stix2/v21/common.py similarity index 100% rename from stix2/v21/common.py rename to misp_lib_stix2/v21/common.py diff --git a/stix2/v21/observables.py b/misp_lib_stix2/v21/observables.py similarity index 100% rename from stix2/v21/observables.py rename to misp_lib_stix2/v21/observables.py diff --git a/stix2/v21/sdo.py b/misp_lib_stix2/v21/sdo.py similarity index 100% rename from stix2/v21/sdo.py rename to misp_lib_stix2/v21/sdo.py diff --git a/stix2/v21/sro.py b/misp_lib_stix2/v21/sro.py similarity index 100% rename from stix2/v21/sro.py rename to misp_lib_stix2/v21/sro.py diff --git a/stix2/v21/vocab.py b/misp_lib_stix2/v21/vocab.py similarity index 100% rename from stix2/v21/vocab.py rename to misp_lib_stix2/v21/vocab.py diff --git a/stix2/version.py b/misp_lib_stix2/version.py similarity index 78% rename from stix2/version.py rename to misp_lib_stix2/version.py index 61521851..cb1c8b95 100644 --- a/stix2/version.py +++ b/misp_lib_stix2/version.py @@ -1,3 +1,3 @@ -__version__ = "3.0.1.1" +__version__ = "3.0.2" DEFAULT_VERSION = '2.1' # Default version will always be the latest STIX 2.X version diff --git a/stix2/versioning.py b/misp_lib_stix2/versioning.py similarity index 95% rename from stix2/versioning.py rename to misp_lib_stix2/versioning.py index 02a1e138..0eeb4eee 100644 --- a/stix2/versioning.py +++ b/misp_lib_stix2/versioning.py @@ -6,12 +6,12 @@ import itertools import uuid -import stix2.base -import stix2.registry -from stix2.utils import ( +import misp_lib_stix2.base +import misp_lib_stix2.registry +from misp_lib_stix2.utils import ( detect_spec_version, get_timestamp, is_sco, parse_into_datetime, ) -import stix2.v20 +import misp_lib_stix2.v20 from .exceptions import ( InvalidValueError, ObjectNotVersionableError, RevokeError, @@ -70,9 +70,9 @@ def _get_stix_version(data): # First, determine spec version. It's easy for our stix2 objects; more # work for dicts. - if isinstance(data, stix2.v20._STIXBase20): + if isinstance(data, misp_lib_stix2.v20._STIXBase20): stix_version = "2.0" - elif isinstance(data, stix2.v21._STIXBase21): + elif isinstance(data, misp_lib_stix2.v21._STIXBase21): stix_version = "2.1" elif isinstance(data, dict): stix_version = detect_spec_version(data) @@ -114,7 +114,7 @@ def _is_versionable_type(data): stix_version = _get_stix_version(data) # Then, determine versionability. - if isinstance(data, stix2.base._STIXBase): + if isinstance(data, misp_lib_stix2.base._STIXBase): is_versionable = _VERSIONING_PROPERTIES.issubset( data._properties, ) @@ -124,7 +124,7 @@ def _is_versionable_type(data): # map to a registered class, and from that get a more complete # picture of its properties. - cls = stix2.registry.class_for_type(data.get("type"), stix_version) + cls = misp_lib_stix2.registry.class_for_type(data.get("type"), stix_version) if cls: is_versionable = _VERSIONING_PROPERTIES.issubset( cls._properties, @@ -218,10 +218,10 @@ def new_version(data, allow_custom=None, **kwargs): if is_sco(data, "2.1"): uuid_ = uuid.UUID(data["id"][-36:]) if uuid_.variant == uuid.RFC_4122 and uuid_.version == 5: - if isinstance(data, stix2.base._Observable): + if isinstance(data, misp_lib_stix2.base._Observable): cls = data.__class__ else: - cls = stix2.registry.class_for_type( + cls = misp_lib_stix2.registry.class_for_type( data["type"], stix_version, "observables", ) @@ -270,7 +270,7 @@ def new_version(data, allow_custom=None, **kwargs): # Set allow_custom appropriately if versioning an object. We will ignore # it for dicts. - if isinstance(data, stix2.base._STIXBase): + if isinstance(data, misp_lib_stix2.base._STIXBase): if allow_custom is None: new_obj_inner["allow_custom"] = data.has_custom else: diff --git a/stix2/workbench.py b/misp_lib_stix2/workbench.py similarity index 100% rename from stix2/workbench.py rename to misp_lib_stix2/workbench.py diff --git a/pyproject.toml b/pyproject.toml index db272c93..3fa46575 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "misp-lib-stix2" -version = "3.0.1.1" +version = "3.0.2" description = "Produce and consume STIX 2 JSON content" authors = ["OASIS Cyber Threat Intelligence Technical Committee "] maintainers = ["OASIS Cyber Threat Intelligence Technical Committee "] diff --git a/setup.cfg b/setup.cfg index b01be01d..40d37ab8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 3.0.1.1 +current_version = 3.0.2 commit = True tag = True