index: make download_repo_index() handle common URL mistakes
This commit is contained in:
parent
a71409815e
commit
5267699d81
|
@ -1072,7 +1072,12 @@ def download_repo_index(url_str, etag=None, verify_fingerprint=True, timeout=600
|
|||
raise VerificationException(_("No fingerprint in URL."))
|
||||
fingerprint = query['fingerprint'][0]
|
||||
|
||||
url = urllib.parse.SplitResult(url.scheme, url.netloc, url.path + '/index-v1.jar', '', '')
|
||||
if url.path.endswith('/index-v1.jar'):
|
||||
path = url.path[:-13].rstrip('/')
|
||||
else:
|
||||
path = url.path.rstrip('/')
|
||||
|
||||
url = urllib.parse.SplitResult(url.scheme, url.netloc, path + '/index-v1.jar', '', '')
|
||||
download, new_etag = net.http_get(url.geturl(), etag, timeout)
|
||||
|
||||
if download is None:
|
||||
|
|
|
@ -23,6 +23,7 @@ if localmodule not in sys.path:
|
|||
|
||||
import fdroidserver.common
|
||||
import fdroidserver.index
|
||||
import fdroidserver.net
|
||||
import fdroidserver.signindex
|
||||
import fdroidserver.publish
|
||||
from testcommon import TmpCwd
|
||||
|
@ -148,6 +149,17 @@ class IndexTest(unittest.TestCase):
|
|||
self.assertEqual(10, len(index['packages']))
|
||||
self.assertEqual('new_etag', new_etag)
|
||||
|
||||
@patch('fdroidserver.net.http_get')
|
||||
def test_download_repo_index_url_parsing(self, mock_http_get):
|
||||
mock_http_get.side_effect = lambda url, etag, timeout: (None, url)
|
||||
repo_url = 'https://example.org/fdroid/repo'
|
||||
index_url = 'https://example.org/fdroid/repo/index-v1.jar'
|
||||
fingerprint_url = 'https://example.org/fdroid/repo?fingerprint=' + GP_FINGERPRINT
|
||||
slash_url = 'https://example.org/fdroid/repo//?fingerprint=' + GP_FINGERPRINT
|
||||
for url in (repo_url, index_url, fingerprint_url, slash_url):
|
||||
_ignored, returned_url = fdroidserver.index.download_repo_index(url, verify_fingerprint=False)
|
||||
self.assertEqual(index_url, returned_url)
|
||||
|
||||
def test_v1_sort_packages(self):
|
||||
|
||||
i = [{'packageName': 'org.smssecure.smssecure',
|
||||
|
|
Loading…
Reference in New Issue