Skip to content

Commit e58e895

Browse files
committed
Raise ValueError for invalid attribute type
Without this patch, the AttributeValueBase set_text method checks for a valid xsi:type before setting the text value, but when it gets to the catchall case, instead of raising an exception it simply creates an unassigned ValueError instance and does nothing with it. This is clearly not intentional, and it is a problem because it means it is possible to set an invalid xsi:type for an AttributeValue. This patch corrects the error by raising the ValueError exception rather than letting it disappear into the ether.
1 parent a17f233 commit e58e895

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/saml2/saml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def set_text(self, val, base64encode=False):
224224
elif typ == "xs:base64Binary":
225225
pass
226226
else:
227-
ValueError("Type and value doesn't match")
227+
raise ValueError("Type and value doesn't match")
228228
elif isinstance(val, bool):
229229
if val:
230230
val = "true"

tests/test_02_saml.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ def test_set_text(self):
243243
av.set_text(None)
244244
assert av.text == ""
245245

246+
av = AttributeValue()
247+
av.set_type('invalid')
248+
raises(ValueError, "av.set_text('free text')")
249+
246250
def test_make_vals_div(self):
247251
foo = saml2.make_vals(666, AttributeValue, part=True)
248252
assert foo.text == "666"

0 commit comments

Comments
 (0)