import optparse
import os
import shutil
+import subprocess
import sys
import tempfile
import unittest
import yaml
from binascii import unhexlify
+from distutils.version import LooseVersion
localmodule = os.path.realpath(
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
class UpdateTest(unittest.TestCase):
'''fdroid update'''
+ 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)
+
def testInsertStoreMetadata(self):
config = dict()
fdroidserver.common.fill_config_defaults(config)
shutil.rmtree(os.path.join('repo', 'info.guardianproject.urzip'), ignore_errors=True)
+ shutil.rmtree(os.path.join('build', 'com.nextcloud.client'), ignore_errors=True)
+ shutil.copytree(os.path.join('source-files', 'com.nextcloud.client'),
+ os.path.join('build', 'com.nextcloud.client'))
+
+ 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'))
+
+ 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'))
+
apps = dict()
- for packageName in ('info.guardianproject.urzip', 'org.videolan.vlc', 'obb.mainpatch.current'):
- apps[packageName] = dict()
+ for packageName in ('info.guardianproject.urzip', 'org.videolan.vlc', 'obb.mainpatch.current',
+ 'com.nextcloud.client', 'com.nextcloud.client.dev',
+ 'eu.siacs.conversations'):
+ apps[packageName] = fdroidserver.metadata.App()
apps[packageName]['id'] = packageName
apps[packageName]['CurrentVersionCode'] = 0xcafebeef
+
apps['info.guardianproject.urzip']['CurrentVersionCode'] = 100
+
+ 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]
+
+ build_conversations = fdroidserver.metadata.Build()
+ build_conversations.gradle = ['free']
+ apps['eu.siacs.conversations']['builds'] = [build_conversations]
+
fdroidserver.update.insert_localized_app_metadata(apps)
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')))
- self.assertEqual(3, len(apps))
+ self.assertEqual(6, len(apps))
for packageName, app in apps.items():
self.assertTrue('localized' in app)
self.assertTrue('en-US' in app['localized'])
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']))
+ 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']))
+ elif packageName == 'eu.siacs.conversations':
+ self.assertEqual('Conversations', app['localized']['en-US']['name'])
def test_insert_triple_t_metadata(self):
- importer = os.path.join(localmodule, 'tests', 'tmp', 'importer')
+ importer = os.path.join(self.basedir, 'tmp', 'importer')
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
- tmpdir = os.path.join(localmodule, '.testfiles')
- if not os.path.exists(tmpdir):
- os.makedirs(tmpdir)
- tmptestsdir = tempfile.mkdtemp(prefix='test_insert_triple_t_metadata-', dir=tmpdir)
+ tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
+ dir=self.tmpdir)
packageDir = os.path.join(tmptestsdir, 'build', packageName)
shutil.copytree(importer, packageDir)
self.assertEqual(apk, frompickle)
def test_process_apk_signed_by_disabled_algorithms(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)
fdroidserver.update.config = config
fdroidserver.update.options.allow_disabled_algorithms = False
knownapks = fdroidserver.common.KnownApks()
- apksourcedir = os.getcwd()
- tmpdir = os.path.join(localmodule, '.testfiles')
- if not os.path.exists(tmpdir):
- os.makedirs(tmpdir)
- tmptestsdir = tempfile.mkdtemp(prefix='test_process_apk_signed_by_disabled_algorithms-',
- dir=tmpdir)
+
+ tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
+ dir=self.tmpdir)
print('tmptestsdir', tmptestsdir)
os.chdir(tmptestsdir)
os.mkdir('repo')
disabledsigs = ['org.bitbucket.tickytacky.mirrormirror_2.apk', ]
for apkName in disabledsigs:
- shutil.copy(os.path.join(apksourcedir, apkName),
+ shutil.copy(os.path.join(self.basedir, apkName),
os.path.join(tmptestsdir, 'repo'))
skip, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'repo',
self.assertFalse(os.path.exists(os.path.join('archive', apkName)))
self.assertTrue(os.path.exists(os.path.join('repo', apkName)))
+ 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
+
# this test only works on systems with fully updated Java/jarsigner
# that has MD5 listed in jdk.jar.disabledAlgorithms in java.security
+ # https://blogs.oracle.com/java-platform-group/oracle-jre-will-no-longer-trust-md5-signed-code-by-default
skip, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'repo',
knownapks,
allow_disabled_algorithms=False,
badsigs = ['urzip-badcert.apk', 'urzip-badsig.apk', 'urzip-release-unsigned.apk', ]
for apkName in badsigs:
- shutil.copy(os.path.join(apksourcedir, apkName),
+ shutil.copy(os.path.join(self.basedir, apkName),
os.path.join(tmptestsdir, 'repo'))
skip, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'repo',
self.assertTrue(foundtest)
def test_create_metadata_from_template(self):
- tmpdir = os.path.join(localmodule, '.testfiles')
- if not os.path.exists(tmpdir):
- os.makedirs(tmpdir)
- tmptestsdir = tempfile.mkdtemp(prefix='test_create_metadata_from_template-',
- dir=tmpdir)
+ tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
+ dir=self.tmpdir)
print('tmptestsdir', tmptestsdir)
os.chdir(tmptestsdir)
os.mkdir('repo')
+ os.mkdir('metadata')
shutil.copy(os.path.join(localmodule, 'tests', 'urzip.apk'), 'repo')
config = dict()
fdroidserver.update.options.rename_apks = False
fdroidserver.update.options.allow_disabled_algorithms = False
- apps = fdroidserver.metadata.read_metadata(xref=True)
- self.assertEqual(0, len(apps))
knownapks = fdroidserver.common.KnownApks()
apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks, False)
self.assertEqual(1, len(apks))
apk = apks[0]
+ 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)
+
# test using internal template
+ apps = fdroidserver.metadata.read_metadata(xref=True)
+ self.assertEqual(0, len(apps))
fdroidserver.update.create_metadata_from_template(apk)
- self.assertTrue(os.path.exists('metadata/info.guardianproject.urzip.yml'))
+ self.assertTrue(os.path.exists(testfile))
apps = fdroidserver.metadata.read_metadata(xref=True)
self.assertEqual(1, len(apps))
for app in apps.values():
break
# test using external template.yml
- os.remove('metadata/info.guardianproject.urzip.yml')
- self.assertFalse(os.path.exists('metadata/info.guardianproject.urzip.yml'))
+ os.remove(testfile)
+ self.assertFalse(os.path.exists(testfile))
shutil.copy(os.path.join(localmodule, 'examples', 'template.yml'), tmptestsdir)
fdroidserver.update.create_metadata_from_template(apk)
- self.assertTrue(os.path.exists('metadata/info.guardianproject.urzip.yml'))
+ self.assertTrue(os.path.exists(testfile))
apps = fdroidserver.metadata.read_metadata(xref=True)
self.assertEqual(1, len(apps))
for app in apps.values():
self.assertEqual(1, len(app['Categories']))
self.assertEqual('Internet', app['Categories'][0])
break
- with open('metadata/info.guardianproject.urzip.yml') as fp:
+ with open(testfile) as fp:
data = yaml.load(fp)
self.assertEqual('urzip', data['Name'])
self.assertEqual('urzip', data['Summary'])
newSuite = unittest.TestSuite()
newSuite.addTest(unittest.makeSuite(UpdateTest))
- unittest.main()
+ unittest.main(failfast=False)