download_repo_index_v2() for verified downloading of index-v2

This commit is contained in:
Hans-Christoph Steiner 2023-03-08 17:30:17 +01:00
parent a557764b4d
commit f3e49f4bcb
No known key found for this signature in database
GPG key ID: 3E177817BA1B9BFA
4 changed files with 200 additions and 11 deletions

View file

@ -67,6 +67,24 @@ class ApiTest(unittest.TestCase):
)
self.assertEqual(index_url, etag_set_to_url)
@mock.patch('fdroidserver.net.http_get')
def test_download_repo_index_v2_url_parsing(self, mock_http_get):
"""Test whether it is trying to download the right file
This passes the URL back via the etag return value just as a
hack to check which URL was actually attempted.
"""
mock_http_get.side_effect = lambda url, etag, timeout: (None, url)
repo_url = 'https://example.org/fdroid/repo'
entry_url = 'https://example.org/fdroid/repo/entry.jar'
index_url = 'https://example.org/fdroid/repo/index-v2.json'
for url in (repo_url, entry_url, index_url):
_ignored, etag_set_to_url = fdroidserver.download_repo_index_v2(
url, verify_fingerprint=False
)
self.assertEqual(entry_url, etag_set_to_url)
if __name__ == "__main__":
newSuite = unittest.TestSuite()