diff options
author | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2022-06-08 19:01:31 +0200 |
---|---|---|
committer | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2022-06-08 19:01:31 +0200 |
commit | d88a979a957c3f52719cc85ae0376ea3fca8771e (patch) | |
tree | 133dfaa13e3007b15ee79bee8cc0945b0cd0126e | |
parent | 348a78179207da3a9547913e6b6616c8c4daedf3 (diff) | |
download | pysaml2-d88a979a957c3f52719cc85ae0376ea3fca8771e.tar.gz |
Add partial supprot for xs:date AttributeValue type
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
-rw-r--r-- | src/saml2/saml.py | 7 | ||||
-rw-r--r-- | tests/test_02_saml.py | 10 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/saml2/saml.py b/src/saml2/saml.py index af91bdeb..d63509fe 100644 --- a/src/saml2/saml.py +++ b/src/saml2/saml.py @@ -15,6 +15,8 @@ import base64 +from datetime import date +from datetime import datetime from saml2.validate import valid_ipv4, MustValueError from saml2.validate import valid_ipv6 @@ -307,6 +309,11 @@ class AttributeValueBase(SamlBase): }[str(x).lower()], 'to_text': lambda x: str(x).lower(), }, + 'date': { + 'type': date, + 'to_type': lambda x: datetime.strptime(x, '%Y-%m-%d').date(), + 'to_text': str, + }, 'base64Binary': { 'type': str, 'to_type': str, diff --git a/tests/test_02_saml.py b/tests/test_02_saml.py index 8147fe0e..9f09f8cf 100644 --- a/tests/test_02_saml.py +++ b/tests/test_02_saml.py @@ -276,6 +276,16 @@ class TestSAMLBase: # the value is unchanged assert av.text == value + def test_set_xs_type_date(self): + _type_name = 'xs:date' + _value = '2022-06-07' + av = AttributeValue() + 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_treat_invalid_types_as_string(self): _type_name = 'invalid-type' _value = 'foobar' |