]> git.ipfire.org Git - thirdparty/pdns.git/blame - regression-tests.dnsdist/test_CheckConfig.py
dnsdist: Fix cache tests. Clean tests backends.
[thirdparty/pdns.git] / regression-tests.dnsdist / test_CheckConfig.py
CommitLineData
5efcfa63
PL
1#!/usr/bin/env python
2import unittest
3import os
4import subprocess
903853f4 5import sys
5efcfa63
PL
6
7class TestCheckConfig(unittest.TestCase):
8
fe1c60f2
RG
9 @staticmethod
10 def tryDNSDist(configTemplate, shouldBeSuccessful=True):
5efcfa63
PL
11 conffile = 'dnsdist_test.conf'
12 with open(conffile, 'w') as conf:
13 conf.write("-- Autogenerated by dnsdisttests.py\n")
14 conf.write(configTemplate)
15
16 dnsdistcmd = [os.environ['DNSDISTBIN'], '-C', conffile, '--check-config']
17
18 with open(os.devnull, 'w') as fdDevNull:
19 dnsdist = subprocess.Popen(dnsdistcmd, close_fds=True, stdout=fdDevNull)
20
21 if dnsdist.poll() is not None:
22 if dnsdist.returncode != 0 and not shouldBeSuccessful:
23 sys.exit(1)
24 sys.exit(0)
25
26 def testWorkingConfig(self):
903853f4
RG
27 """
28 CheckConfig: Working configuration
29 """
5efcfa63
PL
30 configTemplate = """
31 newServer{address="127.0.0.1:53"}
32 truncateTC(true)
33 addAnyTCRule()
34 addAction(RegexRule("evil[0-9]{4,}\\\\.regex\\\\.tests\\\\.powerdns\\\\.com$"), RCodeAction(5))
35 mySMN = newSuffixMatchNode()
36 mySMN:add(newDNSName("nameAndQtype.tests.powerdns.com."))
37 addAction(AndRule{SuffixMatchNodeRule(mySMN), QTypeRule("TXT")}, RCodeAction(4))
38 addAction(makeRule("drop.test.powerdns.com."), DropAction())
39 block=newDNSName("powerdns.org.")
40 function blockFilter(dq)
41 if(dq.qname:isPartOf(block))
42 then
43 print("Blocking *.powerdns.org")
44 return true
45 end
46 return false
47 end
48 """
49
50 self.tryDNSDist(configTemplate)
51
52 def testEmptyConfig(self):
903853f4
RG
53 """
54 CheckConfig: Empty config
55 """
5efcfa63
PL
56 configTemplate = ""
57 self.tryDNSDist(configTemplate)
58
59 def testInvalidFunction(self):
903853f4
RG
60 """
61 CheckConfig: Invalid function
62 """
5efcfa63
PL
63 configTemplate = """
64 oldServer { address="127.0.0.1:55" }
65 """
66 self.tryDNSDist(configTemplate, False)
67
68 def testInvalidParam(self):
903853f4
RG
69 """
70 CheckConfig: Invalid parameter
71 """
5efcfa63
PL
72 configTemplate = """
73 newServer { address="127.0.0.355" }
74 """
75 self.tryDNSDist(configTemplate, False)
76
77 def testSyntaxError(self):
903853f4
RG
78 """
79 CheckConfig: Syntax error
80 """
5efcfa63
PL
81 configTemplate = "blablabla"
82 self.tryDNSDist(configTemplate, False)