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_dict = { "0": obs, } with pytest.raises(ExtraPropertiesError): prop.clean(obs_dict, False) result = prop.clean(obs_dict, True) assert result[0]["0"] == obs assert result[1]
def test_observable_property_obj(): prop = ObservableProperty(spec_version="2.0") obs = stix2.v20.File(name="data.dat") obs_dict = { "0": obs, } result = prop.clean(obs_dict, False) assert result[0]["0"] == obs assert not result[1] result = prop.clean(obs_dict, True) assert result[0]["0"] == obs assert not result[1]
def test_observable_property_dict_custom(): prop = ObservableProperty(spec_version="2.0") obs_dict = { "0": { "type": "file", "name": "data.dat", "foo": True, }, } with pytest.raises(ExtraPropertiesError): prop.clean(obs_dict, False) result = prop.clean(obs_dict, True) assert isinstance(result[0]["0"], stix2.v20.File) assert result[0]["0"]["foo"] assert result[1]
def test_observable_property_dict(): prop = ObservableProperty(spec_version="2.0") obs_dict = { "0": { "type": "file", "name": "data.dat", }, } result = prop.clean(obs_dict, False) assert isinstance(result[0]["0"], 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 result[0]["0"]["name"] == "data.dat" assert not result[1]
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')) ])