diff --git a/.gitignore b/.gitignore index 9a46bd2d..1c57aac4 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ docs/html/ # files generated by tests tmp/ +tests/repo/icons* diff --git a/fdroidserver/update.py b/fdroidserver/update.py index ba7a3998..cd75449d 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -523,9 +523,19 @@ def scan_apks(apps, apkcache, repodir, knownapks, use_date_from_apk=False): logging.error(line.replace('sdkVersion:', '') + ' is not a valid minSdkVersion!') else: - apk['sdkversion'] = m.group(1) + apk['minSdkVersion'] = m.group(1) + # if target not set, default to min + if 'targetSdkVersion' not in apk: + apk['targetSdkVersion'] = m.group(1) + elif line.startswith("targetSdkVersion:"): + m = re.match(sdkversion_pat, line) + if m is None: + logging.error(line.replace('targetSdkVersion:', '') + + ' is not a valid targetSdkVersion!') + else: + apk['targetSdkVersion'] = m.group(1) elif line.startswith("maxSdkVersion:"): - apk['maxsdkversion'] = re.match(sdkversion_pat, line).group(1) + apk['maxSdkVersion'] = re.match(sdkversion_pat, line).group(1) elif line.startswith("native-code:"): apk['nativecode'] = [] for arch in line[13:].split(' '): @@ -545,9 +555,9 @@ def scan_apks(apps, apkcache, repodir, knownapks, use_date_from_apk=False): perm = perm[16:] apk['features'].add(perm) - if 'sdkversion' not in apk: + if 'minSdkVersion' not in apk: logging.warn("No SDK version information found in {0}".format(apkfile)) - apk['sdkversion'] = 0 + apk['minSdkVersion'] = 1 # Check for debuggable apks... if common.isApkDebuggable(apkfile, config): @@ -801,7 +811,7 @@ def make_index(apps, sortedids, apks, repodir, archive, categories): for mirror in config.get('mirrors', []): addElement('mirror', urllib.parse.urljoin(mirror, urlbasepath), doc, repoel) - repoel.setAttribute("version", "15") + repoel.setAttribute("version", "16") repoel.setAttribute("timestamp", str(int(time.time()))) nosigningkey = False @@ -936,9 +946,11 @@ def make_index(apps, sortedids, apks, repodir, archive, categories): apkel.appendChild(hashel) addElement('sig', apk['sig'], doc, apkel) addElement('size', str(apk['size']), doc, apkel) - addElement('sdkver', str(apk['sdkversion']), doc, apkel) - if 'maxsdkversion' in apk: - addElement('maxsdkver', str(apk['maxsdkversion']), doc, apkel) + addElement('sdkver', str(apk['minSdkVersion']), doc, apkel) + if 'targetSdkVersion' in apk: + addElement('targetSdkVersion', str(apk['targetSdkVersion']), doc, apkel) + if 'maxSdkVersion' in apk: + addElement('maxsdkver', str(apk['maxSdkVersion']), doc, apkel) if 'added' in apk: addElement('added', time.strftime('%Y-%m-%d', apk['added']), doc, apkel) addElementNonEmpty('permissions', ','.join(apk['permissions']), doc, apkel) diff --git a/tests/import.TestCase b/tests/import.TestCase index c53b53d4..4d5acc56 100755 --- a/tests/import.TestCase +++ b/tests/import.TestCase @@ -33,9 +33,9 @@ class ImportTest(unittest.TestCase): app = fdroidserver.metadata.get_default_app_info() app.UpdateCheckMode = "Tags" root_dir, src_dir = import_proxy.get_metadata_from_url(app, url) - self.assertEquals(app.RepoType, 'git') - self.assertEquals(app.WebSite, 'https://gitlab.com/fdroid/fdroidclient') - self.assertEquals(app.Repo, 'https://gitlab.com/fdroid/fdroidclient.git') + self.assertEqual(app.RepoType, 'git') + self.assertEqual(app.WebSite, 'https://gitlab.com/fdroid/fdroidclient') + self.assertEqual(app.Repo, 'https://gitlab.com/fdroid/fdroidclient.git') if __name__ == "__main__": diff --git a/tests/metadata.TestCase b/tests/metadata.TestCase index c287a212..0cdf3164 100755 --- a/tests/metadata.TestCase +++ b/tests/metadata.TestCase @@ -44,7 +44,7 @@ class MetadataTest(unittest.TestCase): self.assertTrue(appid in apps) with open(savepath, 'rb') as f: frompickle = pickle.load(f) - self.assertEquals(frommeta, frompickle) + self.assertEqual(frommeta, frompickle) # Uncomment to overwrite # with open(savepath, 'wb') as f: # pickle.dump(frommeta, f) diff --git a/tests/repo/urzip.apk b/tests/repo/urzip.apk new file mode 100644 index 00000000..ee5e5cba Binary files /dev/null and b/tests/repo/urzip.apk differ diff --git a/tests/update.TestCase b/tests/update.TestCase index 0cc93e5c..1005a158 100755 --- a/tests/update.TestCase +++ b/tests/update.TestCase @@ -55,13 +55,13 @@ class UpdateTest(unittest.TestCase): self.assertIsNotNone(sig, "sig is None") pysig = fdroidserver.update.getsig(apkfile) self.assertIsNotNone(pysig, "pysig is None") - self.assertEquals(sig, fdroidserver.update.getsig(apkfile), - "python sig not equal to java sig!") - self.assertEquals(len(sig), len(pysig), - "the length of the two sigs are different!") + self.assertEqual(sig, fdroidserver.update.getsig(apkfile), + "python sig not equal to java sig!") + self.assertEqual(len(sig), len(pysig), + "the length of the two sigs are different!") try: - self.assertEquals(unhexlify(sig), unhexlify(pysig), - "the length of the two sigs are different!") + self.assertEqual(unhexlify(sig), unhexlify(pysig), + "the length of the two sigs are different!") except TypeError as e: print(e) self.assertTrue(False, 'TypeError!') @@ -83,6 +83,32 @@ class UpdateTest(unittest.TestCase): pysig = fdroidserver.update.getsig(apkfile) self.assertIsNone(pysig, "python sig should be None: " + str(sig)) + def testScanApks(self): + os.chdir(os.path.dirname(__file__)) + if os.path.basename(os.getcwd()) != 'tests': + raise Exception('This test must be run in the "tests/" subdir') + + config = dict() + fdroidserver.common.fill_config_defaults(config) + config['ndk_paths'] = dict() + config['accepted_formats'] = ['json', 'txt', 'xml', 'yml'] + fdroidserver.common.config = config + fdroidserver.update.config = config + + fdroidserver.update.options = type('', (), {})() + fdroidserver.update.options.clean = True + + alltestapps = fdroidserver.metadata.read_metadata(xref=True) + apps = dict() + apps['info.guardianproject.urzip'] = alltestapps['info.guardianproject.urzip'] + knownapks = fdroidserver.common.KnownApks() + apks, cachechanged = fdroidserver.update.scan_apks(apps, {}, 'repo', knownapks, False) + self.assertEqual(len(apks), 1) + apk = apks[0] + self.assertEqual(apk['minSdkVersion'], '4') + self.assertEqual(apk['targetSdkVersion'], '18') + self.assertFalse('maxSdkVersion' in apk) + if __name__ == "__main__": parser = optparse.OptionParser()