Should work in UTC always
This commit is contained in:
@@ -42,7 +42,7 @@ FORM_SPEC = """<form method="post" action="%s">
|
||||
<input type="submit" value="Submit" />
|
||||
</form>"""
|
||||
|
||||
LAX = False
|
||||
LAX = True
|
||||
|
||||
SESSION_INFO = {"ava":{}, "came from":"", "not_on_or_after":0,
|
||||
"issuer":"", "session_id":-1}
|
||||
@@ -294,7 +294,8 @@ class Saml2Client(object):
|
||||
assert assertion.conditions
|
||||
condition = assertion.conditions
|
||||
log and log.info("condition: %s" % condition)
|
||||
now = time.gmtime()
|
||||
now = time.gmtime()
|
||||
log and log.info("now: %s" % time.mktime(now))
|
||||
not_on_or_after = str_to_time(condition.not_on_or_after)
|
||||
if not_on_or_after < now:
|
||||
# To old ignore
|
||||
@@ -302,10 +303,12 @@ class Saml2Client(object):
|
||||
raise Exception("To old can't use it")
|
||||
|
||||
not_before = str_to_time(condition.not_before)
|
||||
log and log.info("not_before: %s" % time.mktime(not_before))
|
||||
if not_before > now:
|
||||
# Can't use it yet
|
||||
if not LAX:
|
||||
raise Exception("Can't use it yet")
|
||||
raise Exception("Can't use it yet %s <= %s" (
|
||||
time.mktime(not_before), time.mktime(now)))
|
||||
|
||||
if not for_me(condition, requestor):
|
||||
if not LAX:
|
||||
|
||||
@@ -203,5 +203,5 @@ def str_to_time(timestr):
|
||||
return then
|
||||
|
||||
def instant():
|
||||
return datetime.now().strftime(TIME_FORMAT)
|
||||
return datetime.utcnow().strftime(TIME_FORMAT)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import time
|
||||
from saml2.time_util import f_quotient, modulo, parse_duration, add_duration
|
||||
from saml2.time_util import str_to_time
|
||||
from saml2.time_util import str_to_time, instant
|
||||
|
||||
def test_f_quotient():
|
||||
assert f_quotient(-1,3) == -1
|
||||
@@ -63,4 +64,16 @@ def test_add_duration_2():
|
||||
assert t.tm_hour == 9
|
||||
assert t.tm_min == 0
|
||||
assert t.tm_sec == 0
|
||||
|
||||
def test_str_to_time():
|
||||
t = time.mktime(str_to_time("2000-01-12T00:00:00Z"))
|
||||
assert t == 947631600.0
|
||||
|
||||
def test_instant():
|
||||
inst = str_to_time(instant())
|
||||
print inst
|
||||
now = time.gmtime()
|
||||
print now
|
||||
|
||||
assert now >= inst
|
||||
|
||||
Reference in New Issue
Block a user