]> granicus.if.org Git - pdns/commitdiff
dnsdist: Add regression tests for the console ACL feature
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 28 Mar 2018 15:18:12 +0000 (17:18 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 28 Mar 2018 15:18:12 +0000 (17:18 +0200)
regression-tests.dnsdist/test_Console.py [new file with mode: 0644]

diff --git a/regression-tests.dnsdist/test_Console.py b/regression-tests.dnsdist/test_Console.py
new file mode 100644 (file)
index 0000000..8f1646a
--- /dev/null
@@ -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()'))