diff options
author | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2022-06-08 19:01:00 +0200 |
---|---|---|
committer | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2022-06-08 19:01:00 +0200 |
commit | 348a78179207da3a9547913e6b6616c8c4daedf3 (patch) | |
tree | b22beec8691550b924ddc99e1467843f63e9d4ff | |
parent | ccef0aa78fa0c5ae484ea3737a3d72c0616e7d8c (diff) | |
download | pysaml2-348a78179207da3a9547913e6b6616c8c4daedf3.tar.gz |
Fallback to xs:string for AttributeValue xs types
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
-rw-r--r-- | src/saml2/saml.py | 12 | ||||
-rw-r--r-- | tests/test_02_saml.py | 12 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/saml2/saml.py b/src/saml2/saml.py index fa3afbc5..af91bdeb 100644 --- a/src/saml2/saml.py +++ b/src/saml2/saml.py @@ -327,9 +327,10 @@ class AttributeValueBase(SamlBase): } xsd_string = ( - 'base64Binary' if base64encode - else self.get_type() - or type_to_xsd.get(type(value))) + 'base64Binary' + if base64encode + else self.get_type() or type_to_xsd.get(type(value)) + ) xsd_ns, xsd_type = ( ['', type(None)] if xsd_string is None @@ -340,7 +341,10 @@ class AttributeValueBase(SamlBase): ] if ':' not in xsd_string else xsd_string.split(':', 1)) - xsd_type_props = xsd_types_props.get(xsd_type, {}) + xsd_type_props = xsd_types_props.get(xsd_type) + if not xsd_type_props: + xsd_type_props = xsd_types_props.get("string") + valid_type = xsd_type_props.get('type', type(None)) to_type = xsd_type_props.get('to_type', str) to_text = xsd_type_props.get('to_text', str) diff --git a/tests/test_02_saml.py b/tests/test_02_saml.py index fe5bbb70..8147fe0e 100644 --- a/tests/test_02_saml.py +++ b/tests/test_02_saml.py @@ -276,11 +276,15 @@ class TestSAMLBase: # the value is unchanged assert av.text == value - def test_set_invalid_type_before_text(self): + def test_treat_invalid_types_as_string(self): + _type_name = 'invalid-type' + _value = 'foobar' av = AttributeValue() - av.set_type('invalid-type') - with raises(ValueError): - av.set_text('foobar') + av.set_type(_type_name) + av.set_text(_value) + assert av.get_type() == _type_name + assert av.text == _value + assert type(av.text) is str def test_make_vals_div(self): foo = saml2.make_vals(666, AttributeValue, part=True) |