"""
Set up a dnsdist instance and responder threads.
Queries sent to dnsdist are relayed to the responder threads,
"""
Set up a dnsdist instance and responder threads.
Queries sent to dnsdist are relayed to the responder threads,
output = subprocess.check_output(testcmd, stderr=subprocess.STDOUT, close_fds=True)
except subprocess.CalledProcessError as exc:
raise AssertionError('dnsdist --check-config failed (%d): %s' % (exc.returncode, exc.output))
output = subprocess.check_output(testcmd, stderr=subprocess.STDOUT, close_fds=True)
except subprocess.CalledProcessError as exc:
raise AssertionError('dnsdist --check-config failed (%d): %s' % (exc.returncode, exc.output))
- expectedOutput = ('Configuration \'%s\' OK!\n' % (confFile)).encode()
+ if cls._checkConfigExpectedOutput is not None:
+ expectedOutput = cls._checkConfigExpectedOutput
+ else:
+ expectedOutput = ('Configuration \'%s\' OK!\n' % (confFile)).encode()
- def UDPResponder(cls, port, fromQueue, toQueue, trailingDataResponse=False):
+ def UDPResponder(cls, port, fromQueue, toQueue, trailingDataResponse=False, callback=None):
# trailingDataResponse=True means "ignore trailing data".
# Other values are either False (meaning "raise an exception")
# or are interpreted as a response RCODE for queries with trailing data.
# trailingDataResponse=True means "ignore trailing data".
# Other values are either False (meaning "raise an exception")
# or are interpreted as a response RCODE for queries with trailing data.
ignoreTrailing = trailingDataResponse is True
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ignoreTrailing = trailingDataResponse is True
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
request = dns.message.from_wire(data, ignore_trailing=True)
forceRcode = trailingDataResponse
request = dns.message.from_wire(data, ignore_trailing=True)
forceRcode = trailingDataResponse
- response = cls._getResponse(request, fromQueue, toQueue, synthesize=forceRcode)
- if not response:
- continue
+ wire = None
+ if callback:
+ wire = callback(request)
+ else:
+ response = cls._getResponse(request, fromQueue, toQueue, synthesize=forceRcode)
+ if response:
+ wire = response.to_wire()
+
+ if not wire:
+ continue
- def TCPResponder(cls, port, fromQueue, toQueue, trailingDataResponse=False, multipleResponses=False):
+ def TCPResponder(cls, port, fromQueue, toQueue, trailingDataResponse=False, multipleResponses=False, callback=None):
# trailingDataResponse=True means "ignore trailing data".
# Other values are either False (meaning "raise an exception")
# or are interpreted as a response RCODE for queries with trailing data.
# trailingDataResponse=True means "ignore trailing data".
# Other values are either False (meaning "raise an exception")
# or are interpreted as a response RCODE for queries with trailing data.
ignoreTrailing = trailingDataResponse is True
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ignoreTrailing = trailingDataResponse is True
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
request = dns.message.from_wire(data, ignore_trailing=True)
forceRcode = trailingDataResponse
request = dns.message.from_wire(data, ignore_trailing=True)
forceRcode = trailingDataResponse
- response = cls._getResponse(request, fromQueue, toQueue, synthesize=forceRcode)
- if not response:
+ if callback:
+ wire = callback(request)
+ else:
+ response = cls._getResponse(request, fromQueue, toQueue, synthesize=forceRcode)
+ if response:
+ wire = response.to_wire(max_size=65535)
+
+ if not wire:
if withCookies:
for option in received.options:
self.assertEquals(option.otype, 10)
if withCookies:
for option in received.options:
self.assertEquals(option.otype, 10)
def checkMessageEDNSWithECS(self, expected, received, additionalOptions=0):
self.assertEquals(expected, received)
def checkMessageEDNSWithECS(self, expected, received, additionalOptions=0):
self.assertEquals(expected, received)
def checkResponseNoEDNS(self, expected, received):
self.checkMessageNoEDNS(expected, received)
def checkResponseNoEDNS(self, expected, received):
self.checkMessageNoEDNS(expected, received)