From 4bc2a55239b3766c050f4543f1a10faf093261c2 Mon Sep 17 00:00:00 2001 From: Remi Gacogne <remi.gacogne@powerdns.com> Date: Wed, 28 Mar 2018 17:18:12 +0200 Subject: [PATCH] dnsdist: Add regression tests for the console ACL feature --- regression-tests.dnsdist/test_Console.py | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 regression-tests.dnsdist/test_Console.py 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()')) -- 2.40.0