MCPcopy Index your code
hub / github.com/python/cpython / test_cert_time_to_seconds

Method test_cert_time_to_seconds

Lib/test/test_ssl.py:916–949  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

914 self.cert_time_ok("Jan 5 09:34:43 2018 GMT", 1515144883.0)
915
916 def test_cert_time_to_seconds(self):
917 timestring = "Jan 5 09:34:43 2018 GMT"
918 ts = 1515144883.0
919 self.cert_time_ok(timestring, ts)
920 # accept keyword parameter, assert its name
921 self.assertEqual(ssl.cert_time_to_seconds(cert_time=timestring), ts)
922 # accept both %e and %d (space or zero generated by strftime)
923 self.cert_time_ok("Jan 05 09:34:43 2018 GMT", ts)
924 # case-insensitive
925 self.cert_time_ok("JaN 5 09:34:43 2018 GmT", ts)
926 self.cert_time_fail("Jan 5 09:34 2018 GMT") # no seconds
927 self.cert_time_fail("Jan 5 09:34:43 2018") # no GMT
928 self.cert_time_fail("Jan 5 09:34:43 2018 UTC") # not GMT timezone
929 self.cert_time_fail("Jan 35 09:34:43 2018 GMT") # invalid day
930 self.cert_time_fail("Jon 5 09:34:43 2018 GMT") # invalid month
931 self.cert_time_fail("Jan 5 24:00:00 2018 GMT") # invalid hour
932 self.cert_time_fail("Jan 5 09:60:43 2018 GMT") # invalid minute
933
934 newyear_ts = 1230768000.0
935 # leap seconds
936 self.cert_time_ok("Dec 31 23:59:60 2008 GMT", newyear_ts)
937 # same timestamp
938 self.cert_time_ok("Jan 1 00:00:00 2009 GMT", newyear_ts)
939
940 self.cert_time_ok("Jan 5 09:34:59 2018 GMT", 1515144899)
941 # allow 60th second (even if it is not a leap second)
942 self.cert_time_ok("Jan 5 09:34:60 2018 GMT", 1515144900)
943 # allow 2nd leap second for compatibility with time.strptime()
944 self.cert_time_ok("Jan 5 09:34:61 2018 GMT", 1515144901)
945 self.cert_time_fail("Jan 5 09:34:62 2018 GMT") # invalid seconds
946
947 # no special treatment for the special value:
948 # 99991231235959Z (rfc 5280)
949 self.cert_time_ok("Dec 31 23:59:59 9999 GMT", 253402300799.0)
950
951 @support.run_with_locale('LC_ALL', '')
952 def test_cert_time_to_seconds_locale(self):

Callers

nothing calls this directly

Calls 3

cert_time_okMethod · 0.95
cert_time_failMethod · 0.95
assertEqualMethod · 0.45

Tested by

no test coverage detected