diff --git a/tests/shared_test_code.py b/tests/shared_test_code.py index adb7763c..6eaf44db 100644 --- a/tests/shared_test_code.py +++ b/tests/shared_test_code.py @@ -16,6 +16,7 @@ # along with this program. If not, see . 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 diff --git a/tests/test_index.py b/tests/test_index.py index c9a01305..30c330d3 100755 --- a/tests/test_index.py +++ b/tests/test_index.py @@ -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) diff --git a/tests/test_integration.py b/tests/test_integration.py index 64e6db35..512e17e5 100755 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -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'))