signindex: do not remove index-v1.json after signing

With ~index-v2, the model is changing to offer the plain JSON file for easy
consumption.  Then gpgsign will also provide a detached PGP signature for
systems that would rather verify based on PGP signatures than JAR signatures.

!1080
closes #969
This commit is contained in:
Hans-Christoph Steiner 2022-05-17 12:57:44 +02:00
parent 8f6bc1114a
commit 73c31e6e63
No known key found for this signature in database
GPG Key ID: 3E177817BA1B9BFA
2 changed files with 34 additions and 2 deletions

View File

@ -139,7 +139,6 @@ def main():
index_file = os.path.join(output_dir, json_name)
if os.path.exists(index_file):
sign_index_v1(output_dir, json_name)
os.remove(index_file)
logging.info('Signed ' + index_file)
signed.append(index_file)

View File

@ -17,8 +17,19 @@ print('localmodule: ' + localmodule)
if localmodule not in sys.path:
sys.path.insert(0, localmodule)
from fdroidserver import common, signindex
from fdroidserver import common, signindex, update
from pathlib import Path
from unittest.mock import patch
class Options:
allow_disabled_algorithms = False
clean = False
delete_unknown = False
nosign = False
pretty = True
rename_apks = False
verbose = False
class SignindexTest(unittest.TestCase):
@ -49,6 +60,7 @@ class SignindexTest(unittest.TestCase):
shutil.copy(str(self.basedir / 'repo/index-v1.json'), 'repo')
signindex.sign_index_v1(str(self.repodir), 'index-v1.json')
self.assertTrue((self.repodir / 'index-v1.jar').exists())
self.assertTrue((self.repodir / 'index-v1.json').exists())
def test_sign_index_v1_corrupt(self):
with open('repo/index-v1.json', 'w') as fp:
@ -56,6 +68,27 @@ class SignindexTest(unittest.TestCase):
with self.assertRaises(json.decoder.JSONDecodeError, msg='error on bad JSON'):
signindex.sign_index_v1(str(self.repodir), 'index-v1.json')
def test_signindex(self):
os.mkdir('archive')
metadata = Path('metadata')
metadata.mkdir()
with (metadata / 'info.guardianproject.urzip.yml').open('w') as fp:
fp.write('# placeholder')
shutil.copy(str(self.basedir / 'urzip.apk'), 'repo')
index_files = []
for f in ('index.xml', 'index.jar', 'index-v1.json', 'index-v1.jar'):
for section in (Path('repo'), Path('archive')):
path = section / f
self.assertFalse(path.exists(), '%s should not exist yet!' % path)
index_files.append(path)
common.options = Options
with patch('sys.argv', ['fdroid update']):
update.main()
with patch('sys.argv', ['fdroid signindex', '--verbose']):
signindex.main()
for f in index_files:
self.assertTrue(f.exists(), '%s should exist!' % f)
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__))