def test_add_duration_2(): # 2000-01-12 PT33H 2000-01-13 t = add_duration(str_to_time("2000-01-12T00:00:00Z"), "PT33H") assert t.tm_year == 2000 assert t.tm_mon == 1 assert t.tm_mday == 14 assert t.tm_hour == 9 assert t.tm_min == 0 assert t.tm_sec == 0
def test_add_duration_1(): # 2000-01-12T12:13:14Z P1Y3M5DT7H10M3S 2001-04-17T19:23:17Z t = add_duration(str_to_time("2000-01-12T12:13:14Z"), "P1Y3M5DT7H10M3S") assert t.tm_year == 2001 assert t.tm_mon == 4 assert t.tm_mday == 17 assert t.tm_hour == 19 assert t.tm_min == 23 assert t.tm_sec == 17
def id_token(self, released_claims, idp_entity_id, transaction_id, transaction_session): """Make a JWT encoded id token and pass it to the redirect URI. :param released_claims: dictionary containing the following user_id: identifier for the user (as delivered by the IdP, dependent on whether transient or persistent id was requested) auth_time: time of the authentication reported from the IdP idp_entity_id: entity id of the selected IdP :param transaction_id: :return: raises cherrypy.HTTPRedirect. """ identifier = released_claims["Identifier"] auth_time = released_claims["Authentication time"] # have to convert text representation into seconds since epoch _time = time.mktime(str_to_time(auth_time)) # construct the OIDC response transaction_session["sub"] = identifier extra_claims = {k.lower(): released_claims[k] for k in ["Country", "Domain"] if k in released_claims} _jwt = self.OP.id_token_as_signed_jwt(transaction_session, loa="", auth_time=_time, exp={"minutes": 30}, extra_claims=extra_claims) _elapsed_transaction_time = get_timestamp() - transaction_session["start_time"] log_transaction_complete(logger, cherrypy.request, transaction_id, transaction_session["client_id"], idp_entity_id, _time, _elapsed_transaction_time, extra_claims, _jwt) try: _state = transaction_session["state"] except KeyError: _state = None authzresp = AuthorizationResponse(state=_state, id_token=_jwt) if "redirect_uri" in transaction_session: _ruri = transaction_session["redirect_uri"] else: _error_msg = _("We could not complete your validation because an error occurred while " "handling your request. Please return to the service which initiated the " "validation request and try again.") try: cinfo = self.OP.cdb[transaction_session["client_id"]] _ruri = cinfo["redirect_uris"][0] except KeyError as e: abort_with_enduser_error(transaction_id, transaction_session["client_id"], cherrypy.request, logger, _error_msg, "Unknown RP client id '{}': '{}'.".format(transaction_session["client_id"], str(e))) location = authzresp.request(_ruri, True) logger.debug("Redirected to: '{}' ({})".format(location, type(location))) raise cherrypy.HTTPRedirect(location)
def test_add_duration_3(): # 2000-01-12 PT33H 2000-01-13 t = add_duration(str_to_time("2000-01-12T00:00:00Z"), "P32D") assert t.tm_year == 2000 assert t.tm_mon == 2 assert t.tm_mday == 12 assert t.tm_hour == 0 assert t.tm_min == 0 assert t.tm_sec == 0 assert t.tm_wday == 5 assert t.tm_wday == 5 assert t.tm_yday == 43 assert t.tm_isdst == 0
def test_str_to_time(): t = calendar.timegm(str_to_time("2000-01-12T00:00:00Z")) assert t == 947635200
def test_str_to_time_str_error(): with pytest.raises(TimeUtilError): str_to_time("2000-01-12T00:00:00ZABC")
def test_str_to_time_str_error(): with pytest.raises(AttributeError): str_to_time("2000-01-12T00:00:00ZABC")
def test_str_to_time_1(): t = str_to_time("") assert t == 0
def test_instant(): inst = str_to_time(instant()) now = time.gmtime() assert now >= inst
def test_a_while_ago(): dt = time.mktime(time.gmtime()) then = a_while_ago(seconds=10) t = time.mktime(str_to_time(then)) delta = dt - t # slightly less than 10 assert 9 <= delta <= 10
def test_add_duration_4(): # 2000-01-12 PT33H 2000-01-13 t = add_duration(str_to_time("2000-01-12T00:00:00Z"), "-P32D") assert t is None
def test_a_while_ago(): dt = time.mktime(time.gmtime()) then = a_while_ago(seconds=10) t = time.mktime(str_to_time(then)) delta = dt - t # slightly less than 10 assert delta == 10