]>
git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests.dnsdist/test_CheckConfig.py
8 class TestCheckConfig(unittest
.TestCase
):
10 def tryDNSDist(self
, configTemplate
, shouldBeSuccessful
=True, delay
=1):
11 conffile
= 'dnsdist_test.conf'
12 with
open(conffile
, 'w') as conf
:
13 conf
.write("-- Autogenerated by dnsdisttests.py\n")
14 conf
.write(configTemplate
)
16 dnsdistcmd
= [os
.environ
['DNSDISTBIN'], '-C', conffile
, '--check-config']
18 with
open(os
.devnull
, 'w') as fdDevNull
:
19 dnsdist
= subprocess
.Popen(dnsdistcmd
, close_fds
=True, stdout
=fdDevNull
)
21 if dnsdist
.poll() is None:
23 self
.assertNotEqual(dnsdist
.poll(), None)
25 if shouldBeSuccessful
:
26 self
.assertEquals(dnsdist
.returncode
, 0)
28 self
.assertNotEqual(dnsdist
.returncode
, 0)
30 def testWorkingConfig(self
):
32 CheckConfig: Working configuration
35 newServer{address="127.0.0.1:53"}
38 addAction(RegexRule("evil[0-9]{4,}\\\\.regex\\\\.tests\\\\.powerdns\\\\.com$"), RCodeAction(5))
39 mySMN = newSuffixMatchNode()
40 mySMN:add(newDNSName("nameAndQtype.tests.powerdns.com."))
41 addAction(AndRule{SuffixMatchNodeRule(mySMN), QTypeRule("TXT")}, RCodeAction(4))
42 addAction(makeRule("drop.test.powerdns.com."), DropAction())
43 block=newDNSName("powerdns.org.")
44 function blockFilter(dq)
45 if(dq.qname:isPartOf(block))
47 print("Blocking *.powerdns.org")
54 self
.tryDNSDist(configTemplate
)
56 def testEmptyConfig(self
):
58 CheckConfig: Empty config
61 self
.tryDNSDist(configTemplate
)
63 def testInvalidFunction(self
):
65 CheckConfig: Invalid function
68 oldServer { address="127.0.0.1:55" }
70 self
.tryDNSDist(configTemplate
, False)
72 def testInvalidParam(self
):
74 CheckConfig: Invalid parameter
79 self
.tryDNSDist(configTemplate
, False)
81 def testSyntaxError(self
):
83 CheckConfig: Syntax error
85 configTemplate
= "blablabla"
86 self
.tryDNSDist(configTemplate
, False)