Пример #1
0
def test_id_property():
    idprop = IDProperty('my-type')

    assert idprop.clean('my-type--90aaca8a-1110-5d32-956d-ac2f34a1bd8c')
    with pytest.raises(ValueError) as excinfo:
        idprop.clean('not-my-type--90aaca8a-1110-5d32-956d-ac2f34a1bd8c')
    assert str(excinfo.value) == "must start with 'my-type--'."
    with pytest.raises(ValueError) as excinfo:
        idprop.clean('my-type--foo')
    assert str(excinfo.value) == "must have a valid UUID after the prefix."

    assert idprop.clean(idprop.default())
Пример #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',
     ]
Пример #3
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')),
     ))
     _id_contributing_properties = []
Пример #4
0
def test_id_property():
    idprop = IDProperty('my-type')

    assert idprop.validate('my-type--90aaca8a-1110-5d32-956d-ac2f34a1bd8c')
    with pytest.raises(ValueError):
        idprop.validate('not-my-type--90aaca8a-1110-5d32-956d-ac2f34a1bd8c')
    assert idprop.validate(idprop.default())
Пример #5
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,
             ),
         ),
         ('sub_obj', EmbeddedObjectProperty(type=SubObj)),
     ))
     _id_contributing_properties = ['sub_obj']
Пример #6
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,
             ),
         ),
         ('hashes', HashesProperty(HASHING_ALGORITHM)),
     ))
     _id_contributing_properties = ['hashes']
Пример #7
0
class StixObservedData(_STIXBase):
    _type = 'observed-data'
    _properties = OrderedDict()
    _properties.update([
        ('type', TypeProperty(_type)), ('id', IDProperty(_type)),
        ('created_by_ref', ReferenceProperty(type="device_ref")),
        ('created',
         TimestampProperty(default=lambda: NOW, precision='millisecond')),
        ('modified',
         TimestampProperty(default=lambda: NOW, precision='millisecond')),
        ('first_observed', TimestampProperty(required=True)),
        ('last_observed', TimestampProperty(required=True)),
        ('number_observed', IntegerProperty(required=True)),
        ('objects', ObservableProperty()), ('revoked', BooleanProperty()),
        ('labels', ListProperty(StringProperty)),
        ('external_references', ListProperty(ExternalReference)),
        ('object_marking_refs',
         ListProperty(ReferenceProperty(type="marking-definition"))),
        ('granular_markings', ListProperty(GranularMarking)),
        ('device_ref', DeviceProperty('device'))
    ])
def test_id_property_valid_for_type(value):
    type = value.split('--', 1)[0]
    assert IDProperty(type=type, spec_version="2.1").clean(value) == value
    assert prop.clean('foobar')
    assert prop.clean(1)
    assert prop.clean([1, 2, 3])


def test_type_property():
    prop = TypeProperty('my-type')

    assert prop.clean('my-type')
    with pytest.raises(ValueError):
        prop.clean('not-my-type')
    assert prop.clean(prop.default())


ID_PROP = IDProperty('my-type', spec_version="2.1")
MY_ID = 'my-type--232c9d3f-49fc-4440-bb01-607f638778e7'


@pytest.mark.parametrize(
    "value", [
        MY_ID,
        'my-type--00000000-0000-4000-8000-000000000000',
    ],
)
def test_id_property_valid(value):
    assert ID_PROP.clean(value) == value


CONSTANT_IDS = [
    constants.ATTACK_PATTERN_ID,
Пример #10
0
def test_id_property_valid_uuid_for_type(value):
    type = value.split('--', 1)[0]
    assert IDProperty(type=type).clean(value) == value
Пример #11
0
    assert prop.clean('foobar')
    assert prop.clean(1)
    assert prop.clean([1, 2, 3])


def test_type_property():
    prop = TypeProperty('my-type')

    assert prop.clean('my-type')
    with pytest.raises(ValueError):
        prop.clean('not-my-type')
    assert prop.clean(prop.default())


ID_PROP = IDProperty('my-type')
MY_ID = 'my-type--232c9d3f-49fc-4440-bb01-607f638778e7'


@pytest.mark.parametrize(
    "value",
    [
        MY_ID,
        'my-type--00000000-0000-4000-8000-000000000000',
    ],
)
def test_id_property_valid(value):
    assert ID_PROP.clean(value) == value


CONSTANT_IDS = [