Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnsdist: Add a regression test rewriting the response code via Lua #14946

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions regression-tests.dnsdist/test_Responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,64 @@ def testCleared(self):
receivedQuery.id = query.id
self.assertEqual(query, receivedQuery)
self.assertEqual(expectedResponse, receivedResponse)

class TestResponseRewriteServFail(DNSDistTest):

_config_params = ['_testServerPort']
_config_template = """
newServer{address="127.0.0.1:%s"}

function rewriteServFail(dq)
if dq.rcode == DNSRCode.SERVFAIL then
dq.rcode = DNSRCode.NOERROR
return DNSResponseAction.HeaderModify
end
return DNSResponse.None
end
addResponseAction(AndRule({QTypeRule(DNSQType.AAAA),RCodeRule(DNSRCode.SERVFAIL)}), LuaResponseAction(rewriteServFail))
"""

def testRewriteServFail(self):
"""
Responses: Rewrite AAAA ServFails as NoError (don't ask)
"""
name = 'rewrite-servfail.responses.tests.powerdns.com.'

query = dns.message.make_query(name, 'AAAA', 'IN')
response = dns.message.make_response(query)
expectedResponse = dns.message.make_response(query)

response.set_rcode(dns.rcode.SERVFAIL)
expectedResponse.set_rcode(dns.rcode.NOERROR)

rrset = dns.rrset.from_text(name,
3660,
dns.rdataclass.IN,
dns.rdatatype.AAAA,
'2001:DB8::1', '2001:DB8::2')
response.answer.append(rrset)
expectedResponse.answer.append(rrset)

for method in ("sendUDPQuery", "sendTCPQuery"):
sender = getattr(self, method)
(receivedQuery, receivedResponse) = sender(query, response)
receivedQuery.id = query.id
self.assertEqual(query, receivedQuery)
self.assertEqual(expectedResponse, receivedResponse)

# but ServFail for a different type should stay the same
query = dns.message.make_query(name, 'A', 'IN')
response = dns.message.make_response(query)
response.set_rcode(dns.rcode.SERVFAIL)
rrset = dns.rrset.from_text(name,
3600,
dns.rdataclass.IN,
dns.rdatatype.A,
'192.0.2.1')
response.answer.append(rrset)
for method in ("sendUDPQuery", "sendTCPQuery"):
sender = getattr(self, method)
(receivedQuery, receivedResponse) = sender(query, response)
receivedQuery.id = query.id
self.assertEqual(query, receivedQuery)
self.assertEqual(response, receivedResponse)
Loading