diff --git a/stix2/__init__.py b/stix2/__init__.py index 80eaa41..e2e95f9 100644 --- a/stix2/__init__.py +++ b/stix2/__init__.py @@ -19,7 +19,7 @@ def format_datetime(dt): # - modified -class Indicator: +class Indicator(object): # REQUIRED (Indicator): # - type # - labels @@ -27,6 +27,9 @@ class Indicator: # - valid_from required = [''] + def __getitem__(self, key): + return getattr(self, key) + def __init__(self, type='indicator', id=None, created=None, modified=None, labels=None, pattern=None, valid_from=None): now = datetime.now(tz=pytz.UTC) diff --git a/stix2/test/test_stix2.py b/stix2/test/test_stix2.py index 902b7de..489e3bd 100644 --- a/stix2/test/test_stix2.py +++ b/stix2/test/test_stix2.py @@ -68,6 +68,14 @@ def test_indicator_autogenerated_fields(): assert indicator.pattern == "[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']" assert indicator.valid_from is not None + assert indicator['type'] == 'indicator' + assert indicator['id'].startswith('indicator--') + assert indicator['created'] is not None + assert indicator['modified'] is not None + assert indicator['labels'] == ['malicious-activity'] + assert indicator['pattern'] == "[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']" + assert indicator['valid_from'] is not None + def test_indicator_type_must_be_indicator(): with pytest.raises(ValueError) as excinfo: