]> git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests.dnsdist/test_CheckConfig.py
Merge pull request #8474 from omoerbeek/auth-fix-logging-no-cache
[thirdparty/pdns.git] / regression-tests.dnsdist / test_CheckConfig.py
1 #!/usr/bin/env python
2 import unittest
3 import os
4 import subprocess
5 import time
6
7 class TestCheckConfig(unittest.TestCase):
8
9 def tryDNSDist(self, configTemplate, shouldBeSuccessful=True, delay=1):
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
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)
28
29 def testWorkingConfig(self):
30 """
31 CheckConfig: Working configuration
32 """
33 configTemplate = """
34 newServer{address="127.0.0.1:53"}
35 truncateTC(true)
36 addAction(AndRule{QTypeRule(DNSQType.ANY), TCPRule(false)}, TCAction())
37 addAction(RegexRule("evil[0-9]{4,}\\\\.regex\\\\.tests\\\\.powerdns\\\\.com$"), RCodeAction(DNSRCode.REFUSED))
38 mySMN = newSuffixMatchNode()
39 mySMN:add(newDNSName("nameAndQtype.tests.powerdns.com."))
40 mySMN:add("string.smn.tests.powerdns.com.")
41 mySMN:add("string-no-dot.smn.tests.powerdns.com")
42 mySMN:add({"string-one.smn.tests.powerdns.com", "string-two.smn.tests.powerdns.com"})
43 mySMN:add({newDNSName("dnsname-one.smn.tests.powerdns.com"), newDNSName("dnsname-two.smn.tests.powerdns.com")})
44 addAction(AndRule{SuffixMatchNodeRule(mySMN), QTypeRule("TXT")}, RCodeAction(DNSRCode.NOTIMP))
45 addAction(makeRule("drop.test.powerdns.com."), DropAction())
46 """
47
48 self.tryDNSDist(configTemplate)
49
50 def testEmptyConfig(self):
51 """
52 CheckConfig: Empty config
53 """
54 configTemplate = ""
55 self.tryDNSDist(configTemplate)
56
57 def testInvalidFunction(self):
58 """
59 CheckConfig: Invalid function
60 """
61 configTemplate = """
62 oldServer { address="127.0.0.1:55" }
63 """
64 self.tryDNSDist(configTemplate, False)
65
66 def testInvalidParam(self):
67 """
68 CheckConfig: Invalid parameter
69 """
70 configTemplate = """
71 addACL("127.0.0.355")
72 """
73 self.tryDNSDist(configTemplate, False)
74
75 def testSyntaxError(self):
76 """
77 CheckConfig: Syntax error
78 """
79 configTemplate = "blablabla"
80 self.tryDNSDist(configTemplate, False)