Merge branch 'dns_tests' into 'master'

Added check for IPv6 support to DNS tests

See merge request fdroid/fdroidserver!1794
This commit is contained in:
Hans-Christoph Steiner
2026-03-12 21:20:29 +00:00
3 changed files with 21 additions and 4 deletions

View File

@@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import socket
import sys
import tempfile
import unittest
@@ -91,3 +92,15 @@ def mock_urlopen(status=200, body=None):
resp.read.return_value = body
resp.__enter__.return_value = resp
return unittest.mock.Mock(return_value=resp)
def supports_ipv6():
if not socket.has_ipv6:
return False
try:
for result in socket.getaddrinfo('f-droid.org', 443):
if result[0] == socket.AF_INET6:
return True
except Exception as e:
print('Failed to get DNS results for test URL: ' + str(e))
return False

View File

@@ -17,7 +17,7 @@ import yaml
import fdroidserver
from fdroidserver import common, index, publish, signindex, update
from .shared_test_code import GP_FINGERPRINT, TmpCwd, mkdtemp
from .shared_test_code import GP_FINGERPRINT, TmpCwd, mkdtemp, supports_ipv6
basedir = Path(__file__).parent
@@ -1200,6 +1200,7 @@ class DnsCacheTest(SetUpTearDownMixin, unittest.TestCase):
common.config = {'include_dns_lookups': True}
self.assertTrue(index.get_dnsa_results(self.url))
@unittest.skipUnless(supports_ipv6(), "Test requires working IPv6 to run")
def test_f_droid_org_aaaa(self):
common.config = {'include_dns_lookups': True}
self.assertTrue(index.get_dnsaaaa_results(self.url))
@@ -1209,6 +1210,7 @@ class DnsCacheTest(SetUpTearDownMixin, unittest.TestCase):
a = index.get_dnsa_results(self.url)
self.assertEqual(a, sorted(set(a)))
@unittest.skipUnless(supports_ipv6(), "Test requires working IPv6 to run")
def test_no_AAAA_duplicates(self):
common.config = {'include_dns_lookups': True}
aaaa = index.get_dnsaaaa_results(self.url)

View File

@@ -21,7 +21,7 @@ except ModuleNotFoundError:
from fdroidserver._yaml import yaml, yaml_dumper
from .shared_test_code import mkdir_testfiles, VerboseFalseOptions
from .shared_test_code import mkdir_testfiles, supports_ipv6, VerboseFalseOptions
# TODO: port generic tests that use index.xml to index-v2 (test that
# explicitly test index-v0 should still use index.xml)
@@ -250,6 +250,7 @@ class IntegrationTest(unittest.TestCase):
@unittest.skipUnless(
(
(shutil.which("gpg-agent") is not None)
and platform.system() == 'Linux'
and (platform.freedesktop_os_release()['ID'] != 'fedora')
),
"requires Debian compatible gpg-agent built for gpg",
@@ -1723,6 +1724,7 @@ class IntegrationTest(unittest.TestCase):
with open('repo/index-v2.json') as fp:
data = json.load(fp)
self.assertIsNotNone(data['repo'].get('dnsA'))
self.assertIsNotNone(data['repo'].get('dnsAAAA'))
self.assertIsNotNone(data['repo']['mirrors'][0].get('dnsA'))
self.assertIsNotNone(data['repo']['mirrors'][0].get('dnsAAAA'))
if supports_ipv6():
self.assertIsNotNone(data['repo'].get('dnsAAAA'))
self.assertIsNotNone(data['repo']['mirrors'][0].get('dnsAAAA'))