]>
Commit | Line | Data |
---|---|---|
5efcfa63 PL |
1 | #!/usr/bin/env python |
2 | import unittest | |
3 | import os | |
4 | import subprocess | |
5 | ||
6 | class TestCheckConfig(unittest.TestCase): | |
7 | ||
8 | def tryDNSDist(self, configTemplate, shouldBeSuccessful = True): | |
9 | conffile = 'dnsdist_test.conf' | |
10 | with open(conffile, 'w') as conf: | |
11 | conf.write("-- Autogenerated by dnsdisttests.py\n") | |
12 | conf.write(configTemplate) | |
13 | ||
14 | dnsdistcmd = [os.environ['DNSDISTBIN'], '-C', conffile, '--check-config'] | |
15 | ||
16 | with open(os.devnull, 'w') as fdDevNull: | |
17 | dnsdist = subprocess.Popen(dnsdistcmd, close_fds=True, stdout=fdDevNull) | |
18 | ||
19 | if dnsdist.poll() is not None: | |
20 | if dnsdist.returncode != 0 and not shouldBeSuccessful: | |
21 | sys.exit(1) | |
22 | sys.exit(0) | |
23 | ||
24 | def testWorkingConfig(self): | |
25 | configTemplate = """ | |
26 | newServer{address="127.0.0.1:53"} | |
27 | truncateTC(true) | |
28 | addAnyTCRule() | |
29 | addAction(RegexRule("evil[0-9]{4,}\\\\.regex\\\\.tests\\\\.powerdns\\\\.com$"), RCodeAction(5)) | |
30 | mySMN = newSuffixMatchNode() | |
31 | mySMN:add(newDNSName("nameAndQtype.tests.powerdns.com.")) | |
32 | addAction(AndRule{SuffixMatchNodeRule(mySMN), QTypeRule("TXT")}, RCodeAction(4)) | |
33 | addAction(makeRule("drop.test.powerdns.com."), DropAction()) | |
34 | block=newDNSName("powerdns.org.") | |
35 | function blockFilter(dq) | |
36 | if(dq.qname:isPartOf(block)) | |
37 | then | |
38 | print("Blocking *.powerdns.org") | |
39 | return true | |
40 | end | |
41 | return false | |
42 | end | |
43 | """ | |
44 | ||
45 | self.tryDNSDist(configTemplate) | |
46 | ||
47 | def testEmptyConfig(self): | |
48 | configTemplate = "" | |
49 | self.tryDNSDist(configTemplate) | |
50 | ||
51 | def testInvalidFunction(self): | |
52 | configTemplate = """ | |
53 | oldServer { address="127.0.0.1:55" } | |
54 | """ | |
55 | self.tryDNSDist(configTemplate, False) | |
56 | ||
57 | def testInvalidParam(self): | |
58 | configTemplate = """ | |
59 | newServer { address="127.0.0.355" } | |
60 | """ | |
61 | self.tryDNSDist(configTemplate, False) | |
62 | ||
63 | def testSyntaxError(self): | |
64 | configTemplate = "blablabla" | |
65 | self.tryDNSDist(configTemplate, False) |