def test_extension_property_invalid3(): ext_prop = ExtensionsProperty(spec_version="2.0") with pytest.raises(ExtraPropertiesError): ext_prop.clean( { 'windows-pebinary-ext': { 'pe_type': 'exe', 'abc': 123, }, }, False, ) result = ext_prop.clean( { 'windows-pebinary-ext': { 'pe_type': 'exe', 'abc': 123, }, }, True, ) assert isinstance( result[0]["windows-pebinary-ext"], stix2.v20.WindowsPEBinaryExt, ) assert result[0]["windows-pebinary-ext"]["abc"] == 123 assert result[1]
def test_extension_property_valid(): ext_prop = ExtensionsProperty(spec_version="2.0") result = ext_prop.clean( { 'windows-pebinary-ext': { 'pe_type': 'exe', }, }, False, ) assert isinstance( result[0]["windows-pebinary-ext"], stix2.v20.WindowsPEBinaryExt, ) assert not result[1] result = ext_prop.clean( { 'windows-pebinary-ext': { 'pe_type': 'exe', }, }, True, ) assert isinstance( result[0]["windows-pebinary-ext"], stix2.v20.WindowsPEBinaryExt, ) assert not result[1]
def test_extension_property_invalid2(): ext_prop = ExtensionsProperty(spec_version="2.0", enclosing_type='file') with pytest.raises(CustomContentError): ext_prop.clean({ 'foobar-ext': { 'pe_type': 'exe', }, }, )
def test_extension_property_invalid_type(): ext_prop = ExtensionsProperty(enclosing_type='indicator') with pytest.raises(ValueError) as excinfo: ext_prop.clean({ 'windows-pebinary-ext': { 'pe_type': 'exe', }, }, ) assert "Can't parse unknown extension" in str(excinfo.value)
def test_extension_property_invalid_type(): ext_prop = ExtensionsProperty(spec_version="2.0", enclosing_type='indicator') with pytest.raises(CustomContentError) as excinfo: ext_prop.clean( { 'windows-pebinary-ext': { 'pe_type': 'exe', }, }, False, ) assert "Can't parse unknown extension" in str(excinfo.value)
def test_extension_property_invalid2(): ext_prop = ExtensionsProperty(spec_version='2.1') with pytest.raises(CustomContentError): ext_prop.clean( { 'foobar-ext': { 'pe_type': 'exe', }, }, False, ) result = ext_prop.clean( { 'foobar-ext': { 'pe_type': 'exe', }, }, True, ) assert result == ({"foobar-ext": {"pe_type": "exe"}}, True)
def test_extension_property_invalid1(): ext_prop = ExtensionsProperty(spec_version='2.1', enclosing_type='file') with pytest.raises(ValueError): ext_prop.clean(1)
def test_extension_property_invalid(data): ext_prop = ExtensionsProperty(enclosing_type='file') with pytest.raises(ValueError): ext_prop.clean(data)
def test_extension_property_invalid1(): ext_prop = ExtensionsProperty(spec_version="2.0") with pytest.raises(ValueError): ext_prop.clean(1, False)