Skip to content

Commit d88a979

Browse files
committed
Add partial supprot for xs:date AttributeValue type
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
1 parent 348a781 commit d88a979

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/saml2/saml.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616

1717
import base64
18+
from datetime import date
19+
from datetime import datetime
1820

1921
from saml2.validate import valid_ipv4, MustValueError
2022
from saml2.validate import valid_ipv6
@@ -307,6 +309,11 @@ def _wrong_type_value(xsd, value):
307309
}[str(x).lower()],
308310
'to_text': lambda x: str(x).lower(),
309311
},
312+
'date': {
313+
'type': date,
314+
'to_type': lambda x: datetime.strptime(x, '%Y-%m-%d').date(),
315+
'to_text': str,
316+
},
310317
'base64Binary': {
311318
'type': str,
312319
'to_type': str,

tests/test_02_saml.py

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

279+
def test_set_xs_type_date(self):
280+
_type_name = 'xs:date'
281+
_value = '2022-06-07'
282+
av = AttributeValue()
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
288+
279289
def test_treat_invalid_types_as_string(self):
280290
_type_name = 'invalid-type'
281291
_value = 'foobar'

0 commit comments

Comments
 (0)