1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-19 21:30:10 +01:00

Merge androguard_test into update.TestCase

This commit is contained in:
Jochen Sprickerhof 2022-05-08 12:41:23 +02:00 committed by Hans-Christoph Steiner
parent e82888837e
commit 08e3e445fb
2 changed files with 64 additions and 124 deletions

View File

@ -1,124 +0,0 @@
#!/usr/bin/env python3
import inspect
import logging
import optparse
import os
import sys
import unittest
localmodule = os.path.realpath(
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
print('localmodule: ' + localmodule)
if localmodule not in sys.path:
sys.path.insert(0, localmodule)
import fdroidserver.common
import fdroidserver.metadata
import fdroidserver.update
class UpdateTest(unittest.TestCase):
'''fdroid androguard manual tests'''
def testScanMetadataAndroguardAAPT(self):
def _create_apkmetadata_object(apkName):
'''Create an empty apk metadata object'''
apk = {}
apk['apkName'] = apkName
apk['uses-permission'] = []
apk['uses-permission-sdk-23'] = []
apk['features'] = []
apk['icons_src'] = {}
return apk
config = dict()
fdroidserver.common.fill_config_defaults(config)
fdroidserver.update.config = config
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['ndk_paths'] = dict()
fdroidserver.common.config = config
fdroidserver.update.config = config
fdroidserver.update.options = type('', (), {})()
fdroidserver.update.options.clean = True
fdroidserver.update.options.delete_unknown = True
self.assertTrue(fdroidserver.common.SdkToolsPopen(['aapt']))
try:
from androguard.core.bytecodes.apk import APK
dir(APK)
except ImportError:
raise Exception("androguard not installed!")
apkList = [
(
'../org.dyndns.fules.ck_20.apk',
{
'apkName': '../org.dyndns.fules.ck_20.apk',
'uses-permission': [
fdroidserver.update.UsesPermission(
name='android.permission.BIND_INPUT_METHOD',
maxSdkVersion=None,
),
fdroidserver.update.UsesPermission(
name='android.permission.READ_EXTERNAL_STORAGE',
maxSdkVersion=None,
),
fdroidserver.update.UsesPermission(
name='android.permission.VIBRATE', maxSdkVersion=None
),
],
'uses-permission-sdk-23': [],
'features': [],
'icons_src': {
'240': 'res/drawable-hdpi-v4/icon_launcher.png',
'120': 'res/drawable-ldpi-v4/icon_launcher.png',
'160': 'res/drawable-mdpi-v4/icon_launcher.png',
'-1': 'res/drawable-mdpi-v4/icon_launcher.png',
},
'packageName': 'org.dyndns.fules.ck',
'versionCode': 20,
'versionName': 'v1.6pre2',
'minSdkVersion': 7,
'targetSdkVersion': 8,
'nativecode': [
'arm64-v8a',
'armeabi',
'armeabi-v7a',
'mips',
'mips64',
'x86',
'x86_64',
],
},
)
]
for apkName, apkaapt in apkList:
logging.debug("Processing " + apkName)
apkfile = os.path.join('repo', apkName)
apkandroguard = _create_apkmetadata_object(apkName)
logging.debug("Using androguard for metadata")
fdroidserver.update.scan_apk_androguard(apkandroguard, apkfile)
# avoid AAPT application name bug
del apkandroguard['name']
self.maxDiff = None
self.assertEqual(apkaapt, apkandroguard)
if __name__ == "__main__":
parser = optparse.OptionParser()
parser.add_option("-v", "--verbose", action="store_true", default=False,
help="Spew out even more information than normal")
(fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
newSuite = unittest.TestSuite()
newSuite.addTest(unittest.makeSuite(UpdateTest))
unittest.main()

View File

@ -1652,6 +1652,70 @@ class UpdateTest(unittest.TestCase):
self.assertEqual(fdroidserver.update.config['jarsigner'], data['jarsigner']) self.assertEqual(fdroidserver.update.config['jarsigner'], data['jarsigner'])
self.assertEqual(fdroidserver.update.config['keytool'], data['keytool']) self.assertEqual(fdroidserver.update.config['keytool'], data['keytool'])
def test_scan_metadata_androguard(self):
def _create_apkmetadata_object(apkName):
"""Create an empty apk metadata object."""
apk = {}
apk['apkName'] = apkName
apk['uses-permission'] = []
apk['uses-permission-sdk-23'] = []
apk['features'] = []
apk['icons_src'] = {}
return apk
apkList = [
(
'org.dyndns.fules.ck_20.apk',
{
'apkName': 'org.dyndns.fules.ck_20.apk',
'uses-permission': [
fdroidserver.update.UsesPermission(
name='android.permission.BIND_INPUT_METHOD',
maxSdkVersion=None,
),
fdroidserver.update.UsesPermission(
name='android.permission.READ_EXTERNAL_STORAGE',
maxSdkVersion=None,
),
fdroidserver.update.UsesPermission(
name='android.permission.VIBRATE', maxSdkVersion=None
),
],
'uses-permission-sdk-23': [],
'features': [],
'icons_src': {
'240': 'res/drawable-hdpi-v4/icon_launcher.png',
'120': 'res/drawable-ldpi-v4/icon_launcher.png',
'160': 'res/drawable-mdpi-v4/icon_launcher.png',
'-1': 'res/drawable-mdpi-v4/icon_launcher.png',
},
'packageName': 'org.dyndns.fules.ck',
'versionCode': 20,
'versionName': 'v1.6pre2',
'minSdkVersion': 7,
'name': 'Compass Keyboard',
'targetSdkVersion': 8,
'nativecode': [
'arm64-v8a',
'armeabi',
'armeabi-v7a',
'mips',
'mips64',
'x86',
'x86_64',
],
},
)
]
for apkfile, apkaapt in apkList:
apkandroguard = _create_apkmetadata_object(apkfile)
fdroidserver.update.scan_apk_androguard(apkandroguard, apkfile)
self.maxDiff = None
self.assertEqual(apkaapt, apkandroguard)
if __name__ == "__main__": if __name__ == "__main__":
os.chdir(os.path.dirname(__file__)) os.chdir(os.path.dirname(__file__))