From 2252452453af79db4bea557c0523fc8e853fc180 Mon Sep 17 00:00:00 2001 From: dfeinzeig Date: Thu, 19 Mar 2015 21:20:07 -0400 Subject: [PATCH 1/3] some IdPs (for example OneLogin seem to exclude the trailing Z in the IssueInstant. str_to_time throws an exception in those cases. updated the regex to handle the possible seconds in addition to the possible missing Z. looked at the saml spec and it is unclear if the Z is required or just that the datetime is expected to be UTC. --- src/saml2/time_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/saml2/time_util.py b/src/saml2/time_util.py index 81987ef..e0cc5d3 100644 --- a/src/saml2/time_util.py +++ b/src/saml2/time_util.py @@ -16,7 +16,7 @@ from datetime import datetime TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" TIME_FORMAT_WITH_FRAGMENT = re.compile( - "^(\d{4,4}-\d{2,2}-\d{2,2}T\d{2,2}:\d{2,2}:\d{2,2})\.\d*Z$") + "^(\d{4,4}-\d{2,2}-\d{2,2}T\d{2,2}:\d{2,2}:\d{2,2})(\.\d)*Z?$") # --------------------------------------------------------------------------- # I'm sure this is implemented somewhere else can't find it now though, so I From 7f5acb607859f15e9ba8266cb09b8cfce15a4550 Mon Sep 17 00:00:00 2001 From: dfeinzeig Date: Thu, 19 Mar 2015 21:30:08 -0400 Subject: [PATCH 2/3] now properly handles seconds and or Z --- src/saml2/time_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/saml2/time_util.py b/src/saml2/time_util.py index e0cc5d3..fc35b30 100644 --- a/src/saml2/time_util.py +++ b/src/saml2/time_util.py @@ -16,7 +16,7 @@ from datetime import datetime TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" TIME_FORMAT_WITH_FRAGMENT = re.compile( - "^(\d{4,4}-\d{2,2}-\d{2,2}T\d{2,2}:\d{2,2}:\d{2,2})(\.\d)*Z?$") + "^(\d{4,4}-\d{2,2}-\d{2,2}T\d{2,2}:\d{2,2}:\d{2,2})(\.\d*)?Z?$") # --------------------------------------------------------------------------- # I'm sure this is implemented somewhere else can't find it now though, so I From 348892465ba04f3accf79f86cd37e715c8c04ebc Mon Sep 17 00:00:00 2001 From: dfeinzeig Date: Thu, 19 Mar 2015 21:50:52 -0400 Subject: [PATCH 3/3] update test_str_to_time() bc some IdPs omit the trailing Z --- tests/test_10_time_util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_10_time_util.py b/tests/test_10_time_util.py index 5ebc369..323126d 100644 --- a/tests/test_10_time_util.py +++ b/tests/test_10_time_util.py @@ -123,7 +123,9 @@ def test_str_to_time(): #TODO: add something to show how this time was arrived at # do this as an external method in the assert t == 947635200 - + # some IdPs omit the trailing Z, and SAML spec is unclear if it is actually required + t = calendar.timegm(str_to_time("2000-01-12T00:00:00")) + assert t == 947635200 def test_instant(): inst = str_to_time(instant())