|
Server : LiteSpeed System : Linux srv526460274 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : kerao9884 ( 1082) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /usr/local/CyberCP/lib/python3.10/site-packages/CloudFlare/tests/ |
Upload File : |
""" certificates tests """
import os
import sys
import random
sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('..'))
import CloudFlare
# test /centificates - a weird call (will fail if you don't have a certtoken)
cf = None
def test_cloudflare(debug=False):
""" test_cloudflare """
global cf
cf = CloudFlare.CloudFlare(debug=debug)
assert isinstance(cf, CloudFlare.CloudFlare)
zone_name = None
zone_id = None
def test_find_zone(domain_name=None):
""" test_find_zone """
global zone_name, zone_id
# grab a random zone identifier from the first 10 zones
if domain_name:
params = {'per_page':1, 'name':domain_name}
else:
params = {'per_page':10}
try:
zones = cf.zones.get(params=params)
except CloudFlare.exceptions.CloudFlareAPIError as e:
print('%s: Error %d=%s' % (domain_name, int(e), str(e)), file=sys.stderr)
assert False
assert len(zones) > 0 and len(zones) <= 10
n = random.randrange(len(zones))
zone_name = zones[n]['name']
zone_id = zones[n]['id']
assert len(zone_id) == 32
print('zone: %s %s' % (zone_id, zone_name), file=sys.stderr)
def test_certificates():
""" test_certificates """
params = {'zone_id':zone_id}
try:
certificates = cf.certificates(params=params)
except CloudFlare.exceptions.CloudFlareAPIError as e:
print('%s: Error %d=%s - can not run this test on this domain - no worries - skipping' % (zone_name, int(e), str(e)), file=sys.stderr)
return
assert isinstance(certificates, list)
if len(certificates) == 0:
# no cert's for this domain - which is the norm
print('no cert(s) returned', file=sys.stderr)
return
for c in certificates:
assert isinstance(c, dict)
assert 'id' in c
assert 'expires_on' in c
assert 'hostnames' in c
assert 'certificate' in c
print('%s: %48s %29s %s' % (zone_name, c['id'], c['expires_on'], c['hostnames']), file=sys.stderr)
if __name__ == '__main__':
test_cloudflare(debug=True)
if len(sys.argv) > 1:
test_find_zone(sys.argv[1])
else:
test_find_zone()
test_certificates()