diff --git a/fdroidserver/update.py b/fdroidserver/update.py index a0f9a5f2..dbc44f23 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -1203,7 +1203,7 @@ def _sanitize_sdk_version(value): try: sdk_version = int(value) if sdk_version > 0: - return str(sdk_version) # heinous, but this is still str in the codebase + return sdk_version except (TypeError, ValueError): pass return None diff --git a/tests/metadata/apk/info.guardianproject.urzip.yaml b/tests/metadata/apk/info.guardianproject.urzip.yaml index a2312cdd..f2e17651 100644 --- a/tests/metadata/apk/info.guardianproject.urzip.yaml +++ b/tests/metadata/apk/info.guardianproject.urzip.yaml @@ -9,12 +9,12 @@ icons: icons_src: '-1': res/drawable/ic_launcher.png '160': res/drawable/ic_launcher.png -minSdkVersion: '4' +minSdkVersion: 4 packageName: info.guardianproject.urzip sig: e0ecb5fc2d63088e4a07ae410a127722 signer: 7eabd8c15de883d1e82b5df2fd4f7f769e498078e9ad6dc901f0e96db77ceac3 size: 9969 -targetSdkVersion: '18' +targetSdkVersion: 18 uses-permission: [] uses-permission-sdk-23: [] versionCode: 100 diff --git a/tests/metadata/apk/org.dyndns.fules.ck.yaml b/tests/metadata/apk/org.dyndns.fules.ck.yaml index 2f382c48..76f7cacb 100644 --- a/tests/metadata/apk/org.dyndns.fules.ck.yaml +++ b/tests/metadata/apk/org.dyndns.fules.ck.yaml @@ -13,7 +13,7 @@ icons_src: '120': res/drawable-ldpi-v4/icon_launcher.png '160': res/drawable-mdpi-v4/icon_launcher.png '240': res/drawable-hdpi-v4/icon_launcher.png -minSdkVersion: '7' +minSdkVersion: 7 nativecode: - arm64-v8a - armeabi @@ -26,7 +26,7 @@ packageName: org.dyndns.fules.ck sig: 9bf7a6a67f95688daec75eab4b1436ac signer: 9326a2cc1a2f148202bc7837a0af3b81200bd37fd359c9e13a2296a71d342056 size: 132453 -targetSdkVersion: '8' +targetSdkVersion: 8 uses-permission: - !!python/object/new:fdroidserver.update.UsesPermission - android.permission.BIND_INPUT_METHOD diff --git a/tests/repo/index-v1.json b/tests/repo/index-v1.json index 5063697c..a5a1d1e9 100644 --- a/tests/repo/index-v1.json +++ b/tests/repo/index-v1.json @@ -215,12 +215,12 @@ "apkName": "com.politedroid_6.apk", "hash": "70c2f776a2bac38a58a7d521f96ee0414c6f0fb1de973c3ca8b10862a009247d", "hashType": "sha256", - "minSdkVersion": "14", + "minSdkVersion": 14, "packageName": "com.politedroid", "sig": "b4964fd759edaa54e65bb476d0276880", "signer": "32a23624c201b949f085996ba5ed53d40f703aca4989476949cae891022e0ed6", "size": 16578, - "targetSdkVersion": "21", + "targetSdkVersion": 21, "uses-permission": [ [ "android.permission.READ_CALENDAR", @@ -242,12 +242,12 @@ "apkName": "com.politedroid_5.apk", "hash": "5bdbfa071cca4b8d05ced41d6b28763595d6e8096cca5bbf0f9253c9a2622e5d", "hashType": "sha256", - "minSdkVersion": "3", + "minSdkVersion": 3, "packageName": "com.politedroid", "sig": "b4964fd759edaa54e65bb476d0276880", "signer": "32a23624c201b949f085996ba5ed53d40f703aca4989476949cae891022e0ed6", "size": 18817, - "targetSdkVersion": "10", + "targetSdkVersion": 10, "uses-permission": [ [ "android.permission.READ_CALENDAR", @@ -269,7 +269,7 @@ "apkName": "com.politedroid_4.apk", "hash": "c809bdff83715fbf919f3840ee09869b038e209378b906e135ee40d3f0e1f075", "hashType": "sha256", - "minSdkVersion": "3", + "minSdkVersion": 3, "packageName": "com.politedroid", "sig": "b4964fd759edaa54e65bb476d0276880", "signer": "32a23624c201b949f085996ba5ed53d40f703aca4989476949cae891022e0ed6", @@ -310,7 +310,7 @@ "apkName": "com.politedroid_3.apk", "hash": "665d03d61ebc642289fda697f71a59305b0202b16cafc5ffdae91cbe91f0b25d", "hashType": "sha256", - "minSdkVersion": "3", + "minSdkVersion": 3, "packageName": "com.politedroid", "sig": "b4964fd759edaa54e65bb476d0276880", "signer": "32a23624c201b949f085996ba5ed53d40f703aca4989476949cae891022e0ed6", @@ -347,12 +347,12 @@ "apkName": "duplicate.permisssions_9999999.apk", "hash": "8367857fe75f85321ce2c344b34804d0bc193707f6ba03710d025d9030803434", "hashType": "sha256", - "minSdkVersion": "18", + "minSdkVersion": 18, "packageName": "duplicate.permisssions", "sig": "056c9f1554c40ba59a2103009c82b420", "signer": "659e1fd284549f70d13fb02c620100e27eeea3420558cce62b0f5d4cf2b77d84", "size": 27446, - "targetSdkVersion": "27", + "targetSdkVersion": 27, "uses-permission": [ [ "android.permission.INTERNET", @@ -414,12 +414,12 @@ "apkName": "urzip-; \u0420\u0430\u0445\u043c\u0430\u0301, [r\u0250x\u02c8man\u02b2\u026an\u0259f] \u0633\u064a\u0631\u062c\u064a_\u0631\u062e\u0645\u0627\u0646\u064a\u0646\u0648\u0641 \u8c22\u00b7.apk", "hash": "15c0ec72c74a3791f42cdb43c57df0fb11a4dbb656851bbb8cf05b26a8372789", "hashType": "sha256", - "minSdkVersion": "4", + "minSdkVersion": 4, "packageName": "info.guardianproject.urzip", "sig": "b4964fd759edaa54e65bb476d0276880", "signer": "32a23624c201b949f085996ba5ed53d40f703aca4989476949cae891022e0ed6", "size": 11471, - "targetSdkVersion": "18", + "targetSdkVersion": 18, "versionCode": 100, "versionName": "0.1" } @@ -430,12 +430,12 @@ "apkName": "info.zwanenburg.caffeinetile_4.apk", "hash": "dbbdd7deadb038862f426b71efe4a64df8c3edf25d669e935f349510e16f65db", "hashType": "sha256", - "minSdkVersion": "24", + "minSdkVersion": 24, "packageName": "info.zwanenburg.caffeinetile", "sig": "03f9b2f848d22fd1d8d1331e8b1b486d", "signer": "51cfa5c8a743833ad89acf81cb755936876a5c8b8eca54d1ffdcec0cdca25d0e", "size": 11740, - "targetSdkVersion": "25", + "targetSdkVersion": 25, "uses-permission": [ [ "android.permission.WAKE_LOCK", @@ -481,14 +481,14 @@ "apkName": "obb.main.oldversion_1444412523.apk", "hash": "c5f149e526f89c05c62923bdb7bb1e2be5673c46ec85143f41e514340631449c", "hashType": "sha256", - "minSdkVersion": "4", + "minSdkVersion": 4, "obbMainFile": "main.1434483388.obb.main.oldversion.obb", "obbMainFileSha256": "d3eb539a556352f3f47881d71fb0e5777b2f3e9a4251d283c18c67ce996774b7", "packageName": "obb.main.oldversion", "sig": "eb41d4d6082bb3e81c3d58dbf7fc7332", "signer": "818e469465f96b704e27be2fee4c63ab9f83ddf30e7a34c7371a4728d83b0bc1", "size": 14323, - "targetSdkVersion": "18", + "targetSdkVersion": 18, "uses-permission": [ [ "android.permission.INTERNET", @@ -551,7 +551,7 @@ "apkName": "obb.main.twoversions_1101617.apk", "hash": "9bc74566f089ef030ac33e7fbd99d92f1a38f363fb499fed138d9e7b774e821c", "hashType": "sha256", - "minSdkVersion": "4", + "minSdkVersion": 4, "obbMainFile": "main.1101615.obb.main.twoversions.obb", "obbMainFileSha256": "d3eb539a556352f3f47881d71fb0e5777b2f3e9a4251d283c18c67ce996774b7", "packageName": "obb.main.twoversions", @@ -559,7 +559,7 @@ "signer": "32a23624c201b949f085996ba5ed53d40f703aca4989476949cae891022e0ed6", "size": 11481, "srcname": "obb.main.twoversions_1101617_src.tar.gz", - "targetSdkVersion": "18", + "targetSdkVersion": 18, "versionCode": 1101617, "versionName": "0.1" }, @@ -568,14 +568,14 @@ "apkName": "obb.main.twoversions_1101615.apk", "hash": "7b0b7b9ba248e15751a16e3a0e01e1e24cbb673686c38422030cb75d5c33f0bb", "hashType": "sha256", - "minSdkVersion": "4", + "minSdkVersion": 4, "obbMainFile": "main.1101615.obb.main.twoversions.obb", "obbMainFileSha256": "d3eb539a556352f3f47881d71fb0e5777b2f3e9a4251d283c18c67ce996774b7", "packageName": "obb.main.twoversions", "sig": "b4964fd759edaa54e65bb476d0276880", "signer": "32a23624c201b949f085996ba5ed53d40f703aca4989476949cae891022e0ed6", "size": 11480, - "targetSdkVersion": "18", + "targetSdkVersion": 18, "versionCode": 1101615, "versionName": "0.1" }, @@ -584,14 +584,14 @@ "apkName": "obb.main.twoversions_1101613.apk", "hash": "cce97a52ff18d843185be7f22ecb1a557c36b7a9f8ba07a8be94e328e00b35dc", "hashType": "sha256", - "minSdkVersion": "4", + "minSdkVersion": 4, "obbMainFile": "main.1101613.obb.main.twoversions.obb", "obbMainFileSha256": "d3eb539a556352f3f47881d71fb0e5777b2f3e9a4251d283c18c67ce996774b7", "packageName": "obb.main.twoversions", "sig": "b4964fd759edaa54e65bb476d0276880", "signer": "32a23624c201b949f085996ba5ed53d40f703aca4989476949cae891022e0ed6", "size": 11477, - "targetSdkVersion": "18", + "targetSdkVersion": 18, "versionCode": 1101613, "versionName": "0.1" } @@ -602,7 +602,7 @@ "apkName": "obb.mainpatch.current_1619.apk", "hash": "eda5fc3ecfdac3252717e36bdbc9820865baeef162264af9ba5db7364f0e7a0c", "hashType": "sha256", - "minSdkVersion": "4", + "minSdkVersion": 4, "obbMainFile": "main.1619.obb.mainpatch.current.obb", "obbMainFileSha256": "d3eb539a556352f3f47881d71fb0e5777b2f3e9a4251d283c18c67ce996774b7", "obbPatchFile": "patch.1619.obb.mainpatch.current.obb", @@ -611,7 +611,7 @@ "sig": "b4964fd759edaa54e65bb476d0276880", "signer": "32a23624c201b949f085996ba5ed53d40f703aca4989476949cae891022e0ed6", "size": 11479, - "targetSdkVersion": "18", + "targetSdkVersion": 18, "versionCode": 1619, "versionName": "0.1" }, @@ -620,7 +620,7 @@ "apkName": "obb.mainpatch.current_1619_another-release-key.apk", "hash": "42e7d6d2f8254aaf9fe95ba6ecc233ee8c3cd543a3e4f3f9ebe1b638221122fa", "hashType": "sha256", - "minSdkVersion": "4", + "minSdkVersion": 4, "obbMainFile": "main.1619.obb.mainpatch.current.obb", "obbMainFileSha256": "d3eb539a556352f3f47881d71fb0e5777b2f3e9a4251d283c18c67ce996774b7", "obbPatchFile": "patch.1619.obb.mainpatch.current.obb", @@ -629,7 +629,7 @@ "sig": "4cbb9827107da5ab4f34228fa997fbf8", "signer": "ce9e200667f02d96d49891a2e08a3c178870e91853d61bdd33ef5f0b54701aa5", "size": 10541, - "targetSdkVersion": "18", + "targetSdkVersion": 18, "versionCode": 1619, "versionName": "0.1" } @@ -640,12 +640,12 @@ "apkName": "souch.smsbypass_9.apk", "hash": "80b0ae68a1189baa3ee6717092e3dbf1a4210165f7f7e5f2f9616bd63a2ec01d", "hashType": "sha256", - "minSdkVersion": "8", + "minSdkVersion": 8, "packageName": "souch.smsbypass", "sig": "e50c99753cd45e2736d52cb49be07581", "signer": "d3aec784b1fd71549fc22c999789122e3639895db6bd585da5835fbe3db6985c", "size": 81295, - "targetSdkVersion": "18", + "targetSdkVersion": 18, "uses-permission": [ [ "android.permission.RECEIVE_SMS", diff --git a/tests/update.TestCase b/tests/update.TestCase index 2ba207b8..1d3db8a7 100755 --- a/tests/update.TestCase +++ b/tests/update.TestCase @@ -298,14 +298,14 @@ class UpdateTest(unittest.TestCase): apk = apks[1] self.assertEqual(apk['packageName'], 'com.politedroid') self.assertEqual(apk['versionCode'], 3) - self.assertEqual(apk['minSdkVersion'], '3') + self.assertEqual(apk['minSdkVersion'], 3) self.assertIsNone(apk.get('targetSdkVersion')) self.assertFalse('maxSdkVersion' in apk) apk = apks[8] self.assertEqual(apk['packageName'], 'obb.main.oldversion') self.assertEqual(apk['versionCode'], 1444412523) - self.assertEqual(apk['minSdkVersion'], '4') - self.assertEqual(apk['targetSdkVersion'], '18') + self.assertEqual(apk['minSdkVersion'], 4) + self.assertEqual(apk['targetSdkVersion'], 18) self.assertFalse('maxSdkVersion' in apk) fdroidserver.update.insert_obbs('repo', apps, apks) @@ -438,10 +438,10 @@ class UpdateTest(unittest.TestCase): self.assertEqual(apk_info['size'], 132453) self.assertEqual(apk_info['nativecode'], ['arm64-v8a', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'x86', 'x86_64']) - self.assertEqual(apk_info['minSdkVersion'], '7') + self.assertEqual(apk_info['minSdkVersion'], 7) self.assertEqual(apk_info['sig'], '9bf7a6a67f95688daec75eab4b1436ac') self.assertEqual(apk_info['hashType'], 'sha256') - self.assertEqual(apk_info['targetSdkVersion'], '8') + self.assertEqual(apk_info['targetSdkVersion'], 8) apk_info = fdroidserver.update.scan_apk('org.bitbucket.tickytacky.mirrormirror_4.apk') self.assertEqual(apk_info.get('versionName'), '1.0.3') @@ -465,6 +465,38 @@ class UpdateTest(unittest.TestCase): self.assertEqual(apk_info.get('versionName'), '1.0') self.assertEqual(apk_info['icons_src'], {}) + def test_scan_apk_no_min_target(self): + config = dict() + fdroidserver.common.fill_config_defaults(config) + fdroidserver.common.config = config + fdroidserver.update.config = config + apk_info = fdroidserver.update.scan_apk('repo/no.min.target.sdk_987.apk') + self.maxDiff = None + self.assertDictEqual(apk_info, { + 'icons': {}, + 'icons_src': {'-1': 'res/drawable/ic_launcher.png', + '160': 'res/drawable/ic_launcher.png'}, + 'name': 'No minSdkVersion or targetSdkVersion', + 'signer': '32a23624c201b949f085996ba5ed53d40f703aca4989476949cae891022e0ed6', + 'hashType': 'sha256', + 'packageName': 'no.min.target.sdk', + 'features': [], + 'antiFeatures': set(), + 'size': 14102, + 'sig': 'b4964fd759edaa54e65bb476d0276880', + 'versionName': '1.2-fake', + 'uses-permission-sdk-23': [], + 'hash': 'e2e1dc1d550df2b5bc383860139207258645b5540abeccd305ed8b2cb6459d2c', + 'versionCode': 987, + 'minSdkVersion': 3, + 'uses-permission': [ + fdroidserver.update.UsesPermission(name='android.permission.WRITE_EXTERNAL_STORAGE', + maxSdkVersion=None), + fdroidserver.update.UsesPermission(name='android.permission.READ_PHONE_STATE', + maxSdkVersion=None), + fdroidserver.update.UsesPermission(name='android.permission.READ_EXTERNAL_STORAGE', + maxSdkVersion=None)]}) + def test_scan_apk_no_sig(self): config = dict() fdroidserver.common.fill_config_defaults(config) @@ -534,9 +566,9 @@ class UpdateTest(unittest.TestCase): # yaml.dump(apk, f, default_flow_style=False) with open(savepath, 'r') as f: - frompickle = yaml.load(f) + from_yaml = yaml.load(f) self.maxDiff = None - self.assertEqual(apk, frompickle) + self.assertEqual(apk, from_yaml) def test_process_apk_signed_by_disabled_algorithms(self): config = dict()