Skip to content

Commit 348a781

Browse files
committed
Fallback to xs:string for AttributeValue xs types
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
1 parent ccef0aa commit 348a781

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/saml2/saml.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,10 @@ def _wrong_type_value(xsd, value):
327327
}
328328

329329
xsd_string = (
330-
'base64Binary' if base64encode
331-
else self.get_type()
332-
or type_to_xsd.get(type(value)))
330+
'base64Binary'
331+
if base64encode
332+
else self.get_type() or type_to_xsd.get(type(value))
333+
)
333334

334335
xsd_ns, xsd_type = (
335336
['', type(None)] if xsd_string is None
@@ -340,7 +341,10 @@ def _wrong_type_value(xsd, value):
340341
] if ':' not in xsd_string
341342
else xsd_string.split(':', 1))
342343

343-
xsd_type_props = xsd_types_props.get(xsd_type, {})
344+
xsd_type_props = xsd_types_props.get(xsd_type)
345+
if not xsd_type_props:
346+
xsd_type_props = xsd_types_props.get("string")
347+
344348
valid_type = xsd_type_props.get('type', type(None))
345349
to_type = xsd_type_props.get('to_type', str)
346350
to_text = xsd_type_props.get('to_text', str)

tests/test_02_saml.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,15 @@ def test_set_xs_type_anytype_unchanged_value(self):
276276
# the value is unchanged
277277
assert av.text == value
278278

279-
def test_set_invalid_type_before_text(self):
279+
def test_treat_invalid_types_as_string(self):
280+
_type_name = 'invalid-type'
281+
_value = 'foobar'
280282
av = AttributeValue()
281-
av.set_type('invalid-type')
282-
with raises(ValueError):
283-
av.set_text('foobar')
283+
av.set_type(_type_name)
284+
av.set_text(_value)
285+
assert av.get_type() == _type_name
286+
assert av.text == _value
287+
assert type(av.text) is str
284288

285289
def test_make_vals_div(self):
286290
foo = saml2.make_vals(666, AttributeValue, part=True)

0 commit comments

Comments
 (0)