]>
git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests.dnsdist/test_CheckConfig.py
7 class TestCheckConfig(unittest
.TestCase
):
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
)
15 dnsdistcmd
= [os
.environ
['DNSDISTBIN'], '-C', conffile
, '--check-config']
17 with
open(os
.devnull
, 'w') as fdDevNull
:
18 dnsdist
= subprocess
.Popen(dnsdistcmd
, close_fds
=True, stdout
=fdDevNull
)
20 if dnsdist
.poll() is None:
22 self
.assertNotEqual(dnsdist
.poll(), None)
24 if shouldBeSuccessful
:
25 self
.assertEquals(dnsdist
.returncode
, 0)
27 self
.assertNotEqual(dnsdist
.returncode
, 0)
29 def testWorkingConfig(self
):
31 CheckConfig: Working configuration
34 newServer{address="127.0.0.1:53"}
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())
48 self
.tryDNSDist(configTemplate
)
50 def testEmptyConfig(self
):
52 CheckConfig: Empty config
55 self
.tryDNSDist(configTemplate
)
57 def testInvalidFunction(self
):
59 CheckConfig: Invalid function
62 oldServer { address="127.0.0.1:55" }
64 self
.tryDNSDist(configTemplate
, False)
66 def testInvalidParam(self
):
68 CheckConfig: Invalid parameter
73 self
.tryDNSDist(configTemplate
, False)
75 def testSyntaxError(self
):
77 CheckConfig: Syntax error
79 configTemplate
= "blablabla"
80 self
.tryDNSDist(configTemplate
, False)