File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -1367,7 +1367,10 @@ def has_expired(self):
1367
1367
:return: ``True`` if the certificate has expired, ``False`` otherwise.
1368
1368
:rtype: bool
1369
1369
"""
1370
- time_string = self .get_notAfter ().decode ("utf-8" )
1370
+ time_string = self .get_notAfter ()
1371
+ if time_string is None :
1372
+ raise ValueError ("Unable to determine notAfter" )
1373
+ time_string = time_string .decode ("utf-8" )
1371
1374
not_after = datetime .datetime .strptime (time_string , "%Y%m%d%H%M%SZ" )
1372
1375
1373
1376
return not_after < datetime .datetime .utcnow ()
Original file line number Diff line number Diff line change @@ -1968,6 +1968,14 @@ def test_has_not_expired(self):
1968
1968
cert .gmtime_adj_notAfter (2 )
1969
1969
assert not cert .has_expired ()
1970
1970
1971
+ def test_has_expired_exception (self ):
1972
+ """
1973
+ `X509.has_expired` throws ValueError if not-after time is not set
1974
+ """
1975
+ cert = X509 ()
1976
+ with pytest .raises (ValueError ):
1977
+ cert .has_expired ()
1978
+
1971
1979
def test_root_has_not_expired (self ):
1972
1980
"""
1973
1981
`X509.has_expired` returns `False` if the certificate's not-after time
You can’t perform that action at this time.
0 commit comments