From 77db3ea709f253ca27721a2c4bb74dd54acde6de Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 30 Nov 2020 12:35:51 +0100 Subject: [PATCH] mirror: if index is verified, save a copy in the local mirror --- fdroidserver/mirror.py | 11 +++++++---- tests/run-tests | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/fdroidserver/mirror.py b/fdroidserver/mirror.py index 983a9dcd..89da89f8 100644 --- a/fdroidserver/mirror.py +++ b/fdroidserver/mirror.py @@ -87,7 +87,8 @@ def main(): def _get_index(section, etag=None): url = _append_to_url_path(section) - return index.download_repo_index(url, etag=etag) + data, etag = index.download_repo_index(url, etag=etag) + return data, etag, _append_to_url_path(section, 'index-v1.jar') else: def _get_index(section, etag=None): import io @@ -99,7 +100,7 @@ def main(): with zipfile.ZipFile(io.BytesIO(content)) as zip: jsoncontents = zip.open('index-v1.json').read() data = json.loads(jsoncontents.decode('utf-8')) - return data, etag + return data, etag, None # no verified index file to return ip = None try: @@ -138,14 +139,16 @@ def main(): for section in sections: sectiondir = os.path.join(basedir, section) - data, etag = _get_index(section) + urls = [] + data, etag, index_url = _get_index(section) + if index_url: + urls.append(index_url) os.makedirs(sectiondir, exist_ok=True) os.chdir(sectiondir) for icondir in icondirs: os.makedirs(os.path.join(sectiondir, icondir), exist_ok=True) - urls = [] for packageName, packageList in data['packages'].items(): for package in packageList: to_fetch = [] diff --git a/tests/run-tests b/tests/run-tests index 8645a366..7300e9aa 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -1254,6 +1254,39 @@ if which apksigner; then fi +#------------------------------------------------------------------------------# +echo_header 'test mirroring a repo' + +if which wget; then + REPOROOT=`create_test_dir` + cd $WORKSPACE/tests + test -d archive || mkdir archive + cp repo/index-v1.json $REPOROOT/ + $fdroid signindex + mv $REPOROOT/index-v1.json repo/index-v1.json + + port=321${RANDOM:3} + timeout 5m python3 -m http.server $port --bind 127.0.0.1 > http.server.log 2>&1 & + http_server_pid=$! + + cd $REPOROOT + http_proxy= HTTP_PROXY= $fdroid mirror http://127.0.0.1:${port}/ + test -e 127.0.0.1\:${port}/repo/souch.smsbypass_9.apk + test -e 127.0.0.1\:${port}/repo/icons-640/souch.smsbypass.9.png + # the index shouldn't be saved unless it was verified + ! test -e 127.0.0.1\:${port}/repo/index-v1.jar + ! http_proxy= HTTP_PROXY= $fdroid mirror "http://127.0.0.1:${port}/?fingerprint=asdfasdf" + ! test -e 127.0.0.1\:${port}/repo/index-v1.jar + http_proxy= HTTP_PROXY= $fdroid mirror "http://127.0.0.1:${port}/?fingerprint=F49AF3F11EFDDF20DFFD70F5E3117B9976674167ADCA280E6B1932A0601B26F6" + test -e 127.0.0.1\:${port}/repo/index-v1.jar + + # clean up + kill -9 $http_server_pid + rm -f 127.0.0.1\:${port}/repo/*.apk 127.0.0.1\:${port}/repo/*/*/*/*.png +else + echo "WARNING: wget not installed, skipping" +fi + #------------------------------------------------------------------------------# # remove this to prevent git conflicts and complaining