diff --git a/selfprivacy_api/services/mailserver/__init__.py b/selfprivacy_api/services/mailserver/__init__.py index 5f7365f..b82a793 100644 --- a/selfprivacy_api/services/mailserver/__init__.py +++ b/selfprivacy_api/services/mailserver/__init__.py @@ -44,7 +44,7 @@ class MailServer(Service): return None @staticmethod - def get_subdomain() -> str | None: + def get_subdomain() -> Optional[str]: return None @staticmethod diff --git a/selfprivacy_api/utils/network.py b/selfprivacy_api/utils/network.py index e0ace0e..5ccbd37 100644 --- a/selfprivacy_api/utils/network.py +++ b/selfprivacy_api/utils/network.py @@ -2,6 +2,7 @@ """Network utils""" import subprocess import re +import ipaddress from typing import Optional @@ -23,9 +24,9 @@ def get_ip6() -> Optional[str]: ip6 = subprocess.check_output(["ip", "addr", "show", "dev", "eth0"]).decode( "utf-8" ) - # We ignore link-local addresses - ip6 = re.search(r"inet6 (?!fe80:\S+)(\S+)\/\d+", ip6) - + ip6 = re.findall(r"inet6 (\S+)\/\d+", ip6) + for address in ip6: + if ipaddress.IPv6Address(address).is_global: + return address except subprocess.CalledProcessError: - ip6 = None - return ip6.group(1) if ip6 else None + return None diff --git a/tests/test_services.py b/tests/test_services.py index 9dbecd8..de3665a 100644 --- a/tests/test_services.py +++ b/tests/test_services.py @@ -168,13 +168,14 @@ def test_enabling_disabling_writes_json( # more detailed testing of this is in test_graphql/test_system.py +# Using the same random global IPs as the test_network_utils def test_mailserver_with_dkim_returns_some_dns(dkim_file): - records = MailServer().get_dns_records("203.0.113.3", "2001:db8::1") + records = MailServer().get_dns_records("157.90.247.192", "2a01:4f8:c17:7e3d::2") assert len(records) > 0 def test_mailserver_with_no_dkim_returns_no_dns(no_dkim_file): - assert MailServer().get_dns_records("203.0.113.3", "2001:db8::1") == [] + assert MailServer().get_dns_records("157.90.247.192", "2a01:4f8:c17:7e3d::2") == [] def test_services_enabled_by_default(generic_userdata):