commit 528fc89935ed0c3c0c322263b0c33dca5ba6dbcd Author: Arturo Filastò art@fuffa.org Date: Tue Dec 25 00:58:33 2012 +0100
Fix major bug in DNS test template that prevented PTR lookups from working properly I was calling the queryUDP function with the arguments in the wrong order. Twisted, why you API no consistent? * Misc refactoring for better formatting of results in the report --- ooni/templates/dnst.py | 34 ++++++++++++++++++++++++---------- 1 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/ooni/templates/dnst.py b/ooni/templates/dnst.py index ece1ff4..08d660a 100644 --- a/ooni/templates/dnst.py +++ b/ooni/templates/dnst.py @@ -14,6 +14,12 @@ from ooni.utils import log from ooni.nettest import NetTestCase, failureToString from socket import gaierror
+ +def representAnswer(answer): + # We store the resource record and the answer payload in a + # tuple + return (repr(answer), repr(answer.payload)) + class DNSTest(NetTestCase): name = "Base DNS Test" version = 0.1 @@ -34,18 +40,24 @@ class DNSTest(NetTestCase): tuple of ip port (ex. ("127.0.0.1", 53)) """ ptr = '.'.join(address.split('.')[::-1]) + '.in-addr.arpa' - query = [dns.Query(ptr, dns.IN, dns.PTR)] + query = [dns.Query(ptr, dns.PTR, dns.IN)] def gotResponse(message): + log.debug("Lookup successful") + log.debug(message) answers = [] - name = None + name = '' for answer in message.answers: if answer.type is 12: - name = answer.payload.name + name = str(answer.payload.name) + answers.append(representAnswer(answer)) + self.addToReport(query, resolver=dns_server, query_type = 'PTR', answers=answers, name=name) return name
def gotError(failure): + log.err("Failed to perform lookup") + log.exception(failure) failure.trap(gaierror, TimeoutError) self.addToReport(query, resolver=dns_server, query_type = 'PTR', failure=failure) @@ -67,7 +79,7 @@ class DNSTest(NetTestCase): :dns_server: is the dns_server that should be used for the lookup as a tuple of ip port (ex. ("127.0.0.1", 53)) """ - query = [dns.Query(hostname, dns.IN, dns.A)] + query = [dns.Query(hostname, dns.A, dns.IN)] def gotResponse(message): addrs = [] answers = [] @@ -75,10 +87,8 @@ class DNSTest(NetTestCase): if answer.type is 1: addr = answer.payload.dottedQuad() addrs.append(addr) - # We store the resource record and the answer payload in a - # tuple - r = (repr(answer), repr(answer.payload)) - answers.append(r) + answers.append(representAnswer(answer)) + self.addToReport(query, resolver=dns_server, query_type='A', answers=answers, addrs=addrs) return addrs @@ -104,8 +114,12 @@ class DNSTest(NetTestCase): result['query'] = repr(query) if failure: result['failure'] = failureToString(failure) + if answers: result['answers'] = answers - if name: result['name'] = name - if addrs: result['addrs'] = addrs + if name: + result['name'] = name + if addrs: + result['addrs'] = addrs + self.report['queries'].append(result)
tor-commits@lists.torproject.org