diff --git a/setup.py b/setup.py index eff4c2b..0fbad77 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -from setuptools import setup, find_packages +from setuptools import find_packages, setup install_requires = [ 'pytz', diff --git a/stix2/bundle.py b/stix2/bundle.py index 5785d43..85be3e1 100644 --- a/stix2/bundle.py +++ b/stix2/bundle.py @@ -1,7 +1,7 @@ """STIX 2 Bundle object""" from .base import _STIXBase -from .properties import IDProperty, TypeProperty, Property +from .properties import IDProperty, Property, TypeProperty class Bundle(_STIXBase): diff --git a/stix2/common.py b/stix2/common.py index a541b09..29cbf62 100644 --- a/stix2/common.py +++ b/stix2/common.py @@ -1,8 +1,8 @@ """STIX 2 Common Data Types and Properties""" -from .properties import (ListProperty, BooleanProperty, - ReferenceProperty, TimestampProperty) from .other import ExternalReference, GranularMarking +from .properties import (BooleanProperty, ListProperty, ReferenceProperty, + TimestampProperty) from .utils import NOW COMMON_PROPERTIES = { diff --git a/stix2/other.py b/stix2/other.py index d8d5f1d..9b7f03a 100644 --- a/stix2/other.py +++ b/stix2/other.py @@ -1,10 +1,10 @@ """STIX 2.0 Objects that are neither SDOs nor SROs""" from .base import _STIXBase -from .properties import (IDProperty, TypeProperty, ListProperty, TimestampProperty, - ReferenceProperty, Property, SelectorProperty, - StringProperty) -from .utils import NOW, get_dict +from .properties import (IDProperty, ListProperty, Property, ReferenceProperty, + SelectorProperty, StringProperty, TimestampProperty, + TypeProperty) +from .utils import get_dict, NOW class ExternalReference(_STIXBase): diff --git a/stix2/properties.py b/stix2/properties.py index 07b84a9..ecdbf18 100644 --- a/stix2/properties.py +++ b/stix2/properties.py @@ -1,11 +1,13 @@ +import collections +import datetime as dt +import inspect import re import uuid -from six import text_type -import datetime as dt -import pytz + from dateutil import parser -import inspect -import collections +import pytz +from six import text_type + from .base import _STIXBase diff --git a/stix2/sdo.py b/stix2/sdo.py index 105786b..693b750 100644 --- a/stix2/sdo.py +++ b/stix2/sdo.py @@ -3,9 +3,9 @@ from .base import _STIXBase from .common import COMMON_PROPERTIES from .other import KillChainPhase -from .properties import (Property, ListProperty, StringProperty, TypeProperty, - IDProperty, TimestampProperty, ReferenceProperty, - IntegerProperty) +from .properties import (IDProperty, IntegerProperty, ListProperty, Property, + ReferenceProperty, StringProperty, TimestampProperty, + TypeProperty) from .utils import NOW diff --git a/stix2/sro.py b/stix2/sro.py index 30feef9..c13fff3 100644 --- a/stix2/sro.py +++ b/stix2/sro.py @@ -2,9 +2,9 @@ from .base import _STIXBase from .common import COMMON_PROPERTIES -from .properties import (ListProperty, StringProperty, TypeProperty, - IDProperty, TimestampProperty, ReferenceProperty, - IntegerProperty) +from .properties import (IDProperty, IntegerProperty, ListProperty, + ReferenceProperty, StringProperty, TimestampProperty, + TypeProperty) class Relationship(_STIXBase): diff --git a/stix2/test/test_attack_pattern.py b/stix2/test/test_attack_pattern.py index 33be679..c0891a5 100644 --- a/stix2/test/test_attack_pattern.py +++ b/stix2/test/test_attack_pattern.py @@ -1,6 +1,7 @@ +import datetime as dt + import pytest import pytz -import datetime as dt import stix2 from .constants import ATTACK_PATTERN_ID diff --git a/stix2/test/test_campaign.py b/stix2/test/test_campaign.py index e1bec3b..7f6c4e6 100644 --- a/stix2/test/test_campaign.py +++ b/stix2/test/test_campaign.py @@ -1,6 +1,7 @@ +import datetime as dt + import pytest import pytz -import datetime as dt import stix2 from .constants import CAMPAIGN_ID diff --git a/stix2/test/test_course_of_action.py b/stix2/test/test_course_of_action.py index 3626539..f566e10 100644 --- a/stix2/test/test_course_of_action.py +++ b/stix2/test/test_course_of_action.py @@ -1,6 +1,7 @@ +import datetime as dt + import pytest import pytz -import datetime as dt import stix2 from .constants import COURSE_OF_ACTION_ID diff --git a/stix2/test/test_external_reference.py b/stix2/test/test_external_reference.py index 5d46f87..f8d9b66 100644 --- a/stix2/test/test_external_reference.py +++ b/stix2/test/test_external_reference.py @@ -1,8 +1,8 @@ """Tests for stix.ExternalReference""" -import pytest import re +import pytest import stix2 VERIS = """{ diff --git a/stix2/test/test_identity.py b/stix2/test/test_identity.py index 00726c9..41c87bb 100644 --- a/stix2/test/test_identity.py +++ b/stix2/test/test_identity.py @@ -1,6 +1,7 @@ +import datetime as dt + import pytest import pytz -import datetime as dt import stix2 from .constants import IDENTITY_ID diff --git a/stix2/test/test_indicator.py b/stix2/test/test_indicator.py index dfa04b2..1c2b610 100644 --- a/stix2/test/test_indicator.py +++ b/stix2/test/test_indicator.py @@ -1,9 +1,8 @@ import datetime as dt +import re import pytest import pytz -import re - import stix2 from .constants import FAKE_TIME, INDICATOR_ID, INDICATOR_KWARGS diff --git a/stix2/test/test_intrusion_set.py b/stix2/test/test_intrusion_set.py index e6cf1cf..19fb641 100644 --- a/stix2/test/test_intrusion_set.py +++ b/stix2/test/test_intrusion_set.py @@ -1,6 +1,7 @@ +import datetime as dt + import pytest import pytz -import datetime as dt import stix2 from .constants import INTRUSION_SET_ID diff --git a/stix2/test/test_malware.py b/stix2/test/test_malware.py index 0006ef2..edc35b6 100644 --- a/stix2/test/test_malware.py +++ b/stix2/test/test_malware.py @@ -1,9 +1,8 @@ import datetime as dt +import re import pytest import pytz -import re - import stix2 from .constants import FAKE_TIME, MALWARE_ID, MALWARE_KWARGS @@ -148,3 +147,16 @@ def test_parse_malware_kill_chain_phases(): assert mal.kill_chain_phases[0].phase_name == "reconnaissance" assert mal['kill_chain_phases'][0]['kill_chain_name'] == "lockheed-martin-cyber-kill-chain" assert mal['kill_chain_phases'][0]['phase_name'] == "reconnaissance" + + +def test_parse_malware_clean_kill_chain_phases(): + kill_chain = """ + "kill_chain_phases": [ + { + "kill_chain_name": "lockheed-martin-cyber-kill-chain", + "phase_name": 1 + } + ]""" + data = EXPECTED_MALWARE.replace('malware"', 'malware",%s' % kill_chain) + mal = stix2.parse(data) + assert mal['kill_chain_phases'][0]['phase_name'] == "1" diff --git a/stix2/test/test_markings.py b/stix2/test/test_markings.py index c23abcb..b3cc479 100644 --- a/stix2/test/test_markings.py +++ b/stix2/test/test_markings.py @@ -1,8 +1,9 @@ -import stix2 -from stix2.other import TLP_WHITE +import datetime as dt + import pytest import pytz -import datetime as dt +import stix2 +from stix2.other import TLP_WHITE from .constants import MARKING_DEFINITION_ID diff --git a/stix2/test/test_observed_data.py b/stix2/test/test_observed_data.py index f4243e2..52dc15b 100644 --- a/stix2/test/test_observed_data.py +++ b/stix2/test/test_observed_data.py @@ -1,6 +1,7 @@ +import datetime as dt + import pytest import pytz -import datetime as dt import stix2 from .constants import OBSERVED_DATA_ID diff --git a/stix2/test/test_properties.py b/stix2/test/test_properties.py index 7e9dc13..06172ab 100644 --- a/stix2/test/test_properties.py +++ b/stix2/test/test_properties.py @@ -1,9 +1,8 @@ import pytest -from stix2.properties import (Property, BooleanProperty, ListProperty, - StringProperty, TypeProperty, IDProperty, - IntegerProperty, ReferenceProperty, - TimestampProperty) +from stix2.properties import (BooleanProperty, IDProperty, IntegerProperty, + ListProperty, Property, ReferenceProperty, + StringProperty, TimestampProperty, TypeProperty) from .constants import FAKE_TIME diff --git a/stix2/test/test_report.py b/stix2/test/test_report.py index f28e607..46a0a16 100644 --- a/stix2/test/test_report.py +++ b/stix2/test/test_report.py @@ -1,7 +1,9 @@ -import stix2 +import datetime as dt + import pytest import pytz -import datetime as dt +import stix2 + from .constants import INDICATOR_KWARGS, REPORT_ID EXPECTED = """{ diff --git a/stix2/test/test_threat_actor.py b/stix2/test/test_threat_actor.py index 7eabbed..5844775 100644 --- a/stix2/test/test_threat_actor.py +++ b/stix2/test/test_threat_actor.py @@ -1,6 +1,7 @@ +import datetime as dt + import pytest import pytz -import datetime as dt import stix2 from .constants import THREAT_ACTOR_ID diff --git a/stix2/test/test_tool.py b/stix2/test/test_tool.py index 0e4cd5c..3193807 100644 --- a/stix2/test/test_tool.py +++ b/stix2/test/test_tool.py @@ -1,6 +1,7 @@ +import datetime as dt + import pytest import pytz -import datetime as dt import stix2 from .constants import TOOL_ID diff --git a/stix2/test/test_vulnerability.py b/stix2/test/test_vulnerability.py index bfa9c26..565f077 100644 --- a/stix2/test/test_vulnerability.py +++ b/stix2/test/test_vulnerability.py @@ -1,6 +1,7 @@ +import datetime as dt + import pytest import pytz -import datetime as dt import stix2 from .constants import VULNERABILITY_ID diff --git a/stix2/utils.py b/stix2/utils.py index f91215b..cdc7f54 100644 --- a/stix2/utils.py +++ b/stix2/utils.py @@ -1,9 +1,10 @@ """Utility functions and classes for the stix2 library.""" import datetime as dt -import pytz import json +import pytz + # Sentinel value for fields that should be set to the current time. # We can't use the standard 'default' approach, since if there are multiple # timestamps in a single object, the timestamps will vary by a few microseconds. diff --git a/tox.ini b/tox.ini index fd580f9..80213d7 100644 --- a/tox.ini +++ b/tox.ini @@ -8,10 +8,11 @@ commands = pytest [testenv:pycodestyle] deps = flake8 + flake8-import-order pycodestyle commands = pycodestyle ./stix2 - flake8 --max-line-length=160 + flake8 --max-line-length=160 --import-order-style='google' [pycodestyle] ignore=