Exemplo n.º 1
0
def test_dictionary_property_invalid_key(d):
    dict_prop = DictionaryProperty()

    with pytest.raises(DictionaryKeyError) as excinfo:
        dict_prop.clean(d[0])

    assert str(excinfo.value) == d[1]
Exemplo n.º 2
0
 class SomeSCO(stix2.v21._Observable):
     _type = "some-sco"
     _properties = OrderedDict((
         ('type', TypeProperty(_type, spec_version='2.1')),
         ('id', IDProperty(_type, spec_version='2.1')),
         (
             'extensions',
             ExtensionsProperty(
                 spec_version='2.1',
                 enclosing_type=_type,
             ),
         ),
         ('string', StringProperty()),
         ('int', IntegerProperty()),
         ('float', FloatProperty()),
         ('bool', BooleanProperty()),
         ('list', ListProperty(IntegerProperty())),
         ('dict', DictionaryProperty(spec_version="2.1")),
     ))
     _id_contributing_properties = [
         'string',
         'int',
         'float',
         'bool',
         'list',
         'dict',
     ]
Exemplo n.º 3
0
def test_property_list_of_dictionary():
    @CustomObject('x-new-obj', [
        ('property1', ListProperty(DictionaryProperty(), required=True)),
    ])
    class NewObj():
        pass

    test_obj = NewObj(property1=[{'foo': 'bar'}])
    assert test_obj.property1[0]['foo'] == 'bar'
def test_property_list_of_dictionary():
    @stix2.v21.CustomObject(
        'x-new-obj', [
            ('property1', ListProperty(DictionaryProperty(spec_version='2.1'), required=True)),
        ],
    )
    class NewObj():
        pass

    test_obj = NewObj(property1=[{'foo': 'bar'}])
    assert test_obj.property1[0]['foo'] == 'bar'
Exemplo n.º 5
0
def test_dictionary_property_valid(d):
    dict_prop = DictionaryProperty()
    assert dict_prop.clean(d)
def test_dictionary_property():
    p = DictionaryProperty(StringProperty)

    assert p.clean({'spec_version': '2.1'})
    with pytest.raises(ValueError):
        p.clean({})
def test_dictionary_property_invalid(d):
    dict_prop = DictionaryProperty(spec_version='2.1')

    with pytest.raises(ValueError) as excinfo:
        dict_prop.clean(d[0])
    assert str(excinfo.value) == d[1]
def test_dictionary_no_longer_raises(d):
    dict_prop = DictionaryProperty(spec_version='2.1')
    dict_prop.clean(d[0])
def test_dictionary_property_valid(d):
    dict_prop = DictionaryProperty(spec_version='2.1')
    assert dict_prop.clean(d)
Exemplo n.º 10
0
import stip.common.const as const
from stix2.properties import StringProperty, ReferenceProperty, ListProperty, DictionaryProperty
from stix2.v21.bundle import Bundle
from stix2.v21.sdo import Report, CustomObject, Vulnerability, ThreatActor, Indicator, Identity
from stix2.v21.common import GranularMarking


# S-TIP SNS 用カスタムオブジェクト
@CustomObject(const.STIP_STIX2_X_STIP_SNS_TYPE, [
    ('name', StringProperty(required=True)),
    ('description', StringProperty(required=True)),
    ('created_by_ref', ReferenceProperty(valid_types='identity')),
    ('lang', StringProperty()),
    ('granular_markings', ListProperty(GranularMarking)),
    (const.STIP_STIX2_PROP_TYPE, StringProperty(required=True)),
    (const.STIP_STIX2_PROP_AUTHOR, DictionaryProperty(required=True)),
    (const.STIP_STIX2_PROP_POST, DictionaryProperty()),
    (const.STIP_STIX2_PROP_ATTACHMENTS, ListProperty(DictionaryProperty)),
    (const.STIP_STIX2_PROP_BUNDLE_ID, StringProperty()),
    (const.STIP_STIX2_PROP_BUNDLE_VERSION, StringProperty()),
    (const.STIP_STIX2_PROP_ATTACHMENT, DictionaryProperty()),
    (const.STIP_STIX2_PROP_TAGS, ListProperty(StringProperty)),
    (const.STIP_STIX2_PROP_INDICATORS, ListProperty(StringProperty)),
    (const.STIP_STIX2_PROP_IDENTITY, StringProperty(required=True)),
    (const.STIP_STIX2_PROP_TOOL, DictionaryProperty(required=True)),
])
class StipSns(object):
    pass