{
vector<string> locals;
vector<string> remotes;
+ bool checkConfig{false};
bool beDaemon{false};
bool beClient{false};
bool beSupervised{false};
struct option longopts[]={
{"acl", required_argument, 0, 'a'},
{"config", required_argument, 0, 'C'},
+ {"check-config", 0, 0, 1},
{"execute", required_argument, 0, 'e'},
{"client", 0, 0, 'c'},
{"gid", required_argument, 0, 'g'},
if(c==-1)
break;
switch(c) {
+ case 1:
+ g_cmdLine.checkConfig=true;
+ break;
case 'C':
g_cmdLine.config=optarg;
break;
g_ACL.setState(acl);
}
+ if (g_cmdLine.checkConfig) {
+ setupLua(true, g_cmdLine.config);
+ // No exception was thrown
+ infolog("Configuration '%s' OK!", g_cmdLine.config);
+ _exit(0);
+ }
+
auto todo=setupLua(false, g_cmdLine.config);
if(g_cmdLine.locals.size()) {
--- /dev/null
+#!/usr/bin/env python
+import unittest
+import os
+import subprocess
+
+class TestCheckConfig(unittest.TestCase):
+
+ def tryDNSDist(self, configTemplate, shouldBeSuccessful = True):
+ conffile = 'dnsdist_test.conf'
+ with open(conffile, 'w') as conf:
+ conf.write("-- Autogenerated by dnsdisttests.py\n")
+ conf.write(configTemplate)
+
+ dnsdistcmd = [os.environ['DNSDISTBIN'], '-C', conffile, '--check-config']
+
+ with open(os.devnull, 'w') as fdDevNull:
+ dnsdist = subprocess.Popen(dnsdistcmd, close_fds=True, stdout=fdDevNull)
+
+ if dnsdist.poll() is not None:
+ if dnsdist.returncode != 0 and not shouldBeSuccessful:
+ sys.exit(1)
+ sys.exit(0)
+
+ def testWorkingConfig(self):
+ configTemplate = """
+ newServer{address="127.0.0.1:53"}
+ truncateTC(true)
+ addAnyTCRule()
+ addAction(RegexRule("evil[0-9]{4,}\\\\.regex\\\\.tests\\\\.powerdns\\\\.com$"), RCodeAction(5))
+ mySMN = newSuffixMatchNode()
+ mySMN:add(newDNSName("nameAndQtype.tests.powerdns.com."))
+ addAction(AndRule{SuffixMatchNodeRule(mySMN), QTypeRule("TXT")}, RCodeAction(4))
+ addAction(makeRule("drop.test.powerdns.com."), DropAction())
+ block=newDNSName("powerdns.org.")
+ function blockFilter(dq)
+ if(dq.qname:isPartOf(block))
+ then
+ print("Blocking *.powerdns.org")
+ return true
+ end
+ return false
+ end
+ """
+
+ self.tryDNSDist(configTemplate)
+
+ def testEmptyConfig(self):
+ configTemplate = ""
+ self.tryDNSDist(configTemplate)
+
+ def testInvalidFunction(self):
+ configTemplate = """
+ oldServer { address="127.0.0.1:55" }
+ """
+ self.tryDNSDist(configTemplate, False)
+
+ def testInvalidParam(self):
+ configTemplate = """
+ newServer { address="127.0.0.355" }
+ """
+ self.tryDNSDist(configTemplate, False)
+
+ def testSyntaxError(self):
+ configTemplate = "blablabla"
+ self.tryDNSDist(configTemplate, False)