mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-13 14:32:28 +03:00
tests: use context manager and/or standard setup temp files
This commit is contained in:
parent
1eeb992118
commit
d29a486e31
12 changed files with 465 additions and 680 deletions
|
@ -22,11 +22,14 @@ print('localmodule: ' + localmodule)
|
||||||
if localmodule not in sys.path:
|
if localmodule not in sys.path:
|
||||||
sys.path.insert(0, localmodule)
|
sys.path.insert(0, localmodule)
|
||||||
|
|
||||||
|
from testcommon import TmpCwd
|
||||||
|
|
||||||
import fdroidserver.build
|
import fdroidserver.build
|
||||||
import fdroidserver.common
|
import fdroidserver.common
|
||||||
import fdroidserver.metadata
|
import fdroidserver.metadata
|
||||||
import fdroidserver.scanner
|
import fdroidserver.scanner
|
||||||
import fdroidserver.vmtools
|
import fdroidserver.vmtools
|
||||||
|
from testcommon import mkdtemp
|
||||||
|
|
||||||
|
|
||||||
class FakeProcess:
|
class FakeProcess:
|
||||||
|
@ -45,12 +48,15 @@ class BuildTest(unittest.TestCase):
|
||||||
logger = logging.getLogger('androguard.axml')
|
logger = logging.getLogger('androguard.axml')
|
||||||
logger.setLevel(logging.INFO) # tame the axml debug messages
|
logger.setLevel(logging.INFO) # tame the axml debug messages
|
||||||
self.basedir = os.path.join(localmodule, 'tests')
|
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)
|
os.chdir(self.basedir)
|
||||||
fdroidserver.common.config = None
|
fdroidserver.common.config = None
|
||||||
fdroidserver.build.config = None
|
fdroidserver.build.config = None
|
||||||
|
self._td = mkdtemp()
|
||||||
|
self.testdir = self._td.name
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
os.chdir(self.basedir)
|
||||||
|
self._td.cleanup()
|
||||||
|
|
||||||
def create_fake_android_home(self, d):
|
def create_fake_android_home(self, d):
|
||||||
os.makedirs(os.path.join(d, 'build-tools'), exist_ok=True)
|
os.makedirs(os.path.join(d, 'build-tools'), exist_ok=True)
|
||||||
|
@ -210,106 +216,100 @@ class BuildTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_build_local_ndk(self):
|
def test_build_local_ndk(self):
|
||||||
"""Test if `fdroid build` detects installed NDKs and auto-installs when missing"""
|
"""Test if `fdroid build` detects installed NDKs and auto-installs when missing"""
|
||||||
testdir = tempfile.mkdtemp(
|
with tempfile.TemporaryDirectory() as testdir, TmpCwd(
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
testdir
|
||||||
)
|
), tempfile.TemporaryDirectory() as sdk_path:
|
||||||
os.chdir(testdir)
|
config = {'ndk_paths': {}, 'sdk_path': sdk_path}
|
||||||
|
fdroidserver.common.config = config
|
||||||
|
fdroidserver.build.config = config
|
||||||
|
fdroidserver.build.options = mock.Mock()
|
||||||
|
fdroidserver.build.options.scan_binary = False
|
||||||
|
fdroidserver.build.options.notarball = True
|
||||||
|
fdroidserver.build.options.skipscan = True
|
||||||
|
|
||||||
config = {'ndk_paths': {}, 'sdk_path': tempfile.mkdtemp(prefix='android-sdk-')}
|
app = fdroidserver.metadata.App()
|
||||||
fdroidserver.common.config = config
|
app.id = 'mocked.app.id'
|
||||||
fdroidserver.build.config = config
|
build = fdroidserver.metadata.Build()
|
||||||
fdroidserver.build.options = mock.Mock()
|
build.commit = '1.0'
|
||||||
fdroidserver.build.options.scan_binary = False
|
build.output = app.id + '.apk'
|
||||||
fdroidserver.build.options.notarball = True
|
build.versionCode = 1
|
||||||
fdroidserver.build.options.skipscan = True
|
build.versionName = '1.0'
|
||||||
|
build.ndk = 'r21e' # aka 21.4.7075529
|
||||||
|
vcs = mock.Mock()
|
||||||
|
|
||||||
app = fdroidserver.metadata.App()
|
def make_fake_apk(output, build):
|
||||||
app.id = 'mocked.app.id'
|
with open(build.output, 'w') as fp:
|
||||||
build = fdroidserver.metadata.Build()
|
fp.write('APK PLACEHOLDER')
|
||||||
build.commit = '1.0'
|
return output
|
||||||
build.output = app.id + '.apk'
|
|
||||||
build.versionCode = 1
|
|
||||||
build.versionName = '1.0'
|
|
||||||
build.ndk = 'r21e' # aka 21.4.7075529
|
|
||||||
vcs = mock.Mock()
|
|
||||||
|
|
||||||
def make_fake_apk(output, build):
|
def fake_download_file(_ignored, local_filename):
|
||||||
with open(build.output, 'w') as fp:
|
_ignored # silence the linters
|
||||||
fp.write('APK PLACEHOLDER')
|
with zipfile.ZipFile(local_filename, 'x') as zipfp:
|
||||||
return output
|
zipfp.writestr(
|
||||||
|
'android-ndk-r21e/source.properties',
|
||||||
|
'Pkg.Revision = 21.4.7075529\n',
|
||||||
|
)
|
||||||
|
|
||||||
def fake_download_file(_ignored, local_filename):
|
# use "as _ignored" just to make a pretty layout
|
||||||
_ignored # silence the linters
|
with mock.patch(
|
||||||
with zipfile.ZipFile(local_filename, 'x') as zipfp:
|
'fdroidserver.common.replace_build_vars', wraps=make_fake_apk
|
||||||
zipfp.writestr(
|
) as _ignored, mock.patch(
|
||||||
'android-ndk-r21e/source.properties',
|
'fdroidserver.common.get_native_code', return_value='x86'
|
||||||
'Pkg.Revision = 21.4.7075529\n',
|
) as _ignored, mock.patch(
|
||||||
)
|
'fdroidserver.common.get_apk_id',
|
||||||
|
return_value=(app.id, build.versionCode, build.versionName),
|
||||||
# use "as _ignored" just to make a pretty layout
|
) as _ignored, mock.patch(
|
||||||
with mock.patch(
|
'fdroidserver.common.is_apk_and_debuggable', return_value=False
|
||||||
'fdroidserver.common.replace_build_vars', wraps=make_fake_apk
|
) as _ignored, mock.patch(
|
||||||
) as _ignored, mock.patch(
|
'fdroidserver.common.sha256sum',
|
||||||
'fdroidserver.common.get_native_code', return_value='x86'
|
return_value='ad7ce5467e18d40050dc51b8e7affc3e635c85bd8c59be62de32352328ed467e',
|
||||||
) as _ignored, mock.patch(
|
) as _ignored, mock.patch(
|
||||||
'fdroidserver.common.get_apk_id',
|
'fdroidserver.common.is_apk_and_debuggable', return_value=False
|
||||||
return_value=(app.id, build.versionCode, build.versionName),
|
) as _ignored, mock.patch(
|
||||||
) as _ignored, mock.patch(
|
'fdroidserver.build.FDroidPopen', FakeProcess
|
||||||
'fdroidserver.common.is_apk_and_debuggable', return_value=False
|
) as _ignored, mock.patch(
|
||||||
) as _ignored, mock.patch(
|
'fdroidserver.net.download_file', wraps=fake_download_file
|
||||||
'fdroidserver.common.sha256sum',
|
) as _ignored:
|
||||||
return_value='ad7ce5467e18d40050dc51b8e7affc3e635c85bd8c59be62de32352328ed467e',
|
_ignored # silence the linters
|
||||||
) as _ignored, mock.patch(
|
with self.assertRaises(
|
||||||
'fdroidserver.common.is_apk_and_debuggable', return_value=False
|
fdroidserver.exception.FDroidException,
|
||||||
) as _ignored, mock.patch(
|
msg="No NDK setup, `fdroid build` should fail with error",
|
||||||
'fdroidserver.build.FDroidPopen', FakeProcess
|
):
|
||||||
) as _ignored, mock.patch(
|
fdroidserver.build.build_local(
|
||||||
'fdroidserver.net.download_file', wraps=fake_download_file
|
app,
|
||||||
) as _ignored:
|
build,
|
||||||
_ignored # silence the linters
|
vcs,
|
||||||
with self.assertRaises(
|
build_dir=testdir,
|
||||||
fdroidserver.exception.FDroidException,
|
output_dir=testdir,
|
||||||
msg="No NDK setup, `fdroid build` should fail with error",
|
log_dir=None,
|
||||||
):
|
srclib_dir=None,
|
||||||
|
extlib_dir=None,
|
||||||
|
tmp_dir=None,
|
||||||
|
force=False,
|
||||||
|
onserver=False,
|
||||||
|
refresh=False,
|
||||||
|
)
|
||||||
|
# now run `fdroid build --onserver`
|
||||||
|
self.assertTrue('r21e' not in config['ndk_paths'])
|
||||||
fdroidserver.build.build_local(
|
fdroidserver.build.build_local(
|
||||||
app,
|
app,
|
||||||
build,
|
build,
|
||||||
vcs,
|
vcs,
|
||||||
build_dir=testdir,
|
build_dir=testdir,
|
||||||
output_dir=testdir,
|
output_dir=testdir,
|
||||||
log_dir=None,
|
log_dir=os.getcwd(),
|
||||||
srclib_dir=None,
|
srclib_dir=None,
|
||||||
extlib_dir=None,
|
extlib_dir=None,
|
||||||
tmp_dir=None,
|
tmp_dir=None,
|
||||||
force=False,
|
force=False,
|
||||||
onserver=False,
|
onserver=True,
|
||||||
refresh=False,
|
refresh=False,
|
||||||
)
|
)
|
||||||
# now run `fdroid build --onserver`
|
self.assertTrue(os.path.exists(config['ndk_paths']['r21e']))
|
||||||
self.assertTrue('r21e' not in config['ndk_paths'])
|
|
||||||
fdroidserver.build.build_local(
|
|
||||||
app,
|
|
||||||
build,
|
|
||||||
vcs,
|
|
||||||
build_dir=testdir,
|
|
||||||
output_dir=testdir,
|
|
||||||
log_dir=os.getcwd(),
|
|
||||||
srclib_dir=None,
|
|
||||||
extlib_dir=None,
|
|
||||||
tmp_dir=None,
|
|
||||||
force=False,
|
|
||||||
onserver=True,
|
|
||||||
refresh=False,
|
|
||||||
)
|
|
||||||
self.assertTrue(os.path.exists(config['ndk_paths']['r21e']))
|
|
||||||
|
|
||||||
def test_build_local_clean(self):
|
def test_build_local_clean(self):
|
||||||
"""Test if `fdroid build` cleans ant and gradle build products"""
|
"""Test if `fdroid build` cleans ant and gradle build products"""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
|
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
|
@ -374,8 +374,8 @@ class BuildTest(unittest.TestCase):
|
||||||
app,
|
app,
|
||||||
build,
|
build,
|
||||||
vcs,
|
vcs,
|
||||||
build_dir=testdir,
|
build_dir=self.testdir,
|
||||||
output_dir=testdir,
|
output_dir=self.testdir,
|
||||||
log_dir=None,
|
log_dir=None,
|
||||||
srclib_dir=None,
|
srclib_dir=None,
|
||||||
extlib_dir=None,
|
extlib_dir=None,
|
||||||
|
@ -396,10 +396,7 @@ class BuildTest(unittest.TestCase):
|
||||||
self.assertFalse(os.path.exists('gradle-wrapper.jar'))
|
self.assertFalse(os.path.exists('gradle-wrapper.jar'))
|
||||||
|
|
||||||
def test_scan_with_extlib(self):
|
def test_scan_with_extlib(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
os.mkdir("build")
|
os.mkdir("build")
|
||||||
|
|
||||||
config = fdroidserver.common.get_config()
|
config = fdroidserver.common.get_config()
|
||||||
|
@ -446,11 +443,8 @@ class BuildTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_failed_verifies_are_not_in_unsigned(self):
|
def test_failed_verifies_are_not_in_unsigned(self):
|
||||||
|
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
sdk_path = os.path.join(self.testdir, 'android-sdk')
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
sdk_path = os.path.join(testdir, 'android-sdk')
|
|
||||||
self.create_fake_android_home(sdk_path)
|
self.create_fake_android_home(sdk_path)
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
yaml.dump({'sdk_path': sdk_path}, fp)
|
yaml.dump({'sdk_path': sdk_path}, fp)
|
||||||
|
@ -567,10 +561,7 @@ class BuildTest(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
self.assertFalse(flag in args, flag + ' should not be present')
|
self.assertFalse(flag in args, flag + ' should not be present')
|
||||||
|
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
os.mkdir('tmp')
|
os.mkdir('tmp')
|
||||||
|
|
||||||
chan = mock.MagicMock()
|
chan = mock.MagicMock()
|
||||||
|
|
|
@ -38,7 +38,7 @@ import fdroidserver.index
|
||||||
import fdroidserver.signindex
|
import fdroidserver.signindex
|
||||||
import fdroidserver.common
|
import fdroidserver.common
|
||||||
import fdroidserver.metadata
|
import fdroidserver.metadata
|
||||||
from testcommon import TmpCwd
|
from testcommon import TmpCwd, mkdtemp
|
||||||
from fdroidserver.exception import FDroidException, VCSException,\
|
from fdroidserver.exception import FDroidException, VCSException,\
|
||||||
MetaDataException, VerificationException
|
MetaDataException, VerificationException
|
||||||
|
|
||||||
|
@ -60,8 +60,13 @@ class CommonTest(unittest.TestCase):
|
||||||
fdroidserver.common.options.verbose = False
|
fdroidserver.common.options.verbose = False
|
||||||
self.path = os.environ['PATH']
|
self.path = os.environ['PATH']
|
||||||
self.android_home = os.environ.get('ANDROID_HOME')
|
self.android_home = os.environ.get('ANDROID_HOME')
|
||||||
|
self._td = mkdtemp()
|
||||||
|
self.testdir = self._td.name
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
os.chdir(self.basedir)
|
||||||
|
self._td.cleanup()
|
||||||
|
shutil.rmtree(self.tmpdir)
|
||||||
os.environ['PATH'] = self.path
|
os.environ['PATH'] = self.path
|
||||||
if self.android_home:
|
if self.android_home:
|
||||||
os.environ['ANDROID_HOME'] = self.android_home
|
os.environ['ANDROID_HOME'] = self.android_home
|
||||||
|
@ -142,10 +147,7 @@ class CommonTest(unittest.TestCase):
|
||||||
print('no build-tools found: ' + build_tools)
|
print('no build-tools found: ' + build_tools)
|
||||||
|
|
||||||
def test_find_java_root_path(self):
|
def test_find_java_root_path(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
|
|
||||||
all_pathlists = [
|
all_pathlists = [
|
||||||
(
|
(
|
||||||
|
@ -282,16 +284,13 @@ class CommonTest(unittest.TestCase):
|
||||||
testint = 99999999
|
testint = 99999999
|
||||||
teststr = 'FAKE_STR_FOR_TESTING'
|
teststr = 'FAKE_STR_FOR_TESTING'
|
||||||
|
|
||||||
testdir = tempfile.mkdtemp(
|
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
os.path.join(self.basedir, 'source-files'),
|
os.path.join(self.basedir, 'source-files'),
|
||||||
os.path.join(testdir, 'source-files'),
|
os.path.join(self.tmpdir, 'source-files'),
|
||||||
)
|
)
|
||||||
|
|
||||||
fdroidclient_testdir = os.path.join(
|
fdroidclient_testdir = os.path.join(
|
||||||
testdir, 'source-files', 'fdroid', 'fdroidclient'
|
self.tmpdir, 'source-files', 'fdroid', 'fdroidclient'
|
||||||
)
|
)
|
||||||
|
|
||||||
config = dict()
|
config = dict()
|
||||||
|
@ -340,10 +339,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
@unittest.skipIf(os.name == 'nt', "`fdroid build` assumes POSIX scripting")
|
@unittest.skipIf(os.name == 'nt', "`fdroid build` assumes POSIX scripting")
|
||||||
def test_prepare_sources_with_prebuild_subdir(self):
|
def test_prepare_sources_with_prebuild_subdir(self):
|
||||||
testdir = tempfile.mkdtemp(
|
app_build_dir = os.path.join(self.testdir, 'build', 'com.example')
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
app_build_dir = os.path.join(testdir, 'build', 'com.example')
|
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
os.path.join(self.basedir, 'source-files', 'fdroid', 'fdroidclient'),
|
os.path.join(self.basedir, 'source-files', 'fdroid', 'fdroidclient'),
|
||||||
app_build_dir,
|
app_build_dir,
|
||||||
|
@ -360,7 +356,7 @@ class CommonTest(unittest.TestCase):
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
|
|
||||||
srclibname = 'FakeSrcLib'
|
srclibname = 'FakeSrcLib'
|
||||||
srclib_testdir = os.path.join(testdir, 'build', 'srclib')
|
srclib_testdir = os.path.join(self.testdir, 'build', 'srclib')
|
||||||
os.makedirs(os.path.join(srclib_testdir, srclibname, 'testdirshouldexist'))
|
os.makedirs(os.path.join(srclib_testdir, srclibname, 'testdirshouldexist'))
|
||||||
fdroidserver.metadata.srclibs = {
|
fdroidserver.metadata.srclibs = {
|
||||||
srclibname: {
|
srclibname: {
|
||||||
|
@ -397,11 +393,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_prepare_sources_refresh(self):
|
def test_prepare_sources_refresh(self):
|
||||||
packageName = 'org.fdroid.ci.test.app'
|
packageName = 'org.fdroid.ci.test.app'
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
print('testdir', testdir)
|
|
||||||
os.chdir(testdir)
|
|
||||||
os.mkdir('build')
|
os.mkdir('build')
|
||||||
os.mkdir('metadata')
|
os.mkdir('metadata')
|
||||||
|
|
||||||
|
@ -419,7 +411,7 @@ class CommonTest(unittest.TestCase):
|
||||||
with open(os.path.join('metadata', packageName + '.yml'), 'w') as fp:
|
with open(os.path.join('metadata', packageName + '.yml'), 'w') as fp:
|
||||||
yaml.dump(metadata, fp)
|
yaml.dump(metadata, fp)
|
||||||
|
|
||||||
gitrepo = os.path.join(testdir, 'build', packageName)
|
gitrepo = os.path.join(self.tmpdir, 'build', packageName)
|
||||||
vcs0 = fdroidserver.common.getvcs('git', git_url, gitrepo)
|
vcs0 = fdroidserver.common.getvcs('git', git_url, gitrepo)
|
||||||
vcs0.gotorevision('0.3', refresh=True)
|
vcs0.gotorevision('0.3', refresh=True)
|
||||||
vcs1 = fdroidserver.common.getvcs('git', git_url, gitrepo)
|
vcs1 = fdroidserver.common.getvcs('git', git_url, gitrepo)
|
||||||
|
@ -445,18 +437,18 @@ class CommonTest(unittest.TestCase):
|
||||||
fdroidserver.signindex.config = config
|
fdroidserver.signindex.config = config
|
||||||
|
|
||||||
sourcedir = os.path.join(self.basedir, 'signindex')
|
sourcedir = os.path.join(self.basedir, 'signindex')
|
||||||
testsdir = tempfile.mkdtemp(
|
with tempfile.TemporaryDirectory(
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
||||||
)
|
) as testsdir:
|
||||||
for f in ('testy.jar', 'guardianproject.jar'):
|
for f in ('testy.jar', 'guardianproject.jar'):
|
||||||
sourcefile = os.path.join(sourcedir, f)
|
sourcefile = os.path.join(sourcedir, f)
|
||||||
testfile = os.path.join(testsdir, f)
|
testfile = os.path.join(testsdir, f)
|
||||||
shutil.copy(sourcefile, testsdir)
|
shutil.copy(sourcefile, testsdir)
|
||||||
fdroidserver.signindex.sign_jar(testfile, use_old_algs=True)
|
fdroidserver.signindex.sign_jar(testfile, use_old_algs=True)
|
||||||
# these should be resigned, and therefore different
|
# these should be resigned, and therefore different
|
||||||
self.assertNotEqual(
|
self.assertNotEqual(
|
||||||
open(sourcefile, 'rb').read(), open(testfile, 'rb').read()
|
open(sourcefile, 'rb').read(), open(testfile, 'rb').read()
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_verify_apk_signature(self):
|
def test_verify_apk_signature(self):
|
||||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||||
|
@ -519,19 +511,14 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
sourceapk = os.path.join(self.basedir, 'urzip.apk')
|
sourceapk = os.path.join(self.basedir, 'urzip.apk')
|
||||||
|
|
||||||
testdir = tempfile.mkdtemp(
|
copyapk = os.path.join(self.testdir, 'urzip-copy.apk')
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
print('testdir', testdir)
|
|
||||||
|
|
||||||
copyapk = os.path.join(testdir, 'urzip-copy.apk')
|
|
||||||
shutil.copy(sourceapk, copyapk)
|
shutil.copy(sourceapk, copyapk)
|
||||||
self.assertTrue(fdroidserver.common.verify_apk_signature(copyapk))
|
self.assertTrue(fdroidserver.common.verify_apk_signature(copyapk))
|
||||||
self.assertIsNone(
|
self.assertIsNone(
|
||||||
fdroidserver.common.verify_apks(sourceapk, copyapk, self.tmpdir)
|
fdroidserver.common.verify_apks(sourceapk, copyapk, self.tmpdir)
|
||||||
)
|
)
|
||||||
|
|
||||||
unsignedapk = os.path.join(testdir, 'urzip-unsigned.apk')
|
unsignedapk = os.path.join(self.testdir, 'urzip-unsigned.apk')
|
||||||
with ZipFile(sourceapk, 'r') as apk:
|
with ZipFile(sourceapk, 'r') as apk:
|
||||||
with ZipFile(unsignedapk, 'w') as testapk:
|
with ZipFile(unsignedapk, 'w') as testapk:
|
||||||
for info in apk.infolist():
|
for info in apk.infolist():
|
||||||
|
@ -541,7 +528,7 @@ class CommonTest(unittest.TestCase):
|
||||||
fdroidserver.common.verify_apks(sourceapk, unsignedapk, self.tmpdir)
|
fdroidserver.common.verify_apks(sourceapk, unsignedapk, self.tmpdir)
|
||||||
)
|
)
|
||||||
|
|
||||||
twosigapk = os.path.join(testdir, 'urzip-twosig.apk')
|
twosigapk = os.path.join(self.testdir, 'urzip-twosig.apk')
|
||||||
otherapk = ZipFile(os.path.join(self.basedir, 'urzip-release.apk'), 'r')
|
otherapk = ZipFile(os.path.join(self.basedir, 'urzip-release.apk'), 'r')
|
||||||
with ZipFile(sourceapk, 'r') as apk:
|
with ZipFile(sourceapk, 'r') as apk:
|
||||||
with ZipFile(twosigapk, 'w') as testapk:
|
with ZipFile(twosigapk, 'w') as testapk:
|
||||||
|
@ -715,17 +702,14 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_find_apksigner_config_overrides(self):
|
def test_find_apksigner_config_overrides(self):
|
||||||
"""apksigner should come from config before any auto-detection"""
|
"""apksigner should come from config before any auto-detection"""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
android_home = os.path.join(self.tmpdir, 'ANDROID_HOME')
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
android_home = os.path.join(testdir, 'ANDROID_HOME')
|
|
||||||
do_not_use = os.path.join(android_home, 'build-tools', '30.0.3', 'apksigner')
|
do_not_use = os.path.join(android_home, 'build-tools', '30.0.3', 'apksigner')
|
||||||
os.makedirs(os.path.dirname(do_not_use))
|
os.makedirs(os.path.dirname(do_not_use))
|
||||||
with open(do_not_use, 'w') as fp:
|
with open(do_not_use, 'w') as fp:
|
||||||
fp.write('#!/bin/sh\ndate\n')
|
fp.write('#!/bin/sh\ndate\n')
|
||||||
os.chmod(do_not_use, 0o0755)
|
os.chmod(do_not_use, 0o0755)
|
||||||
apksigner = os.path.join(testdir, 'apksigner')
|
apksigner = os.path.join(self.tmpdir, 'apksigner')
|
||||||
config = {'apksigner': apksigner}
|
config = {'apksigner': apksigner}
|
||||||
os.environ['ANDROID_HOME'] = android_home
|
os.environ['ANDROID_HOME'] = android_home
|
||||||
os.environ['PATH'] = '%s:/usr/local/bin:/usr/bin:/bin' % android_home
|
os.environ['PATH'] = '%s:/usr/local/bin:/usr/bin:/bin' % android_home
|
||||||
|
@ -734,17 +718,13 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_find_apksigner_prefer_path(self):
|
def test_find_apksigner_prefer_path(self):
|
||||||
"""apksigner should come from PATH before ANDROID_HOME"""
|
"""apksigner should come from PATH before ANDROID_HOME"""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
apksigner = os.path.join(self.tmpdir, 'apksigner')
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
|
|
||||||
apksigner = os.path.join(testdir, 'apksigner')
|
|
||||||
with open(apksigner, 'w') as fp:
|
with open(apksigner, 'w') as fp:
|
||||||
fp.write('#!/bin/sh\ndate\n')
|
fp.write('#!/bin/sh\ndate\n')
|
||||||
os.chmod(apksigner, 0o0755)
|
os.chmod(apksigner, 0o0755)
|
||||||
|
|
||||||
android_home = os.path.join(testdir, 'ANDROID_HOME')
|
android_home = os.path.join(self.tmpdir, 'ANDROID_HOME')
|
||||||
do_not_use = os.path.join(android_home, 'build-tools', '30.0.3', 'apksigner')
|
do_not_use = os.path.join(android_home, 'build-tools', '30.0.3', 'apksigner')
|
||||||
os.makedirs(os.path.dirname(do_not_use))
|
os.makedirs(os.path.dirname(do_not_use))
|
||||||
with open(do_not_use, 'w') as fp:
|
with open(do_not_use, 'w') as fp:
|
||||||
|
@ -759,11 +739,8 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_find_apksigner_prefer_newest(self):
|
def test_find_apksigner_prefer_newest(self):
|
||||||
"""apksigner should be the newest available in ANDROID_HOME"""
|
"""apksigner should be the newest available in ANDROID_HOME"""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
android_home = os.path.join(self.tmpdir, 'ANDROID_HOME')
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
android_home = os.path.join(testdir, 'ANDROID_HOME')
|
|
||||||
|
|
||||||
apksigner = os.path.join(android_home, 'build-tools', '30.0.3', 'apksigner')
|
apksigner = os.path.join(android_home, 'build-tools', '30.0.3', 'apksigner')
|
||||||
os.makedirs(os.path.dirname(apksigner))
|
os.makedirs(os.path.dirname(apksigner))
|
||||||
|
@ -784,10 +761,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_find_apksigner_system_package_android_home(self):
|
def test_find_apksigner_system_package_android_home(self):
|
||||||
"""Test that apksigner v30 or newer is found"""
|
"""Test that apksigner v30 or newer is found"""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
android_home = os.getenv('ANDROID_HOME')
|
android_home = os.getenv('ANDROID_HOME')
|
||||||
if not android_home or not os.path.isdir(android_home):
|
if not android_home or not os.path.isdir(android_home):
|
||||||
self.skipTest('SKIPPING since ANDROID_HOME (%s) is not a dir!' % android_home)
|
self.skipTest('SKIPPING since ANDROID_HOME (%s) is not a dir!' % android_home)
|
||||||
|
@ -825,12 +799,9 @@ class CommonTest(unittest.TestCase):
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
fdroidserver.signindex.config = config
|
fdroidserver.signindex.config = config
|
||||||
|
|
||||||
testdir = tempfile.mkdtemp(
|
unsigned = os.path.join(self.testdir, 'urzip-release-unsigned.apk')
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
signed = os.path.join(self.testdir, 'urzip-release.apk')
|
||||||
)
|
shutil.copy(os.path.join(self.basedir, 'urzip-release-unsigned.apk'), self.testdir)
|
||||||
unsigned = os.path.join(testdir, 'urzip-release-unsigned.apk')
|
|
||||||
signed = os.path.join(testdir, 'urzip-release.apk')
|
|
||||||
shutil.copy(os.path.join(self.basedir, 'urzip-release-unsigned.apk'), testdir)
|
|
||||||
|
|
||||||
self.assertFalse(fdroidserver.common.verify_apk_signature(unsigned))
|
self.assertFalse(fdroidserver.common.verify_apk_signature(unsigned))
|
||||||
|
|
||||||
|
@ -840,8 +811,8 @@ class CommonTest(unittest.TestCase):
|
||||||
self.assertTrue(fdroidserver.common.verify_apk_signature(signed))
|
self.assertTrue(fdroidserver.common.verify_apk_signature(signed))
|
||||||
|
|
||||||
# now sign an APK with minSdkVersion >= 18
|
# now sign an APK with minSdkVersion >= 18
|
||||||
unsigned = os.path.join(testdir, 'duplicate.permisssions_9999999-unsigned.apk')
|
unsigned = os.path.join(self.testdir, 'duplicate.permisssions_9999999-unsigned.apk')
|
||||||
signed = os.path.join(testdir, 'duplicate.permisssions_9999999.apk')
|
signed = os.path.join(self.testdir, 'duplicate.permisssions_9999999.apk')
|
||||||
shutil.copy(
|
shutil.copy(
|
||||||
os.path.join(self.basedir, 'repo', 'duplicate.permisssions_9999999.apk'),
|
os.path.join(self.basedir, 'repo', 'duplicate.permisssions_9999999.apk'),
|
||||||
os.path.join(unsigned),
|
os.path.join(unsigned),
|
||||||
|
@ -853,9 +824,9 @@ class CommonTest(unittest.TestCase):
|
||||||
self.assertTrue(fdroidserver.common.verify_apk_signature(signed))
|
self.assertTrue(fdroidserver.common.verify_apk_signature(signed))
|
||||||
self.assertEqual('18', fdroidserver.common._get_androguard_APK(signed).get_min_sdk_version())
|
self.assertEqual('18', fdroidserver.common._get_androguard_APK(signed).get_min_sdk_version())
|
||||||
|
|
||||||
shutil.copy(os.path.join(self.basedir, 'minimal_targetsdk_30_unsigned.apk'), testdir)
|
shutil.copy(os.path.join(self.basedir, 'minimal_targetsdk_30_unsigned.apk'), self.testdir)
|
||||||
unsigned = os.path.join(testdir, 'minimal_targetsdk_30_unsigned.apk')
|
unsigned = os.path.join(self.testdir, 'minimal_targetsdk_30_unsigned.apk')
|
||||||
signed = os.path.join(testdir, 'minimal_targetsdk_30.apk')
|
signed = os.path.join(self.testdir, 'minimal_targetsdk_30.apk')
|
||||||
|
|
||||||
self.assertFalse(fdroidserver.common.verify_apk_signature(unsigned))
|
self.assertFalse(fdroidserver.common.verify_apk_signature(unsigned))
|
||||||
fdroidserver.common.sign_apk(unsigned, signed, config['keyalias'])
|
fdroidserver.common.sign_apk(unsigned, signed, config['keyalias'])
|
||||||
|
@ -866,17 +837,17 @@ class CommonTest(unittest.TestCase):
|
||||||
# verify it has a v2 signature
|
# verify it has a v2 signature
|
||||||
self.assertTrue(fdroidserver.common._get_androguard_APK(signed).is_signed_v2())
|
self.assertTrue(fdroidserver.common._get_androguard_APK(signed).is_signed_v2())
|
||||||
|
|
||||||
shutil.copy(os.path.join(self.basedir, 'no_targetsdk_minsdk30_unsigned.apk'), testdir)
|
shutil.copy(os.path.join(self.basedir, 'no_targetsdk_minsdk30_unsigned.apk'), self.testdir)
|
||||||
unsigned = os.path.join(testdir, 'no_targetsdk_minsdk30_unsigned.apk')
|
unsigned = os.path.join(self.testdir, 'no_targetsdk_minsdk30_unsigned.apk')
|
||||||
signed = os.path.join(testdir, 'no_targetsdk_minsdk30_signed.apk')
|
signed = os.path.join(self.testdir, 'no_targetsdk_minsdk30_signed.apk')
|
||||||
|
|
||||||
fdroidserver.common.sign_apk(unsigned, signed, config['keyalias'])
|
fdroidserver.common.sign_apk(unsigned, signed, config['keyalias'])
|
||||||
self.assertTrue(fdroidserver.common.verify_apk_signature(signed))
|
self.assertTrue(fdroidserver.common.verify_apk_signature(signed))
|
||||||
self.assertTrue(fdroidserver.common._get_androguard_APK(signed).is_signed_v2())
|
self.assertTrue(fdroidserver.common._get_androguard_APK(signed).is_signed_v2())
|
||||||
|
|
||||||
shutil.copy(os.path.join(self.basedir, 'no_targetsdk_minsdk1_unsigned.apk'), testdir)
|
shutil.copy(os.path.join(self.basedir, 'no_targetsdk_minsdk1_unsigned.apk'), self.testdir)
|
||||||
unsigned = os.path.join(testdir, 'no_targetsdk_minsdk1_unsigned.apk')
|
unsigned = os.path.join(self.testdir, 'no_targetsdk_minsdk1_unsigned.apk')
|
||||||
signed = os.path.join(testdir, 'no_targetsdk_minsdk1_signed.apk')
|
signed = os.path.join(self.testdir, 'no_targetsdk_minsdk1_signed.apk')
|
||||||
|
|
||||||
self.assertFalse(fdroidserver.common.verify_apk_signature(unsigned))
|
self.assertFalse(fdroidserver.common.verify_apk_signature(unsigned))
|
||||||
fdroidserver.common.sign_apk(unsigned, signed, config['keyalias'])
|
fdroidserver.common.sign_apk(unsigned, signed, config['keyalias'])
|
||||||
|
@ -901,10 +872,7 @@ class CommonTest(unittest.TestCase):
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
fdroidserver.signindex.config = config
|
fdroidserver.signindex.config = config
|
||||||
|
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
os.mkdir('unsigned')
|
os.mkdir('unsigned')
|
||||||
os.mkdir('repo')
|
os.mkdir('repo')
|
||||||
|
|
||||||
|
@ -1431,15 +1399,11 @@ class CommonTest(unittest.TestCase):
|
||||||
self.assertEqual(fdroidserver.common.parse_srclib_spec('@multi@at-signs@'))
|
self.assertEqual(fdroidserver.common.parse_srclib_spec('@multi@at-signs@'))
|
||||||
|
|
||||||
def test_remove_signing_keys(self):
|
def test_remove_signing_keys(self):
|
||||||
testdir = tempfile.mkdtemp(
|
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
print(testdir)
|
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
os.path.join(self.basedir, 'source-files'),
|
os.path.join(self.basedir, 'source-files'),
|
||||||
os.path.join(testdir, 'source-files'),
|
os.path.join(self.tmpdir, 'source-files'),
|
||||||
)
|
)
|
||||||
os.chdir(testdir)
|
os.chdir(self.tmpdir)
|
||||||
with_signingConfigs = [
|
with_signingConfigs = [
|
||||||
'source-files/com.seafile.seadroid2/app/build.gradle',
|
'source-files/com.seafile.seadroid2/app/build.gradle',
|
||||||
'source-files/eu.siacs.conversations/build.gradle',
|
'source-files/eu.siacs.conversations/build.gradle',
|
||||||
|
@ -1608,14 +1572,11 @@ class CommonTest(unittest.TestCase):
|
||||||
self.assertEqual(f.read(), mocklogcontent)
|
self.assertEqual(f.read(), mocklogcontent)
|
||||||
|
|
||||||
def test_deploy_status_json(self):
|
def test_deploy_status_json(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
|
|
||||||
fakesubcommand = 'fakesubcommand'
|
fakesubcommand = 'fakesubcommand'
|
||||||
fake_timestamp = 1234567890
|
fake_timestamp = 1234567890
|
||||||
fakeserver = 'example.com:/var/www/fbot/'
|
fakeserver = 'example.com:/var/www/fbot/'
|
||||||
expected_dir = os.path.join(testdir, fakeserver.replace(':', ''), 'repo', 'status')
|
expected_dir = os.path.join(self.tmpdir, fakeserver.replace(':', ''), 'repo', 'status')
|
||||||
|
|
||||||
fdroidserver.common.options = mock.Mock()
|
fdroidserver.common.options = mock.Mock()
|
||||||
fdroidserver.common.config = {}
|
fdroidserver.common.config = {}
|
||||||
|
@ -1623,7 +1584,7 @@ class CommonTest(unittest.TestCase):
|
||||||
fdroidserver.common.config['identity_file'] = 'ssh/id_rsa'
|
fdroidserver.common.config['identity_file'] = 'ssh/id_rsa'
|
||||||
|
|
||||||
def assert_subprocess_call(cmd):
|
def assert_subprocess_call(cmd):
|
||||||
dest_path = os.path.join(testdir, cmd[-1].replace(':', ''))
|
dest_path = os.path.join(self.tmpdir, cmd[-1].replace(':', ''))
|
||||||
if not os.path.exists(dest_path):
|
if not os.path.exists(dest_path):
|
||||||
os.makedirs(dest_path)
|
os.makedirs(dest_path)
|
||||||
return subprocess.run(cmd[:-1] + [dest_path]).returncode
|
return subprocess.run(cmd[:-1] + [dest_path]).returncode
|
||||||
|
@ -1779,10 +1740,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_with_no_config(self):
|
def test_with_no_config(self):
|
||||||
"""It should set defaults if no config file is found"""
|
"""It should set defaults if no config file is found"""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
self.assertFalse(os.path.exists('config.yml'))
|
self.assertFalse(os.path.exists('config.yml'))
|
||||||
self.assertFalse(os.path.exists('config.py'))
|
self.assertFalse(os.path.exists('config.py'))
|
||||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||||
|
@ -1791,8 +1749,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_with_zero_size_config(self):
|
def test_with_zero_size_config(self):
|
||||||
"""It should set defaults if config file has nothing in it"""
|
"""It should set defaults if config file has nothing in it"""
|
||||||
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
|
os.chdir(self.tmpdir)
|
||||||
os.chdir(testdir)
|
|
||||||
open('config.yml', 'w').close()
|
open('config.yml', 'w').close()
|
||||||
self.assertTrue(os.path.exists('config.yml'))
|
self.assertTrue(os.path.exists('config.yml'))
|
||||||
self.assertFalse(os.path.exists('config.py'))
|
self.assertFalse(os.path.exists('config.py'))
|
||||||
|
@ -1802,10 +1759,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_with_config_yml(self):
|
def test_with_config_yml(self):
|
||||||
"""Make sure it is possible to use config.yml alone."""
|
"""Make sure it is possible to use config.yml alone."""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
fp.write('apksigner: yml')
|
fp.write('apksigner: yml')
|
||||||
self.assertTrue(os.path.exists('config.yml'))
|
self.assertTrue(os.path.exists('config.yml'))
|
||||||
|
@ -1815,10 +1769,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_with_config_yml_utf8(self):
|
def test_with_config_yml_utf8(self):
|
||||||
"""Make sure it is possible to use config.yml in UTF-8 encoding."""
|
"""Make sure it is possible to use config.yml in UTF-8 encoding."""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
teststr = '/πÇÇ现代通用字-български-عربي1/ö/yml'
|
teststr = '/πÇÇ现代通用字-български-عربي1/ö/yml'
|
||||||
with open('config.yml', 'w', encoding='utf-8') as fp:
|
with open('config.yml', 'w', encoding='utf-8') as fp:
|
||||||
fp.write('apksigner: ' + teststr)
|
fp.write('apksigner: ' + teststr)
|
||||||
|
@ -1829,10 +1780,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_with_config_yml_utf8_as_ascii(self):
|
def test_with_config_yml_utf8_as_ascii(self):
|
||||||
"""Make sure it is possible to use config.yml Unicode encoded as ASCII."""
|
"""Make sure it is possible to use config.yml Unicode encoded as ASCII."""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
teststr = '/πÇÇ现代通用字-български-عربي1/ö/yml'
|
teststr = '/πÇÇ现代通用字-български-عربي1/ö/yml'
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
yaml.dump({'apksigner': teststr}, fp)
|
yaml.dump({'apksigner': teststr}, fp)
|
||||||
|
@ -1843,10 +1791,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_with_config_yml_with_env_var(self):
|
def test_with_config_yml_with_env_var(self):
|
||||||
"""Make sure it is possible to use config.yml alone."""
|
"""Make sure it is possible to use config.yml alone."""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
os.environ['SECRET'] = 'mysecretpassword'
|
os.environ['SECRET'] = 'mysecretpassword'
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
fp.write("""keypass: {'env': 'SECRET'}""")
|
fp.write("""keypass: {'env': 'SECRET'}""")
|
||||||
|
@ -1857,10 +1802,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_with_config_py(self):
|
def test_with_config_py(self):
|
||||||
"""Make sure it is still possible to use config.py alone."""
|
"""Make sure it is still possible to use config.py alone."""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.py', 'w') as fp:
|
with open('config.py', 'w') as fp:
|
||||||
fp.write('apksigner = "py"')
|
fp.write('apksigner = "py"')
|
||||||
self.assertFalse(os.path.exists('config.yml'))
|
self.assertFalse(os.path.exists('config.yml'))
|
||||||
|
@ -1870,10 +1812,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_config_perm_warning(self):
|
def test_config_perm_warning(self):
|
||||||
"""Exercise the code path that issues a warning about unsafe permissions."""
|
"""Exercise the code path that issues a warning about unsafe permissions."""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
fp.write('keystore: foo.jks')
|
fp.write('keystore: foo.jks')
|
||||||
self.assertTrue(os.path.exists(fp.name))
|
self.assertTrue(os.path.exists(fp.name))
|
||||||
|
@ -1890,10 +1829,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_with_both_config_yml_py(self):
|
def test_with_both_config_yml_py(self):
|
||||||
"""If config.yml and config.py are present, config.py should be ignored."""
|
"""If config.yml and config.py are present, config.py should be ignored."""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
fp.write('apksigner: yml')
|
fp.write('apksigner: yml')
|
||||||
with open('config.py', 'w') as fp:
|
with open('config.py', 'w') as fp:
|
||||||
|
@ -1905,10 +1841,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_config_repo_url(self):
|
def test_config_repo_url(self):
|
||||||
"""repo_url ends in /repo, archive_url ends in /archive."""
|
"""repo_url ends in /repo, archive_url ends in /archive."""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
fp.write('repo_url: https://MyFirstFDroidRepo.org/fdroid/repo\n')
|
fp.write('repo_url: https://MyFirstFDroidRepo.org/fdroid/repo\n')
|
||||||
fp.write('archive_url: https://MyFirstFDroidRepo.org/fdroid/archive')
|
fp.write('archive_url: https://MyFirstFDroidRepo.org/fdroid/archive')
|
||||||
|
@ -1918,10 +1851,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_config_repo_url_extra_slash(self):
|
def test_config_repo_url_extra_slash(self):
|
||||||
"""repo_url ends in /repo, archive_url ends in /archive."""
|
"""repo_url ends in /repo, archive_url ends in /archive."""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
fp.write('repo_url: https://MyFirstFDroidRepo.org/fdroid/repo/')
|
fp.write('repo_url: https://MyFirstFDroidRepo.org/fdroid/repo/')
|
||||||
with self.assertRaises(FDroidException):
|
with self.assertRaises(FDroidException):
|
||||||
|
@ -1929,10 +1859,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_config_repo_url_not_repo(self):
|
def test_config_repo_url_not_repo(self):
|
||||||
"""repo_url ends in /repo, archive_url ends in /archive."""
|
"""repo_url ends in /repo, archive_url ends in /archive."""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
fp.write('repo_url: https://MyFirstFDroidRepo.org/fdroid/foo')
|
fp.write('repo_url: https://MyFirstFDroidRepo.org/fdroid/foo')
|
||||||
with self.assertRaises(FDroidException):
|
with self.assertRaises(FDroidException):
|
||||||
|
@ -1940,10 +1867,7 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_config_archive_url_extra_slash(self):
|
def test_config_archive_url_extra_slash(self):
|
||||||
"""repo_url ends in /repo, archive_url ends in /archive."""
|
"""repo_url ends in /repo, archive_url ends in /archive."""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
fp.write('archive_url: https://MyFirstFDroidRepo.org/fdroid/archive/')
|
fp.write('archive_url: https://MyFirstFDroidRepo.org/fdroid/archive/')
|
||||||
with self.assertRaises(FDroidException):
|
with self.assertRaises(FDroidException):
|
||||||
|
@ -1951,20 +1875,14 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_config_archive_url_not_repo(self):
|
def test_config_archive_url_not_repo(self):
|
||||||
"""repo_url ends in /repo, archive_url ends in /archive."""
|
"""repo_url ends in /repo, archive_url ends in /archive."""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
fp.write('archive_url: https://MyFirstFDroidRepo.org/fdroid/foo')
|
fp.write('archive_url: https://MyFirstFDroidRepo.org/fdroid/foo')
|
||||||
with self.assertRaises(FDroidException):
|
with self.assertRaises(FDroidException):
|
||||||
fdroidserver.common.read_config()
|
fdroidserver.common.read_config()
|
||||||
|
|
||||||
def test_write_to_config_yml(self):
|
def test_write_to_config_yml(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
fp.write('apksigner: yml')
|
fp.write('apksigner: yml')
|
||||||
self.assertTrue(os.path.exists(fp.name))
|
self.assertTrue(os.path.exists(fp.name))
|
||||||
|
@ -1980,10 +1898,7 @@ class CommonTest(unittest.TestCase):
|
||||||
self.assertEqual('mysecretpassword', config['keypass'])
|
self.assertEqual('mysecretpassword', config['keypass'])
|
||||||
|
|
||||||
def test_write_to_config_py(self):
|
def test_write_to_config_py(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.py', 'w') as fp:
|
with open('config.py', 'w') as fp:
|
||||||
fp.write('apksigner = "py"')
|
fp.write('apksigner = "py"')
|
||||||
self.assertTrue(os.path.exists(fp.name))
|
self.assertTrue(os.path.exists(fp.name))
|
||||||
|
@ -1997,10 +1912,7 @@ class CommonTest(unittest.TestCase):
|
||||||
self.assertEqual('mysecretpassword', config['keypass'])
|
self.assertEqual('mysecretpassword', config['keypass'])
|
||||||
|
|
||||||
def test_config_dict_with_int_keys(self):
|
def test_config_dict_with_int_keys(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
fp.write('java_paths:\n 8: /usr/lib/jvm/java-8-openjdk\n')
|
fp.write('java_paths:\n 8: /usr/lib/jvm/java-8-openjdk\n')
|
||||||
self.assertTrue(os.path.exists(fp.name))
|
self.assertTrue(os.path.exists(fp.name))
|
||||||
|
@ -2010,17 +1922,14 @@ class CommonTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_loading_config_buildserver_yml(self):
|
def test_loading_config_buildserver_yml(self):
|
||||||
"""Smoke check to make sure this file is properly parsed"""
|
"""Smoke check to make sure this file is properly parsed"""
|
||||||
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
|
os.chdir(self.tmpdir)
|
||||||
os.chdir(testdir)
|
|
||||||
shutil.copy(os.path.join(self.basedir, '..', 'buildserver', 'config.buildserver.yml'),
|
shutil.copy(os.path.join(self.basedir, '..', 'buildserver', 'config.buildserver.yml'),
|
||||||
'config.yml')
|
'config.yml')
|
||||||
self.assertFalse(os.path.exists('config.py'))
|
self.assertFalse(os.path.exists('config.py'))
|
||||||
fdroidserver.common.read_config(fdroidserver.common.options)
|
fdroidserver.common.read_config(fdroidserver.common.options)
|
||||||
|
|
||||||
def test_setup_status_output(self):
|
def test_setup_status_output(self):
|
||||||
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
|
os.chdir(self.tmpdir)
|
||||||
print(testdir)
|
|
||||||
os.chdir(testdir)
|
|
||||||
start_timestamp = time.gmtime()
|
start_timestamp = time.gmtime()
|
||||||
subcommand = 'test'
|
subcommand = 'test'
|
||||||
|
|
||||||
|
@ -2036,13 +1945,9 @@ class CommonTest(unittest.TestCase):
|
||||||
self.assertEqual(subcommand, data['subcommand'])
|
self.assertEqual(subcommand, data['subcommand'])
|
||||||
|
|
||||||
def test_setup_status_output_in_git_repo(self):
|
def test_setup_status_output_in_git_repo(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
|
|
||||||
logging.getLogger('git.cmd').setLevel(logging.INFO)
|
logging.getLogger('git.cmd').setLevel(logging.INFO)
|
||||||
git_repo = git.Repo.init(testdir)
|
git_repo = git.Repo.init(self.tmpdir)
|
||||||
file_in_git = 'README.md'
|
file_in_git = 'README.md'
|
||||||
with open(file_in_git, 'w') as fp:
|
with open(file_in_git, 'w') as fp:
|
||||||
fp.write('this is just a test')
|
fp.write('this is just a test')
|
||||||
|
@ -2153,11 +2058,8 @@ class CommonTest(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_apk_strip_v1_signatures(self):
|
def test_apk_strip_v1_signatures(self):
|
||||||
testdir = tempfile.mkdtemp(
|
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
before = os.path.join(self.basedir, 'no_targetsdk_minsdk1_unsigned.apk')
|
before = os.path.join(self.basedir, 'no_targetsdk_minsdk1_unsigned.apk')
|
||||||
after = os.path.join(testdir, 'after.apk')
|
after = os.path.join(self.testdir, 'after.apk')
|
||||||
shutil.copy(before, after)
|
shutil.copy(before, after)
|
||||||
fdroidserver.common.apk_strip_v1_signatures(after, strip_manifest=False)
|
fdroidserver.common.apk_strip_v1_signatures(after, strip_manifest=False)
|
||||||
|
|
||||||
|
@ -2229,13 +2131,10 @@ class CommonTest(unittest.TestCase):
|
||||||
@unittest.skip("This test downloads and unzips a 1GB file.")
|
@unittest.skip("This test downloads and unzips a 1GB file.")
|
||||||
def test_install_ndk(self):
|
def test_install_ndk(self):
|
||||||
"""NDK r10e is a special case since its missing source.properties"""
|
"""NDK r10e is a special case since its missing source.properties"""
|
||||||
sdk_path = tempfile.mkdtemp(
|
config = {'sdk_path': self.tmpdir}
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
config = {'sdk_path': sdk_path}
|
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
fdroidserver.common._install_ndk('r10e')
|
fdroidserver.common._install_ndk('r10e')
|
||||||
r10e = os.path.join(sdk_path, 'ndk', 'r10e')
|
r10e = os.path.join(self.tmpdir, 'ndk', 'r10e')
|
||||||
self.assertEqual('r10e', fdroidserver.common.get_ndk_version(r10e))
|
self.assertEqual('r10e', fdroidserver.common.get_ndk_version(r10e))
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
self.assertEqual({'r10e': r10e}, config['ndk_paths'])
|
self.assertEqual({'r10e': r10e}, config['ndk_paths'])
|
||||||
|
@ -2248,31 +2147,31 @@ class CommonTest(unittest.TestCase):
|
||||||
with ZipFile(zipball, 'w') as zipfp:
|
with ZipFile(zipball, 'w') as zipfp:
|
||||||
zipfp.writestr(os.path.basename(url), url)
|
zipfp.writestr(os.path.basename(url), url)
|
||||||
|
|
||||||
sdk_path = tempfile.mkdtemp(
|
with tempfile.TemporaryDirectory(
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
||||||
)
|
) as sdk_path:
|
||||||
config = {'sdk_path': sdk_path}
|
config = {'sdk_path': sdk_path}
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
for r, sha256 in (
|
for r, sha256 in (
|
||||||
(
|
(
|
||||||
'r10e',
|
'r10e',
|
||||||
'ee5f405f3b57c4f5c3b3b8b5d495ae12b660e03d2112e4ed5c728d349f1e520c',
|
'ee5f405f3b57c4f5c3b3b8b5d495ae12b660e03d2112e4ed5c728d349f1e520c',
|
||||||
),
|
),
|
||||||
('r20', '57435158f109162f41f2f43d5563d2164e4d5d0364783a9a6fab3ef12cb06ce0'),
|
('r20', '57435158f109162f41f2f43d5563d2164e4d5d0364783a9a6fab3ef12cb06ce0'),
|
||||||
(
|
(
|
||||||
'23.0.7599858',
|
'23.0.7599858',
|
||||||
'e3eacf80016b91d4cd2c8ca9f34eebd32df912bb799c859cc5450b6b19277b4f',
|
'e3eacf80016b91d4cd2c8ca9f34eebd32df912bb799c859cc5450b6b19277b4f',
|
||||||
),
|
),
|
||||||
):
|
|
||||||
with mock.patch(
|
|
||||||
'fdroidserver.net.download_file', side_effect=fake_download
|
|
||||||
) as _ignored, mock.patch(
|
|
||||||
'fdroidserver.common.get_ndk_version', return_value=r
|
|
||||||
) as _ignored, mock.patch(
|
|
||||||
'fdroidserver.common.sha256sum', return_value=sha256
|
|
||||||
):
|
):
|
||||||
_ignored # silence the linters
|
with mock.patch(
|
||||||
fdroidserver.common._install_ndk(r)
|
'fdroidserver.net.download_file', side_effect=fake_download
|
||||||
|
) as _ignored, mock.patch(
|
||||||
|
'fdroidserver.common.get_ndk_version', return_value=r
|
||||||
|
) as _ignored, mock.patch(
|
||||||
|
'fdroidserver.common.sha256sum', return_value=sha256
|
||||||
|
):
|
||||||
|
_ignored # silence the linters
|
||||||
|
fdroidserver.common._install_ndk(r)
|
||||||
|
|
||||||
def test_install_ndk_with_symlinks(self):
|
def test_install_ndk_with_symlinks(self):
|
||||||
"""Some NDK zipballs might have symlinks in them."""
|
"""Some NDK zipballs might have symlinks in them."""
|
||||||
|
@ -2314,10 +2213,7 @@ class CommonTest(unittest.TestCase):
|
||||||
zipInfo.external_attr = unix_st_mode << 16
|
zipInfo.external_attr = unix_st_mode << 16
|
||||||
zipfp.writestr(zipInfo, 'foo/../../../../../../../../../etc/passwd')
|
zipfp.writestr(zipInfo, 'foo/../../../../../../../../../etc/passwd')
|
||||||
|
|
||||||
sdk_path = tempfile.mkdtemp(
|
config = {'sdk_path': self.tmpdir}
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
config = {'sdk_path': sdk_path}
|
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
r = 'r20'
|
r = 'r20'
|
||||||
sha256 = '57435158f109162f41f2f43d5563d2164e4d5d0364783a9a6fab3ef12cb06ce0'
|
sha256 = '57435158f109162f41f2f43d5563d2164e4d5d0364783a9a6fab3ef12cb06ce0'
|
||||||
|
@ -2331,40 +2227,36 @@ class CommonTest(unittest.TestCase):
|
||||||
_ignored # silence the linters
|
_ignored # silence the linters
|
||||||
fdroidserver.common._install_ndk(r)
|
fdroidserver.common._install_ndk(r)
|
||||||
|
|
||||||
self.assertTrue(os.path.exists(os.path.join(sdk_path, 'ndk', 'r20')))
|
self.assertTrue(os.path.exists(os.path.join(self.tmpdir, 'ndk', 'r20')))
|
||||||
self.assertTrue(os.path.exists(os.path.join(sdk_path, 'ndk', 'r20', 'basename')))
|
self.assertTrue(os.path.exists(os.path.join(self.tmpdir, 'ndk', 'r20', 'basename')))
|
||||||
self.assertFalse(os.path.exists(os.path.join(sdk_path, 'ndk', 'r20', 'bad_abs_link')))
|
self.assertFalse(os.path.exists(os.path.join(self.tmpdir, 'ndk', 'r20', 'bad_abs_link')))
|
||||||
self.assertFalse(os.path.exists(os.path.join(sdk_path, 'ndk', 'r20', 'bad_rel_link')))
|
self.assertFalse(os.path.exists(os.path.join(self.tmpdir, 'ndk', 'r20', 'bad_rel_link')))
|
||||||
self.assertFalse(os.path.exists(os.path.join(sdk_path, 'ndk', 'r20', 'bad_rel_link2')))
|
self.assertFalse(os.path.exists(os.path.join(self.tmpdir, 'ndk', 'r20', 'bad_rel_link2')))
|
||||||
os.system('ls -l ' + os.path.join(sdk_path, 'ndk', 'r20'))
|
os.system('ls -l ' + os.path.join(self.tmpdir, 'ndk', 'r20'))
|
||||||
|
|
||||||
def test_fill_config_defaults(self):
|
def test_fill_config_defaults(self):
|
||||||
"""Test the auto-detection of NDKs installed in standard paths"""
|
"""Test the auto-detection of NDKs installed in standard paths"""
|
||||||
sdk_path = tempfile.mkdtemp(
|
ndk_bundle = os.path.join(self.tmpdir, 'ndk-bundle')
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
|
|
||||||
ndk_bundle = os.path.join(sdk_path, 'ndk-bundle')
|
|
||||||
os.makedirs(ndk_bundle)
|
os.makedirs(ndk_bundle)
|
||||||
with open(os.path.join(ndk_bundle, 'source.properties'), 'w') as fp:
|
with open(os.path.join(ndk_bundle, 'source.properties'), 'w') as fp:
|
||||||
fp.write('Pkg.Desc = Android NDK\nPkg.Revision = 17.2.4988734\n')
|
fp.write('Pkg.Desc = Android NDK\nPkg.Revision = 17.2.4988734\n')
|
||||||
config = {'sdk_path': sdk_path}
|
config = {'sdk_path': self.tmpdir}
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
self.assertEqual({'r17c': ndk_bundle}, config['ndk_paths'])
|
self.assertEqual({'r17c': ndk_bundle}, config['ndk_paths'])
|
||||||
|
|
||||||
r21e = os.path.join(sdk_path, 'ndk', '21.4.7075529')
|
r21e = os.path.join(self.tmpdir, 'ndk', '21.4.7075529')
|
||||||
os.makedirs(r21e)
|
os.makedirs(r21e)
|
||||||
with open(os.path.join(r21e, 'source.properties'), 'w') as fp:
|
with open(os.path.join(r21e, 'source.properties'), 'w') as fp:
|
||||||
fp.write('Pkg.Desc = Android NDK\nPkg.Revision = 21.4.7075529\n')
|
fp.write('Pkg.Desc = Android NDK\nPkg.Revision = 21.4.7075529\n')
|
||||||
config = {'sdk_path': sdk_path}
|
config = {'sdk_path': self.tmpdir}
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
self.assertEqual({'r17c': ndk_bundle, 'r21e': r21e}, config['ndk_paths'])
|
self.assertEqual({'r17c': ndk_bundle, 'r21e': r21e}, config['ndk_paths'])
|
||||||
|
|
||||||
r10e = os.path.join(sdk_path, 'ndk', 'r10e')
|
r10e = os.path.join(self.tmpdir, 'ndk', 'r10e')
|
||||||
os.makedirs(r10e)
|
os.makedirs(r10e)
|
||||||
with open(os.path.join(r10e, 'RELEASE.TXT'), 'w') as fp:
|
with open(os.path.join(r10e, 'RELEASE.TXT'), 'w') as fp:
|
||||||
fp.write('r10e-rc4 (64-bit)\n')
|
fp.write('r10e-rc4 (64-bit)\n')
|
||||||
config = {'sdk_path': sdk_path}
|
config = {'sdk_path': self.tmpdir}
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
{'r10e': r10e, 'r17c': ndk_bundle, 'r21e': r21e}, config['ndk_paths']
|
{'r10e': r10e, 'r17c': ndk_bundle, 'r21e': r21e}, config['ndk_paths']
|
||||||
|
@ -2516,10 +2408,7 @@ class CommonTest(unittest.TestCase):
|
||||||
self.assertFalse(is_repo_file(f), f + ' not repo file')
|
self.assertFalse(is_repo_file(f), f + ' not repo file')
|
||||||
|
|
||||||
def test_get_apksigner_smartcardoptions(self):
|
def test_get_apksigner_smartcardoptions(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
d = {
|
d = {
|
||||||
'smartcardoptions': '-storetype PKCS11'
|
'smartcardoptions': '-storetype PKCS11'
|
||||||
|
@ -2547,10 +2436,7 @@ class CommonTest(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_get_smartcardoptions_list(self):
|
def test_get_smartcardoptions_list(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
fp.write(
|
fp.write(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
|
@ -2585,10 +2471,7 @@ class CommonTest(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_get_smartcardoptions_spaces(self):
|
def test_get_smartcardoptions_spaces(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
fp.write(
|
fp.write(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
|
@ -2616,10 +2499,7 @@ class CommonTest(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_get_smartcardoptions_config_py(self):
|
def test_get_smartcardoptions_config_py(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.tmpdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.py', 'w') as fp:
|
with open('config.py', 'w') as fp:
|
||||||
fp.write(
|
fp.write(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
@ -31,36 +30,30 @@ class ImportTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
self.basedir = localmodule / 'tests'
|
self.basedir = localmodule / 'tests'
|
||||||
self.tmpdir = localmodule / '.testfiles'
|
|
||||||
self.tmpdir.mkdir(exist_ok=True)
|
|
||||||
# TODO: Python3.6: Accepts a path-like object.
|
|
||||||
os.chdir(str(self.basedir))
|
|
||||||
fdroidserver.import_subcommand.options = mock.Mock()
|
fdroidserver.import_subcommand.options = mock.Mock()
|
||||||
fdroidserver.import_subcommand.options.rev = None
|
fdroidserver.import_subcommand.options.rev = None
|
||||||
|
|
||||||
def test_import_gitlab(self):
|
def test_import_gitlab(self):
|
||||||
# FDroidPopen needs some config to work
|
with tempfile.TemporaryDirectory() as testdir, TmpCwd(testdir):
|
||||||
config = dict()
|
# FDroidPopen needs some config to work
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
config = dict()
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
|
fdroidserver.common.config = config
|
||||||
|
|
||||||
url = 'https://gitlab.com/fdroid/ci-test-app'
|
url = 'https://gitlab.com/fdroid/ci-test-app'
|
||||||
r = requests.head(url, timeout=300)
|
r = requests.head(url, timeout=300)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
print("ERROR", url, 'unreachable (', r.status_code, ')')
|
print("ERROR", url, 'unreachable (', r.status_code, ')')
|
||||||
print('Skipping ImportTest!')
|
print('Skipping ImportTest!')
|
||||||
return
|
return
|
||||||
|
|
||||||
app = fdroidserver.import_subcommand.get_app_from_url(url)
|
app = fdroidserver.import_subcommand.get_app_from_url(url)
|
||||||
fdroidserver.import_subcommand.clone_to_tmp_dir(app)
|
fdroidserver.import_subcommand.clone_to_tmp_dir(app)
|
||||||
self.assertEqual(app.RepoType, 'git')
|
self.assertEqual(app.RepoType, 'git')
|
||||||
self.assertEqual(app.Repo, 'https://gitlab.com/fdroid/ci-test-app.git')
|
self.assertEqual(app.Repo, 'https://gitlab.com/fdroid/ci-test-app.git')
|
||||||
|
|
||||||
def test_get_app_from_url(self):
|
def test_get_app_from_url(self):
|
||||||
# TODO: Pytohn3.6: The dir parameter now accepts a path-like object.
|
with tempfile.TemporaryDirectory() as testdir, TmpCwd(testdir):
|
||||||
with tempfile.TemporaryDirectory(dir=str(self.tmpdir)) as testdir, TmpCwd(
|
|
||||||
testdir
|
|
||||||
):
|
|
||||||
testdir = Path(testdir)
|
testdir = Path(testdir)
|
||||||
(testdir / 'tmp').mkdir()
|
(testdir / 'tmp').mkdir()
|
||||||
tmp_importer = testdir / 'tmp/importer'
|
tmp_importer = testdir / 'tmp/importer'
|
||||||
|
|
|
@ -26,7 +26,7 @@ import fdroidserver.index
|
||||||
import fdroidserver.net
|
import fdroidserver.net
|
||||||
import fdroidserver.signindex
|
import fdroidserver.signindex
|
||||||
import fdroidserver.publish
|
import fdroidserver.publish
|
||||||
from testcommon import TmpCwd
|
from testcommon import TmpCwd, mkdtemp
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,10 +44,6 @@ class IndexTest(unittest.TestCase):
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
self.basedir = os.path.join(localmodule, 'tests')
|
self.basedir = os.path.join(localmodule, 'tests')
|
||||||
os.chmod(os.path.join(self.basedir, 'config.py'), 0o600)
|
os.chmod(os.path.join(self.basedir, 'config.py'), 0o600)
|
||||||
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)
|
|
||||||
|
|
||||||
fdroidserver.common.config = None
|
fdroidserver.common.config = None
|
||||||
fdroidserver.common.options = Options
|
fdroidserver.common.options = Options
|
||||||
|
@ -60,6 +56,13 @@ class IndexTest(unittest.TestCase):
|
||||||
fdroidserver.signindex.sign_index(
|
fdroidserver.signindex.sign_index(
|
||||||
os.path.join(self.basedir, 'repo'), 'index-v1.json'
|
os.path.join(self.basedir, 'repo'), 'index-v1.json'
|
||||||
)
|
)
|
||||||
|
self._td = mkdtemp()
|
||||||
|
self.testdir = self._td.name
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
os.chdir(self.basedir)
|
||||||
|
self._td.cleanup()
|
||||||
|
os.remove('repo/index-v1.jar')
|
||||||
|
|
||||||
def test_get_public_key_from_jar_succeeds(self):
|
def test_get_public_key_from_jar_succeeds(self):
|
||||||
source_dir = os.path.join(self.basedir, 'signindex')
|
source_dir = os.path.join(self.basedir, 'signindex')
|
||||||
|
@ -269,10 +272,7 @@ class IndexTest(unittest.TestCase):
|
||||||
self.assertEqual(json.dumps(i, indent=2), json.dumps(o, indent=2))
|
self.assertEqual(json.dumps(i, indent=2), json.dumps(o, indent=2))
|
||||||
|
|
||||||
def test_make_v0_repo_only(self):
|
def test_make_v0_repo_only(self):
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(tmptestsdir)
|
|
||||||
os.mkdir('repo')
|
os.mkdir('repo')
|
||||||
repo_icons_dir = os.path.join('repo', 'icons')
|
repo_icons_dir = os.path.join('repo', 'icons')
|
||||||
self.assertFalse(os.path.isdir(repo_icons_dir))
|
self.assertFalse(os.path.isdir(repo_icons_dir))
|
||||||
|
@ -298,10 +298,7 @@ class IndexTest(unittest.TestCase):
|
||||||
self.assertTrue(os.path.exists(os.path.join('repo', 'index.xml')))
|
self.assertTrue(os.path.exists(os.path.join('repo', 'index.xml')))
|
||||||
|
|
||||||
def test_make_v0(self):
|
def test_make_v0(self):
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(tmptestsdir)
|
|
||||||
os.mkdir('metadata')
|
os.mkdir('metadata')
|
||||||
os.mkdir('repo')
|
os.mkdir('repo')
|
||||||
metadatafile = 'metadata/info.zwanenburg.caffeinetile.yml'
|
metadatafile = 'metadata/info.zwanenburg.caffeinetile.yml'
|
||||||
|
@ -368,10 +365,7 @@ class IndexTest(unittest.TestCase):
|
||||||
present.
|
present.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(tmptestsdir)
|
|
||||||
os.mkdir('repo')
|
os.mkdir('repo')
|
||||||
repo_icons_dir = os.path.join('repo', 'icons')
|
repo_icons_dir = os.path.join('repo', 'icons')
|
||||||
self.assertFalse(os.path.isdir(repo_icons_dir))
|
self.assertFalse(os.path.isdir(repo_icons_dir))
|
||||||
|
@ -463,10 +457,7 @@ class IndexTest(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_make_website(self):
|
def test_make_website(self):
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(tmptestsdir)
|
|
||||||
os.mkdir('metadata')
|
os.mkdir('metadata')
|
||||||
os.mkdir('repo')
|
os.mkdir('repo')
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import os
|
||||||
import optparse
|
import optparse
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +19,7 @@ if localmodule not in sys.path:
|
||||||
sys.path.insert(0, localmodule)
|
sys.path.insert(0, localmodule)
|
||||||
|
|
||||||
import fdroidserver.init
|
import fdroidserver.init
|
||||||
|
from testcommon import mkdtemp
|
||||||
|
|
||||||
|
|
||||||
class InitTest(unittest.TestCase):
|
class InitTest(unittest.TestCase):
|
||||||
|
@ -28,18 +28,17 @@ class InitTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
self.basedir = os.path.join(localmodule, 'tests')
|
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)
|
|
||||||
fdroidserver.common.config = None
|
fdroidserver.common.config = None
|
||||||
fdroidserver.init.config = None
|
fdroidserver.init.config = None
|
||||||
|
self._td = mkdtemp()
|
||||||
|
self.testdir = self._td.name
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self._td.cleanup()
|
||||||
|
os.chdir(self.basedir)
|
||||||
|
|
||||||
def test_disable_in_config(self):
|
def test_disable_in_config(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.yml', 'w') as fp:
|
with open('config.yml', 'w') as fp:
|
||||||
fp.write('keystore: NONE\n')
|
fp.write('keystore: NONE\n')
|
||||||
fp.write('keypass: mysupersecrets\n')
|
fp.write('keypass: mysupersecrets\n')
|
||||||
|
@ -57,12 +56,9 @@ class InitTest(unittest.TestCase):
|
||||||
@unittest.skipIf(os.name == 'nt', "calling main() like this hangs on Windows")
|
@unittest.skipIf(os.name == 'nt', "calling main() like this hangs on Windows")
|
||||||
def test_main_in_empty_dir(self):
|
def test_main_in_empty_dir(self):
|
||||||
"""Test that `fdroid init` will find apksigner and add it to the config"""
|
"""Test that `fdroid init` will find apksigner and add it to the config"""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
|
|
||||||
shutil.copy(os.path.join(self.basedir, 'keystore.jks'), testdir)
|
shutil.copy(os.path.join(self.basedir, 'keystore.jks'), self.testdir)
|
||||||
|
|
||||||
bindir = os.path.join(os.getcwd(), 'bin')
|
bindir = os.path.join(os.getcwd(), 'bin')
|
||||||
os.mkdir(bindir)
|
os.mkdir(bindir)
|
||||||
|
|
|
@ -38,10 +38,18 @@ class MetadataTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
self.basedir = localmodule / 'tests'
|
self.basedir = localmodule / 'tests'
|
||||||
self.tmpdir = localmodule / '.testfiles'
|
os.chdir(self.basedir)
|
||||||
self.tmpdir.mkdir(exist_ok=True)
|
|
||||||
# TODO: Python3.6: Accepts a path-like object.
|
def tearDown(self):
|
||||||
os.chdir(str(self.basedir))
|
# auto-generated dirs by functions, not tests, so they are not always cleaned up
|
||||||
|
try:
|
||||||
|
os.rmdir("srclibs")
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
os.rmdir("tmp")
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
def test_fieldtypes_key_exist(self):
|
def test_fieldtypes_key_exist(self):
|
||||||
for k in fdroidserver.metadata.fieldtypes.keys():
|
for k in fdroidserver.metadata.fieldtypes.keys():
|
||||||
|
@ -218,8 +226,7 @@ class MetadataTest(unittest.TestCase):
|
||||||
# yaml.dump(frommeta, f, default_flow_style=False)
|
# yaml.dump(frommeta, f, default_flow_style=False)
|
||||||
|
|
||||||
def test_rewrite_yaml_fakeotaupdate(self):
|
def test_rewrite_yaml_fakeotaupdate(self):
|
||||||
# TODO: Pytohn3.6: The dir parameter now accepts a path-like object.
|
with tempfile.TemporaryDirectory() as testdir:
|
||||||
with tempfile.TemporaryDirectory(dir=str(self.tmpdir)) as testdir:
|
|
||||||
testdir = Path(testdir)
|
testdir = Path(testdir)
|
||||||
fdroidserver.common.config = {'accepted_formats': ['yml']}
|
fdroidserver.common.config = {'accepted_formats': ['yml']}
|
||||||
fdroidserver.metadata.warnings_action = None
|
fdroidserver.metadata.warnings_action = None
|
||||||
|
@ -241,8 +248,7 @@ class MetadataTest(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_rewrite_yaml_fdroidclient(self):
|
def test_rewrite_yaml_fdroidclient(self):
|
||||||
# TODO: Pytohn3.6: The dir parameter now accepts a path-like object.
|
with tempfile.TemporaryDirectory() as testdir:
|
||||||
with tempfile.TemporaryDirectory(dir=str(self.tmpdir)) as testdir:
|
|
||||||
testdir = Path(testdir)
|
testdir = Path(testdir)
|
||||||
fdroidserver.common.config = {'accepted_formats': ['yml']}
|
fdroidserver.common.config = {'accepted_formats': ['yml']}
|
||||||
|
|
||||||
|
@ -263,8 +269,7 @@ class MetadataTest(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_rewrite_yaml_special_build_params(self):
|
def test_rewrite_yaml_special_build_params(self):
|
||||||
# TODO: Pytohn3.6: The dir parameter now accepts a path-like object.
|
with tempfile.TemporaryDirectory() as testdir:
|
||||||
with tempfile.TemporaryDirectory(dir=str(self.tmpdir)) as testdir:
|
|
||||||
testdir = Path(testdir)
|
testdir = Path(testdir)
|
||||||
|
|
||||||
# rewrite metadata
|
# rewrite metadata
|
||||||
|
@ -334,10 +339,7 @@ class MetadataTest(unittest.TestCase):
|
||||||
self.assertEqual('1234567890', yamldata['Builds'][0]['commit'])
|
self.assertEqual('1234567890', yamldata['Builds'][0]['commit'])
|
||||||
|
|
||||||
def test_read_metadata_sort_by_time(self):
|
def test_read_metadata_sort_by_time(self):
|
||||||
# TODO: Pytohn3.6: The dir parameter now accepts a path-like object.
|
with tempfile.TemporaryDirectory() as testdir, TmpCwd(testdir):
|
||||||
with tempfile.TemporaryDirectory(dir=str(self.tmpdir)) as testdir, TmpCwd(
|
|
||||||
testdir
|
|
||||||
):
|
|
||||||
testdir = Path(testdir)
|
testdir = Path(testdir)
|
||||||
metadatadir = testdir / 'metadata'
|
metadatadir = testdir / 'metadata'
|
||||||
metadatadir.mkdir()
|
metadatadir.mkdir()
|
||||||
|
@ -393,8 +395,7 @@ class MetadataTest(unittest.TestCase):
|
||||||
fdroidserver.metadata.parse_yaml_metadata(mf, {})
|
fdroidserver.metadata.parse_yaml_metadata(mf, {})
|
||||||
|
|
||||||
def test_parse_yaml_srclib_corrupt_file(self):
|
def test_parse_yaml_srclib_corrupt_file(self):
|
||||||
# TODO: Pytohn3.6: The dir parameter now accepts a path-like object.
|
with tempfile.TemporaryDirectory() as testdir:
|
||||||
with tempfile.TemporaryDirectory(dir=str(self.tmpdir)) as testdir:
|
|
||||||
testdir = Path(testdir)
|
testdir = Path(testdir)
|
||||||
srclibfile = testdir / 'srclib/mock.yml'
|
srclibfile = testdir / 'srclib/mock.yml'
|
||||||
srclibfile.parent.mkdir()
|
srclibfile.parent.mkdir()
|
||||||
|
@ -1117,29 +1118,30 @@ class MetadataTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_build_ndk_path(self):
|
def test_build_ndk_path(self):
|
||||||
""""""
|
""""""
|
||||||
config = {'ndk_paths': {}, 'sdk_path': tempfile.mkdtemp(prefix='android-sdk-')}
|
with tempfile.TemporaryDirectory(prefix='android-sdk-') as sdk_path:
|
||||||
fdroidserver.common.config = config
|
config = {'ndk_paths': {}, 'sdk_path': sdk_path}
|
||||||
|
fdroidserver.common.config = config
|
||||||
|
|
||||||
build = fdroidserver.metadata.Build()
|
build = fdroidserver.metadata.Build()
|
||||||
build.ndk = 'r10e'
|
build.ndk = 'r10e'
|
||||||
self.assertEqual('', build.ndk_path())
|
self.assertEqual('', build.ndk_path())
|
||||||
|
|
||||||
correct = '/fake/path/ndk/r21b'
|
correct = '/fake/path/ndk/r21b'
|
||||||
config['ndk_paths'] = {'r21b': correct}
|
config['ndk_paths'] = {'r21b': correct}
|
||||||
self.assertEqual('', build.ndk_path())
|
self.assertEqual('', build.ndk_path())
|
||||||
config['ndk_paths'] = {'r10e': correct}
|
config['ndk_paths'] = {'r10e': correct}
|
||||||
self.assertEqual(correct, build.ndk_path())
|
self.assertEqual(correct, build.ndk_path())
|
||||||
|
|
||||||
r10e = '/fake/path/ndk/r10e'
|
r10e = '/fake/path/ndk/r10e'
|
||||||
r22b = '/fake/path/ndk/r22e'
|
r22b = '/fake/path/ndk/r22e'
|
||||||
config['ndk_paths'] = {'r10e': r10e, 'r22b': r22b}
|
config['ndk_paths'] = {'r10e': r10e, 'r22b': r22b}
|
||||||
self.assertEqual(r10e, build.ndk_path())
|
self.assertEqual(r10e, build.ndk_path())
|
||||||
|
|
||||||
build.ndk = ['r10e', 'r22b']
|
build.ndk = ['r10e', 'r22b']
|
||||||
self.assertEqual(r10e, build.ndk_path())
|
self.assertEqual(r10e, build.ndk_path())
|
||||||
|
|
||||||
build.ndk = ['r22b', 'r10e']
|
build.ndk = ['r22b', 'r10e']
|
||||||
self.assertEqual(r22b, build.ndk_path())
|
self.assertEqual(r22b, build.ndk_path())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -122,6 +122,7 @@ class NightlyTest(unittest.TestCase):
|
||||||
assert '-----BEGIN RSA PRIVATE KEY-----' in fp.read()
|
assert '-----BEGIN RSA PRIVATE KEY-----' in fp.read()
|
||||||
with open(ssh_private_key_file + '.pub') as fp:
|
with open(ssh_private_key_file + '.pub') as fp:
|
||||||
assert fp.read(8) == 'ssh-rsa '
|
assert fp.read(8) == 'ssh-rsa '
|
||||||
|
shutil.rmtree(os.path.dirname(ssh_private_key_file))
|
||||||
|
|
||||||
@patch.dict(os.environ, clear=True)
|
@patch.dict(os.environ, clear=True)
|
||||||
@patch('sys.argv', ['fdroid nightly', '--verbose'])
|
@patch('sys.argv', ['fdroid nightly', '--verbose'])
|
||||||
|
|
|
@ -34,6 +34,7 @@ from fdroidserver import common
|
||||||
from fdroidserver import metadata
|
from fdroidserver import metadata
|
||||||
from fdroidserver import signatures
|
from fdroidserver import signatures
|
||||||
from fdroidserver.exception import FDroidException
|
from fdroidserver.exception import FDroidException
|
||||||
|
from testcommon import mkdtemp
|
||||||
|
|
||||||
|
|
||||||
class PublishTest(unittest.TestCase):
|
class PublishTest(unittest.TestCase):
|
||||||
|
@ -42,9 +43,12 @@ class PublishTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
self.basedir = os.path.join(localmodule, 'tests')
|
self.basedir = os.path.join(localmodule, 'tests')
|
||||||
self.tmpdir = os.path.abspath(os.path.join(self.basedir, '..', '.testfiles'))
|
os.chdir(self.basedir)
|
||||||
if not os.path.exists(self.tmpdir):
|
self._td = mkdtemp()
|
||||||
os.makedirs(self.tmpdir)
|
self.testdir = self._td.name
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self._td.cleanup()
|
||||||
os.chdir(self.basedir)
|
os.chdir(self.basedir)
|
||||||
|
|
||||||
def test_key_alias(self):
|
def test_key_alias(self):
|
||||||
|
@ -88,7 +92,7 @@ class PublishTest(unittest.TestCase):
|
||||||
publish.config = common.config
|
publish.config = common.config
|
||||||
publish.config['keystorepass'] = '123456'
|
publish.config['keystorepass'] = '123456'
|
||||||
publish.config['keypass'] = '123456'
|
publish.config['keypass'] = '123456'
|
||||||
publish.config['keystore'] = os.path.join(os.getcwd(), 'dummy-keystore.jks')
|
publish.config['keystore'] = os.path.join(self.basedir, 'dummy-keystore.jks')
|
||||||
publish.config['repo_keyalias'] = 'repokey'
|
publish.config['repo_keyalias'] = 'repokey'
|
||||||
|
|
||||||
appids = [
|
appids = [
|
||||||
|
@ -99,10 +103,7 @@ class PublishTest(unittest.TestCase):
|
||||||
'org.org.org',
|
'org.org.org',
|
||||||
]
|
]
|
||||||
|
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
with open('config.py', 'w') as f:
|
with open('config.py', 'w') as f:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -142,14 +143,11 @@ class PublishTest(unittest.TestCase):
|
||||||
publish.config = common.config
|
publish.config = common.config
|
||||||
publish.config['keystorepass'] = '123456'
|
publish.config['keystorepass'] = '123456'
|
||||||
publish.config['keypass'] = '123456'
|
publish.config['keypass'] = '123456'
|
||||||
publish.config['keystore'] = os.path.join(os.getcwd(), 'dummy-keystore.jks')
|
publish.config['keystore'] = os.path.join(self.basedir, 'dummy-keystore.jks')
|
||||||
publish.config['repo_keyalias'] = 'repokey'
|
publish.config['repo_keyalias'] = 'repokey'
|
||||||
publish.config['repo_key_sha256'] = 'bad bad bad bad bad bad bad bad bad bad bad bad'
|
publish.config['repo_key_sha256'] = 'bad bad bad bad bad bad bad bad bad bad bad bad'
|
||||||
|
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
publish.store_stats_fdroid_signing_key_fingerprints({}, indent=2)
|
publish.store_stats_fdroid_signing_key_fingerprints({}, indent=2)
|
||||||
with self.assertRaises(FDroidException):
|
with self.assertRaises(FDroidException):
|
||||||
common.load_stats_fdroid_signing_key_fingerprints()
|
common.load_stats_fdroid_signing_key_fingerprints()
|
||||||
|
@ -162,24 +160,20 @@ class PublishTest(unittest.TestCase):
|
||||||
publish.config['repo_keyalias'] = 'sova'
|
publish.config['repo_keyalias'] = 'sova'
|
||||||
publish.config['keystorepass'] = 'r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI='
|
publish.config['keystorepass'] = 'r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI='
|
||||||
publish.config['keypass'] = 'r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI='
|
publish.config['keypass'] = 'r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI='
|
||||||
testdir = tempfile.mkdtemp(
|
shutil.copy('keystore.jks', self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
os.mkdir(os.path.join(self.testdir, 'repo'))
|
||||||
)
|
metadata_dir = os.path.join(self.testdir, 'metadata')
|
||||||
|
|
||||||
shutil.copy('keystore.jks', testdir)
|
|
||||||
os.mkdir(os.path.join(testdir, 'repo'))
|
|
||||||
metadata_dir = os.path.join(testdir, 'metadata')
|
|
||||||
os.mkdir(metadata_dir)
|
os.mkdir(metadata_dir)
|
||||||
shutil.copy(os.path.join('metadata', 'com.politedroid.yml'), metadata_dir)
|
shutil.copy(os.path.join('metadata', 'com.politedroid.yml'), metadata_dir)
|
||||||
with open(os.path.join(metadata_dir, 'com.politedroid.yml'), 'a') as fp:
|
with open(os.path.join(metadata_dir, 'com.politedroid.yml'), 'a') as fp:
|
||||||
fp.write('\nBinaries: https://placeholder/foo%v.apk\n')
|
fp.write('\nBinaries: https://placeholder/foo%v.apk\n')
|
||||||
os.mkdir(os.path.join(testdir, 'unsigned'))
|
os.mkdir(os.path.join(self.testdir, 'unsigned'))
|
||||||
shutil.copy('repo/com.politedroid_6.apk', os.path.join(testdir, 'unsigned'))
|
shutil.copy('repo/com.politedroid_6.apk', os.path.join(self.testdir, 'unsigned'))
|
||||||
os.mkdir(os.path.join(testdir, 'unsigned', 'binaries'))
|
os.mkdir(os.path.join(self.testdir, 'unsigned', 'binaries'))
|
||||||
shutil.copy('repo/com.politedroid_6.apk',
|
shutil.copy('repo/com.politedroid_6.apk',
|
||||||
os.path.join(testdir, 'unsigned', 'binaries', 'com.politedroid_6.binary.apk'))
|
os.path.join(self.testdir, 'unsigned', 'binaries', 'com.politedroid_6.binary.apk'))
|
||||||
|
|
||||||
os.chdir(testdir)
|
os.chdir(self.testdir)
|
||||||
with mock.patch.object(sys, 'argv', ['fdroid fakesubcommand']):
|
with mock.patch.object(sys, 'argv', ['fdroid fakesubcommand']):
|
||||||
publish.main()
|
publish.main()
|
||||||
|
|
||||||
|
@ -222,8 +216,7 @@ class PublishTest(unittest.TestCase):
|
||||||
publish.config['keypass'] = '654321'
|
publish.config['keypass'] = '654321'
|
||||||
publish.config['keystore'] = "keystore.jks"
|
publish.config['keystore'] = "keystore.jks"
|
||||||
publish.config['keydname'] = 'CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US'
|
publish.config['keydname'] = 'CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US'
|
||||||
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
|
os.chdir(self.testdir)
|
||||||
os.chdir(testdir)
|
|
||||||
keystore = jks.KeyStore.new("jks", [])
|
keystore = jks.KeyStore.new("jks", [])
|
||||||
keystore.save(publish.config['keystore'], publish.config['keystorepass'])
|
keystore.save(publish.config['keystore'], publish.config['keystorepass'])
|
||||||
|
|
||||||
|
@ -272,10 +265,7 @@ class PublishTest(unittest.TestCase):
|
||||||
class Options:
|
class Options:
|
||||||
verbose = False
|
verbose = False
|
||||||
|
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
|
|
||||||
config = common.read_config(Options)
|
config = common.read_config(Options)
|
||||||
if 'apksigner' not in config:
|
if 'apksigner' not in config:
|
||||||
|
@ -283,7 +273,7 @@ class PublishTest(unittest.TestCase):
|
||||||
config['repo_keyalias'] = 'sova'
|
config['repo_keyalias'] = 'sova'
|
||||||
config['keystorepass'] = 'r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI='
|
config['keystorepass'] = 'r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI='
|
||||||
config['keypass'] = 'r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI='
|
config['keypass'] = 'r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI='
|
||||||
shutil.copy(os.path.join(self.basedir, 'keystore.jks'), testdir)
|
shutil.copy(os.path.join(self.basedir, 'keystore.jks'), self.testdir)
|
||||||
config['keystore'] = 'keystore.jks'
|
config['keystore'] = 'keystore.jks'
|
||||||
config['keydname'] = 'CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US'
|
config['keydname'] = 'CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US'
|
||||||
publish.config = config
|
publish.config = config
|
||||||
|
|
|
@ -30,17 +30,20 @@ import fdroidserver.build
|
||||||
import fdroidserver.common
|
import fdroidserver.common
|
||||||
import fdroidserver.metadata
|
import fdroidserver.metadata
|
||||||
import fdroidserver.scanner
|
import fdroidserver.scanner
|
||||||
from testcommon import TmpCwd, mock_open_to_str
|
from testcommon import TmpCwd, mkdtemp, mock_open_to_str
|
||||||
|
|
||||||
|
|
||||||
class ScannerTest(unittest.TestCase):
|
class ScannerTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
self.basedir = os.path.join(localmodule, 'tests')
|
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)
|
os.chdir(self.basedir)
|
||||||
|
self._td = mkdtemp()
|
||||||
|
self.testdir = self._td.name
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
os.chdir(self.basedir)
|
||||||
|
self._td.cleanup()
|
||||||
|
|
||||||
def test_scan_source_files(self):
|
def test_scan_source_files(self):
|
||||||
fdroidserver.scanner.options = mock.Mock()
|
fdroidserver.scanner.options = mock.Mock()
|
||||||
|
@ -97,10 +100,7 @@ class ScannerTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_scan_source_files_sneaky_maven(self):
|
def test_scan_source_files_sneaky_maven(self):
|
||||||
"""Check for sneaking in banned maven repos"""
|
"""Check for sneaking in banned maven repos"""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
fdroidserver.scanner.config = None
|
fdroidserver.scanner.config = None
|
||||||
fdroidserver.scanner.options = mock.Mock()
|
fdroidserver.scanner.options = mock.Mock()
|
||||||
fdroidserver.scanner.options.json = True
|
fdroidserver.scanner.options.json = True
|
||||||
|
@ -119,7 +119,7 @@ class ScannerTest(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
count = fdroidserver.scanner.scan_source(testdir)
|
count = fdroidserver.scanner.scan_source(self.testdir)
|
||||||
self.assertEqual(2, count, 'there should be this many errors')
|
self.assertEqual(2, count, 'there should be this many errors')
|
||||||
|
|
||||||
def test_scan_source_file_types(self):
|
def test_scan_source_file_types(self):
|
||||||
|
@ -129,11 +129,8 @@ class ScannerTest(unittest.TestCase):
|
||||||
difference between absolute and relative paths.
|
difference between absolute and relative paths.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
testdir = tempfile.mkdtemp(
|
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
build_dir = os.path.join('build', 'fake.app')
|
build_dir = os.path.join('build', 'fake.app')
|
||||||
abs_build_dir = os.path.join(testdir, build_dir)
|
abs_build_dir = os.path.join(self.testdir, build_dir)
|
||||||
os.makedirs(abs_build_dir, exist_ok=True)
|
os.makedirs(abs_build_dir, exist_ok=True)
|
||||||
os.chdir(abs_build_dir)
|
os.chdir(abs_build_dir)
|
||||||
|
|
||||||
|
@ -174,7 +171,7 @@ class ScannerTest(unittest.TestCase):
|
||||||
os.system('ls -l fake.png')
|
os.system('ls -l fake.png')
|
||||||
|
|
||||||
# run scanner as if from `fdroid build`
|
# run scanner as if from `fdroid build`
|
||||||
os.chdir(testdir)
|
os.chdir(self.testdir)
|
||||||
count = fdroidserver.scanner.scan_source(build_dir)
|
count = fdroidserver.scanner.scan_source(build_dir)
|
||||||
self.assertEqual(6, count, 'there should be this many errors')
|
self.assertEqual(6, count, 'there should be this many errors')
|
||||||
os.chdir(build_dir)
|
os.chdir(build_dir)
|
||||||
|
@ -224,11 +221,7 @@ class ScannerTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_build_local_scanner(self):
|
def test_build_local_scanner(self):
|
||||||
"""`fdroid build` calls scanner functions, test them here"""
|
"""`fdroid build` calls scanner functions, test them here"""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
|
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
|
@ -284,8 +277,8 @@ class ScannerTest(unittest.TestCase):
|
||||||
app,
|
app,
|
||||||
build,
|
build,
|
||||||
vcs,
|
vcs,
|
||||||
build_dir=testdir,
|
build_dir=self.testdir,
|
||||||
output_dir=testdir,
|
output_dir=self.testdir,
|
||||||
log_dir=None,
|
log_dir=None,
|
||||||
srclib_dir=None,
|
srclib_dir=None,
|
||||||
extlib_dir=None,
|
extlib_dir=None,
|
||||||
|
@ -314,10 +307,7 @@ class ScannerTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_scan_gradle_file_with_multiple_problems(self):
|
def test_scan_gradle_file_with_multiple_problems(self):
|
||||||
"""Check that the scanner can handle scandelete with gradle files with multiple problems"""
|
"""Check that the scanner can handle scandelete with gradle files with multiple problems"""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
fdroidserver.scanner.config = None
|
fdroidserver.scanner.config = None
|
||||||
fdroidserver.scanner.options = mock.Mock()
|
fdroidserver.scanner.options = mock.Mock()
|
||||||
build = fdroidserver.metadata.Build()
|
build = fdroidserver.metadata.Build()
|
||||||
|
@ -335,7 +325,7 @@ class ScannerTest(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
count = fdroidserver.scanner.scan_source(testdir, build)
|
count = fdroidserver.scanner.scan_source(self.testdir, build)
|
||||||
self.assertFalse(os.path.exists("build.gradle"))
|
self.assertFalse(os.path.exists("build.gradle"))
|
||||||
self.assertEqual(0, count, 'there should be this many errors')
|
self.assertEqual(0, count, 'there should be this many errors')
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
class TmpCwd():
|
class TmpCwd():
|
||||||
|
@ -58,3 +59,10 @@ def mock_open_to_str(mock):
|
||||||
return "".join([
|
return "".join([
|
||||||
x.args[0] for x in mock.mock_calls if str(x).startswith("call().write(")
|
x.args[0] for x in mock.mock_calls if str(x).startswith("call().write(")
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def mkdtemp():
|
||||||
|
if sys.version_info < (3, 10): # ignore_cleanup_errors was added in 3.10
|
||||||
|
return tempfile.TemporaryDirectory()
|
||||||
|
else:
|
||||||
|
return tempfile.TemporaryDirectory(ignore_cleanup_errors=True)
|
||||||
|
|
|
@ -22,7 +22,7 @@ import zipfile
|
||||||
import textwrap
|
import textwrap
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
from testcommon import TmpCwd
|
from testcommon import TmpCwd, mkdtemp
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -79,19 +79,19 @@ class UpdateTest(unittest.TestCase):
|
||||||
|
|
||||||
logging.getLogger(PngImagePlugin.__name__).setLevel(logging.INFO)
|
logging.getLogger(PngImagePlugin.__name__).setLevel(logging.INFO)
|
||||||
self.basedir = os.path.join(localmodule, 'tests')
|
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)
|
os.chdir(self.basedir)
|
||||||
|
self._td = mkdtemp()
|
||||||
|
self.testdir = self._td.name
|
||||||
|
|
||||||
fdroidserver.common.config = None
|
fdroidserver.common.config = None
|
||||||
fdroidserver.common.options = None
|
fdroidserver.common.options = None
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
os.chdir(self.basedir)
|
||||||
|
self._td.cleanup()
|
||||||
|
|
||||||
def test_insert_store_metadata(self):
|
def test_insert_store_metadata(self):
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(tmptestsdir)
|
|
||||||
|
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
|
@ -124,7 +124,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
):
|
):
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
os.path.join(self.basedir, 'source-files', packageName),
|
os.path.join(self.basedir, 'source-files', packageName),
|
||||||
os.path.join(tmptestsdir, 'build', packageName),
|
os.path.join(self.testdir, 'build', packageName),
|
||||||
)
|
)
|
||||||
|
|
||||||
testfilename = 'icon_yAfSvPRJukZzMMfUzvbYqwaD1XmHXNtiPBtuPVHW-6s=.png'
|
testfilename = 'icon_yAfSvPRJukZzMMfUzvbYqwaD1XmHXNtiPBtuPVHW-6s=.png'
|
||||||
|
@ -215,10 +215,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
|
|
||||||
https://docs.fastlane.tools/actions/supply/#changelogs-whats-new
|
https://docs.fastlane.tools/actions/supply/#changelogs-whats-new
|
||||||
"""
|
"""
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(tmptestsdir)
|
|
||||||
|
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
|
@ -254,11 +251,12 @@ class UpdateTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_name_title_scraping(self):
|
def test_name_title_scraping(self):
|
||||||
"""metadata file --> fdroiddata localized files --> fastlane/triple-t in app source --> APK"""
|
"""metadata file --> fdroiddata localized files --> fastlane/triple-t in app source --> APK"""
|
||||||
|
shutil.copytree(self.basedir, self.testdir, dirs_exist_ok=True)
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
fdroidserver.update.config = config
|
fdroidserver.update.config = config
|
||||||
os.chdir(os.path.join(localmodule, 'tests'))
|
os.chdir(self.testdir)
|
||||||
fdroidserver.common.options = Options
|
fdroidserver.common.options = Options
|
||||||
fdroidserver.update.options = fdroidserver.common.options
|
fdroidserver.update.options = fdroidserver.common.options
|
||||||
fdroidserver.update.options.clean = True
|
fdroidserver.update.options.clean = True
|
||||||
|
@ -340,6 +338,8 @@ class UpdateTest(unittest.TestCase):
|
||||||
self.assertEqual(testvalue, app['localized']['en-US']['name'])
|
self.assertEqual(testvalue, app['localized']['en-US']['name'])
|
||||||
|
|
||||||
def test_insert_missing_app_names_from_apks_from_repo(self):
|
def test_insert_missing_app_names_from_apks_from_repo(self):
|
||||||
|
os.chdir(self.testdir)
|
||||||
|
shutil.copytree(self.basedir, self.testdir, dirs_exist_ok=True)
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
|
@ -393,9 +393,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
if not os.path.isdir(importer):
|
if not os.path.isdir(importer):
|
||||||
logging.warning('skipping test_insert_triple_t_metadata, import.TestCase must run first!')
|
logging.warning('skipping test_insert_triple_t_metadata, import.TestCase must run first!')
|
||||||
return
|
return
|
||||||
tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
|
packageDir = os.path.join(self.testdir, 'build', packageName)
|
||||||
dir=self.tmpdir)
|
|
||||||
packageDir = os.path.join(tmptestsdir, 'build', packageName)
|
|
||||||
shutil.copytree(importer, packageDir)
|
shutil.copytree(importer, packageDir)
|
||||||
|
|
||||||
# always use the same commit so these tests work when ci-test-app.git is updated
|
# always use the same commit so these tests work when ci-test-app.git is updated
|
||||||
|
@ -405,17 +403,17 @@ class UpdateTest(unittest.TestCase):
|
||||||
repo.git.reset('--hard', 'b9e5d1a0d8d6fc31d4674b2f0514fef10762ed4f')
|
repo.git.reset('--hard', 'b9e5d1a0d8d6fc31d4674b2f0514fef10762ed4f')
|
||||||
repo.git.clean('-fdx')
|
repo.git.clean('-fdx')
|
||||||
|
|
||||||
os.mkdir(os.path.join(tmptestsdir, 'metadata'))
|
os.mkdir(os.path.join(self.testdir, 'metadata'))
|
||||||
metadata = dict()
|
metadata = dict()
|
||||||
metadata['Description'] = 'This is just a test app'
|
metadata['Description'] = 'This is just a test app'
|
||||||
with open(os.path.join(tmptestsdir, 'metadata', packageName + '.yml'), 'w') as fp:
|
with open(os.path.join(self.testdir, 'metadata', packageName + '.yml'), 'w') as fp:
|
||||||
yaml.dump(metadata, fp)
|
yaml.dump(metadata, fp)
|
||||||
|
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
fdroidserver.update.config = config
|
fdroidserver.update.config = config
|
||||||
os.chdir(tmptestsdir)
|
os.chdir(self.testdir)
|
||||||
|
|
||||||
apps = fdroidserver.metadata.read_metadata()
|
apps = fdroidserver.metadata.read_metadata()
|
||||||
fdroidserver.update.copy_triple_t_store_metadata(apps)
|
fdroidserver.update.copy_triple_t_store_metadata(apps)
|
||||||
|
@ -436,12 +434,8 @@ class UpdateTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_insert_triple_t_2_metadata(self):
|
def test_insert_triple_t_2_metadata(self):
|
||||||
packageName = 'org.piwigo.android'
|
packageName = 'org.piwigo.android'
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
shutil.copytree(os.path.join(self.basedir, 'triple-t-2'), self.testdir, dirs_exist_ok=True)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
os.chdir(self.testdir)
|
||||||
)
|
|
||||||
os.rmdir(tmptestsdir)
|
|
||||||
shutil.copytree(os.path.join(self.basedir, 'triple-t-2'), tmptestsdir)
|
|
||||||
os.chdir(tmptestsdir)
|
|
||||||
|
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
|
@ -478,12 +472,8 @@ class UpdateTest(unittest.TestCase):
|
||||||
packages = ('com.anysoftkeyboard.languagepack.dutch', 'com.menny.android.anysoftkeyboard')
|
packages = ('com.anysoftkeyboard.languagepack.dutch', 'com.menny.android.anysoftkeyboard')
|
||||||
names = ('Dutch for AnySoftKeyboard', 'AnySoftKeyboard')
|
names = ('Dutch for AnySoftKeyboard', 'AnySoftKeyboard')
|
||||||
|
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
shutil.copytree(os.path.join(self.basedir, 'triple-t-anysoftkeyboard'), self.testdir, dirs_exist_ok=True)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
os.chdir(self.testdir)
|
||||||
)
|
|
||||||
os.rmdir(tmptestsdir)
|
|
||||||
shutil.copytree(os.path.join(self.basedir, 'triple-t-anysoftkeyboard'), tmptestsdir)
|
|
||||||
os.chdir(tmptestsdir)
|
|
||||||
|
|
||||||
for packageName, name in zip(packages, names):
|
for packageName, name in zip(packages, names):
|
||||||
config = dict()
|
config = dict()
|
||||||
|
@ -503,12 +493,8 @@ class UpdateTest(unittest.TestCase):
|
||||||
packages = ('verifier', 'wallet')
|
packages = ('verifier', 'wallet')
|
||||||
names = dict(verifier='COVID Certificate Check', wallet='COVID Certificate')
|
names = dict(verifier='COVID Certificate Check', wallet='COVID Certificate')
|
||||||
|
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
shutil.copytree(os.path.join(self.basedir, 'triple-t-multiple'), self.testdir, dirs_exist_ok=True)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
os.chdir(self.testdir)
|
||||||
)
|
|
||||||
os.rmdir(tmptestsdir)
|
|
||||||
shutil.copytree(os.path.join(self.basedir, 'triple-t-multiple'), tmptestsdir)
|
|
||||||
os.chdir(tmptestsdir)
|
|
||||||
|
|
||||||
for p in packages:
|
for p in packages:
|
||||||
packageName = namespace + p
|
packageName = namespace + p
|
||||||
|
@ -527,12 +513,8 @@ class UpdateTest(unittest.TestCase):
|
||||||
def test_insert_triple_t_flutter(self):
|
def test_insert_triple_t_flutter(self):
|
||||||
packageName = 'fr.emersion.goguma'
|
packageName = 'fr.emersion.goguma'
|
||||||
|
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
shutil.copytree(os.path.join(self.basedir, 'triple-t-flutter'), self.testdir, dirs_exist_ok=True)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
os.chdir(self.testdir)
|
||||||
)
|
|
||||||
os.rmdir(tmptestsdir)
|
|
||||||
shutil.copytree(os.path.join(self.basedir, 'triple-t-flutter'), tmptestsdir)
|
|
||||||
os.chdir(tmptestsdir)
|
|
||||||
|
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
|
@ -609,11 +591,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
"python sig was: " + str(sig))
|
"python sig was: " + str(sig))
|
||||||
|
|
||||||
def testScanApksAndObbs(self):
|
def testScanApksAndObbs(self):
|
||||||
os.chdir(os.path.join(localmodule, 'tests'))
|
os.chdir(self.testdir)
|
||||||
testdir = tempfile.mkdtemp(
|
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
shutil.copytree(os.path.join(self.basedir, 'repo'), 'repo')
|
shutil.copytree(os.path.join(self.basedir, 'repo'), 'repo')
|
||||||
shutil.copytree(os.path.join(self.basedir, 'metadata'), 'metadata')
|
shutil.copytree(os.path.join(self.basedir, 'metadata'), 'metadata')
|
||||||
config = dict()
|
config = dict()
|
||||||
|
@ -668,11 +646,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_apkcache_json(self):
|
def test_apkcache_json(self):
|
||||||
"""test the migration from pickle to json"""
|
"""test the migration from pickle to json"""
|
||||||
os.chdir(os.path.join(localmodule, 'tests'))
|
os.chdir(self.testdir)
|
||||||
testdir = tempfile.mkdtemp(
|
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
shutil.copytree(os.path.join(self.basedir, 'repo'), 'repo')
|
shutil.copytree(os.path.join(self.basedir, 'repo'), 'repo')
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
|
@ -711,10 +685,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
fdroidserver.update.config = config
|
fdroidserver.update.config = config
|
||||||
|
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
os.mkdir('repo')
|
os.mkdir('repo')
|
||||||
os.mkdir('stats')
|
os.mkdir('stats')
|
||||||
with open(os.path.join('stats', 'known_apks.txt'), 'w') as fp:
|
with open(os.path.join('stats', 'known_apks.txt'), 'w') as fp:
|
||||||
|
@ -736,25 +707,27 @@ class UpdateTest(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_read_added_date_from_all_apks(self):
|
def test_read_added_date_from_all_apks(self):
|
||||||
|
os.chdir(self.testdir)
|
||||||
|
shutil.copytree(os.path.join(self.basedir, 'repo'), 'repo')
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
fdroidserver.update.config = config
|
fdroidserver.update.config = config
|
||||||
fdroidserver.common.options = Options
|
fdroidserver.common.options = Options
|
||||||
os.chdir(os.path.join(localmodule, 'tests'))
|
|
||||||
apps = fdroidserver.metadata.read_metadata()
|
apps = fdroidserver.metadata.read_metadata()
|
||||||
knownapks = fdroidserver.common.KnownApks()
|
knownapks = fdroidserver.common.KnownApks()
|
||||||
apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks)
|
apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks)
|
||||||
fdroidserver.update.read_added_date_from_all_apks(apps, apks)
|
fdroidserver.update.read_added_date_from_all_apks(apps, apks)
|
||||||
|
|
||||||
def test_apply_info_from_latest_apk(self):
|
def test_apply_info_from_latest_apk(self):
|
||||||
|
os.chdir(self.testdir)
|
||||||
|
shutil.copytree(os.path.join(self.basedir, 'repo'), 'repo')
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
fdroidserver.update.config = config
|
fdroidserver.update.config = config
|
||||||
fdroidserver.common.options = Options
|
fdroidserver.common.options = Options
|
||||||
fdroidserver.update.options = fdroidserver.common.options
|
fdroidserver.update.options = fdroidserver.common.options
|
||||||
os.chdir(os.path.join(localmodule, 'tests'))
|
|
||||||
apps = fdroidserver.metadata.read_metadata()
|
apps = fdroidserver.metadata.read_metadata()
|
||||||
knownapks = fdroidserver.common.KnownApks()
|
knownapks = fdroidserver.common.KnownApks()
|
||||||
apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks)
|
apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks)
|
||||||
|
@ -765,7 +738,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
fdroidserver.update.config = config
|
fdroidserver.update.config = config
|
||||||
os.chdir(os.path.join(localmodule, 'tests'))
|
os.chdir(self.basedir)
|
||||||
|
|
||||||
if 'apksigner' in config:
|
if 'apksigner' in config:
|
||||||
apk_info = fdroidserver.update.scan_apk('v2.only.sig_2.apk')
|
apk_info = fdroidserver.update.scan_apk('v2.only.sig_2.apk')
|
||||||
|
@ -873,7 +846,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
fdroidserver.update.config = config
|
fdroidserver.update.config = config
|
||||||
os.chdir(os.path.join(localmodule, 'tests'))
|
os.chdir(self.basedir)
|
||||||
if os.path.basename(os.getcwd()) != 'tests':
|
if os.path.basename(os.getcwd()) != 'tests':
|
||||||
raise Exception('This test must be run in the "tests/" subdir')
|
raise Exception('This test must be run in the "tests/" subdir')
|
||||||
|
|
||||||
|
@ -885,10 +858,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
fdroidserver.update.config = config
|
fdroidserver.update.config = config
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
os.mkdir('repo')
|
os.mkdir('repo')
|
||||||
apkfile = 'repo/badzip_1.apk'
|
apkfile = 'repo/badzip_1.apk'
|
||||||
with open(apkfile, 'w') as fp:
|
with open(apkfile, 'w') as fp:
|
||||||
|
@ -935,11 +905,13 @@ class UpdateTest(unittest.TestCase):
|
||||||
'''Creates a YAML representation of a Build instance'''
|
'''Creates a YAML representation of a Build instance'''
|
||||||
return dumper.represent_dict(data)
|
return dumper.represent_dict(data)
|
||||||
|
|
||||||
|
os.chdir(self.testdir)
|
||||||
|
shutil.copytree(self.basedir, 'tests')
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
fdroidserver.update.config = config
|
fdroidserver.update.config = config
|
||||||
os.chdir(os.path.join(localmodule, 'tests'))
|
os.chdir("tests")
|
||||||
|
|
||||||
config['ndk_paths'] = dict()
|
config['ndk_paths'] = dict()
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
|
@ -1016,87 +988,83 @@ class UpdateTest(unittest.TestCase):
|
||||||
|
|
||||||
knownapks = fdroidserver.common.KnownApks()
|
knownapks = fdroidserver.common.KnownApks()
|
||||||
|
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
with tempfile.TemporaryDirectory() as tmptestsdir, TmpCwd(tmptestsdir):
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
os.mkdir('repo')
|
||||||
)
|
os.mkdir('archive')
|
||||||
print('tmptestsdir', tmptestsdir)
|
# setup the repo, create icons dirs, etc.
|
||||||
os.chdir(tmptestsdir)
|
fdroidserver.update.process_apks({}, 'repo', knownapks)
|
||||||
os.mkdir('repo')
|
fdroidserver.update.process_apks({}, 'archive', knownapks)
|
||||||
os.mkdir('archive')
|
|
||||||
# setup the repo, create icons dirs, etc.
|
|
||||||
fdroidserver.update.process_apks({}, 'repo', knownapks)
|
|
||||||
fdroidserver.update.process_apks({}, 'archive', knownapks)
|
|
||||||
|
|
||||||
disabledsigs = ['org.bitbucket.tickytacky.mirrormirror_2.apk']
|
disabledsigs = ['org.bitbucket.tickytacky.mirrormirror_2.apk']
|
||||||
for apkName in disabledsigs:
|
for apkName in disabledsigs:
|
||||||
shutil.copy(os.path.join(self.basedir, apkName),
|
shutil.copy(os.path.join(self.basedir, apkName),
|
||||||
os.path.join(tmptestsdir, 'repo'))
|
os.path.join(tmptestsdir, 'repo'))
|
||||||
|
|
||||||
skip, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'repo',
|
skip, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'repo',
|
||||||
knownapks,
|
knownapks,
|
||||||
allow_disabled_algorithms=True,
|
allow_disabled_algorithms=True,
|
||||||
archive_bad_sig=False)
|
archive_bad_sig=False)
|
||||||
self.assertFalse(skip)
|
self.assertFalse(skip)
|
||||||
self.assertIsNotNone(apk)
|
self.assertIsNotNone(apk)
|
||||||
self.assertTrue(cachechanged)
|
self.assertTrue(cachechanged)
|
||||||
self.assertFalse(os.path.exists(os.path.join('archive', apkName)))
|
self.assertFalse(os.path.exists(os.path.join('archive', apkName)))
|
||||||
self.assertTrue(os.path.exists(os.path.join('repo', apkName)))
|
self.assertTrue(os.path.exists(os.path.join('repo', apkName)))
|
||||||
|
|
||||||
if os.path.exists('/usr/bin/apksigner') or 'apksigner' in config:
|
if os.path.exists('/usr/bin/apksigner') or 'apksigner' in config:
|
||||||
print('SKIPPING: apksigner installed and it allows MD5 signatures')
|
print('SKIPPING: apksigner installed and it allows MD5 signatures')
|
||||||
return
|
return
|
||||||
|
|
||||||
javac = config['jarsigner'].replace('jarsigner', 'javac')
|
javac = config['jarsigner'].replace('jarsigner', 'javac')
|
||||||
v = subprocess.check_output([javac, '-version'], stderr=subprocess.STDOUT)[6:-1].decode('utf-8')
|
v = subprocess.check_output([javac, '-version'], stderr=subprocess.STDOUT)[6:-1].decode('utf-8')
|
||||||
if LooseVersion(v) < LooseVersion('1.8.0_132'):
|
if LooseVersion(v) < LooseVersion('1.8.0_132'):
|
||||||
print('SKIPPING: running tests with old Java (' + v + ')')
|
print('SKIPPING: running tests with old Java (' + v + ')')
|
||||||
return
|
return
|
||||||
|
|
||||||
# this test only works on systems with fully updated Java/jarsigner
|
# this test only works on systems with fully updated Java/jarsigner
|
||||||
# that has MD5 listed in jdk.jar.disabledAlgorithms in java.security
|
# 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
|
# 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',
|
skip, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'repo',
|
||||||
knownapks,
|
knownapks,
|
||||||
allow_disabled_algorithms=False,
|
allow_disabled_algorithms=False,
|
||||||
archive_bad_sig=True)
|
archive_bad_sig=True)
|
||||||
self.assertTrue(skip)
|
self.assertTrue(skip)
|
||||||
self.assertIsNone(apk)
|
self.assertIsNone(apk)
|
||||||
self.assertFalse(cachechanged)
|
self.assertFalse(cachechanged)
|
||||||
self.assertTrue(os.path.exists(os.path.join('archive', apkName)))
|
self.assertTrue(os.path.exists(os.path.join('archive', apkName)))
|
||||||
self.assertFalse(os.path.exists(os.path.join('repo', apkName)))
|
self.assertFalse(os.path.exists(os.path.join('repo', apkName)))
|
||||||
|
|
||||||
skip, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'archive',
|
skip, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'archive',
|
||||||
knownapks,
|
knownapks,
|
||||||
allow_disabled_algorithms=False,
|
allow_disabled_algorithms=False,
|
||||||
archive_bad_sig=False)
|
archive_bad_sig=False)
|
||||||
self.assertFalse(skip)
|
self.assertFalse(skip)
|
||||||
self.assertIsNotNone(apk)
|
self.assertIsNotNone(apk)
|
||||||
self.assertTrue(cachechanged)
|
self.assertTrue(cachechanged)
|
||||||
self.assertTrue(os.path.exists(os.path.join('archive', apkName)))
|
self.assertTrue(os.path.exists(os.path.join('archive', apkName)))
|
||||||
self.assertFalse(os.path.exists(os.path.join('repo', apkName)))
|
self.assertFalse(os.path.exists(os.path.join('repo', apkName)))
|
||||||
|
|
||||||
# ensure that icons have been moved to the archive as well
|
# ensure that icons have been moved to the archive as well
|
||||||
for density in fdroidserver.update.screen_densities:
|
for density in fdroidserver.update.screen_densities:
|
||||||
icon_path = os.path.join(fdroidserver.update.get_icon_dir('archive', density),
|
icon_path = os.path.join(fdroidserver.update.get_icon_dir('archive', density),
|
||||||
apk['icon'])
|
apk['icon'])
|
||||||
self.assertTrue(os.path.isfile(icon_path))
|
self.assertTrue(os.path.isfile(icon_path))
|
||||||
self.assertTrue(os.path.getsize(icon_path) > 1)
|
self.assertTrue(os.path.getsize(icon_path) > 1)
|
||||||
|
|
||||||
badsigs = ['urzip-badcert.apk', 'urzip-badsig.apk', 'urzip-release-unsigned.apk', ]
|
badsigs = ['urzip-badcert.apk', 'urzip-badsig.apk', 'urzip-release-unsigned.apk', ]
|
||||||
for apkName in badsigs:
|
for apkName in badsigs:
|
||||||
shutil.copy(os.path.join(self.basedir, apkName),
|
shutil.copy(os.path.join(self.basedir, apkName),
|
||||||
os.path.join(tmptestsdir, 'repo'))
|
os.path.join(self.testdir, 'repo'))
|
||||||
|
|
||||||
skip, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'repo',
|
skip, apk, cachechanged = fdroidserver.update.process_apk({}, apkName, 'repo',
|
||||||
knownapks,
|
knownapks,
|
||||||
allow_disabled_algorithms=False,
|
allow_disabled_algorithms=False,
|
||||||
archive_bad_sig=False)
|
archive_bad_sig=False)
|
||||||
self.assertTrue(skip)
|
self.assertTrue(skip)
|
||||||
self.assertIsNone(apk)
|
self.assertIsNone(apk)
|
||||||
self.assertFalse(cachechanged)
|
self.assertFalse(cachechanged)
|
||||||
|
|
||||||
def test_process_invalid_apk(self):
|
def test_process_invalid_apk(self):
|
||||||
os.chdir(os.path.join(localmodule, 'tests'))
|
os.chdir(self.basedir)
|
||||||
if os.path.basename(os.getcwd()) != 'tests':
|
if os.path.basename(os.getcwd()) != 'tests':
|
||||||
raise Exception('This test must be run in the "tests/" subdir')
|
raise Exception('This test must be run in the "tests/" subdir')
|
||||||
|
|
||||||
|
@ -1119,6 +1087,8 @@ class UpdateTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_get_apks_without_allowed_signatures(self):
|
def test_get_apks_without_allowed_signatures(self):
|
||||||
"""Test when no AllowedAPKSigningKeys is specified"""
|
"""Test when no AllowedAPKSigningKeys is specified"""
|
||||||
|
os.chdir(self.testdir)
|
||||||
|
shutil.copytree(os.path.join(self.basedir, 'repo'), 'repo')
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
|
@ -1127,6 +1097,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
|
|
||||||
app = fdroidserver.metadata.App()
|
app = fdroidserver.metadata.App()
|
||||||
knownapks = fdroidserver.common.KnownApks()
|
knownapks = fdroidserver.common.KnownApks()
|
||||||
|
apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks)
|
||||||
apkfile = 'v1.v2.sig_1020.apk'
|
apkfile = 'v1.v2.sig_1020.apk'
|
||||||
(skip, apk, cachechanged) = fdroidserver.update.process_apk(
|
(skip, apk, cachechanged) = fdroidserver.update.process_apk(
|
||||||
{}, apkfile, 'repo', knownapks, False
|
{}, apkfile, 'repo', knownapks, False
|
||||||
|
@ -1137,6 +1108,8 @@ class UpdateTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_get_apks_without_allowed_signatures_allowed(self):
|
def test_get_apks_without_allowed_signatures_allowed(self):
|
||||||
"""Test when the APK matches the specified AllowedAPKSigningKeys"""
|
"""Test when the APK matches the specified AllowedAPKSigningKeys"""
|
||||||
|
os.chdir(self.testdir)
|
||||||
|
shutil.copytree(os.path.join(self.basedir, 'repo'), 'repo')
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
|
@ -1149,6 +1122,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
knownapks = fdroidserver.common.KnownApks()
|
knownapks = fdroidserver.common.KnownApks()
|
||||||
|
apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks)
|
||||||
apkfile = 'v1.v2.sig_1020.apk'
|
apkfile = 'v1.v2.sig_1020.apk'
|
||||||
(skip, apk, cachechanged) = fdroidserver.update.process_apk(
|
(skip, apk, cachechanged) = fdroidserver.update.process_apk(
|
||||||
{}, apkfile, 'repo', knownapks, False
|
{}, apkfile, 'repo', knownapks, False
|
||||||
|
@ -1159,6 +1133,8 @@ class UpdateTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_get_apks_without_allowed_signatures_blocked(self):
|
def test_get_apks_without_allowed_signatures_blocked(self):
|
||||||
"""Test when the APK does not match any specified AllowedAPKSigningKeys"""
|
"""Test when the APK does not match any specified AllowedAPKSigningKeys"""
|
||||||
|
os.chdir(self.testdir)
|
||||||
|
shutil.copytree(os.path.join(self.basedir, 'repo'), 'repo')
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.common.config = config
|
fdroidserver.common.config = config
|
||||||
|
@ -1171,6 +1147,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
knownapks = fdroidserver.common.KnownApks()
|
knownapks = fdroidserver.common.KnownApks()
|
||||||
|
apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks)
|
||||||
apkfile = 'v1.v2.sig_1020.apk'
|
apkfile = 'v1.v2.sig_1020.apk'
|
||||||
(skip, apk, cachechanged) = fdroidserver.update.process_apk(
|
(skip, apk, cachechanged) = fdroidserver.update.process_apk(
|
||||||
{}, apkfile, 'repo', knownapks, False
|
{}, apkfile, 'repo', knownapks, False
|
||||||
|
@ -1181,11 +1158,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_update_with_AllowedAPKSigningKeys(self):
|
def test_update_with_AllowedAPKSigningKeys(self):
|
||||||
"""Test that APKs without allowed signatures get deleted."""
|
"""Test that APKs without allowed signatures get deleted."""
|
||||||
# Prepare test environment
|
os.chdir(self.testdir)
|
||||||
testdir = tempfile.mkdtemp(
|
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
os.mkdir('repo')
|
os.mkdir('repo')
|
||||||
testapk = os.path.join('repo', 'com.politedroid_6.apk')
|
testapk = os.path.join('repo', 'com.politedroid_6.apk')
|
||||||
shutil.copy(os.path.join(self.basedir, testapk), testapk)
|
shutil.copy(os.path.join(self.basedir, testapk), testapk)
|
||||||
|
@ -1229,11 +1202,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
self.assertFalse(os.path.exists(testapk))
|
self.assertFalse(os.path.exists(testapk))
|
||||||
|
|
||||||
def test_translate_per_build_anti_features(self):
|
def test_translate_per_build_anti_features(self):
|
||||||
os.chdir(os.path.join(localmodule, 'tests'))
|
os.chdir(self.testdir)
|
||||||
testdir = tempfile.mkdtemp(
|
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
shutil.copytree(os.path.join(self.basedir, 'repo'), 'repo')
|
shutil.copytree(os.path.join(self.basedir, 'repo'), 'repo')
|
||||||
shutil.copytree(os.path.join(self.basedir, 'metadata'), 'metadata')
|
shutil.copytree(os.path.join(self.basedir, 'metadata'), 'metadata')
|
||||||
config = dict()
|
config = dict()
|
||||||
|
@ -1262,11 +1231,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
self.assertTrue(foundtest)
|
self.assertTrue(foundtest)
|
||||||
|
|
||||||
def test_create_metadata_from_template(self):
|
def test_create_metadata_from_template(self):
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
print('tmptestsdir', tmptestsdir)
|
|
||||||
os.chdir(tmptestsdir)
|
|
||||||
os.mkdir('repo')
|
os.mkdir('repo')
|
||||||
os.mkdir('metadata')
|
os.mkdir('metadata')
|
||||||
shutil.copy(os.path.join(localmodule, 'tests', 'urzip.apk'), 'repo')
|
shutil.copy(os.path.join(localmodule, 'tests', 'urzip.apk'), 'repo')
|
||||||
|
@ -1308,7 +1273,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
# test using external template.yml
|
# test using external template.yml
|
||||||
os.remove(testfile)
|
os.remove(testfile)
|
||||||
self.assertFalse(os.path.exists(testfile))
|
self.assertFalse(os.path.exists(testfile))
|
||||||
shutil.copy(os.path.join(localmodule, 'examples', 'template.yml'), tmptestsdir)
|
shutil.copy(os.path.join(localmodule, 'examples', 'template.yml'), self.testdir)
|
||||||
fdroidserver.update.create_metadata_from_template(apk)
|
fdroidserver.update.create_metadata_from_template(apk)
|
||||||
self.assertTrue(os.path.exists(testfile))
|
self.assertTrue(os.path.exists(testfile))
|
||||||
apps = fdroidserver.metadata.read_metadata()
|
apps = fdroidserver.metadata.read_metadata()
|
||||||
|
@ -1363,17 +1328,13 @@ class UpdateTest(unittest.TestCase):
|
||||||
assert not icons_src
|
assert not icons_src
|
||||||
|
|
||||||
def test_strip_and_copy_image(self):
|
def test_strip_and_copy_image(self):
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
|
|
||||||
in_file = os.path.join(self.basedir, 'metadata', 'info.guardianproject.urzip', 'en-US', 'images', 'icon.png')
|
in_file = os.path.join(self.basedir, 'metadata', 'info.guardianproject.urzip', 'en-US', 'images', 'icon.png')
|
||||||
out_file = os.path.join(tmptestsdir, 'icon.png')
|
out_file = os.path.join(self.testdir, 'icon.png')
|
||||||
fdroidserver.update._strip_and_copy_image(in_file, out_file)
|
fdroidserver.update._strip_and_copy_image(in_file, out_file)
|
||||||
self.assertTrue(os.path.exists(out_file))
|
self.assertTrue(os.path.exists(out_file))
|
||||||
|
|
||||||
in_file = os.path.join(self.basedir, 'corrupt-featureGraphic.png')
|
in_file = os.path.join(self.basedir, 'corrupt-featureGraphic.png')
|
||||||
out_file = os.path.join(tmptestsdir, 'corrupt-featureGraphic.png')
|
out_file = os.path.join(self.testdir, 'corrupt-featureGraphic.png')
|
||||||
fdroidserver.update._strip_and_copy_image(in_file, out_file)
|
fdroidserver.update._strip_and_copy_image(in_file, out_file)
|
||||||
self.assertFalse(os.path.exists(out_file))
|
self.assertFalse(os.path.exists(out_file))
|
||||||
|
|
||||||
|
@ -1463,10 +1424,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_insert_funding_yml_donation_links(self):
|
def test_insert_funding_yml_donation_links(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
os.mkdir('build')
|
os.mkdir('build')
|
||||||
content = textwrap.dedent(
|
content = textwrap.dedent(
|
||||||
"""
|
"""
|
||||||
|
@ -1507,10 +1465,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_insert_funding_yml_donation_links_one_at_a_time(self):
|
def test_insert_funding_yml_donation_links_one_at_a_time(self):
|
||||||
"""Exercise the FUNDING.yml code one entry at a time"""
|
"""Exercise the FUNDING.yml code one entry at a time"""
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
os.mkdir('build')
|
os.mkdir('build')
|
||||||
|
|
||||||
app = fdroidserver.metadata.App()
|
app = fdroidserver.metadata.App()
|
||||||
|
@ -1551,10 +1506,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
self.assertEqual(app.get('Donate', '').split('/')[-1], v)
|
self.assertEqual(app.get('Donate', '').split('/')[-1], v)
|
||||||
|
|
||||||
def test_insert_funding_yml_donation_links_with_corrupt_file(self):
|
def test_insert_funding_yml_donation_links_with_corrupt_file(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
os.mkdir('build')
|
os.mkdir('build')
|
||||||
app = fdroidserver.metadata.App()
|
app = fdroidserver.metadata.App()
|
||||||
app.id = 'fake.app.id'
|
app.id = 'fake.app.id'
|
||||||
|
@ -1598,10 +1550,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
self.assertIsNotNone(fdroidserver.update.sanitize_funding_yml_entry(['first', 'second']))
|
self.assertIsNotNone(fdroidserver.update.sanitize_funding_yml_entry(['first', 'second']))
|
||||||
|
|
||||||
def test_set_localized_text_entry(self):
|
def test_set_localized_text_entry(self):
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(tmptestsdir)
|
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.update.config = config
|
fdroidserver.update.config = config
|
||||||
|
@ -1630,10 +1579,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
self.assertIsNone(app['localized'].get(locale, {}).get(key))
|
self.assertIsNone(app['localized'].get(locale, {}).get(key))
|
||||||
|
|
||||||
def test_set_author_entry(self):
|
def test_set_author_entry(self):
|
||||||
tmptestsdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(tmptestsdir)
|
|
||||||
config = dict()
|
config = dict()
|
||||||
fdroidserver.common.fill_config_defaults(config)
|
fdroidserver.common.fill_config_defaults(config)
|
||||||
fdroidserver.update.config = config
|
fdroidserver.update.config = config
|
||||||
|
@ -1760,10 +1706,7 @@ class UpdateTest(unittest.TestCase):
|
||||||
self.assertEqual(apkaapt, apkandroguard)
|
self.assertEqual(apkaapt, apkandroguard)
|
||||||
|
|
||||||
def test_exclude_disabled_apks(self):
|
def test_exclude_disabled_apks(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
os.mkdir('repo')
|
os.mkdir('repo')
|
||||||
testapk = os.path.join('repo', 'com.politedroid_6.apk')
|
testapk = os.path.join('repo', 'com.politedroid_6.apk')
|
||||||
testapk_new = os.path.join('repo', 'Politedroid-1.5.apk')
|
testapk_new = os.path.join('repo', 'Politedroid-1.5.apk')
|
||||||
|
|
|
@ -7,7 +7,6 @@ import logging
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from git import Repo
|
from git import Repo
|
||||||
|
@ -23,6 +22,7 @@ import fdroidserver.build
|
||||||
import fdroidserver.common
|
import fdroidserver.common
|
||||||
import fdroidserver.metadata
|
import fdroidserver.metadata
|
||||||
import fdroidserver.scanner
|
import fdroidserver.scanner
|
||||||
|
from testcommon import mkdtemp
|
||||||
|
|
||||||
|
|
||||||
class VCSTest(unittest.TestCase):
|
class VCSTest(unittest.TestCase):
|
||||||
|
@ -31,16 +31,16 @@ class VCSTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
self.basedir = os.path.join(localmodule, 'tests')
|
self.basedir = os.path.join(localmodule, 'tests')
|
||||||
self.tmpdir = os.path.abspath(os.path.join(self.basedir, '..', '.testfiles'))
|
os.chdir(self.basedir)
|
||||||
if not os.path.exists(self.tmpdir):
|
self._td = mkdtemp()
|
||||||
os.makedirs(self.tmpdir)
|
self.testdir = self._td.name
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self._td.cleanup()
|
||||||
os.chdir(self.basedir)
|
os.chdir(self.basedir)
|
||||||
|
|
||||||
def test_remote_set_head_can_fail(self):
|
def test_remote_set_head_can_fail(self):
|
||||||
testdir = tempfile.mkdtemp(
|
os.chdir(self.testdir)
|
||||||
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
||||||
)
|
|
||||||
os.chdir(testdir)
|
|
||||||
# First create an upstream repo with one commit
|
# First create an upstream repo with one commit
|
||||||
upstream_repo = Repo.init("upstream_repo")
|
upstream_repo = Repo.init("upstream_repo")
|
||||||
with open(upstream_repo.working_dir + "/file", 'w') as f:
|
with open(upstream_repo.working_dir + "/file", 'w') as f:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue