From 8be2b867e08b49cdc11a0452476229ceaa1ce6f6 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 12 Mar 2024 15:16:19 +0100 Subject: [PATCH] dnsdist: Add a regression test for IPv6 console connections --- regression-tests.dnsdist/dnsdisttests.py | 6 +++--- regression-tests.dnsdist/test_Console.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/regression-tests.dnsdist/dnsdisttests.py b/regression-tests.dnsdist/dnsdisttests.py index c829e398cd..3f53bd451a 100644 --- a/regression-tests.dnsdist/dnsdisttests.py +++ b/regression-tests.dnsdist/dnsdisttests.py @@ -816,15 +816,15 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase): return result.decode('UTF-8') @classmethod - def sendConsoleCommand(cls, command, timeout=5.0): + def sendConsoleCommand(cls, command, timeout=5.0, IPv6=False): ourNonce = libnacl.utils.rand_nonce() theirNonce = None - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock = socket.socket(socket.AF_INET if not IPv6 else socket.AF_INET6, socket.SOCK_STREAM) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) if timeout: sock.settimeout(timeout) - sock.connect(("127.0.0.1", cls._consolePort)) + sock.connect(("::1", cls._consolePort, 0, 0) if IPv6 else ("127.0.0.1", cls._consolePort)) sock.send(ourNonce) theirNonce = sock.recv(len(ourNonce)) if len(theirNonce) != len(ourNonce): diff --git a/regression-tests.dnsdist/test_Console.py b/regression-tests.dnsdist/test_Console.py index ee37961251..ff55c36f66 100644 --- a/regression-tests.dnsdist/test_Console.py +++ b/regression-tests.dnsdist/test_Console.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import base64 import dns +import os import socket import time from dnsdisttests import DNSDistTest @@ -24,6 +25,27 @@ class TestConsoleAllowed(DNSDistTest): version = self.sendConsoleCommand('showVersion()') self.assertTrue(version.startswith('dnsdist ')) +class TestConsoleAllowedV6(DNSDistTest): + + _consoleKey = DNSDistTest.generateConsoleKey() + _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii') + + _config_params = ['_consoleKeyB64', '_consolePort', '_testServerPort'] + _config_template = """ + setKey("%s") + controlSocket("[::1]:%s") + newServer{address="127.0.0.1:%d"} + """ + + def testConsoleAllowed(self): + """ + Console: Allowed IPv6 + """ + if 'SKIP_IPV6_TESTS' in os.environ: + raise unittest.SkipTest('IPv6 tests are disabled') + version = self.sendConsoleCommand('showVersion()', IPv6=True) + self.assertTrue(version.startswith('dnsdist ')) + class TestConsoleNotAllowed(DNSDistTest): _consoleKey = DNSDistTest.generateConsoleKey() -- 2.47.2