def test_embedded_property(): emb_prop = EmbeddedObjectProperty(type=EmailMIMEComponent) mime = EmailMIMEComponent(content_type="text/plain; charset=utf-8", content_disposition="inline", body="Cats are funny!") assert emb_prop.clean(mime) with pytest.raises(ValueError): emb_prop.clean("string")
def test_embedded_property_custom(): emb_prop = EmbeddedObjectProperty(type=stix2.v20.EmailMIMEComponent) mime = stix2.v20.EmailMIMEComponent( content_type="text/plain; charset=utf-8", content_disposition="inline", body="Cats are funny!", foo=123, allow_custom=True, ) with pytest.raises(CustomContentError): emb_prop.clean(mime, False) result = emb_prop.clean(mime, True) assert result == (mime, True)
def test_embedded_property(): emb_prop = EmbeddedObjectProperty(type=stix2.v20.EmailMIMEComponent) mime = stix2.v20.EmailMIMEComponent( content_type="text/plain; charset=utf-8", content_disposition="inline", body="Cats are funny!", ) result = emb_prop.clean(mime, False) assert result == (mime, False) result = emb_prop.clean(mime, True) assert result == (mime, False) with pytest.raises(ValueError): emb_prop.clean("string", False)
def test_embedded_property_dict_custom(): emb_prop = EmbeddedObjectProperty(type=stix2.v20.EmailMIMEComponent) mime = { "content_type": "text/plain; charset=utf-8", "content_disposition": "inline", "body": "Cats are funny!", "foo": 123, } with pytest.raises(ExtraPropertiesError): emb_prop.clean(mime, False) result = emb_prop.clean(mime, True) assert isinstance(result[0], stix2.v20.EmailMIMEComponent) assert result[0]["body"] == "Cats are funny!" assert result[1]
def test_embedded_property_dict(): emb_prop = EmbeddedObjectProperty(type=stix2.v20.EmailMIMEComponent) mime = { "content_type": "text/plain; charset=utf-8", "content_disposition": "inline", "body": "Cats are funny!", } result = emb_prop.clean(mime, False) assert isinstance(result[0], stix2.v20.EmailMIMEComponent) assert result[0]["body"] == "Cats are funny!" assert not result[1] result = emb_prop.clean(mime, True) assert isinstance(result[0], stix2.v20.EmailMIMEComponent) assert result[0]["body"] == "Cats are funny!" assert not result[1]