Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 068751c

Browse files
committed
Added more iat/exp tests.
1 parent 2a9a8e8 commit 068751c

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/oidcmsg/oidc/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,11 @@ def verify(self, **kwargs):
824824
else:
825825
if (_iat + _storage_time) < (_now - _skew):
826826
raise IATError('Issued too long ago')
827+
elif _iat > _now + _skew:
828+
raise IATError('Issued sometime in the future')
829+
830+
if _exp < _iat:
831+
raise IATError('Expiration time can not be earlier the issued at')
827832

828833
if 'nonce' in kwargs and 'nonce' in self:
829834
if kwargs['nonce'] != self['nonce']:

tests/test_06_oidc.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from oidcmsg.exception import OidcMsgError
2424
from oidcmsg.oauth2 import ResponseMessage
2525
from oidcmsg.oauth2 import ROPCAccessTokenRequest
26+
from oidcmsg.oidc import EXPError
27+
from oidcmsg.oidc import IATError
2628
from oidcmsg.oidc import JRD
2729
from oidcmsg.oidc import AccessTokenRequest
2830
from oidcmsg.oidc import AccessTokenResponse
@@ -929,6 +931,68 @@ def test_id_token():
929931
idt.verify()
930932

931933

934+
def test_id_token_expired():
935+
_now = time_util.utc_time_sans_frac()
936+
937+
idt = IdToken(**{
938+
"sub": "553df2bcf909104751cfd8b2",
939+
"aud": [
940+
"5542958437706128204e0000",
941+
"554295ce3770612820620000"
942+
],
943+
"auth_time": 1441364872,
944+
"azp": "554295ce3770612820620000",
945+
"at_hash": "L4Ign7TCAD_EppRbHAuCyw",
946+
"iat": _now - 200,
947+
"exp": _now - 100,
948+
"iss": "https://sso.qa.7pass.ctf.prosiebensat1.com"
949+
})
950+
951+
with pytest.raises(EXPError):
952+
idt.verify()
953+
954+
955+
def test_id_token_iat_in_the_future():
956+
_now = time_util.utc_time_sans_frac()
957+
958+
idt = IdToken(**{
959+
"sub": "553df2bcf909104751cfd8b2",
960+
"aud": [
961+
"5542958437706128204e0000",
962+
"554295ce3770612820620000"
963+
],
964+
"auth_time": 1441364872,
965+
"azp": "554295ce3770612820620000",
966+
"at_hash": "L4Ign7TCAD_EppRbHAuCyw",
967+
"iat": _now + 600,
968+
"exp": _now + 1200,
969+
"iss": "https://sso.qa.7pass.ctf.prosiebensat1.com"
970+
})
971+
972+
with pytest.raises(IATError):
973+
idt.verify()
974+
975+
976+
def test_id_token_exp_before_iat():
977+
_now = time_util.utc_time_sans_frac()
978+
979+
idt = IdToken(**{
980+
"sub": "553df2bcf909104751cfd8b2",
981+
"aud": [
982+
"5542958437706128204e0000",
983+
"554295ce3770612820620000"
984+
],
985+
"auth_time": 1441364872,
986+
"azp": "554295ce3770612820620000",
987+
"at_hash": "L4Ign7TCAD_EppRbHAuCyw",
988+
"iat": _now + 50,
989+
"exp": _now,
990+
"iss": "https://sso.qa.7pass.ctf.prosiebensat1.com"
991+
})
992+
993+
with pytest.raises(IATError):
994+
idt.verify(skew=100)
995+
932996
class TestAccessTokenRequest(object):
933997
def test_example(self):
934998
_txt = 'grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA' \

0 commit comments

Comments
 (0)