def test_fuzzyExpires_lt_day(): """It returns 2 hours 20 minutes and some seconds.""" ts = int(time.time()) ts += (3600 * 2) + (60 * 20) dt = datetime.datetime.fromtimestamp(ts) gotts, gotstr = UT.fuzzyExpires(dt) assert gotstr.startswith("2 hours 20 minutes")
def test_fuzzyExpires_lt_month(): """It returns 23 days and some hours.""" ts = int(time.time()) ts += 86400 * 23 dt = datetime.datetime.fromtimestamp(ts) gotts, gotstr = UT.fuzzyExpires(dt) assert gotstr.startswith("23 days")
def test_fuzzyExpires_gt_month(): """It returns 1 month and some days.""" ts = int(time.time()) ts += 86400 * 33 dt = datetime.datetime.fromtimestamp(ts) gotts, gotstr = UT.fuzzyExpires(dt) assert gotstr.startswith("1 month")
def test_fuzzyExpires_gt_year(): """It returns 1 year and 2 months.""" ts = int(time.time()) ts += (86400 * 365) + (86400 * 70) expstr = "1 year 2 months" dt = datetime.datetime.fromtimestamp(ts) gotts, gotstr = UT.fuzzyExpires(dt) assert gotstr == expstr
def test_fuzzyExpires_Expired(): """It returns the string 'EXPIRED'.""" dt = datetime.datetime(year=2020, month=3, day=6, hour=16, minute=19, second=12) expts = 1583511552 expstr = "EXPIRED" gotts, gotstr = UT.fuzzyExpires(dt) assert expstr == gotstr and expts == gotts
def _setupTCert(self, arn, cert): tcert = None isemail = False if len(cert) > 0: # print("{}".format(cert)) tcert = {"arn": arn} tcert["inuse"] = [] if "InUseBy" in cert: tcert["inuse"] = cert["InUseBy"] if "NotAfter" in cert: tcert["expirests"], tcert["expires"] = UT.fuzzyExpires( cert["NotAfter"]) else: tcert["expirests"] = 0 tcert["expires"] = "" tcert["domain"] = cert["DomainName"] tcert["altdomains"] = cert["SubjectAlternativeNames"] vopt = [] tcert["status"] = "unknown" for opt in cert["DomainValidationOptions"]: tcert["validation"] = None try: if "ValidationMethod" in opt: tcert["validation"] = opt["ValidationMethod"] if tcert["validation"] == "EMAIL": isemail = True if "ValidationStatus" in opt: tcert["status"] = opt["ValidationStatus"] xval = { "domain": opt["DomainName"], "validationdomain": opt["ValidationDomain"], } vopt.append(xval) except KeyError: continue tcert["validations"] = vopt return (isemail, tcert)