Many more tests added

master
Stephane Bortzmeyer 3 years ago
parent 6773e12737
commit dca841efa9
  1. 82
      test_service.py

@ -17,6 +17,9 @@ formats = {'': 'text/html; charset=UTF-8', # Default
'JSON': 'application/json',
'XML': 'application/xml'}
# TODO for the XML and (X)HTML outputs, test the validity (or at least
# the well-formedness) of the XML
def fstring(f, add=False):
if f is None or f == '':
return ''
@ -42,7 +45,9 @@ def test_notexist():
r = requests.get(PREFIX + 'doesnotexistatall')
assert r.status_code == 404 and 'does not exist' in r.text
# TODO test unknown format
def test_unknown_format():
r = requests.get(PREFIX + 'icann.org/?format=XXXX')
assert r.status_code == 400 and 'Unsupported format "XXXX"' in r.text
def test_defaulttype(): # ADDR by default
for format in formats:
@ -112,13 +117,41 @@ def test_srv():
assert r.status_code == 200 and r.headers['content-type'] == formats[format] and \
'sipfed.online.lync.com' in r.text, 'format is %s' % format
def test_ds():
for format in formats:
r = requests.get(PREFIX + 'cyberstructure.fr/DS%s' % fstring(format))
assert r.status_code == 200 and r.headers['content-type'] == formats[format] and \
((format == 'ZONE' and 'DS' in r.text) or
(format == 'TXT' and 'Delegation of signature:' in r.text) or
(format == 'JSON' and '"Type": "DS"' in r.text) or
(format == 'XML' and '<RRSet type="DS"' in r.text ) or
('Secure Delegation:' in r.text)), 'format is %s' % format
def test_nsec3param():
for format in formats:
r = requests.get(PREFIX + 'pm/NSEC3PARAM%s' % fstring(format))
assert r.status_code == 200 and r.headers['content-type'].startswith(formats[format]) and \
((format == 'ZONE' and 'NSEC3PARAM' in r.text) or
(format == 'TXT' and 'NSEC3PARAM:' in r.text) or
(format == 'JSON' and '"Iterations": 1' in r.text) or
(format == 'XML') or # Nothing in the XML output?
('NSEC3 parameters:' in r.text)), 'format is %s' % format
def test_uri():
for format in formats:
r = requests.get(PREFIX + '78000.cp.bortzmeyer.fr/URI%s' % fstring(format))
assert r.status_code == 200 and r.headers['content-type'] == formats[format] and \
'https://www.openstreetmap.org/' in r.text, 'format is %s' % format
# TODO an unformatted QTYPE such as TLSA
# Once #40 is done, we'll have to use another type
def test_unformatted_type():
for format in formats:
r = requests.get(PREFIX + '_443._tcp.doh.bortzmeyer.fr/TLSA%s' % fstring(format))
assert r.status_code == 200 and r.headers['content-type'] == formats[format] and \
((format == 'ZONE' and 'TYPE52' in r.text) or
(format == 'JSON' and '"Type": "unknown 52"' in r.text) or
(format == 'XML' and '<binaryRR rtype="52"' in r.text) or
('Unknown record type' in r.text)), 'format is %s' % format
def test_rev_v4():
for format in formats:
@ -142,11 +175,50 @@ def test_dnssec():
(format == 'XML' and '<ad>1</ad>' in r.text) or
('Authentic data' in r.text)), 'format is %s' % format
# TODO other options (tcp, server, edns), for all formats
def test_tcp():
for format in formats:
r = requests.get(PREFIX + 'fr.wikipedia.org/A?tcp=1%s' % fstring(format, add=True))
assert r.status_code == 200 and r.headers['content-type'] == formats[format]
def test_bufsize():
for format in formats:
r = requests.get(PREFIX + 'fr.wikipedia.org/A?buffersize=512%s' % fstring(format, add=True))
assert r.status_code == 200 and r.headers['content-type'] == formats[format]
def test_both():
for format in formats:
r = requests.get(PREFIX + 'fr.wikipedia.org/A?tcp=1&buffersize=1024%s' % fstring(format, add=True))
assert r.status_code == 200 and r.headers['content-type'] == formats[format]
# TODO CNAME and DNAME types
# TODO the root
# TODO other resolver
# TODO other classes
# TODO test several options together
# TODO broken DNSSEC domains
# TODO non-existing QTYPE
# TODO special characters
# TODO other methods than GET
def test_no_such_qtype():
for format in formats:
r = requests.get(PREFIX + 'gouvernement.fr/XXXX%s' % fstring(format))
assert r.status_code == 400 and r.headers['content-type'].startswith('text/plain') and \
'Record type XXXX does not exist\n' == r.text, 'format is %s' % format
def test_nodata():
for format in formats:
r = requests.get(PREFIX + 'com/AAAA%s' % fstring(format))
assert r.status_code == 200 and r.headers['content-type'] == formats[format] and \
((format == 'TXT') or
(format == 'ZONE') or
(format == 'JSON' and '"AnswerSection": []' in r.text) or
(format == 'XML') or
('No data was found' in r.text)), 'format is %s' % format
def test_idn():
for format in formats:

Loading…
Cancel
Save