From e77c42b04d2bb317fc8ea520e59237e6a9423b0d Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Mon, 6 Sep 2021 15:28:48 +0100 Subject: [PATCH] Add simple DNS probes --- test/Dockerfile | 2 +- test/float_integration_test/__init__.py | 5 +++++ test/float_integration_test/test_system.py | 21 +++++++++++++++++++++ test/setup.py | 2 +- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/test/Dockerfile b/test/Dockerfile index 5c401540..4cf0707f 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -1,7 +1,7 @@ FROM debian:stable RUN apt-get -q update && env DEBIAN_FRONTEND=noninteractive \ - apt-get install --no-install-recommends -y python3 python3-pip python3-setuptools python3-yaml python3-jinja2 python3-nose + apt-get install --no-install-recommends -y python3 python3-pip python3-setuptools python3-yaml python3-jinja2 python3-nose python3-dnspython ADD . /src WORKDIR /src diff --git a/test/float_integration_test/__init__.py b/test/float_integration_test/__init__.py index a22c2d6f..f3ff2e52 100644 --- a/test/float_integration_test/__init__.py +++ b/test/float_integration_test/__init__.py @@ -52,6 +52,11 @@ class TestBase(unittest.TestCase): host = random.choice(hosts_in_group('frontend')) return ANSIBLE_VARS['hostvars'][host]['ip'] + def all_frontend_ips(self): + """Return all IPs in the 'frontend' group.""" + return [ANSIBLE_VARS['hostvars'][x]['ip'] + for x in hosts_in_group('frontend')] + def sso_conversation(self, sso_username=None, sso_password=None): url = _ansible_eval( '{{ sso_server_url | default("https://login." + domain_public[0]) }}') diff --git a/test/float_integration_test/test_system.py b/test/float_integration_test/test_system.py index cbee3bf8..114eac30 100644 --- a/test/float_integration_test/test_system.py +++ b/test/float_integration_test/test_system.py @@ -1,6 +1,7 @@ import json import time import unittest +from dns.resolver import Resolver from float_integration_test import TestBase, ANSIBLE_VARS @@ -34,6 +35,26 @@ class TestHTTPRouter(URLTestBase): self.assertTrue(UNKNOWN_DOMAIN_MSG in result['body']) +class TestDNS(TestBase): + + def setUp(self): + self.resolver = Resolver(configure=False) + self.resolver.nameservers = self.all_frontend_ips() + + def test_public_dns_entries_for_services(self): + frontend_ips = set(self.all_frontend_ips()) + for service in ANSIBLE_VARS['services'].values(): + for pe in service.get('public_endpoints', []): + if pe.get('skip_dns', False): + continue + name = '%s.%s' % (pe['name'], + ANSIBLE_VARS['domain_public'][0]) + print(f'querying {name}') + resp = self.resolver.query(name, 'A') + for record in resp: + self.assertTrue(str(record) in frontend_ips) + + class TestBuiltinServiceURLs(URLTestBase): """Verify that all the public_endpoints are reachable. diff --git a/test/setup.py b/test/setup.py index 734aa5a3..3aafda5e 100755 --- a/test/setup.py +++ b/test/setup.py @@ -11,7 +11,7 @@ setup( url="https://git.autistici.org/ai3/float", install_requires=["Jinja2", "PyYAML", - ], + "dnspython"], setup_requires=[], zip_safe=True, packages=find_packages(), -- GitLab