]> git.ipfire.org Git - thirdparty/pdns.git/blame - regression-tests.dnsdist/test_CheckConfig.py
Merge pull request #7911 from rgacogne/dnsdist-doh-server-header
[thirdparty/pdns.git] / regression-tests.dnsdist / test_CheckConfig.py
CommitLineData
5efcfa63
PL
1#!/usr/bin/env python
2import unittest
3import os
4import subprocess
61b4aa90 5import time
5efcfa63
PL
6
7class TestCheckConfig(unittest.TestCase):
8
61b4aa90 9 def tryDNSDist(self, configTemplate, shouldBeSuccessful=True, delay=1):
5efcfa63
PL
10 conffile = 'dnsdist_test.conf'
11 with open(conffile, 'w') as conf:
12 conf.write("-- Autogenerated by dnsdisttests.py\n")
13 conf.write(configTemplate)
14
15 dnsdistcmd = [os.environ['DNSDISTBIN'], '-C', conffile, '--check-config']
16
17 with open(os.devnull, 'w') as fdDevNull:
18 dnsdist = subprocess.Popen(dnsdistcmd, close_fds=True, stdout=fdDevNull)
19
61b4aa90
RG
20 if dnsdist.poll() is None:
21 time.sleep(delay)
22 self.assertNotEqual(dnsdist.poll(), None)
23
24 if shouldBeSuccessful:
25 self.assertEquals(dnsdist.returncode, 0)
26 else:
27 self.assertNotEqual(dnsdist.returncode, 0)
5efcfa63
PL
28
29 def testWorkingConfig(self):
903853f4
RG
30 """
31 CheckConfig: Working configuration
32 """
5efcfa63
PL
33 configTemplate = """
34 newServer{address="127.0.0.1:53"}
35 truncateTC(true)
d3ec24f9
PD
36 addAction(AndRule{QTypeRule(DNSQType.ANY), TCPRule(false)}, TCAction())
37 addAction(RegexRule("evil[0-9]{4,}\\\\.regex\\\\.tests\\\\.powerdns\\\\.com$"), RCodeAction(DNSRCode.REFUSED))
5efcfa63
PL
38 mySMN = newSuffixMatchNode()
39 mySMN:add(newDNSName("nameAndQtype.tests.powerdns.com."))
d3ec24f9 40 addAction(AndRule{SuffixMatchNodeRule(mySMN), QTypeRule("TXT")}, RCodeAction(DNSRCode.NOTIMP))
5efcfa63 41 addAction(makeRule("drop.test.powerdns.com."), DropAction())
5efcfa63
PL
42 """
43
44 self.tryDNSDist(configTemplate)
45
46 def testEmptyConfig(self):
903853f4
RG
47 """
48 CheckConfig: Empty config
49 """
5efcfa63
PL
50 configTemplate = ""
51 self.tryDNSDist(configTemplate)
52
53 def testInvalidFunction(self):
903853f4
RG
54 """
55 CheckConfig: Invalid function
56 """
5efcfa63
PL
57 configTemplate = """
58 oldServer { address="127.0.0.1:55" }
59 """
60 self.tryDNSDist(configTemplate, False)
61
62 def testInvalidParam(self):
903853f4
RG
63 """
64 CheckConfig: Invalid parameter
65 """
5efcfa63 66 configTemplate = """
61b4aa90 67 addACL("127.0.0.355")
5efcfa63
PL
68 """
69 self.tryDNSDist(configTemplate, False)
70
71 def testSyntaxError(self):
903853f4
RG
72 """
73 CheckConfig: Syntax error
74 """
5efcfa63
PL
75 configTemplate = "blablabla"
76 self.tryDNSDist(configTemplate, False)