]>
git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests.dnsdist/test_TeeAction.py
5 import clientsubnetoption
7 from dnsdisttests
import DNSDistTest
9 class TestTeeAction(DNSDistTest
):
11 _consoleKey
= DNSDistTest
.generateConsoleKey()
12 _consoleKeyB64
= base64
.b64encode(_consoleKey
)
14 _toTeeQueue
= Queue
.Queue()
15 _fromTeeQueue
= Queue
.Queue()
16 _config_template
= """
18 controlSocket("127.0.0.1:%s")
19 newServer{address="127.0.0.1:%d"}
20 addAction(QTypeRule(dnsdist.A), TeeAction("127.0.0.1:%d", true))
21 addAction(QTypeRule(dnsdist.AAAA), TeeAction("127.0.0.1:%d", false))
23 _config_params
= ['_consoleKeyB64', '_consolePort', '_testServerPort', '_teeServerPort', '_teeServerPort']
25 def startResponders(cls
):
26 print("Launching responders..")
28 cls
._UDPResponder
= threading
.Thread(name
='UDP Responder', target
=cls
.UDPResponder
, args
=[cls
._testServerPort
, cls
._toResponderQueue
, cls
._fromResponderQueue
])
29 cls
._UDPResponder
.setDaemon(True)
30 cls
._UDPResponder
.start()
32 cls
._TCPResponder
= threading
.Thread(name
='TCP Responder', target
=cls
.TCPResponder
, args
=[cls
._testServerPort
, cls
._toResponderQueue
, cls
._fromResponderQueue
, False, True])
33 cls
._TCPResponder
.setDaemon(True)
34 cls
._TCPResponder
.start()
36 cls
._TeeResponder
= threading
.Thread(name
='Tee Responder', target
=cls
.UDPResponder
, args
=[cls
._teeServerPort
, cls
._toTeeQueue
, cls
._fromTeeQueue
])
37 cls
._TeeResponder
.setDaemon(True)
38 cls
._TeeResponder
.start()
40 def testTeeWithECS(self
):
44 name
= 'ecs.tee.tests.powerdns.com.'
45 query
= dns
.message
.make_query(name
, 'A', 'IN')
46 response
= dns
.message
.make_response(query
)
48 rrset
= dns
.rrset
.from_text(name
,
53 response
.answer
.append(rrset
)
56 for _
in range(numberOfQueries
):
57 # push the response to the Tee server
58 self
._toTeeQueue
.put(response
, True, 2.0)
60 (receivedQuery
, receivedResponse
) = self
.sendUDPQuery(query
, response
)
61 self
.assertTrue(receivedQuery
)
62 self
.assertTrue(receivedResponse
)
63 receivedQuery
.id = query
.id
64 self
.assertEquals(query
, receivedQuery
)
65 self
.assertEquals(response
, receivedResponse
)
67 # retrieve the query from the Tee server
68 teedQuery
= self
._fromTeeQueue
.get(True, 2.0)
69 ecso
= clientsubnetoption
.ClientSubnetOption('127.0.0.1', 24)
70 expectedQuery
= dns
.message
.make_query(name
, 'A', 'IN', use_edns
=True, options
=[ecso
], payload
=512)
71 expectedQuery
.id = query
.id
72 self
.checkQueryEDNSWithECS(expectedQuery
, teedQuery
)
74 # check the TeeAction stats
75 stats
= self
.sendConsoleCommand("getAction(0):printStats()")
76 self
.assertEquals(stats
, """refuseds\t0
86 """ % (numberOfQueries
, numberOfQueries
, numberOfQueries
))
88 def testTeeWithoutECS(self
):
92 name
= 'noecs.tee.tests.powerdns.com.'
93 query
= dns
.message
.make_query(name
, 'AAAA', 'IN')
94 response
= dns
.message
.make_response(query
)
96 rrset
= dns
.rrset
.from_text(name
,
101 response
.answer
.append(rrset
)
104 for _
in range(numberOfQueries
):
105 # push the response to the Tee server
106 self
._toTeeQueue
.put(response
, True, 2.0)
108 (receivedQuery
, receivedResponse
) = self
.sendUDPQuery(query
, response
)
109 self
.assertTrue(receivedQuery
)
110 self
.assertTrue(receivedResponse
)
111 receivedQuery
.id = query
.id
112 self
.assertEquals(query
, receivedQuery
)
113 self
.assertEquals(response
, receivedResponse
)
115 # retrieve the query from the Tee server
116 teedQuery
= self
._fromTeeQueue
.get(True, 2.0)
117 ecso
= clientsubnetoption
.ClientSubnetOption('127.0.0.1', 24)
118 expectedQuery
= dns
.message
.make_query(name
, 'AAAA', 'IN', use_edns
=True, options
=[ecso
], payload
=512)
119 expectedQuery
.id = query
.id
120 self
.checkMessageNoEDNS(expectedQuery
, teedQuery
)
122 # check the TeeAction stats
123 stats
= self
.sendConsoleCommand("getAction(0):printStats()")
124 self
.assertEquals(stats
, """refuseds\t0
134 """ % (numberOfQueries
, numberOfQueries
, numberOfQueries
))