2016-01-04 21:17:58 +01:00
|
|
|
|
#!/usr/bin/env python3
|
2014-08-30 17:07:29 +02:00
|
|
|
|
|
|
|
|
|
# http://www.drdobbs.com/testing/unit-testing-with-python/240165163
|
|
|
|
|
|
2017-04-19 10:04:32 +02:00
|
|
|
|
import git
|
2018-09-03 18:07:40 +02:00
|
|
|
|
import glob
|
2014-08-30 17:07:29 +02:00
|
|
|
|
import inspect
|
2015-07-22 08:19:56 +02:00
|
|
|
|
import logging
|
2014-08-30 17:07:29 +02:00
|
|
|
|
import optparse
|
|
|
|
|
import os
|
2017-04-19 10:04:32 +02:00
|
|
|
|
import shutil
|
2017-09-13 16:00:51 +02:00
|
|
|
|
import subprocess
|
2014-08-30 17:07:29 +02:00
|
|
|
|
import sys
|
2017-04-19 10:04:32 +02:00
|
|
|
|
import tempfile
|
2014-08-30 17:07:29 +02:00
|
|
|
|
import unittest
|
2017-04-19 10:04:32 +02:00
|
|
|
|
import yaml
|
2016-01-04 21:31:22 +01:00
|
|
|
|
from binascii import unhexlify
|
2017-09-13 16:00:51 +02:00
|
|
|
|
from distutils.version import LooseVersion
|
2014-08-30 17:07:29 +02:00
|
|
|
|
|
2015-07-22 08:19:56 +02:00
|
|
|
|
localmodule = os.path.realpath(
|
|
|
|
|
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
|
2014-08-30 17:07:29 +02:00
|
|
|
|
print('localmodule: ' + localmodule)
|
|
|
|
|
if localmodule not in sys.path:
|
2015-07-22 08:19:56 +02:00
|
|
|
|
sys.path.insert(0, localmodule)
|
2014-08-30 17:07:29 +02:00
|
|
|
|
|
|
|
|
|
import fdroidserver.common
|
2017-06-14 16:12:25 +02:00
|
|
|
|
import fdroidserver.exception
|
2017-04-19 10:04:32 +02:00
|
|
|
|
import fdroidserver.metadata
|
2014-08-30 17:07:29 +02:00
|
|
|
|
import fdroidserver.update
|
2015-01-20 22:43:55 +01:00
|
|
|
|
from fdroidserver.common import FDroidPopen
|
2014-08-30 17:07:29 +02:00
|
|
|
|
|
2015-07-22 08:19:56 +02:00
|
|
|
|
|
2014-08-30 17:07:29 +02:00
|
|
|
|
class UpdateTest(unittest.TestCase):
|
|
|
|
|
'''fdroid update'''
|
|
|
|
|
|
2017-12-14 11:06:22 +01:00
|
|
|
|
def setUp(self):
|
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
self.basedir = os.path.join(localmodule, 'tests')
|
|
|
|
|
self.tmpdir = os.path.abspath(os.path.join(self.basedir, '..', '.testfiles'))
|
|
|
|
|
if not os.path.exists(self.tmpdir):
|
|
|
|
|
os.makedirs(self.tmpdir)
|
|
|
|
|
os.chdir(self.basedir)
|
|
|
|
|
|
2017-04-13 23:36:46 +02:00
|
|
|
|
def testInsertStoreMetadata(self):
|
|
|
|
|
config = dict()
|
|
|
|
|
fdroidserver.common.fill_config_defaults(config)
|
|
|
|
|
config['accepted_formats'] = ('txt', 'yml')
|
|
|
|
|
fdroidserver.update.config = config
|
|
|
|
|
fdroidserver.update.options = fdroidserver.common.options
|
|
|
|
|
os.chdir(os.path.join(localmodule, 'tests'))
|
|
|
|
|
|
2017-05-16 12:25:42 +02:00
|
|
|
|
shutil.rmtree(os.path.join('repo', 'info.guardianproject.urzip'), ignore_errors=True)
|
|
|
|
|
|
2017-11-12 16:32:42 +01:00
|
|
|
|
shutil.rmtree(os.path.join('build', 'com.nextcloud.client'), ignore_errors=True)
|
2017-12-14 16:52:02 +01:00
|
|
|
|
shutil.copytree(os.path.join('source-files', 'com.nextcloud.client'),
|
|
|
|
|
os.path.join('build', 'com.nextcloud.client'))
|
2017-11-12 16:32:42 +01:00
|
|
|
|
|
|
|
|
|
shutil.rmtree(os.path.join('build', 'com.nextcloud.client.dev'), ignore_errors=True)
|
|
|
|
|
shutil.copytree(os.path.join('source-files', 'com.nextcloud.client.dev'),
|
|
|
|
|
os.path.join('build', 'com.nextcloud.client.dev'))
|
|
|
|
|
|
2017-12-14 16:52:02 +01:00
|
|
|
|
shutil.rmtree(os.path.join('build', 'eu.siacs.conversations'), ignore_errors=True)
|
|
|
|
|
shutil.copytree(os.path.join('source-files', 'eu.siacs.conversations'),
|
|
|
|
|
os.path.join('build', 'eu.siacs.conversations'))
|
|
|
|
|
|
2017-04-13 23:36:46 +02:00
|
|
|
|
apps = dict()
|
2017-11-12 16:32:42 +01:00
|
|
|
|
for packageName in ('info.guardianproject.urzip', 'org.videolan.vlc', 'obb.mainpatch.current',
|
2017-12-14 16:52:02 +01:00
|
|
|
|
'com.nextcloud.client', 'com.nextcloud.client.dev',
|
|
|
|
|
'eu.siacs.conversations'):
|
2017-11-12 16:32:42 +01:00
|
|
|
|
apps[packageName] = fdroidserver.metadata.App()
|
2017-04-13 23:36:46 +02:00
|
|
|
|
apps[packageName]['id'] = packageName
|
|
|
|
|
apps[packageName]['CurrentVersionCode'] = 0xcafebeef
|
2017-11-12 16:32:42 +01:00
|
|
|
|
|
2017-04-13 23:36:46 +02:00
|
|
|
|
apps['info.guardianproject.urzip']['CurrentVersionCode'] = 100
|
2017-11-12 16:32:42 +01:00
|
|
|
|
|
|
|
|
|
buildnextcloudclient = fdroidserver.metadata.Build()
|
|
|
|
|
buildnextcloudclient.gradle = ['generic']
|
|
|
|
|
apps['com.nextcloud.client']['builds'] = [buildnextcloudclient]
|
|
|
|
|
|
|
|
|
|
buildnextclouddevclient = fdroidserver.metadata.Build()
|
|
|
|
|
buildnextclouddevclient.gradle = ['versionDev']
|
|
|
|
|
apps['com.nextcloud.client.dev']['builds'] = [buildnextclouddevclient]
|
|
|
|
|
|
2017-12-14 16:52:02 +01:00
|
|
|
|
build_conversations = fdroidserver.metadata.Build()
|
|
|
|
|
build_conversations.gradle = ['free']
|
|
|
|
|
apps['eu.siacs.conversations']['builds'] = [build_conversations]
|
|
|
|
|
|
2017-04-13 23:36:46 +02:00
|
|
|
|
fdroidserver.update.insert_localized_app_metadata(apps)
|
|
|
|
|
|
2017-05-16 12:25:42 +02:00
|
|
|
|
appdir = os.path.join('repo', 'info.guardianproject.urzip', 'en-US')
|
|
|
|
|
self.assertTrue(os.path.isfile(os.path.join(appdir, 'icon.png')))
|
|
|
|
|
self.assertTrue(os.path.isfile(os.path.join(appdir, 'featureGraphic.png')))
|
|
|
|
|
|
2017-12-14 16:52:02 +01:00
|
|
|
|
self.assertEqual(6, len(apps))
|
2017-04-13 23:36:46 +02:00
|
|
|
|
for packageName, app in apps.items():
|
|
|
|
|
self.assertTrue('localized' in app)
|
|
|
|
|
self.assertTrue('en-US' in app['localized'])
|
|
|
|
|
self.assertEqual(1, len(app['localized']))
|
|
|
|
|
if packageName == 'info.guardianproject.urzip':
|
2017-05-16 12:25:42 +02:00
|
|
|
|
self.assertEqual(7, len(app['localized']['en-US']))
|
2017-04-27 21:12:49 +02:00
|
|
|
|
self.assertEqual('full description\n', app['localized']['en-US']['description'])
|
|
|
|
|
self.assertEqual('title\n', app['localized']['en-US']['name'])
|
|
|
|
|
self.assertEqual('short description\n', app['localized']['en-US']['summary'])
|
|
|
|
|
self.assertEqual('video\n', app['localized']['en-US']['video'])
|
2017-05-16 12:25:42 +02:00
|
|
|
|
self.assertEqual('icon.png', app['localized']['en-US']['icon'])
|
|
|
|
|
self.assertEqual('featureGraphic.png', app['localized']['en-US']['featureGraphic'])
|
2017-04-27 21:12:49 +02:00
|
|
|
|
self.assertEqual('100\n', app['localized']['en-US']['whatsNew'])
|
2017-04-13 23:36:46 +02:00
|
|
|
|
elif packageName == 'org.videolan.vlc':
|
|
|
|
|
self.assertEqual('icon.png', app['localized']['en-US']['icon'])
|
|
|
|
|
self.assertEqual(9, len(app['localized']['en-US']['phoneScreenshots']))
|
|
|
|
|
self.assertEqual(15, len(app['localized']['en-US']['sevenInchScreenshots']))
|
|
|
|
|
elif packageName == 'obb.mainpatch.current':
|
|
|
|
|
self.assertEqual('icon.png', app['localized']['en-US']['icon'])
|
|
|
|
|
self.assertEqual('featureGraphic.png', app['localized']['en-US']['featureGraphic'])
|
|
|
|
|
self.assertEqual(1, len(app['localized']['en-US']['phoneScreenshots']))
|
|
|
|
|
self.assertEqual(1, len(app['localized']['en-US']['sevenInchScreenshots']))
|
2017-11-12 16:32:42 +01:00
|
|
|
|
elif packageName == 'com.nextcloud.client':
|
|
|
|
|
self.assertEqual('Nextcloud', app['localized']['en-US']['name'])
|
|
|
|
|
self.assertEqual(1073, len(app['localized']['en-US']['description']))
|
|
|
|
|
self.assertEqual(78, len(app['localized']['en-US']['summary']))
|
|
|
|
|
elif packageName == 'com.nextcloud.client.dev':
|
|
|
|
|
self.assertEqual('Nextcloud Dev', app['localized']['en-US']['name'])
|
|
|
|
|
self.assertEqual(586, len(app['localized']['en-US']['description']))
|
|
|
|
|
self.assertEqual(79, len(app['localized']['en-US']['summary']))
|
2017-12-14 16:52:02 +01:00
|
|
|
|
elif packageName == 'eu.siacs.conversations':
|
|
|
|
|
self.assertEqual('Conversations', app['localized']['en-US']['name'])
|
2017-04-13 23:36:46 +02:00
|
|
|
|
|
2017-04-19 10:04:32 +02:00
|
|
|
|
def test_insert_triple_t_metadata(self):
|
2017-12-14 11:06:22 +01:00
|
|
|
|
importer = os.path.join(self.basedir, 'tmp', 'importer')
|
2017-04-19 10:04:32 +02:00
|
|
|
|
packageName = 'org.fdroid.ci.test.app'
|
|
|
|
|
if not os.path.isdir(importer):
|
|
|
|
|
logging.warning('skipping test_insert_triple_t_metadata, import.TestCase must run first!')
|
|
|
|
|
return
|
2017-12-14 11:06:22 +01:00
|
|
|
|
tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
|
|
|
|
|
dir=self.tmpdir)
|
2017-04-19 10:04:32 +02:00
|
|
|
|
packageDir = os.path.join(tmptestsdir, 'build', packageName)
|
|
|
|
|
shutil.copytree(importer, packageDir)
|
|
|
|
|
|
|
|
|
|
# always use the same commit so these tests work when ci-test-app.git is updated
|
|
|
|
|
repo = git.Repo(packageDir)
|
|
|
|
|
for remote in repo.remotes:
|
|
|
|
|
remote.fetch()
|
|
|
|
|
repo.git.reset('--hard', 'b9e5d1a0d8d6fc31d4674b2f0514fef10762ed4f')
|
|
|
|
|
repo.git.clean('-fdx')
|
|
|
|
|
|
|
|
|
|
os.mkdir(os.path.join(tmptestsdir, 'metadata'))
|
|
|
|
|
metadata = dict()
|
|
|
|
|
metadata['Description'] = 'This is just a test app'
|
|
|
|
|
with open(os.path.join(tmptestsdir, 'metadata', packageName + '.yml'), 'w') as fp:
|
|
|
|
|
yaml.dump(metadata, fp)
|
|
|
|
|
|
|
|
|
|
config = dict()
|
|
|
|
|
fdroidserver.common.fill_config_defaults(config)
|
|
|
|
|
config['accepted_formats'] = ('yml')
|
|
|
|
|
fdroidserver.common.config = config
|
|
|
|
|
fdroidserver.update.config = config
|
|
|
|
|
fdroidserver.update.options = fdroidserver.common.options
|
|
|
|
|
os.chdir(tmptestsdir)
|
|
|
|
|
|
|
|
|
|
apps = fdroidserver.metadata.read_metadata(xref=True)
|
|
|
|
|
fdroidserver.update.copy_triple_t_store_metadata(apps)
|
|
|
|
|
|
|
|
|
|
# TODO ideally, this would compare the whole dict like in metadata.TestCase's test_read_metadata()
|
|
|
|
|
correctlocales = [
|
|
|
|
|
'ar', 'ast_ES', 'az', 'ca', 'ca_ES', 'cs-CZ', 'cs_CZ', 'da',
|
|
|
|
|
'da-DK', 'de', 'de-DE', 'el', 'en-US', 'es', 'es-ES', 'es_ES', 'et',
|
|
|
|
|
'fi', 'fr', 'fr-FR', 'he_IL', 'hi-IN', 'hi_IN', 'hu', 'id', 'it',
|
|
|
|
|
'it-IT', 'it_IT', 'iw-IL', 'ja', 'ja-JP', 'kn_IN', 'ko', 'ko-KR',
|
|
|
|
|
'ko_KR', 'lt', 'nb', 'nb_NO', 'nl', 'nl-NL', 'no', 'pl', 'pl-PL',
|
|
|
|
|
'pl_PL', 'pt', 'pt-BR', 'pt-PT', 'pt_BR', 'ro', 'ro_RO', 'ru-RU',
|
|
|
|
|
'ru_RU', 'sv-SE', 'sv_SE', 'te', 'tr', 'tr-TR', 'uk', 'uk_UA', 'vi',
|
|
|
|
|
'vi_VN', 'zh-CN', 'zh_CN', 'zh_TW',
|
|
|
|
|
]
|
|
|
|
|
locales = sorted(list(apps['org.fdroid.ci.test.app']['localized'].keys()))
|
|
|
|
|
self.assertEqual(correctlocales, locales)
|
|
|
|
|
|
2014-08-30 17:07:29 +02:00
|
|
|
|
def javagetsig(self, apkfile):
|
2018-08-08 02:36:38 +02:00
|
|
|
|
getsig_dir = 'getsig'
|
2014-08-30 17:07:29 +02:00
|
|
|
|
if not os.path.exists(getsig_dir + "/getsig.class"):
|
|
|
|
|
logging.critical("getsig.class not found. To fix: cd '%s' && ./make.sh" % getsig_dir)
|
|
|
|
|
sys.exit(1)
|
2015-08-05 14:39:58 +02:00
|
|
|
|
# FDroidPopen needs some config to work
|
|
|
|
|
config = dict()
|
|
|
|
|
fdroidserver.common.fill_config_defaults(config)
|
|
|
|
|
fdroidserver.common.config = config
|
2018-08-08 02:36:38 +02:00
|
|
|
|
p = FDroidPopen(['java', '-cp', 'getsig',
|
|
|
|
|
'getsig', apkfile])
|
2014-08-30 17:07:29 +02:00
|
|
|
|
sig = None
|
|
|
|
|
for line in p.output.splitlines():
|
|
|
|
|
if line.startswith('Result:'):
|
|
|
|
|
sig = line[7:].strip()
|
|
|
|
|
break
|
|
|
|
|
if p.returncode == 0:
|
|
|
|
|
return sig
|
|
|
|
|
else:
|
|
|
|
|
return None
|
2015-07-22 08:19:56 +02:00
|
|
|
|
|
2014-08-30 17:07:29 +02:00
|
|
|
|
def testGoodGetsig(self):
|
2016-02-11 20:43:55 +01:00
|
|
|
|
# config needed to use jarsigner and keytool
|
|
|
|
|
config = dict()
|
|
|
|
|
fdroidserver.common.fill_config_defaults(config)
|
|
|
|
|
fdroidserver.update.config = config
|
2018-08-08 02:36:38 +02:00
|
|
|
|
apkfile = 'urzip.apk'
|
2014-08-30 17:07:29 +02:00
|
|
|
|
sig = self.javagetsig(apkfile)
|
|
|
|
|
self.assertIsNotNone(sig, "sig is None")
|
|
|
|
|
pysig = fdroidserver.update.getsig(apkfile)
|
2015-07-22 08:19:56 +02:00
|
|
|
|
self.assertIsNotNone(pysig, "pysig is None")
|
2016-06-10 12:02:03 +02:00
|
|
|
|
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!")
|
2014-08-30 17:07:29 +02:00
|
|
|
|
try:
|
2016-06-10 12:02:03 +02:00
|
|
|
|
self.assertEqual(unhexlify(sig), unhexlify(pysig),
|
|
|
|
|
"the length of the two sigs are different!")
|
2014-08-30 17:07:29 +02:00
|
|
|
|
except TypeError as e:
|
2016-01-04 17:28:55 +01:00
|
|
|
|
print(e)
|
2014-08-30 17:07:29 +02:00
|
|
|
|
self.assertTrue(False, 'TypeError!')
|
|
|
|
|
|
|
|
|
|
def testBadGetsig(self):
|
2017-06-01 16:24:31 +02:00
|
|
|
|
"""getsig() should still be able to fetch the fingerprint of bad signatures"""
|
2016-02-11 20:43:55 +01:00
|
|
|
|
# config needed to use jarsigner and keytool
|
|
|
|
|
config = dict()
|
|
|
|
|
fdroidserver.common.fill_config_defaults(config)
|
|
|
|
|
fdroidserver.update.config = config
|
2017-06-01 16:24:31 +02:00
|
|
|
|
|
2018-08-08 02:36:38 +02:00
|
|
|
|
apkfile = 'urzip-badsig.apk'
|
2017-06-01 16:24:31 +02:00
|
|
|
|
sig = fdroidserver.update.getsig(apkfile)
|
|
|
|
|
self.assertEqual(sig, 'e0ecb5fc2d63088e4a07ae410a127722',
|
|
|
|
|
"python sig should be: " + str(sig))
|
2014-08-30 17:07:29 +02:00
|
|
|
|
|
2018-08-08 02:36:38 +02:00
|
|
|
|
apkfile = 'urzip-badcert.apk'
|
2017-06-01 16:24:31 +02:00
|
|
|
|
sig = fdroidserver.update.getsig(apkfile)
|
|
|
|
|
self.assertEqual(sig, 'e0ecb5fc2d63088e4a07ae410a127722',
|
|
|
|
|
"python sig should be: " + str(sig))
|
2014-08-30 17:07:29 +02:00
|
|
|
|
|
2016-06-20 13:41:30 +02:00
|
|
|
|
def testScanApksAndObbs(self):
|
2017-04-13 23:36:46 +02:00
|
|
|
|
os.chdir(os.path.join(localmodule, 'tests'))
|
2016-06-14 11:43:07 +02:00
|
|
|
|
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()
|
2016-11-23 15:01:23 +01:00
|
|
|
|
config['accepted_formats'] = ['json', 'txt', 'yml']
|
2016-06-14 11:43:07 +02:00
|
|
|
|
fdroidserver.common.config = config
|
|
|
|
|
fdroidserver.update.config = config
|
|
|
|
|
|
|
|
|
|
fdroidserver.update.options = type('', (), {})()
|
|
|
|
|
fdroidserver.update.options.clean = True
|
2016-06-20 13:41:30 +02:00
|
|
|
|
fdroidserver.update.options.delete_unknown = True
|
2017-05-31 21:20:35 +02:00
|
|
|
|
fdroidserver.update.options.rename_apks = False
|
2017-06-27 21:40:39 +02:00
|
|
|
|
fdroidserver.update.options.allow_disabled_algorithms = False
|
2016-06-14 11:43:07 +02:00
|
|
|
|
|
2016-06-20 13:41:30 +02:00
|
|
|
|
apps = fdroidserver.metadata.read_metadata(xref=True)
|
2016-06-14 11:43:07 +02:00
|
|
|
|
knownapks = fdroidserver.common.KnownApks()
|
2017-06-14 16:12:25 +02:00
|
|
|
|
apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks, False)
|
2018-04-26 13:17:25 +02:00
|
|
|
|
self.assertEqual(len(apks), 14)
|
2016-06-14 11:43:07 +02:00
|
|
|
|
apk = apks[0]
|
2017-06-27 23:33:24 +02:00
|
|
|
|
self.assertEqual(apk['packageName'], 'com.politedroid')
|
|
|
|
|
self.assertEqual(apk['versionCode'], 3)
|
|
|
|
|
self.assertEqual(apk['minSdkVersion'], '3')
|
|
|
|
|
self.assertEqual(apk['targetSdkVersion'], '3')
|
|
|
|
|
self.assertFalse('maxSdkVersion' in apk)
|
2018-02-14 13:44:58 +01:00
|
|
|
|
apk = apks[6]
|
2017-06-27 23:33:24 +02:00
|
|
|
|
self.assertEqual(apk['packageName'], 'obb.main.oldversion')
|
|
|
|
|
self.assertEqual(apk['versionCode'], 1444412523)
|
2016-06-14 11:43:07 +02:00
|
|
|
|
self.assertEqual(apk['minSdkVersion'], '4')
|
|
|
|
|
self.assertEqual(apk['targetSdkVersion'], '18')
|
|
|
|
|
self.assertFalse('maxSdkVersion' in apk)
|
|
|
|
|
|
2016-06-20 13:41:30 +02:00
|
|
|
|
fdroidserver.update.insert_obbs('repo', apps, apks)
|
|
|
|
|
for apk in apks:
|
2016-11-29 13:40:21 +01:00
|
|
|
|
if apk['packageName'] == 'obb.mainpatch.current':
|
2016-06-20 13:41:30 +02:00
|
|
|
|
self.assertEqual(apk.get('obbMainFile'), 'main.1619.obb.mainpatch.current.obb')
|
|
|
|
|
self.assertEqual(apk.get('obbPatchFile'), 'patch.1619.obb.mainpatch.current.obb')
|
2016-11-29 13:40:21 +01:00
|
|
|
|
elif apk['packageName'] == 'obb.main.oldversion':
|
2016-06-20 13:41:30 +02:00
|
|
|
|
self.assertEqual(apk.get('obbMainFile'), 'main.1434483388.obb.main.oldversion.obb')
|
|
|
|
|
self.assertIsNone(apk.get('obbPatchFile'))
|
2016-11-29 13:40:21 +01:00
|
|
|
|
elif apk['packageName'] == 'obb.main.twoversions':
|
2016-06-20 13:41:30 +02:00
|
|
|
|
self.assertIsNone(apk.get('obbPatchFile'))
|
2016-11-29 13:40:21 +01:00
|
|
|
|
if apk['versionCode'] == 1101613:
|
2016-06-20 13:41:30 +02:00
|
|
|
|
self.assertEqual(apk.get('obbMainFile'), 'main.1101613.obb.main.twoversions.obb')
|
2016-11-29 13:40:21 +01:00
|
|
|
|
elif apk['versionCode'] == 1101615:
|
2016-06-20 13:41:30 +02:00
|
|
|
|
self.assertEqual(apk.get('obbMainFile'), 'main.1101615.obb.main.twoversions.obb')
|
2016-11-29 13:40:21 +01:00
|
|
|
|
elif apk['versionCode'] == 1101617:
|
2016-06-20 13:41:30 +02:00
|
|
|
|
self.assertEqual(apk.get('obbMainFile'), 'main.1101615.obb.main.twoversions.obb')
|
|
|
|
|
else:
|
|
|
|
|
self.assertTrue(False)
|
2016-11-29 13:40:21 +01:00
|
|
|
|
elif apk['packageName'] == 'info.guardianproject.urzip':
|
2016-06-20 13:41:30 +02:00
|
|
|
|
self.assertIsNone(apk.get('obbMainFile'))
|
|
|
|
|
self.assertIsNone(apk.get('obbPatchFile'))
|
|
|
|
|
|
2018-09-03 18:07:40 +02:00
|
|
|
|
def test_apkcache_json(self):
|
|
|
|
|
"""test the migration from pickle to json"""
|
|
|
|
|
os.chdir(os.path.join(localmodule, 'tests'))
|
|
|
|
|
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', 'yml']
|
|
|
|
|
fdroidserver.common.config = config
|
|
|
|
|
fdroidserver.update.config = config
|
|
|
|
|
|
|
|
|
|
fdroidserver.update.options = type('', (), {})()
|
|
|
|
|
fdroidserver.update.options.clean = True
|
|
|
|
|
fdroidserver.update.options.delete_unknown = True
|
|
|
|
|
fdroidserver.update.options.rename_apks = False
|
|
|
|
|
fdroidserver.update.options.allow_disabled_algorithms = False
|
|
|
|
|
|
|
|
|
|
fdroidserver.metadata.read_metadata(xref=True)
|
|
|
|
|
knownapks = fdroidserver.common.KnownApks()
|
|
|
|
|
apkcache = fdroidserver.update.get_cache()
|
|
|
|
|
self.assertEqual(2, len(apkcache))
|
|
|
|
|
self.assertEqual(fdroidserver.update.METADATA_VERSION, apkcache["METADATA_VERSION"])
|
|
|
|
|
self.assertEqual(fdroidserver.update.options.allow_disabled_algorithms,
|
|
|
|
|
apkcache['allow_disabled_algorithms'])
|
|
|
|
|
apks, cachechanged = fdroidserver.update.process_apks(apkcache, 'repo', knownapks, False)
|
|
|
|
|
fdroidserver.update.write_cache(apkcache)
|
|
|
|
|
|
|
|
|
|
fdroidserver.update.options.clean = False
|
|
|
|
|
read_from_json = fdroidserver.update.get_cache()
|
|
|
|
|
self.assertEqual(16, len(read_from_json))
|
|
|
|
|
for f in glob.glob('repo/*.apk'):
|
|
|
|
|
self.assertTrue(os.path.basename(f) in read_from_json)
|
|
|
|
|
|
|
|
|
|
fdroidserver.update.options.clean = True
|
|
|
|
|
reset = fdroidserver.update.get_cache()
|
|
|
|
|
self.assertEqual(2, len(reset))
|
|
|
|
|
|
2017-06-14 16:12:25 +02:00
|
|
|
|
def test_scan_apk(self):
|
|
|
|
|
config = dict()
|
|
|
|
|
fdroidserver.common.fill_config_defaults(config)
|
2018-04-16 11:35:30 +02:00
|
|
|
|
fdroidserver.common.config = config
|
2017-06-14 16:12:25 +02:00
|
|
|
|
fdroidserver.update.config = config
|
|
|
|
|
os.chdir(os.path.join(localmodule, 'tests'))
|
|
|
|
|
if os.path.basename(os.getcwd()) != 'tests':
|
|
|
|
|
raise Exception('This test must be run in the "tests/" subdir')
|
|
|
|
|
|
2018-04-26 13:17:25 +02:00
|
|
|
|
apk_info = fdroidserver.update.scan_apk('repo/souch.smsbypass_9.apk')
|
|
|
|
|
self.assertIsNone(apk_info.get('maxSdkVersion'))
|
|
|
|
|
self.assertEqual(apk_info.get('versionName'), '0.9')
|
|
|
|
|
|
2018-04-16 11:35:30 +02:00
|
|
|
|
apk_info = fdroidserver.update.scan_apk('repo/duplicate.permisssions_9999999.apk')
|
2018-08-08 02:36:38 +02:00
|
|
|
|
self.assertEqual(apk_info.get('versionName'), '')
|
2018-04-16 11:35:30 +02:00
|
|
|
|
self.assertEqual(apk_info['icons_src'], {'160': 'res/drawable/ic_launcher.png',
|
|
|
|
|
'-1': 'res/drawable/ic_launcher.png'})
|
|
|
|
|
|
2017-06-14 16:12:25 +02:00
|
|
|
|
apk_info = fdroidserver.update.scan_apk('org.dyndns.fules.ck_20.apk')
|
|
|
|
|
self.assertEqual(apk_info['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'})
|
|
|
|
|
self.assertEqual(apk_info['icons'], {})
|
|
|
|
|
self.assertEqual(apk_info['features'], [])
|
|
|
|
|
self.assertEqual(apk_info['antiFeatures'], set())
|
|
|
|
|
self.assertEqual(apk_info['versionName'], 'v1.6pre2')
|
|
|
|
|
self.assertEqual(apk_info['hash'],
|
|
|
|
|
'897486e1f857c6c0ee32ccbad0e1b8cd82f6d0e65a44a23f13f852d2b63a18c8')
|
|
|
|
|
self.assertEqual(apk_info['packageName'], 'org.dyndns.fules.ck')
|
|
|
|
|
self.assertEqual(apk_info['versionCode'], 20)
|
|
|
|
|
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['sig'], '9bf7a6a67f95688daec75eab4b1436ac')
|
|
|
|
|
self.assertEqual(apk_info['hashType'], 'sha256')
|
|
|
|
|
self.assertEqual(apk_info['targetSdkVersion'], '8')
|
|
|
|
|
|
2018-02-14 13:44:58 +01:00
|
|
|
|
apk_info = fdroidserver.update.scan_apk('org.bitbucket.tickytacky.mirrormirror_4.apk')
|
2018-04-26 13:20:43 +02:00
|
|
|
|
self.assertEqual(apk_info.get('versionName'), '1.0.3')
|
2018-02-14 13:44:58 +01:00
|
|
|
|
self.assertEqual(apk_info['icons_src'], {'160': 'res/drawable-mdpi/mirror.png',
|
|
|
|
|
'-1': 'res/drawable-mdpi/mirror.png'})
|
|
|
|
|
|
|
|
|
|
apk_info = fdroidserver.update.scan_apk('repo/info.zwanenburg.caffeinetile_4.apk')
|
2018-04-26 13:20:43 +02:00
|
|
|
|
self.assertEqual(apk_info.get('versionName'), '1.3')
|
2018-02-14 13:44:58 +01:00
|
|
|
|
self.assertEqual(apk_info['icons_src'], {'160': 'res/drawable/ic_coffee_on.xml',
|
|
|
|
|
'-1': 'res/drawable/ic_coffee_on.xml'})
|
|
|
|
|
|
|
|
|
|
apk_info = fdroidserver.update.scan_apk('repo/com.politedroid_6.apk')
|
2018-04-26 13:20:43 +02:00
|
|
|
|
self.assertEqual(apk_info.get('versionName'), '1.5')
|
2018-02-14 13:44:58 +01:00
|
|
|
|
self.assertEqual(apk_info['icons_src'], {'120': 'res/drawable-ldpi-v4/icon.png',
|
|
|
|
|
'160': 'res/drawable-mdpi-v4/icon.png',
|
|
|
|
|
'240': 'res/drawable-hdpi-v4/icon.png',
|
|
|
|
|
'320': 'res/drawable-xhdpi-v4/icon.png',
|
|
|
|
|
'-1': 'res/drawable-mdpi-v4/icon.png'})
|
|
|
|
|
|
2018-03-11 22:09:09 +01:00
|
|
|
|
apk_info = fdroidserver.update.scan_apk('SpeedoMeterApp.main_1.apk')
|
2018-04-26 13:20:43 +02:00
|
|
|
|
self.assertEqual(apk_info.get('versionName'), '1.0')
|
2018-03-11 22:09:09 +01:00
|
|
|
|
self.assertEqual(apk_info['icons_src'], {})
|
|
|
|
|
|
2017-06-14 16:12:25 +02:00
|
|
|
|
def test_scan_apk_no_sig(self):
|
|
|
|
|
config = dict()
|
|
|
|
|
fdroidserver.common.fill_config_defaults(config)
|
|
|
|
|
fdroidserver.update.config = config
|
|
|
|
|
os.chdir(os.path.join(localmodule, 'tests'))
|
|
|
|
|
if os.path.basename(os.getcwd()) != 'tests':
|
|
|
|
|
raise Exception('This test must be run in the "tests/" subdir')
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(fdroidserver.exception.BuildException):
|
|
|
|
|
fdroidserver.update.scan_apk('urzip-release-unsigned.apk')
|
|
|
|
|
|
|
|
|
|
def test_process_apk(self):
|
2017-04-13 14:18:48 +02:00
|
|
|
|
|
|
|
|
|
def _build_yaml_representer(dumper, data):
|
|
|
|
|
'''Creates a YAML representation of a Build instance'''
|
|
|
|
|
return dumper.represent_dict(data)
|
|
|
|
|
|
|
|
|
|
config = dict()
|
|
|
|
|
fdroidserver.common.fill_config_defaults(config)
|
|
|
|
|
fdroidserver.update.config = config
|
2017-06-27 21:40:39 +02:00
|
|
|
|
os.chdir(os.path.join(localmodule, 'tests'))
|
2017-04-13 14:18:48 +02:00
|
|
|
|
if os.path.basename(os.getcwd()) != 'tests':
|
|
|
|
|
raise Exception('This test must be run in the "tests/" subdir')
|
|
|
|
|
|
|
|
|
|
config['ndk_paths'] = dict()
|
|
|
|
|
config['accepted_formats'] = ['json', 'txt', 'yml']
|
|
|
|
|
fdroidserver.common.config = config
|
|
|
|
|
fdroidserver.update.config = config
|
|
|
|
|
|
|
|
|
|
fdroidserver.update.options = type('', (), {})()
|
|
|
|
|
fdroidserver.update.options.clean = True
|
2017-05-16 12:25:42 +02:00
|
|
|
|
fdroidserver.update.options.rename_apks = False
|
2017-04-13 14:18:48 +02:00
|
|
|
|
fdroidserver.update.options.delete_unknown = True
|
2017-06-27 21:40:39 +02:00
|
|
|
|
fdroidserver.update.options.allow_disabled_algorithms = False
|
2017-04-13 14:18:48 +02:00
|
|
|
|
|
|
|
|
|
for icon_dir in fdroidserver.update.get_all_icon_dirs('repo'):
|
|
|
|
|
if not os.path.exists(icon_dir):
|
|
|
|
|
os.makedirs(icon_dir)
|
|
|
|
|
|
|
|
|
|
knownapks = fdroidserver.common.KnownApks()
|
|
|
|
|
apkList = ['../urzip.apk', '../org.dyndns.fules.ck_20.apk']
|
|
|
|
|
|
|
|
|
|
for apkName in apkList:
|
2017-06-14 16:12:25 +02:00
|
|
|
|
_, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'repo', knownapks,
|
|
|
|
|
False)
|
2017-04-13 14:18:48 +02:00
|
|
|
|
# Don't care about the date added to the repo and relative apkName
|
|
|
|
|
del apk['added']
|
|
|
|
|
del apk['apkName']
|
|
|
|
|
# avoid AAPT application name bug
|
|
|
|
|
del apk['name']
|
|
|
|
|
|
2017-06-14 16:12:25 +02:00
|
|
|
|
# ensure that icons have been extracted properly
|
|
|
|
|
if apkName == '../urzip.apk':
|
|
|
|
|
self.assertEqual(apk['icon'], 'info.guardianproject.urzip.100.png')
|
|
|
|
|
if apkName == '../org.dyndns.fules.ck_20.apk':
|
|
|
|
|
self.assertEqual(apk['icon'], 'org.dyndns.fules.ck.20.png')
|
|
|
|
|
for density in fdroidserver.update.screen_densities:
|
|
|
|
|
icon_path = os.path.join(fdroidserver.update.get_icon_dir('repo', density),
|
|
|
|
|
apk['icon'])
|
|
|
|
|
self.assertTrue(os.path.isfile(icon_path))
|
|
|
|
|
self.assertTrue(os.path.getsize(icon_path) > 1)
|
|
|
|
|
|
2017-04-13 14:18:48 +02:00
|
|
|
|
savepath = os.path.join('metadata', 'apk', apk['packageName'] + '.yaml')
|
|
|
|
|
# Uncomment to save APK metadata
|
|
|
|
|
# with open(savepath, 'w') as f:
|
|
|
|
|
# yaml.add_representer(fdroidserver.metadata.Build, _build_yaml_representer)
|
|
|
|
|
# yaml.dump(apk, f, default_flow_style=False)
|
|
|
|
|
|
|
|
|
|
with open(savepath, 'r') as f:
|
|
|
|
|
frompickle = yaml.load(f)
|
|
|
|
|
self.maxDiff = None
|
|
|
|
|
self.assertEqual(apk, frompickle)
|
|
|
|
|
|
2017-06-14 16:12:25 +02:00
|
|
|
|
def test_process_apk_signed_by_disabled_algorithms(self):
|
2017-06-27 21:40:39 +02:00
|
|
|
|
config = dict()
|
|
|
|
|
fdroidserver.common.fill_config_defaults(config)
|
|
|
|
|
fdroidserver.update.config = config
|
|
|
|
|
|
|
|
|
|
config['ndk_paths'] = dict()
|
|
|
|
|
config['accepted_formats'] = ['json', 'txt', 'yml']
|
|
|
|
|
fdroidserver.common.config = config
|
|
|
|
|
fdroidserver.update.config = config
|
|
|
|
|
|
|
|
|
|
fdroidserver.update.options = type('', (), {})()
|
|
|
|
|
fdroidserver.update.options.clean = True
|
|
|
|
|
fdroidserver.update.options.verbose = True
|
|
|
|
|
fdroidserver.update.options.rename_apks = False
|
|
|
|
|
fdroidserver.update.options.delete_unknown = True
|
|
|
|
|
fdroidserver.update.options.allow_disabled_algorithms = False
|
|
|
|
|
|
|
|
|
|
knownapks = fdroidserver.common.KnownApks()
|
2017-12-14 11:06:22 +01:00
|
|
|
|
|
2017-11-30 09:59:02 +01:00
|
|
|
|
tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
|
2017-12-14 11:06:22 +01:00
|
|
|
|
dir=self.tmpdir)
|
2017-06-27 21:40:39 +02:00
|
|
|
|
print('tmptestsdir', tmptestsdir)
|
|
|
|
|
os.chdir(tmptestsdir)
|
|
|
|
|
os.mkdir('repo')
|
|
|
|
|
os.mkdir('archive')
|
|
|
|
|
# setup the repo, create icons dirs, etc.
|
2017-06-14 16:12:25 +02:00
|
|
|
|
fdroidserver.update.process_apks({}, 'repo', knownapks)
|
|
|
|
|
fdroidserver.update.process_apks({}, 'archive', knownapks)
|
2017-06-27 21:40:39 +02:00
|
|
|
|
|
|
|
|
|
disabledsigs = ['org.bitbucket.tickytacky.mirrormirror_2.apk', ]
|
|
|
|
|
for apkName in disabledsigs:
|
2017-12-14 11:06:22 +01:00
|
|
|
|
shutil.copy(os.path.join(self.basedir, apkName),
|
2017-06-27 21:40:39 +02:00
|
|
|
|
os.path.join(tmptestsdir, 'repo'))
|
|
|
|
|
|
2017-06-14 16:12:25 +02:00
|
|
|
|
skip, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'repo',
|
|
|
|
|
knownapks,
|
|
|
|
|
allow_disabled_algorithms=True,
|
|
|
|
|
archive_bad_sig=False)
|
2017-06-27 21:40:39 +02:00
|
|
|
|
self.assertFalse(skip)
|
|
|
|
|
self.assertIsNotNone(apk)
|
|
|
|
|
self.assertTrue(cachechanged)
|
|
|
|
|
self.assertFalse(os.path.exists(os.path.join('archive', apkName)))
|
|
|
|
|
self.assertTrue(os.path.exists(os.path.join('repo', apkName)))
|
|
|
|
|
|
2017-09-13 16:00:51 +02:00
|
|
|
|
javac = config['jarsigner'].replace('jarsigner', 'javac')
|
|
|
|
|
v = subprocess.check_output([javac, '-version'], stderr=subprocess.STDOUT)[6:-1].decode('utf-8')
|
|
|
|
|
if LooseVersion(v) < LooseVersion('1.8.0_132'):
|
|
|
|
|
print('SKIPPING: running tests with old Java (' + v + ')')
|
|
|
|
|
return
|
|
|
|
|
|
2017-06-27 21:40:39 +02:00
|
|
|
|
# this test only works on systems with fully updated Java/jarsigner
|
|
|
|
|
# that has MD5 listed in jdk.jar.disabledAlgorithms in java.security
|
2017-09-13 16:00:51 +02:00
|
|
|
|
# https://blogs.oracle.com/java-platform-group/oracle-jre-will-no-longer-trust-md5-signed-code-by-default
|
2017-06-14 16:12:25 +02:00
|
|
|
|
skip, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'repo',
|
|
|
|
|
knownapks,
|
|
|
|
|
allow_disabled_algorithms=False,
|
|
|
|
|
archive_bad_sig=True)
|
2017-06-27 21:40:39 +02:00
|
|
|
|
self.assertTrue(skip)
|
|
|
|
|
self.assertIsNone(apk)
|
|
|
|
|
self.assertFalse(cachechanged)
|
|
|
|
|
self.assertTrue(os.path.exists(os.path.join('archive', apkName)))
|
|
|
|
|
self.assertFalse(os.path.exists(os.path.join('repo', apkName)))
|
|
|
|
|
|
2017-06-14 16:12:25 +02:00
|
|
|
|
skip, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'archive',
|
|
|
|
|
knownapks,
|
|
|
|
|
allow_disabled_algorithms=False,
|
|
|
|
|
archive_bad_sig=False)
|
2017-06-27 21:40:39 +02:00
|
|
|
|
self.assertFalse(skip)
|
|
|
|
|
self.assertIsNotNone(apk)
|
|
|
|
|
self.assertTrue(cachechanged)
|
|
|
|
|
self.assertTrue(os.path.exists(os.path.join('archive', apkName)))
|
|
|
|
|
self.assertFalse(os.path.exists(os.path.join('repo', apkName)))
|
|
|
|
|
|
2017-06-14 16:12:25 +02:00
|
|
|
|
# ensure that icons have been moved to the archive as well
|
|
|
|
|
for density in fdroidserver.update.screen_densities:
|
|
|
|
|
icon_path = os.path.join(fdroidserver.update.get_icon_dir('archive', density),
|
|
|
|
|
apk['icon'])
|
|
|
|
|
self.assertTrue(os.path.isfile(icon_path))
|
|
|
|
|
self.assertTrue(os.path.getsize(icon_path) > 1)
|
|
|
|
|
|
2017-06-27 21:40:39 +02:00
|
|
|
|
badsigs = ['urzip-badcert.apk', 'urzip-badsig.apk', 'urzip-release-unsigned.apk', ]
|
|
|
|
|
for apkName in badsigs:
|
2017-12-14 11:06:22 +01:00
|
|
|
|
shutil.copy(os.path.join(self.basedir, apkName),
|
2017-06-27 21:40:39 +02:00
|
|
|
|
os.path.join(tmptestsdir, 'repo'))
|
|
|
|
|
|
2017-06-14 16:12:25 +02:00
|
|
|
|
skip, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'repo',
|
|
|
|
|
knownapks,
|
|
|
|
|
allow_disabled_algorithms=False,
|
|
|
|
|
archive_bad_sig=False)
|
2017-06-27 21:40:39 +02:00
|
|
|
|
self.assertTrue(skip)
|
|
|
|
|
self.assertIsNone(apk)
|
|
|
|
|
self.assertFalse(cachechanged)
|
|
|
|
|
|
2017-06-14 16:12:25 +02:00
|
|
|
|
def test_process_invalid_apk(self):
|
2017-04-13 23:36:46 +02:00
|
|
|
|
os.chdir(os.path.join(localmodule, 'tests'))
|
2017-04-03 18:07:49 +02:00
|
|
|
|
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)
|
|
|
|
|
fdroidserver.common.config = config
|
|
|
|
|
fdroidserver.update.config = config
|
|
|
|
|
fdroidserver.update.options.delete_unknown = False
|
|
|
|
|
|
|
|
|
|
knownapks = fdroidserver.common.KnownApks()
|
|
|
|
|
apk = 'fake.ota.update_1234.zip' # this is not an APK, scanning should fail
|
2017-06-14 16:12:25 +02:00
|
|
|
|
(skip, apk, cachechanged) = fdroidserver.update.process_apk({}, apk, 'repo', knownapks,
|
|
|
|
|
False)
|
2017-04-03 18:07:49 +02:00
|
|
|
|
|
|
|
|
|
self.assertTrue(skip)
|
|
|
|
|
self.assertIsNone(apk)
|
|
|
|
|
self.assertFalse(cachechanged)
|
|
|
|
|
|
2017-06-27 23:55:38 +02:00
|
|
|
|
def test_translate_per_build_anti_features(self):
|
|
|
|
|
os.chdir(os.path.join(localmodule, 'tests'))
|
|
|
|
|
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', 'yml']
|
|
|
|
|
fdroidserver.common.config = config
|
|
|
|
|
fdroidserver.update.config = config
|
|
|
|
|
|
|
|
|
|
fdroidserver.update.options = type('', (), {})()
|
|
|
|
|
fdroidserver.update.options.clean = True
|
|
|
|
|
fdroidserver.update.options.delete_unknown = True
|
|
|
|
|
fdroidserver.update.options.rename_apks = False
|
|
|
|
|
fdroidserver.update.options.allow_disabled_algorithms = False
|
|
|
|
|
|
|
|
|
|
apps = fdroidserver.metadata.read_metadata(xref=True)
|
|
|
|
|
knownapks = fdroidserver.common.KnownApks()
|
|
|
|
|
apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks, False)
|
|
|
|
|
fdroidserver.update.translate_per_build_anti_features(apps, apks)
|
2018-04-26 13:17:25 +02:00
|
|
|
|
self.assertEqual(len(apks), 14)
|
2017-06-27 23:55:38 +02:00
|
|
|
|
foundtest = False
|
|
|
|
|
for apk in apks:
|
|
|
|
|
if apk['packageName'] == 'com.politedroid' and apk['versionCode'] == 3:
|
|
|
|
|
antiFeatures = apk.get('antiFeatures')
|
|
|
|
|
self.assertTrue('KnownVuln' in antiFeatures)
|
|
|
|
|
self.assertEqual(3, len(antiFeatures))
|
|
|
|
|
foundtest = True
|
|
|
|
|
self.assertTrue(foundtest)
|
|
|
|
|
|
2017-07-27 00:34:13 +02:00
|
|
|
|
def test_create_metadata_from_template(self):
|
2017-11-30 09:59:02 +01:00
|
|
|
|
tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
|
2017-12-14 11:06:22 +01:00
|
|
|
|
dir=self.tmpdir)
|
2017-07-27 00:34:13 +02:00
|
|
|
|
print('tmptestsdir', tmptestsdir)
|
|
|
|
|
os.chdir(tmptestsdir)
|
|
|
|
|
os.mkdir('repo')
|
2017-07-27 03:21:28 +02:00
|
|
|
|
os.mkdir('metadata')
|
2017-07-27 00:34:13 +02:00
|
|
|
|
shutil.copy(os.path.join(localmodule, 'tests', 'urzip.apk'), 'repo')
|
|
|
|
|
|
|
|
|
|
config = dict()
|
|
|
|
|
fdroidserver.common.fill_config_defaults(config)
|
|
|
|
|
config['ndk_paths'] = dict()
|
|
|
|
|
config['accepted_formats'] = ['json', 'txt', 'yml']
|
|
|
|
|
fdroidserver.common.config = config
|
|
|
|
|
fdroidserver.update.config = config
|
|
|
|
|
|
|
|
|
|
fdroidserver.update.options = type('', (), {})()
|
|
|
|
|
fdroidserver.update.options.clean = True
|
|
|
|
|
fdroidserver.update.options.delete_unknown = False
|
|
|
|
|
fdroidserver.update.options.rename_apks = False
|
|
|
|
|
fdroidserver.update.options.allow_disabled_algorithms = False
|
|
|
|
|
|
|
|
|
|
knownapks = fdroidserver.common.KnownApks()
|
|
|
|
|
apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks, False)
|
|
|
|
|
self.assertEqual(1, len(apks))
|
|
|
|
|
apk = apks[0]
|
|
|
|
|
|
2017-07-27 03:21:28 +02:00
|
|
|
|
testfile = 'metadata/info.guardianproject.urzip.yml'
|
|
|
|
|
# create empty 0 byte .yml file, run read_metadata, it should work
|
|
|
|
|
open(testfile, 'a').close()
|
|
|
|
|
apps = fdroidserver.metadata.read_metadata(xref=True)
|
|
|
|
|
self.assertEqual(1, len(apps))
|
|
|
|
|
os.remove(testfile)
|
|
|
|
|
|
2017-07-27 00:34:13 +02:00
|
|
|
|
# test using internal template
|
2017-07-27 03:21:28 +02:00
|
|
|
|
apps = fdroidserver.metadata.read_metadata(xref=True)
|
|
|
|
|
self.assertEqual(0, len(apps))
|
2017-07-27 00:34:13 +02:00
|
|
|
|
fdroidserver.update.create_metadata_from_template(apk)
|
2017-07-27 03:21:28 +02:00
|
|
|
|
self.assertTrue(os.path.exists(testfile))
|
2017-07-27 00:34:13 +02:00
|
|
|
|
apps = fdroidserver.metadata.read_metadata(xref=True)
|
|
|
|
|
self.assertEqual(1, len(apps))
|
|
|
|
|
for app in apps.values():
|
|
|
|
|
self.assertEqual('urzip', app['Name'])
|
|
|
|
|
self.assertEqual(1, len(app['Categories']))
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
# test using external template.yml
|
2017-07-27 03:21:28 +02:00
|
|
|
|
os.remove(testfile)
|
|
|
|
|
self.assertFalse(os.path.exists(testfile))
|
2017-07-27 00:34:13 +02:00
|
|
|
|
shutil.copy(os.path.join(localmodule, 'examples', 'template.yml'), tmptestsdir)
|
|
|
|
|
fdroidserver.update.create_metadata_from_template(apk)
|
2017-07-27 03:21:28 +02:00
|
|
|
|
self.assertTrue(os.path.exists(testfile))
|
2017-07-27 00:34:13 +02:00
|
|
|
|
apps = fdroidserver.metadata.read_metadata(xref=True)
|
|
|
|
|
self.assertEqual(1, len(apps))
|
|
|
|
|
for app in apps.values():
|
|
|
|
|
self.assertEqual('urzip', app['Name'])
|
|
|
|
|
self.assertEqual(1, len(app['Categories']))
|
|
|
|
|
self.assertEqual('Internet', app['Categories'][0])
|
|
|
|
|
break
|
2017-07-27 03:21:28 +02:00
|
|
|
|
with open(testfile) as fp:
|
2017-07-27 00:34:13 +02:00
|
|
|
|
data = yaml.load(fp)
|
|
|
|
|
self.assertEqual('urzip', data['Name'])
|
|
|
|
|
self.assertEqual('urzip', data['Summary'])
|
|
|
|
|
|
2017-12-11 18:36:21 +01:00
|
|
|
|
def test_has_known_vulnerability(self):
|
|
|
|
|
good = [
|
|
|
|
|
'org.bitbucket.tickytacky.mirrormirror_1.apk',
|
|
|
|
|
'org.bitbucket.tickytacky.mirrormirror_2.apk',
|
|
|
|
|
'org.bitbucket.tickytacky.mirrormirror_3.apk',
|
|
|
|
|
'org.bitbucket.tickytacky.mirrormirror_4.apk',
|
|
|
|
|
'org.dyndns.fules.ck_20.apk',
|
|
|
|
|
'urzip.apk',
|
|
|
|
|
'urzip-badcert.apk',
|
|
|
|
|
'urzip-badsig.apk',
|
|
|
|
|
'urzip-release.apk',
|
|
|
|
|
'urzip-release-unsigned.apk',
|
|
|
|
|
'repo/com.politedroid_3.apk',
|
|
|
|
|
'repo/com.politedroid_4.apk',
|
|
|
|
|
'repo/com.politedroid_5.apk',
|
|
|
|
|
'repo/com.politedroid_6.apk',
|
|
|
|
|
'repo/obb.main.oldversion_1444412523.apk',
|
|
|
|
|
'repo/obb.mainpatch.current_1619_another-release-key.apk',
|
|
|
|
|
'repo/obb.mainpatch.current_1619.apk',
|
|
|
|
|
'repo/obb.main.twoversions_1101613.apk',
|
|
|
|
|
'repo/obb.main.twoversions_1101615.apk',
|
|
|
|
|
'repo/obb.main.twoversions_1101617.apk',
|
2018-05-25 17:27:58 +02:00
|
|
|
|
'repo/urzip-; Рахма́, [rɐxˈmanʲɪnəf] سيرجي_رخمانينوف 谢·.apk',
|
2017-12-11 18:36:21 +01:00
|
|
|
|
]
|
|
|
|
|
for f in good:
|
|
|
|
|
self.assertFalse(fdroidserver.update.has_known_vulnerability(f))
|
|
|
|
|
with self.assertRaises(fdroidserver.exception.FDroidException):
|
|
|
|
|
fdroidserver.update.has_known_vulnerability('janus.apk')
|
|
|
|
|
|
2018-03-27 18:39:59 +02:00
|
|
|
|
def test_get_apk_icon_when_src_is_none(self):
|
|
|
|
|
config = dict()
|
|
|
|
|
fdroidserver.common.fill_config_defaults(config)
|
|
|
|
|
fdroidserver.common.config = config
|
|
|
|
|
fdroidserver.update.config = config
|
|
|
|
|
|
|
|
|
|
# pylint: disable=protected-access
|
|
|
|
|
icons_src = fdroidserver.update._get_apk_icons_src('urzip-release.apk', None)
|
|
|
|
|
assert icons_src == {}
|
|
|
|
|
|
2014-08-30 17:07:29 +02:00
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-08-08 02:36:38 +02:00
|
|
|
|
os.chdir(os.path.dirname(__file__))
|
|
|
|
|
|
2014-08-30 17:07:29 +02:00
|
|
|
|
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))
|
2017-10-20 11:51:59 +02:00
|
|
|
|
unittest.main(failfast=False)
|