From: Remi Gacogne Date: Wed, 28 Mar 2018 15:18:12 +0000 (+0200) Subject: dnsdist: Add regression tests for the console ACL feature X-Git-Tag: dnsdist-1.3.0~8^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4bc2a55239b3766c050f4543f1a10faf093261c2;p=pdns dnsdist: Add regression tests for the console ACL feature --- diff --git a/regression-tests.dnsdist/test_Console.py b/regression-tests.dnsdist/test_Console.py new file mode 100644 index 000000000..8f1646a4d --- /dev/null +++ b/regression-tests.dnsdist/test_Console.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +import base64 +import dns +from socket import error as SocketError +from dnsdisttests import DNSDistTest + +class TestConsoleAllowed(DNSDistTest): + + _consoleKey = DNSDistTest.generateConsoleKey() + _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii') + + _config_params = ['_consoleKeyB64', '_consolePort', '_testServerPort'] + _config_template = """ + setKey("%s") + controlSocket("127.0.0.1:%s") + newServer{address="127.0.0.1:%d"} + """ + + def testConsoleAllowed(self): + """ + Console: Allowed + """ + version = self.sendConsoleCommand('showVersion()') + self.assertTrue(version.startswith('dnsdist ')) + +class TestConsoleNotAllowed(DNSDistTest): + + _consoleKey = DNSDistTest.generateConsoleKey() + _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii') + + _config_params = ['_consoleKeyB64', '_consolePort', '_testServerPort'] + _config_template = """ + setKey("%s") + controlSocket("127.0.0.1:%s") + setConsoleACL({'192.0.2.1'}) + newServer{address="127.0.0.1:%d"} + """ + + def testConsoleAllowed(self): + """ + Console: Not allowed by the ACL + """ + self.assertRaises(SocketError, self.sendConsoleCommand('showVersion()'))