]> git.ipfire.org Git - thirdparty/pdns.git/blame - regression-tests.dnsdist/test_CheckConfig.py
Merge pull request #8795 from omoerbeek/rec-lua-docs-policytag
[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."))
41ff82c9
PL
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")})
d3ec24f9 44 addAction(AndRule{SuffixMatchNodeRule(mySMN), QTypeRule("TXT")}, RCodeAction(DNSRCode.NOTIMP))
5efcfa63 45 addAction(makeRule("drop.test.powerdns.com."), DropAction())
5efcfa63
PL
46 """
47
48 self.tryDNSDist(configTemplate)
49
50 def testEmptyConfig(self):
903853f4
RG
51 """
52 CheckConfig: Empty config
53 """
5efcfa63
PL
54 configTemplate = ""
55 self.tryDNSDist(configTemplate)
56
57 def testInvalidFunction(self):
903853f4
RG
58 """
59 CheckConfig: Invalid function
60 """
5efcfa63
PL
61 configTemplate = """
62 oldServer { address="127.0.0.1:55" }
63 """
64 self.tryDNSDist(configTemplate, False)
65
66 def testInvalidParam(self):
903853f4
RG
67 """
68 CheckConfig: Invalid parameter
69 """
5efcfa63 70 configTemplate = """
61b4aa90 71 addACL("127.0.0.355")
5efcfa63
PL
72 """
73 self.tryDNSDist(configTemplate, False)
74
75 def testSyntaxError(self):
903853f4
RG
76 """
77 CheckConfig: Syntax error
78 """
5efcfa63
PL
79 configTemplate = "blablabla"
80 self.tryDNSDist(configTemplate, False)