mirror of
				https://github.com/f-droid/fdroidserver.git
				synced 2025-11-04 14:30:30 +03:00 
			
		
		
		
	easy changes to black code format in test cases
This does not change areas of code that should be manually reformatted.
This commit is contained in:
		
							parent
							
								
									d95a3029a8
								
							
						
					
					
						commit
						d05ff9db1d
					
				
					 18 changed files with 1144 additions and 564 deletions
				
			
		| 
						 | 
				
			
			@ -242,12 +242,15 @@ class BuildTest(unittest.TestCase):
 | 
			
		|||
        os.mkdir('bin')
 | 
			
		||||
        os.mkdir('gen')
 | 
			
		||||
        with open('build.xml', 'w') as fp:
 | 
			
		||||
            fp.write(textwrap.dedent(
 | 
			
		||||
                """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 | 
			
		||||
            fp.write(
 | 
			
		||||
                textwrap.dedent(
 | 
			
		||||
                    """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 | 
			
		||||
                <project basedir="." default="clean" name="mockapp">
 | 
			
		||||
                <target name="release"/>
 | 
			
		||||
                <target name="clean"/>
 | 
			
		||||
                </project>"""))
 | 
			
		||||
                </project>"""
 | 
			
		||||
                )
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        def make_fake_apk(output, build):
 | 
			
		||||
            with open(build.output, 'w') as fp:
 | 
			
		||||
| 
						 | 
				
			
			@ -277,7 +280,9 @@ class BuildTest(unittest.TestCase):
 | 
			
		|||
        self.assertFalse(os.path.exists('gradle-wrapper.jar'))
 | 
			
		||||
 | 
			
		||||
    def test_scan_with_extlib(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        os.mkdir("build")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -293,9 +298,11 @@ class BuildTest(unittest.TestCase):
 | 
			
		|||
        os.makedirs("extlib/android")
 | 
			
		||||
        # write a fake binary jar file the scanner should definitely error on
 | 
			
		||||
        with open('extlib/android/android-support-v4r11.jar', 'wb') as file:
 | 
			
		||||
            file.write(b'PK\x03\x04\x14\x00\x08\x00\x08\x00-\x0eiA\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\x00\x04\x00META-INF/\xfe\xca\x00\x00\x03\x00PK\x07\x08\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00')
 | 
			
		||||
            file.write(
 | 
			
		||||
                b'PK\x03\x04\x14\x00\x08\x00\x08\x00-\x0eiA\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\x00\x04\x00META-INF/\xfe\xca\x00\x00\x03\x00PK\x07\x08\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00'
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        class FakeVcs():
 | 
			
		||||
        class FakeVcs:
 | 
			
		||||
            # no need to change to the correct commit here
 | 
			
		||||
            def gotorevision(self, rev, refresh=True):
 | 
			
		||||
                pass
 | 
			
		||||
| 
						 | 
				
			
			@ -307,15 +314,17 @@ class BuildTest(unittest.TestCase):
 | 
			
		|||
        build.extlibs = []
 | 
			
		||||
        os.makedirs('build/libs')
 | 
			
		||||
        shutil.copy('extlib/android/android-support-v4r11.jar', 'build/libs')
 | 
			
		||||
        fdroidserver.common.prepare_source(FakeVcs(), app, build,
 | 
			
		||||
                                           "build", "ignore", "extlib")
 | 
			
		||||
        fdroidserver.common.prepare_source(
 | 
			
		||||
            FakeVcs(), app, build, "build", "ignore", "extlib"
 | 
			
		||||
        )
 | 
			
		||||
        count = fdroidserver.scanner.scan_source("build", build)
 | 
			
		||||
        self.assertEqual(1, count, "Should produce a scanner error without extlib")
 | 
			
		||||
 | 
			
		||||
        # Now try again as an extlib
 | 
			
		||||
        build.extlibs = ['android/android-support-v4r11.jar']
 | 
			
		||||
        fdroidserver.common.prepare_source(FakeVcs(), app, build,
 | 
			
		||||
                                           "build", "ignore", "extlib")
 | 
			
		||||
        fdroidserver.common.prepare_source(
 | 
			
		||||
            FakeVcs(), app, build, "build", "ignore", "extlib"
 | 
			
		||||
        )
 | 
			
		||||
        count = fdroidserver.scanner.scan_source("build", build)
 | 
			
		||||
        self.assertEqual(0, count, "Shouldn't error on jar from extlib")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -335,25 +344,31 @@ class BuildTest(unittest.TestCase):
 | 
			
		|||
        os.mkdir('metadata')
 | 
			
		||||
        appid = 'info.guardianproject.checkey'
 | 
			
		||||
        metadata_file = os.path.join('metadata', appid + '.yml')
 | 
			
		||||
        shutil.copy(os.path.join(self.basedir, metadata_file),
 | 
			
		||||
                    'metadata')
 | 
			
		||||
        shutil.copy(os.path.join(self.basedir, metadata_file), 'metadata')
 | 
			
		||||
        with open(metadata_file) as fp:
 | 
			
		||||
            app = fdroidserver.metadata.App(yaml.safe_load(fp))
 | 
			
		||||
        app['RepoType'] = 'git'
 | 
			
		||||
        app['Binaries'] = 'https://example.com/fdroid/repo/info.guardianproject.checkey_%v.apk'
 | 
			
		||||
        build = fdroidserver.metadata.Build({
 | 
			
		||||
            'versionCode': 123,
 | 
			
		||||
            'versionName': '1.2.3',
 | 
			
		||||
            'commit': '1.2.3',
 | 
			
		||||
            'disable': False,
 | 
			
		||||
        })
 | 
			
		||||
        app[
 | 
			
		||||
            'Binaries'
 | 
			
		||||
        ] = 'https://example.com/fdroid/repo/info.guardianproject.checkey_%v.apk'
 | 
			
		||||
        build = fdroidserver.metadata.Build(
 | 
			
		||||
            {
 | 
			
		||||
                'versionCode': 123,
 | 
			
		||||
                'versionName': '1.2.3',
 | 
			
		||||
                'commit': '1.2.3',
 | 
			
		||||
                'disable': False,
 | 
			
		||||
            }
 | 
			
		||||
        )
 | 
			
		||||
        app['Builds'] = [build]
 | 
			
		||||
        fdroidserver.metadata.write_metadata(metadata_file, app)
 | 
			
		||||
 | 
			
		||||
        os.makedirs(os.path.join('unsigned', 'binaries'))
 | 
			
		||||
        production_result = os.path.join('unsigned', '%s_%d.apk' % (appid, build['versionCode']))
 | 
			
		||||
        production_compare_file = os.path.join('unsigned', 'binaries',
 | 
			
		||||
                                               '%s_%d.binary.apk' % (appid, build['versionCode']))
 | 
			
		||||
        production_result = os.path.join(
 | 
			
		||||
            'unsigned', '%s_%d.apk' % (appid, build['versionCode'])
 | 
			
		||||
        )
 | 
			
		||||
        production_compare_file = os.path.join(
 | 
			
		||||
            'unsigned', 'binaries', '%s_%d.binary.apk' % (appid, build['versionCode'])
 | 
			
		||||
        )
 | 
			
		||||
        os.makedirs(os.path.join('tmp', 'binaries'))
 | 
			
		||||
        test_result = os.path.join('tmp', '%s_%d.apk' % (appid, build['versionCode']))
 | 
			
		||||
        test_compare_file = os.path.join(
 | 
			
		||||
| 
						 | 
				
			
			@ -385,7 +400,9 @@ class BuildTest(unittest.TestCase):
 | 
			
		|||
                # failed comparison
 | 
			
		||||
                open(production_result, 'w').close()
 | 
			
		||||
                open(production_compare_file, 'w').close()
 | 
			
		||||
                with mock.patch('fdroidserver.common.verify_apks', lambda *args: 'failed'):
 | 
			
		||||
                with mock.patch(
 | 
			
		||||
                    'fdroidserver.common.verify_apks', lambda *args: 'failed'
 | 
			
		||||
                ):
 | 
			
		||||
                    fdroidserver.build.main()
 | 
			
		||||
                self.assertFalse(os.path.exists(production_result))
 | 
			
		||||
                self.assertFalse(os.path.exists(production_compare_file))
 | 
			
		||||
| 
						 | 
				
			
			@ -403,7 +420,9 @@ class BuildTest(unittest.TestCase):
 | 
			
		|||
                # failed comparison
 | 
			
		||||
                open(test_result, 'w').close()
 | 
			
		||||
                open(test_compare_file, 'w').close()
 | 
			
		||||
                with mock.patch('fdroidserver.common.verify_apks', lambda *args: 'failed'):
 | 
			
		||||
                with mock.patch(
 | 
			
		||||
                    'fdroidserver.common.verify_apks', lambda *args: 'failed'
 | 
			
		||||
                ):
 | 
			
		||||
                    fdroidserver.build.main()
 | 
			
		||||
                self.assertTrue(os.path.exists(test_result))
 | 
			
		||||
                self.assertFalse(os.path.exists(test_compare_file))
 | 
			
		||||
| 
						 | 
				
			
			@ -415,8 +434,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
 | 
			
		||||
    newSuite = unittest.TestSuite()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,7 +12,8 @@ from unittest import mock
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -190,8 +191,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
 | 
			
		||||
    newSuite = unittest.TestSuite()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,7 +25,8 @@ from unittest import mock
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -60,9 +61,17 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
            os.environ['ANDROID_HOME'] = self.android_home
 | 
			
		||||
 | 
			
		||||
    def test_parse_human_readable_size(self):
 | 
			
		||||
        for k, v in ((9827, 9827), (123.456, 123), ('123b', 123), ('1.2', 1),
 | 
			
		||||
                     ('10.43 KiB', 10680), ('11GB', 11000000000), ('59kb', 59000),
 | 
			
		||||
                     ('343.1 mb', 343100000), ('99.9GiB', 107266808217)):
 | 
			
		||||
        for k, v in (
 | 
			
		||||
            (9827, 9827),
 | 
			
		||||
            (123.456, 123),
 | 
			
		||||
            ('123b', 123),
 | 
			
		||||
            ('1.2', 1),
 | 
			
		||||
            ('10.43 KiB', 10680),
 | 
			
		||||
            ('11GB', 11000000000),
 | 
			
		||||
            ('59kb', 59000),
 | 
			
		||||
            ('343.1 mb', 343100000),
 | 
			
		||||
            ('99.9GiB', 107266808217),
 | 
			
		||||
        ):
 | 
			
		||||
            self.assertEqual(fdroidserver.common.parse_human_readable_size(k), v)
 | 
			
		||||
        for v in ((12, 123), '0xfff', [], None, '12,123', '123GG', '982374bb', self):
 | 
			
		||||
            with self.assertRaises(ValueError):
 | 
			
		||||
| 
						 | 
				
			
			@ -74,21 +83,26 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
                fdroidserver.common.assert_config_keystore({})
 | 
			
		||||
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            c = {'repo_keyalias': 'localhost',
 | 
			
		||||
                 'keystore': 'keystore.jks',
 | 
			
		||||
                 'keystorepass': '12345',
 | 
			
		||||
                 'keypass': '12345'}
 | 
			
		||||
            c = {
 | 
			
		||||
                'repo_keyalias': 'localhost',
 | 
			
		||||
                'keystore': 'keystore.jks',
 | 
			
		||||
                'keystorepass': '12345',
 | 
			
		||||
                'keypass': '12345',
 | 
			
		||||
            }
 | 
			
		||||
            with open('keystore.jks', 'w'):
 | 
			
		||||
                pass
 | 
			
		||||
            fdroidserver.common.assert_config_keystore(c)
 | 
			
		||||
 | 
			
		||||
    def _set_build_tools(self):
 | 
			
		||||
        build_tools = os.path.join(fdroidserver.common.config['sdk_path'], 'build-tools')
 | 
			
		||||
        build_tools = os.path.join(
 | 
			
		||||
            fdroidserver.common.config['sdk_path'], 'build-tools'
 | 
			
		||||
        )
 | 
			
		||||
        if os.path.exists(build_tools):
 | 
			
		||||
            for f in sorted(os.listdir(build_tools), reverse=True):
 | 
			
		||||
                versioned = os.path.join(build_tools, f)
 | 
			
		||||
                if os.path.isdir(versioned) \
 | 
			
		||||
                        and os.path.isfile(os.path.join(versioned, 'apksigner')):
 | 
			
		||||
                if os.path.isdir(versioned) and os.path.isfile(
 | 
			
		||||
                    os.path.join(versioned, 'apksigner')
 | 
			
		||||
                ):
 | 
			
		||||
                    break
 | 
			
		||||
            return True
 | 
			
		||||
        else:
 | 
			
		||||
| 
						 | 
				
			
			@ -121,20 +135,28 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
                print('no build-tools found: ' + build_tools)
 | 
			
		||||
 | 
			
		||||
    def test_find_java_root_path(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
 | 
			
		||||
        all_pathlists = [
 | 
			
		||||
            ([  # Debian
 | 
			
		||||
                '/usr/lib/jvm/java-1.5.0-gcj-5-amd64',
 | 
			
		||||
            (
 | 
			
		||||
                [  # Debian
 | 
			
		||||
                    '/usr/lib/jvm/java-1.5.0-gcj-5-amd64',
 | 
			
		||||
                    '/usr/lib/jvm/java-8-openjdk-amd64',
 | 
			
		||||
                    '/usr/lib/jvm/java-1.8.0-openjdk-amd64',
 | 
			
		||||
                ],
 | 
			
		||||
                '/usr/lib/jvm/java-8-openjdk-amd64',
 | 
			
		||||
                '/usr/lib/jvm/java-1.8.0-openjdk-amd64',
 | 
			
		||||
            ], '/usr/lib/jvm/java-8-openjdk-amd64'),
 | 
			
		||||
            ([  # OSX
 | 
			
		||||
            ),
 | 
			
		||||
            (
 | 
			
		||||
                [  # OSX
 | 
			
		||||
                    '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk',
 | 
			
		||||
                    '/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk',
 | 
			
		||||
                    '/System/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk',
 | 
			
		||||
                ],
 | 
			
		||||
                '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk',
 | 
			
		||||
                '/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk',
 | 
			
		||||
                '/System/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk',
 | 
			
		||||
            ], '/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk'),
 | 
			
		||||
            ),
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
        for pathlist, choice in all_pathlists:
 | 
			
		||||
| 
						 | 
				
			
			@ -166,8 +188,10 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        testfiles.append(os.path.join(self.basedir, 'urzip-badsig.apk'))
 | 
			
		||||
        testfiles.append(os.path.join(self.basedir, 'urzip-badcert.apk'))
 | 
			
		||||
        for apkfile in testfiles:
 | 
			
		||||
            self.assertTrue(fdroidserver.common.is_apk_and_debuggable(apkfile),
 | 
			
		||||
                            "debuggable APK state was not properly parsed!")
 | 
			
		||||
            self.assertTrue(
 | 
			
		||||
                fdroidserver.common.is_apk_and_debuggable(apkfile),
 | 
			
		||||
                "debuggable APK state was not properly parsed!",
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        # these are set NOT debuggable
 | 
			
		||||
        testfiles = []
 | 
			
		||||
| 
						 | 
				
			
			@ -175,8 +199,10 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        testfiles.append(os.path.join(self.basedir, 'urzip-release-unsigned.apk'))
 | 
			
		||||
        testfiles.append(os.path.join(self.basedir, 'v2.only.sig_2.apk'))
 | 
			
		||||
        for apkfile in testfiles:
 | 
			
		||||
            self.assertFalse(fdroidserver.common.is_apk_and_debuggable(apkfile),
 | 
			
		||||
                             "debuggable APK state was not properly parsed!")
 | 
			
		||||
            self.assertFalse(
 | 
			
		||||
                fdroidserver.common.is_apk_and_debuggable(apkfile),
 | 
			
		||||
                "debuggable APK state was not properly parsed!",
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    VALID_STRICT_PACKAGE_NAMES = [
 | 
			
		||||
        "An.stop",
 | 
			
		||||
| 
						 | 
				
			
			@ -203,44 +229,63 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_is_valid_package_name(self):
 | 
			
		||||
        for name in self.VALID_STRICT_PACKAGE_NAMES + [
 | 
			
		||||
                "_SpeedoMeterApp.main",
 | 
			
		||||
                "05041684efd9b16c2888b1eddbadd0359f655f311b89bdd1737f560a10d20fb8"]:
 | 
			
		||||
            self.assertTrue(fdroidserver.common.is_valid_package_name(name),
 | 
			
		||||
                            "{0} should be a valid package name".format(name))
 | 
			
		||||
        for name in ["0rg.fdroid.fdroid",
 | 
			
		||||
                     ".f_droid.fdr0ID",
 | 
			
		||||
                     "trailingdot.",
 | 
			
		||||
                     "org.fdroid/fdroid",
 | 
			
		||||
                     "/org.fdroid.fdroid"]:
 | 
			
		||||
            self.assertFalse(fdroidserver.common.is_valid_package_name(name),
 | 
			
		||||
                             "{0} should not be a valid package name".format(name))
 | 
			
		||||
            "_SpeedoMeterApp.main",
 | 
			
		||||
            "05041684efd9b16c2888b1eddbadd0359f655f311b89bdd1737f560a10d20fb8",
 | 
			
		||||
        ]:
 | 
			
		||||
            self.assertTrue(
 | 
			
		||||
                fdroidserver.common.is_valid_package_name(name),
 | 
			
		||||
                "{0} should be a valid package name".format(name),
 | 
			
		||||
            )
 | 
			
		||||
        for name in [
 | 
			
		||||
            "0rg.fdroid.fdroid",
 | 
			
		||||
            ".f_droid.fdr0ID",
 | 
			
		||||
            "trailingdot.",
 | 
			
		||||
            "org.fdroid/fdroid",
 | 
			
		||||
            "/org.fdroid.fdroid",
 | 
			
		||||
        ]:
 | 
			
		||||
            self.assertFalse(
 | 
			
		||||
                fdroidserver.common.is_valid_package_name(name),
 | 
			
		||||
                "{0} should not be a valid package name".format(name),
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    def test_is_strict_application_id(self):
 | 
			
		||||
        """see also tests/valid-package-names/"""
 | 
			
		||||
        for name in self.VALID_STRICT_PACKAGE_NAMES:
 | 
			
		||||
            self.assertTrue(fdroidserver.common.is_strict_application_id(name),
 | 
			
		||||
                            "{0} should be a strict application id".format(name))
 | 
			
		||||
        for name in ["0rg.fdroid.fdroid",
 | 
			
		||||
                     ".f_droid.fdr0ID",
 | 
			
		||||
                     "oneword",
 | 
			
		||||
                     "trailingdot.",
 | 
			
		||||
                     "cafebabe",
 | 
			
		||||
                     "org.fdroid/fdroid",
 | 
			
		||||
                     "/org.fdroid.fdroid",
 | 
			
		||||
                     "_SpeedoMeterApp.main",
 | 
			
		||||
                     "05041684efd9b16c2888b1eddbadd0359f655f311b89bdd1737f560a10d20fb8"]:
 | 
			
		||||
            self.assertFalse(fdroidserver.common.is_strict_application_id(name),
 | 
			
		||||
                             "{0} should not be a strict application id".format(name))
 | 
			
		||||
            self.assertTrue(
 | 
			
		||||
                fdroidserver.common.is_strict_application_id(name),
 | 
			
		||||
                "{0} should be a strict application id".format(name),
 | 
			
		||||
            )
 | 
			
		||||
        for name in [
 | 
			
		||||
            "0rg.fdroid.fdroid",
 | 
			
		||||
            ".f_droid.fdr0ID",
 | 
			
		||||
            "oneword",
 | 
			
		||||
            "trailingdot.",
 | 
			
		||||
            "cafebabe",
 | 
			
		||||
            "org.fdroid/fdroid",
 | 
			
		||||
            "/org.fdroid.fdroid",
 | 
			
		||||
            "_SpeedoMeterApp.main",
 | 
			
		||||
            "05041684efd9b16c2888b1eddbadd0359f655f311b89bdd1737f560a10d20fb8",
 | 
			
		||||
        ]:
 | 
			
		||||
            self.assertFalse(
 | 
			
		||||
                fdroidserver.common.is_strict_application_id(name),
 | 
			
		||||
                "{0} should not be a strict application id".format(name),
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    def test_prepare_sources(self):
 | 
			
		||||
        testint = 99999999
 | 
			
		||||
        teststr = 'FAKE_STR_FOR_TESTING'
 | 
			
		||||
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        shutil.copytree(os.path.join(self.basedir, 'source-files'),
 | 
			
		||||
                        os.path.join(testdir, 'source-files'))
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        shutil.copytree(
 | 
			
		||||
            os.path.join(self.basedir, 'source-files'),
 | 
			
		||||
            os.path.join(testdir, 'source-files'),
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        fdroidclient_testdir = os.path.join(testdir, 'source-files', 'fdroid', 'fdroidclient')
 | 
			
		||||
        fdroidclient_testdir = os.path.join(
 | 
			
		||||
            testdir, 'source-files', 'fdroid', 'fdroidclient'
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        config = dict()
 | 
			
		||||
        config['sdk_path'] = os.getenv('ANDROID_HOME')
 | 
			
		||||
| 
						 | 
				
			
			@ -257,7 +302,7 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        build.versionName = teststr
 | 
			
		||||
        build.versionCode = testint
 | 
			
		||||
 | 
			
		||||
        class FakeVcs():
 | 
			
		||||
        class FakeVcs:
 | 
			
		||||
            # no need to change to the correct commit here
 | 
			
		||||
            def gotorevision(self, rev, refresh=True):
 | 
			
		||||
                pass
 | 
			
		||||
| 
						 | 
				
			
			@ -271,19 +316,29 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
        with open(os.path.join(fdroidclient_testdir, 'build.gradle'), 'r') as f:
 | 
			
		||||
            filedata = f.read()
 | 
			
		||||
        self.assertIsNotNone(re.search(r"\s+compileSdkVersion %s\s+" % testint, filedata))
 | 
			
		||||
        self.assertIsNotNone(
 | 
			
		||||
            re.search(r"\s+compileSdkVersion %s\s+" % testint, filedata)
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        with open(os.path.join(fdroidclient_testdir, 'AndroidManifest.xml')) as f:
 | 
			
		||||
            filedata = f.read()
 | 
			
		||||
        self.assertIsNone(re.search('android:debuggable', filedata))
 | 
			
		||||
        self.assertIsNotNone(re.search('android:versionName="%s"' % build.versionName, filedata))
 | 
			
		||||
        self.assertIsNotNone(re.search('android:versionCode="%s"' % build.versionCode, filedata))
 | 
			
		||||
        self.assertIsNotNone(
 | 
			
		||||
            re.search('android:versionName="%s"' % build.versionName, filedata)
 | 
			
		||||
        )
 | 
			
		||||
        self.assertIsNotNone(
 | 
			
		||||
            re.search('android:versionCode="%s"' % build.versionCode, filedata)
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_prepare_sources_with_prebuild_subdir(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        app_build_dir = os.path.join(testdir, 'build', 'com.example')
 | 
			
		||||
        shutil.copytree(os.path.join(self.basedir, 'source-files', 'fdroid', 'fdroidclient'),
 | 
			
		||||
                        app_build_dir)
 | 
			
		||||
        shutil.copytree(
 | 
			
		||||
            os.path.join(self.basedir, 'source-files', 'fdroid', 'fdroidclient'),
 | 
			
		||||
            app_build_dir,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        subdir = 'baz/bar'
 | 
			
		||||
        subdir_path = os.path.join(app_build_dir, subdir)
 | 
			
		||||
| 
						 | 
				
			
			@ -315,10 +370,10 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        build.prebuild = 'test -d $$FakeSrcLib$$/testdirshouldexist'  # actual test condition
 | 
			
		||||
        build.srclibs = [srclibname + '@1.2.3']
 | 
			
		||||
        build.subdir = subdir
 | 
			
		||||
        build.versionCode = 0xcafe
 | 
			
		||||
        build.versionCode = 0xCAFE
 | 
			
		||||
        build.versionName = 'vCAFE'
 | 
			
		||||
 | 
			
		||||
        class FakeVcs():
 | 
			
		||||
        class FakeVcs:
 | 
			
		||||
            # no need to change to the correct commit here
 | 
			
		||||
            def gotorevision(self, rev, refresh=True):
 | 
			
		||||
                pass
 | 
			
		||||
| 
						 | 
				
			
			@ -333,7 +388,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_prepare_sources_refresh(self):
 | 
			
		||||
        packageName = 'org.fdroid.ci.test.app'
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        print('testdir', testdir)
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        os.mkdir('build')
 | 
			
		||||
| 
						 | 
				
			
			@ -379,14 +436,18 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        fdroidserver.signindex.config = config
 | 
			
		||||
 | 
			
		||||
        sourcedir = os.path.join(self.basedir, 'signindex')
 | 
			
		||||
        testsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        for f in ('testy.jar', 'guardianproject.jar',):
 | 
			
		||||
        testsdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        for f in ('testy.jar', 'guardianproject.jar'):
 | 
			
		||||
            sourcefile = os.path.join(sourcedir, f)
 | 
			
		||||
            testfile = os.path.join(testsdir, f)
 | 
			
		||||
            shutil.copy(sourcefile, testsdir)
 | 
			
		||||
            fdroidserver.signindex.sign_jar(testfile)
 | 
			
		||||
            # these should be resigned, and therefore different
 | 
			
		||||
            self.assertNotEqual(open(sourcefile, 'rb').read(), open(testfile, 'rb').read())
 | 
			
		||||
            self.assertNotEqual(
 | 
			
		||||
                open(sourcefile, 'rb').read(), open(testfile, 'rb').read()
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    def test_verify_apk_signature(self):
 | 
			
		||||
        config = fdroidserver.common.read_config(fdroidserver.common.options)
 | 
			
		||||
| 
						 | 
				
			
			@ -450,13 +511,17 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
        sourceapk = os.path.join(self.basedir, 'urzip.apk')
 | 
			
		||||
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            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)
 | 
			
		||||
        self.assertTrue(fdroidserver.common.verify_apk_signature(copyapk))
 | 
			
		||||
        self.assertIsNone(fdroidserver.common.verify_apks(sourceapk, copyapk, self.tmpdir))
 | 
			
		||||
        self.assertIsNone(
 | 
			
		||||
            fdroidserver.common.verify_apks(sourceapk, copyapk, self.tmpdir)
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        unsignedapk = os.path.join(testdir, 'urzip-unsigned.apk')
 | 
			
		||||
        with ZipFile(sourceapk, 'r') as apk:
 | 
			
		||||
| 
						 | 
				
			
			@ -464,7 +529,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
                for info in apk.infolist():
 | 
			
		||||
                    if not info.filename.startswith('META-INF/'):
 | 
			
		||||
                        testapk.writestr(info, apk.read(info.filename))
 | 
			
		||||
        self.assertIsNone(fdroidserver.common.verify_apks(sourceapk, unsignedapk, self.tmpdir))
 | 
			
		||||
        self.assertIsNone(
 | 
			
		||||
            fdroidserver.common.verify_apks(sourceapk, unsignedapk, self.tmpdir)
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        twosigapk = os.path.join(testdir, 'urzip-twosig.apk')
 | 
			
		||||
        otherapk = ZipFile(os.path.join(self.basedir, 'urzip-release.apk'), 'r')
 | 
			
		||||
| 
						 | 
				
			
			@ -482,7 +549,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        with tempfile.TemporaryDirectory() as tmpPath:
 | 
			
		||||
            cfgPath = os.path.join(tmpPath, 'config.py')
 | 
			
		||||
            with open(cfgPath, 'w') as f:
 | 
			
		||||
                f.write(textwrap.dedent("""\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        """\
 | 
			
		||||
                    # abc
 | 
			
		||||
                    # test = 'example value'
 | 
			
		||||
                    default_me= '%%%'
 | 
			
		||||
| 
						 | 
				
			
			@ -491,7 +560,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
                    do_not_touch = "good value"
 | 
			
		||||
                    default_me="!!!"
 | 
			
		||||
 | 
			
		||||
                    key="123"    # inline"""))
 | 
			
		||||
                    key="123"    # inline"""
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
            cfg = {'key': '111', 'default_me_orig': 'orig'}
 | 
			
		||||
            fdroidserver.common.write_to_config(cfg, 'key', config_file=cfgPath)
 | 
			
		||||
| 
						 | 
				
			
			@ -500,7 +571,10 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
            fdroidserver.common.write_to_config(cfg, 'new_key', value='new', config_file=cfgPath)
 | 
			
		||||
 | 
			
		||||
            with open(cfgPath, 'r') as f:
 | 
			
		||||
                self.assertEqual(f.read(), textwrap.dedent("""\
 | 
			
		||||
                self.assertEqual(
 | 
			
		||||
                    f.read(),
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        """\
 | 
			
		||||
                    # abc
 | 
			
		||||
                    test = 'test value'
 | 
			
		||||
                    default_me = 'orig'
 | 
			
		||||
| 
						 | 
				
			
			@ -511,7 +585,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
                    key = "111"    # inline
 | 
			
		||||
 | 
			
		||||
                    new_key = "new"
 | 
			
		||||
                    """))
 | 
			
		||||
                    """
 | 
			
		||||
                    ),
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
    def test_write_to_config_when_empty(self):
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpPath:
 | 
			
		||||
| 
						 | 
				
			
			@ -520,10 +596,15 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
                pass
 | 
			
		||||
            fdroidserver.common.write_to_config({}, 'key', 'val', cfgPath)
 | 
			
		||||
            with open(cfgPath, 'r') as f:
 | 
			
		||||
                self.assertEqual(f.read(), textwrap.dedent("""\
 | 
			
		||||
                self.assertEqual(
 | 
			
		||||
                    f.read(),
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        """\
 | 
			
		||||
 | 
			
		||||
                key = "val"
 | 
			
		||||
                """))
 | 
			
		||||
                """
 | 
			
		||||
                    ),
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
    def test_apk_name_regex(self):
 | 
			
		||||
        good = [
 | 
			
		||||
| 
						 | 
				
			
			@ -626,7 +707,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_find_apksigner_config_overrides(self):
 | 
			
		||||
        """apksigner should come from config before any auto-detection"""
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        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')
 | 
			
		||||
| 
						 | 
				
			
			@ -643,7 +726,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_find_apksigner_prefer_path(self):
 | 
			
		||||
        """apksigner should come from PATH before ANDROID_HOME"""
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
 | 
			
		||||
        apksigner = os.path.join(testdir, 'apksigner')
 | 
			
		||||
| 
						 | 
				
			
			@ -666,7 +751,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_find_apksigner_prefer_newest(self):
 | 
			
		||||
        """apksigner should be the newest available in ANDROID_HOME"""
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        android_home = os.path.join(testdir, 'ANDROID_HOME')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -688,7 +775,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        self.assertEqual(apksigner, config.get('apksigner'))
 | 
			
		||||
 | 
			
		||||
    def test_find_apksigner_system_package_android_home(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        android_home = os.getenv('ANDROID_HOME')
 | 
			
		||||
        if not android_home or not os.path.isdir(android_home):
 | 
			
		||||
| 
						 | 
				
			
			@ -716,7 +805,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        fdroidserver.common.config = config
 | 
			
		||||
        fdroidserver.signindex.config = config
 | 
			
		||||
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        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)
 | 
			
		||||
| 
						 | 
				
			
			@ -731,8 +822,10 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        # now sign an APK with minSdkVersion >= 18
 | 
			
		||||
        unsigned = os.path.join(testdir, 'duplicate.permisssions_9999999-unsigned.apk')
 | 
			
		||||
        signed = os.path.join(testdir, 'duplicate.permisssions_9999999.apk')
 | 
			
		||||
        shutil.copy(os.path.join(self.basedir, 'repo', 'duplicate.permisssions_9999999.apk'),
 | 
			
		||||
                    os.path.join(unsigned))
 | 
			
		||||
        shutil.copy(
 | 
			
		||||
            os.path.join(self.basedir, 'repo', 'duplicate.permisssions_9999999.apk'),
 | 
			
		||||
            os.path.join(unsigned),
 | 
			
		||||
        )
 | 
			
		||||
        fdroidserver.common.apk_strip_v1_signatures(unsigned, strip_manifest=True)
 | 
			
		||||
        fdroidserver.common.sign_apk(unsigned, signed, config['keyalias'])
 | 
			
		||||
        self.assertTrue(os.path.isfile(signed))
 | 
			
		||||
| 
						 | 
				
			
			@ -1158,7 +1251,12 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
            'org.tasks': 'app',
 | 
			
		||||
            'ut.ewh.audiometrytest': 'app',
 | 
			
		||||
        }
 | 
			
		||||
        for f in ('cn.wildfirechat.chat', 'com.anpmech.launcher', 'org.tasks', 'ut.ewh.audiometrytest'):
 | 
			
		||||
        for f in (
 | 
			
		||||
            'cn.wildfirechat.chat',
 | 
			
		||||
            'com.anpmech.launcher',
 | 
			
		||||
            'org.tasks',
 | 
			
		||||
            'ut.ewh.audiometrytest',
 | 
			
		||||
        ):
 | 
			
		||||
            build_dir = os.path.join('source-files', f)
 | 
			
		||||
            paths = fdroidserver.common.get_all_gradle_and_manifests(build_dir)
 | 
			
		||||
            logging.info(paths)
 | 
			
		||||
| 
						 | 
				
			
			@ -1182,21 +1280,27 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
            self.assertEqual(fdroidserver.common.parse_srclib_spec('@multi@at-signs@'))
 | 
			
		||||
 | 
			
		||||
    def test_bad_urls(self):
 | 
			
		||||
        for url in ('asdf',
 | 
			
		||||
                    'file://thing.git',
 | 
			
		||||
                    'https:///github.com/my/project',
 | 
			
		||||
                    'git:///so/many/slashes',
 | 
			
		||||
                    'ssh:/notabug.org/missing/a/slash',
 | 
			
		||||
                    'git:notabug.org/missing/some/slashes',
 | 
			
		||||
                    'https//github.com/bar/baz'):
 | 
			
		||||
        for url in (
 | 
			
		||||
            'asdf',
 | 
			
		||||
            'file://thing.git',
 | 
			
		||||
            'https:///github.com/my/project',
 | 
			
		||||
            'git:///so/many/slashes',
 | 
			
		||||
            'ssh:/notabug.org/missing/a/slash',
 | 
			
		||||
            'git:notabug.org/missing/some/slashes',
 | 
			
		||||
            'https//github.com/bar/baz',
 | 
			
		||||
        ):
 | 
			
		||||
            with self.assertRaises(ValueError):
 | 
			
		||||
                fdroidserver.common.get_app_from_url(url)
 | 
			
		||||
 | 
			
		||||
    def test_remove_signing_keys(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        print(testdir)
 | 
			
		||||
        shutil.copytree(os.path.join(self.basedir, 'source-files'),
 | 
			
		||||
                        os.path.join(testdir, 'source-files'))
 | 
			
		||||
        shutil.copytree(
 | 
			
		||||
            os.path.join(self.basedir, 'source-files'),
 | 
			
		||||
            os.path.join(testdir, 'source-files'),
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with_signingConfigs = [
 | 
			
		||||
            'source-files/com.seafile.seadroid2/app/build.gradle',
 | 
			
		||||
| 
						 | 
				
			
			@ -1279,11 +1383,16 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_deploy_build_log_with_rsync_with_id_file(self):
 | 
			
		||||
 | 
			
		||||
        mocklogcontent = bytes(textwrap.dedent("""\
 | 
			
		||||
        mocklogcontent = bytes(
 | 
			
		||||
            textwrap.dedent(
 | 
			
		||||
                """\
 | 
			
		||||
            build started
 | 
			
		||||
            building...
 | 
			
		||||
            build completed
 | 
			
		||||
            profit!"""), 'utf-8')
 | 
			
		||||
            profit!"""
 | 
			
		||||
            ),
 | 
			
		||||
            'utf-8',
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        fdroidserver.common.options = mock.Mock()
 | 
			
		||||
        fdroidserver.common.options.verbose = False
 | 
			
		||||
| 
						 | 
				
			
			@ -1291,7 +1400,8 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        fdroidserver.common.config = {}
 | 
			
		||||
        fdroidserver.common.config['serverwebroot'] = [
 | 
			
		||||
            'example.com:/var/www/fdroid/',
 | 
			
		||||
            'example.com:/var/www/fbot/']
 | 
			
		||||
            'example.com:/var/www/fbot/',
 | 
			
		||||
        ]
 | 
			
		||||
        fdroidserver.common.config['deploy_process_logs'] = True
 | 
			
		||||
        fdroidserver.common.config['identity_file'] = 'ssh/id_rsa'
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1344,7 +1454,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
                    self.assertEqual(f.read(), mocklogcontent)
 | 
			
		||||
 | 
			
		||||
    def test_deploy_status_json(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        fakesubcommand = 'fakesubcommand'
 | 
			
		||||
        fake_timestamp = 1234567890
 | 
			
		||||
| 
						 | 
				
			
			@ -1468,42 +1580,54 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
    def test_run_yamllint_wellformed(self):
 | 
			
		||||
        try:
 | 
			
		||||
            import yamllint.config
 | 
			
		||||
 | 
			
		||||
            yamllint.config  # make pyflakes ignore this
 | 
			
		||||
        except ImportError:
 | 
			
		||||
            self.skipTest('yamllint not installed')
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            with open('wellformed.yml', 'w') as f:
 | 
			
		||||
                f.write(textwrap.dedent('''\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        '''\
 | 
			
		||||
                    yaml:
 | 
			
		||||
                        file:
 | 
			
		||||
                            - for
 | 
			
		||||
                            - test
 | 
			
		||||
                        purposeses: true
 | 
			
		||||
                    '''))
 | 
			
		||||
                    '''
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            result = fdroidserver.common.run_yamllint('wellformed.yml')
 | 
			
		||||
            self.assertEqual(result, '')
 | 
			
		||||
 | 
			
		||||
    def test_run_yamllint_malformed(self):
 | 
			
		||||
        try:
 | 
			
		||||
            import yamllint.config
 | 
			
		||||
 | 
			
		||||
            yamllint.config  # make pyflakes ignore this
 | 
			
		||||
        except ImportError:
 | 
			
		||||
            self.skipTest('yamllint not installed')
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            with open('malformed.yml', 'w') as f:
 | 
			
		||||
                f.write(textwrap.dedent('''\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        '''\
 | 
			
		||||
                    yaml:
 | 
			
		||||
                          - that
 | 
			
		||||
                     fails
 | 
			
		||||
                          - test
 | 
			
		||||
                    '''))
 | 
			
		||||
                    '''
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            result = fdroidserver.common.run_yamllint('malformed.yml')
 | 
			
		||||
            self.assertIsNotNone(result)
 | 
			
		||||
            self.assertNotEqual(result, '')
 | 
			
		||||
 | 
			
		||||
    def test_with_no_config(self):
 | 
			
		||||
        """It should set defaults if no config file is found"""
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            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.py'))
 | 
			
		||||
| 
						 | 
				
			
			@ -1513,7 +1637,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_with_config_yml(self):
 | 
			
		||||
        """Make sure it is possible to use config.yml alone."""
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with open('config.yml', 'w') as fp:
 | 
			
		||||
            fp.write('apksigner: yml')
 | 
			
		||||
| 
						 | 
				
			
			@ -1524,7 +1650,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_with_config_yml_with_env_var(self):
 | 
			
		||||
        """Make sure it is possible to use config.yml alone."""
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        os.environ['SECRET'] = 'mysecretpassword'
 | 
			
		||||
        with open('config.yml', 'w') as fp:
 | 
			
		||||
| 
						 | 
				
			
			@ -1536,7 +1664,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_with_config_py(self):
 | 
			
		||||
        """Make sure it is still possible to use config.py alone."""
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with open('config.py', 'w') as fp:
 | 
			
		||||
            fp.write('apksigner = "py"')
 | 
			
		||||
| 
						 | 
				
			
			@ -1547,7 +1677,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_config_perm_warning(self):
 | 
			
		||||
        """Exercise the code path that issues a warning about unsafe permissions."""
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with open('config.yml', 'w') as fp:
 | 
			
		||||
            fp.write('keystore: foo.jks')
 | 
			
		||||
| 
						 | 
				
			
			@ -1565,7 +1697,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_with_both_config_yml_py(self):
 | 
			
		||||
        """If config.yml and config.py are present, config.py should be ignored."""
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with open('config.yml', 'w') as fp:
 | 
			
		||||
            fp.write('apksigner: yml')
 | 
			
		||||
| 
						 | 
				
			
			@ -1577,7 +1711,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        self.assertEqual('yml', config.get('apksigner'))
 | 
			
		||||
 | 
			
		||||
    def test_write_to_config_yml(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with open('config.yml', 'w') as fp:
 | 
			
		||||
            fp.write('apksigner: yml')
 | 
			
		||||
| 
						 | 
				
			
			@ -1594,7 +1730,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        self.assertEqual('mysecretpassword', config['keypass'])
 | 
			
		||||
 | 
			
		||||
    def test_write_to_config_py(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with open('config.py', 'w') as fp:
 | 
			
		||||
            fp.write('apksigner = "py"')
 | 
			
		||||
| 
						 | 
				
			
			@ -1609,7 +1747,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        self.assertEqual('mysecretpassword', config['keypass'])
 | 
			
		||||
 | 
			
		||||
    def test_config_dict_with_int_keys(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with open('config.yml', 'w') as fp:
 | 
			
		||||
            fp.write('java_paths:\n  8: /usr/lib/jvm/java-8-openjdk\n')
 | 
			
		||||
| 
						 | 
				
			
			@ -1646,7 +1786,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        self.assertEqual(subcommand, data['subcommand'])
 | 
			
		||||
 | 
			
		||||
    def test_setup_status_output_in_git_repo(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
 | 
			
		||||
        logging.getLogger('git.cmd').setLevel(logging.INFO)
 | 
			
		||||
| 
						 | 
				
			
			@ -1722,25 +1864,25 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        allow_vercodes = False
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            {'org.fdroid.fdroid': []},
 | 
			
		||||
            fdroidserver.common.read_pkg_args(['org.fdroid.fdroid'], allow_vercodes)
 | 
			
		||||
            fdroidserver.common.read_pkg_args(['org.fdroid.fdroid'], allow_vercodes),
 | 
			
		||||
        )
 | 
			
		||||
        self.assertNotEqual(
 | 
			
		||||
            {'com.example': ['123456']},
 | 
			
		||||
            fdroidserver.common.read_pkg_args(['com.example:123456'], allow_vercodes)
 | 
			
		||||
            fdroidserver.common.read_pkg_args(['com.example:123456'], allow_vercodes),
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        allow_vercodes = True
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            {'org.fdroid.fdroid': []},
 | 
			
		||||
            fdroidserver.common.read_pkg_args(['org.fdroid.fdroid'], allow_vercodes)
 | 
			
		||||
            fdroidserver.common.read_pkg_args(['org.fdroid.fdroid'], allow_vercodes),
 | 
			
		||||
        )
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            {'com.example': ['123456']},
 | 
			
		||||
            fdroidserver.common.read_pkg_args(['com.example:123456'], allow_vercodes)
 | 
			
		||||
            fdroidserver.common.read_pkg_args(['com.example:123456'], allow_vercodes),
 | 
			
		||||
        )
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            {'org.debian_kit': ['6']},
 | 
			
		||||
            fdroidserver.common.read_pkg_args(['org.debian_kit_6.apk'], allow_vercodes)
 | 
			
		||||
            fdroidserver.common.read_pkg_args(['org.debian_kit_6.apk'], allow_vercodes),
 | 
			
		||||
        )
 | 
			
		||||
        appid_versionCode_pairs = (
 | 
			
		||||
            'org.fdroid.fdroid:1',
 | 
			
		||||
| 
						 | 
				
			
			@ -1757,11 +1899,13 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
        )
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            {'com.example': ['67890'], 'org.c_base.c_beam': ['29']},
 | 
			
		||||
            fdroidserver.common.read_pkg_args(appid_versionCode_pairs, allow_vercodes)
 | 
			
		||||
            fdroidserver.common.read_pkg_args(appid_versionCode_pairs, allow_vercodes),
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_apk_strip_v1_signatures(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        before = os.path.join(self.basedir, 'no_targetsdk_minsdk1_unsigned.apk')
 | 
			
		||||
        after = os.path.join(testdir, 'after.apk')
 | 
			
		||||
        shutil.copy(before, after)
 | 
			
		||||
| 
						 | 
				
			
			@ -1780,9 +1924,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
                os.path.join('metadata', appid, 'signatures', vc, '28969C09.RSA'),
 | 
			
		||||
                os.path.join('metadata', appid, 'signatures', vc, '28969C09.SF'),
 | 
			
		||||
                os.path.join('metadata', appid, 'signatures', vc, 'MANIFEST.MF'),
 | 
			
		||||
                None
 | 
			
		||||
                None,
 | 
			
		||||
            ),
 | 
			
		||||
            fdroidserver.common.metadata_find_developer_signing_files(appid, vc)
 | 
			
		||||
            fdroidserver.common.metadata_find_developer_signing_files(appid, vc),
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        vc = '134'
 | 
			
		||||
| 
						 | 
				
			
			@ -1791,9 +1935,9 @@ class CommonTest(unittest.TestCase):
 | 
			
		|||
                os.path.join('metadata', appid, 'signatures', vc, '28969C09.RSA'),
 | 
			
		||||
                os.path.join('metadata', appid, 'signatures', vc, '28969C09.SF'),
 | 
			
		||||
                os.path.join('metadata', appid, 'signatures', vc, 'MANIFEST.MF'),
 | 
			
		||||
                None
 | 
			
		||||
                None,
 | 
			
		||||
            ),
 | 
			
		||||
            fdroidserver.common.metadata_find_developer_signing_files(appid, vc)
 | 
			
		||||
            fdroidserver.common.metadata_find_developer_signing_files(appid, vc),
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_auto_install_ndk(self):
 | 
			
		||||
| 
						 | 
				
			
			@ -1883,8 +2027,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
 | 
			
		||||
    newSuite = unittest.TestSuite()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,7 +10,8 @@ import unittest
 | 
			
		|||
from unittest import mock
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -47,34 +48,52 @@ class DeployTest(unittest.TestCase):
 | 
			
		|||
        def update_server_webroot_call(cmd):
 | 
			
		||||
            nonlocal call_iteration
 | 
			
		||||
            if call_iteration == 0:
 | 
			
		||||
                self.assertListEqual(cmd, ['rsync',
 | 
			
		||||
                                           '--archive',
 | 
			
		||||
                                           '--delete-after',
 | 
			
		||||
                                           '--safe-links',
 | 
			
		||||
                                           '--quiet',
 | 
			
		||||
                                           '--exclude', 'repo/index.xml',
 | 
			
		||||
                                           '--exclude', 'repo/index.jar',
 | 
			
		||||
                                           '--exclude', 'repo/index-v1.jar',
 | 
			
		||||
                                           'repo',
 | 
			
		||||
                                           'example.com:/var/www/fdroid'])
 | 
			
		||||
                self.assertListEqual(
 | 
			
		||||
                    cmd,
 | 
			
		||||
                    [
 | 
			
		||||
                        'rsync',
 | 
			
		||||
                        '--archive',
 | 
			
		||||
                        '--delete-after',
 | 
			
		||||
                        '--safe-links',
 | 
			
		||||
                        '--quiet',
 | 
			
		||||
                        '--exclude',
 | 
			
		||||
                        'repo/index.xml',
 | 
			
		||||
                        '--exclude',
 | 
			
		||||
                        'repo/index.jar',
 | 
			
		||||
                        '--exclude',
 | 
			
		||||
                        'repo/index-v1.jar',
 | 
			
		||||
                        'repo',
 | 
			
		||||
                        'example.com:/var/www/fdroid',
 | 
			
		||||
                    ],
 | 
			
		||||
                )
 | 
			
		||||
            elif call_iteration == 1:
 | 
			
		||||
                self.assertListEqual(cmd, ['rsync',
 | 
			
		||||
                                           '--archive',
 | 
			
		||||
                                           '--delete-after',
 | 
			
		||||
                                           '--safe-links',
 | 
			
		||||
                                           '--quiet',
 | 
			
		||||
                                           'repo',
 | 
			
		||||
                                           serverwebroot])
 | 
			
		||||
                self.assertListEqual(
 | 
			
		||||
                    cmd,
 | 
			
		||||
                    [
 | 
			
		||||
                        'rsync',
 | 
			
		||||
                        '--archive',
 | 
			
		||||
                        '--delete-after',
 | 
			
		||||
                        '--safe-links',
 | 
			
		||||
                        '--quiet',
 | 
			
		||||
                        'repo',
 | 
			
		||||
                        serverwebroot,
 | 
			
		||||
                    ],
 | 
			
		||||
                )
 | 
			
		||||
            elif call_iteration == 2:
 | 
			
		||||
                self.assertListEqual(cmd, ['rsync',
 | 
			
		||||
                                           '--archive',
 | 
			
		||||
                                           '--delete-after',
 | 
			
		||||
                                           '--safe-links',
 | 
			
		||||
                                           '--quiet',
 | 
			
		||||
                                           'Sym.apk',
 | 
			
		||||
                                           'Sym.apk.asc',
 | 
			
		||||
                                           'Sym.apk.sig',
 | 
			
		||||
                                           'example.com:/var/www/fdroid'])
 | 
			
		||||
                self.assertListEqual(
 | 
			
		||||
                    cmd,
 | 
			
		||||
                    [
 | 
			
		||||
                        'rsync',
 | 
			
		||||
                        '--archive',
 | 
			
		||||
                        '--delete-after',
 | 
			
		||||
                        '--safe-links',
 | 
			
		||||
                        '--quiet',
 | 
			
		||||
                        'Sym.apk',
 | 
			
		||||
                        'Sym.apk.asc',
 | 
			
		||||
                        'Sym.apk.sig',
 | 
			
		||||
                        'example.com:/var/www/fdroid',
 | 
			
		||||
                    ],
 | 
			
		||||
                )
 | 
			
		||||
            else:
 | 
			
		||||
                self.fail('unexpected subprocess.call invocation')
 | 
			
		||||
            call_iteration += 1
 | 
			
		||||
| 
						 | 
				
			
			@ -86,8 +105,7 @@ class DeployTest(unittest.TestCase):
 | 
			
		|||
            os.symlink('repo/com.example.sym.apk.asc', 'Sym.apk.asc')
 | 
			
		||||
            os.symlink('repo/com.example.sym.apk.sig', 'Sym.apk.sig')
 | 
			
		||||
            with mock.patch('subprocess.call', side_effect=update_server_webroot_call):
 | 
			
		||||
                fdroidserver.deploy.update_serverwebroot(serverwebroot,
 | 
			
		||||
                                                         repo_section)
 | 
			
		||||
                fdroidserver.deploy.update_serverwebroot(serverwebroot, repo_section)
 | 
			
		||||
        self.assertEqual(call_iteration, 3, 'expected 3 invocations of subprocess.call')
 | 
			
		||||
 | 
			
		||||
    def test_update_serverwebroot_with_id_file(self):
 | 
			
		||||
| 
						 | 
				
			
			@ -108,41 +126,55 @@ class DeployTest(unittest.TestCase):
 | 
			
		|||
        def update_server_webroot_call(cmd):
 | 
			
		||||
            nonlocal call_iteration
 | 
			
		||||
            if call_iteration == 0:
 | 
			
		||||
                self.assertListEqual(cmd, ['rsync',
 | 
			
		||||
                                           '--archive',
 | 
			
		||||
                                           '--delete-after',
 | 
			
		||||
                                           '--safe-links',
 | 
			
		||||
                                           '--verbose',
 | 
			
		||||
                                           '-e',
 | 
			
		||||
                                           'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i '
 | 
			
		||||
                                           + fdroidserver.deploy.config['identity_file'],
 | 
			
		||||
                                           '--exclude', 'archive/index.xml',
 | 
			
		||||
                                           '--exclude', 'archive/index.jar',
 | 
			
		||||
                                           '--exclude', 'archive/index-v1.jar',
 | 
			
		||||
                                           'archive',
 | 
			
		||||
                                           serverwebroot])
 | 
			
		||||
                self.assertListEqual(
 | 
			
		||||
                    cmd,
 | 
			
		||||
                    [
 | 
			
		||||
                        'rsync',
 | 
			
		||||
                        '--archive',
 | 
			
		||||
                        '--delete-after',
 | 
			
		||||
                        '--safe-links',
 | 
			
		||||
                        '--verbose',
 | 
			
		||||
                        '-e',
 | 
			
		||||
                        'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i '
 | 
			
		||||
                        + fdroidserver.deploy.config['identity_file'],
 | 
			
		||||
                        '--exclude',
 | 
			
		||||
                        'archive/index.xml',
 | 
			
		||||
                        '--exclude',
 | 
			
		||||
                        'archive/index.jar',
 | 
			
		||||
                        '--exclude',
 | 
			
		||||
                        'archive/index-v1.jar',
 | 
			
		||||
                        'archive',
 | 
			
		||||
                        serverwebroot,
 | 
			
		||||
                    ],
 | 
			
		||||
                )
 | 
			
		||||
            elif call_iteration == 1:
 | 
			
		||||
                self.assertListEqual(cmd, ['rsync',
 | 
			
		||||
                                           '--archive',
 | 
			
		||||
                                           '--delete-after',
 | 
			
		||||
                                           '--safe-links',
 | 
			
		||||
                                           '--verbose',
 | 
			
		||||
                                           '-e',
 | 
			
		||||
                                           'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i '
 | 
			
		||||
                                           + fdroidserver.deploy.config['identity_file'],
 | 
			
		||||
                                           'archive',
 | 
			
		||||
                                           serverwebroot])
 | 
			
		||||
                self.assertListEqual(
 | 
			
		||||
                    cmd,
 | 
			
		||||
                    [
 | 
			
		||||
                        'rsync',
 | 
			
		||||
                        '--archive',
 | 
			
		||||
                        '--delete-after',
 | 
			
		||||
                        '--safe-links',
 | 
			
		||||
                        '--verbose',
 | 
			
		||||
                        '-e',
 | 
			
		||||
                        'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i '
 | 
			
		||||
                        + fdroidserver.deploy.config['identity_file'],
 | 
			
		||||
                        'archive',
 | 
			
		||||
                        serverwebroot,
 | 
			
		||||
                    ],
 | 
			
		||||
                )
 | 
			
		||||
            else:
 | 
			
		||||
                self.fail('unexpected subprocess.call invocation')
 | 
			
		||||
            call_iteration += 1
 | 
			
		||||
            return 0
 | 
			
		||||
 | 
			
		||||
        with mock.patch('subprocess.call', side_effect=update_server_webroot_call):
 | 
			
		||||
            fdroidserver.deploy.update_serverwebroot(serverwebroot,
 | 
			
		||||
                                                     repo_section)
 | 
			
		||||
            fdroidserver.deploy.update_serverwebroot(serverwebroot, repo_section)
 | 
			
		||||
        self.assertEqual(call_iteration, 2, 'expected 2 invocations of subprocess.call')
 | 
			
		||||
 | 
			
		||||
    @unittest.skipIf(not os.getenv('VIRUSTOTAL_API_KEY'), 'VIRUSTOTAL_API_KEY is not set')
 | 
			
		||||
    @unittest.skipIf(
 | 
			
		||||
        not os.getenv('VIRUSTOTAL_API_KEY'), 'VIRUSTOTAL_API_KEY is not set'
 | 
			
		||||
    )
 | 
			
		||||
    def test_upload_to_virustotal(self):
 | 
			
		||||
        fdroidserver.deploy.options.verbose = True
 | 
			
		||||
        virustotal_apikey = os.getenv('VIRUSTOTAL_API_KEY')
 | 
			
		||||
| 
						 | 
				
			
			@ -150,15 +182,14 @@ class DeployTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_remote_hostname_regex(self):
 | 
			
		||||
        for remote_url, name in (
 | 
			
		||||
                ('git@github.com:guardianproject/fdroid-repo', 'github'),
 | 
			
		||||
                ('git@gitlab.com:guardianproject/fdroid-repo', 'gitlab'),
 | 
			
		||||
                ('https://github.com:guardianproject/fdroid-repo', 'github'),
 | 
			
		||||
                ('https://gitlab.com/guardianproject/fdroid-repo', 'gitlab'),
 | 
			
		||||
                ('https://salsa.debian.org/foo/repo', 'salsa'),
 | 
			
		||||
            ('git@github.com:guardianproject/fdroid-repo', 'github'),
 | 
			
		||||
            ('git@gitlab.com:guardianproject/fdroid-repo', 'gitlab'),
 | 
			
		||||
            ('https://github.com:guardianproject/fdroid-repo', 'github'),
 | 
			
		||||
            ('https://gitlab.com/guardianproject/fdroid-repo', 'gitlab'),
 | 
			
		||||
            ('https://salsa.debian.org/foo/repo', 'salsa'),
 | 
			
		||||
        ):
 | 
			
		||||
            self.assertEqual(
 | 
			
		||||
                name,
 | 
			
		||||
                fdroidserver.deploy.REMOTE_HOSTNAME_REGEX.sub(r'\1', remote_url)
 | 
			
		||||
                name, fdroidserver.deploy.REMOTE_HOSTNAME_REGEX.sub(r'\1', remote_url)
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -166,8 +197,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
 | 
			
		||||
    newSuite = unittest.TestSuite()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,7 +9,8 @@ import sys
 | 
			
		|||
import unittest
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -57,8 +58,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (fdroidserver.exception.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
    fdroidserver.common.options = fdroidserver.exception.options
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,13 +14,15 @@ import unittest
 | 
			
		|||
from unittest import mock
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
 | 
			
		||||
import fdroidserver.common
 | 
			
		||||
import fdroidserver.metadata
 | 
			
		||||
 | 
			
		||||
# work around the syntax error from: import fdroidserver.import
 | 
			
		||||
import import_proxy
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -55,19 +57,37 @@ class ImportTest(unittest.TestCase):
 | 
			
		|||
        self.assertEqual(app.Repo, 'https://gitlab.com/fdroid/ci-test-app.git')
 | 
			
		||||
 | 
			
		||||
    def test_get_app_from_url(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        os.mkdir(os.path.join(testdir, 'tmp'))
 | 
			
		||||
        tmp_importer = os.path.join(testdir, 'tmp', 'importer')
 | 
			
		||||
        data = (
 | 
			
		||||
            ('cn.wildfirechat.chat', 'https://github.com/wildfirechat/android-chat', '0.6.9', '23'),
 | 
			
		||||
            ('com.anpmech.launcher', 'https://github.com/KeikaiLauncher/KeikaiLauncher', 'Unknown', None),
 | 
			
		||||
            ('ut.ewh.audiometrytest', 'https://github.com/ReeceStevens/ut_ewh_audiometer_2014', '1.65', '14'),
 | 
			
		||||
            (
 | 
			
		||||
                'cn.wildfirechat.chat',
 | 
			
		||||
                'https://github.com/wildfirechat/android-chat',
 | 
			
		||||
                '0.6.9',
 | 
			
		||||
                '23',
 | 
			
		||||
            ),
 | 
			
		||||
            (
 | 
			
		||||
                'com.anpmech.launcher',
 | 
			
		||||
                'https://github.com/KeikaiLauncher/KeikaiLauncher',
 | 
			
		||||
                'Unknown',
 | 
			
		||||
                None,
 | 
			
		||||
            ),
 | 
			
		||||
            (
 | 
			
		||||
                'ut.ewh.audiometrytest',
 | 
			
		||||
                'https://github.com/ReeceStevens/ut_ewh_audiometer_2014',
 | 
			
		||||
                '1.65',
 | 
			
		||||
                '14',
 | 
			
		||||
            ),
 | 
			
		||||
        )
 | 
			
		||||
        for appid, url, vn, vc in data:
 | 
			
		||||
            shutil.rmtree(tmp_importer, ignore_errors=True)
 | 
			
		||||
            shutil.copytree(os.path.join(self.basedir, 'source-files', appid),
 | 
			
		||||
                            tmp_importer)
 | 
			
		||||
            shutil.copytree(
 | 
			
		||||
                os.path.join(self.basedir, 'source-files', appid), tmp_importer
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
            app = fdroidserver.common.get_app_from_url(url)
 | 
			
		||||
            with mock.patch('fdroidserver.common.getvcs',
 | 
			
		||||
| 
						 | 
				
			
			@ -92,8 +112,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
 | 
			
		||||
    newSuite = unittest.TestSuite()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,7 +15,8 @@ import json
 | 
			
		|||
import shutil
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -37,7 +38,6 @@ class Options:
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
class IndexTest(unittest.TestCase):
 | 
			
		||||
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        logging.basicConfig(level=logging.DEBUG)
 | 
			
		||||
        self.basedir = os.path.join(localmodule, 'tests')
 | 
			
		||||
| 
						 | 
				
			
			@ -55,8 +55,9 @@ class IndexTest(unittest.TestCase):
 | 
			
		|||
        fdroidserver.signindex.config = config
 | 
			
		||||
 | 
			
		||||
        if not os.path.exists('repo/index-v1.jar'):
 | 
			
		||||
            fdroidserver.signindex.sign_index_v1(os.path.join(self.basedir, 'repo'),
 | 
			
		||||
                                                 'index-v1.json')
 | 
			
		||||
            fdroidserver.signindex.sign_index_v1(
 | 
			
		||||
                os.path.join(self.basedir, 'repo'), 'index-v1.json'
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    def test_get_public_key_from_jar_succeeds(self):
 | 
			
		||||
        source_dir = os.path.join(self.basedir, 'signindex')
 | 
			
		||||
| 
						 | 
				
			
			@ -66,9 +67,11 @@ class IndexTest(unittest.TestCase):
 | 
			
		|||
            _, fingerprint = fdroidserver.index.get_public_key_from_jar(jar)
 | 
			
		||||
            # comparing fingerprints should be sufficient
 | 
			
		||||
            if f == 'testy.jar':
 | 
			
		||||
                self.assertEqual(fingerprint,
 | 
			
		||||
                                 '818E469465F96B704E27BE2FEE4C63AB'
 | 
			
		||||
                                 + '9F83DDF30E7A34C7371A4728D83B0BC1')
 | 
			
		||||
                self.assertEqual(
 | 
			
		||||
                    fingerprint,
 | 
			
		||||
                    '818E469465F96B704E27BE2FEE4C63AB'
 | 
			
		||||
                    + '9F83DDF30E7A34C7371A4728D83B0BC1',
 | 
			
		||||
                )
 | 
			
		||||
            if f == 'guardianproject.jar':
 | 
			
		||||
                self.assertTrue(fingerprint == GP_FINGERPRINT)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -85,12 +88,15 @@ class IndexTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_download_repo_index_no_jar(self):
 | 
			
		||||
        with self.assertRaises(requests.exceptions.RequestException):
 | 
			
		||||
            fdroidserver.index.download_repo_index("http://example.org?fingerprint=nope")
 | 
			
		||||
            fdroidserver.index.download_repo_index(
 | 
			
		||||
                "http://example.org?fingerprint=nope"
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    def test_get_repo_key_fingerprint(self):
 | 
			
		||||
        pubkey, fingerprint = fdroidserver.index.extract_pubkey()
 | 
			
		||||
        data, public_key, public_key_fingerprint = \
 | 
			
		||||
            fdroidserver.index.get_index_from_jar('repo/index-v1.jar', fingerprint)
 | 
			
		||||
        data, public_key, public_key_fingerprint = fdroidserver.index.get_index_from_jar(
 | 
			
		||||
            'repo/index-v1.jar', fingerprint
 | 
			
		||||
        )
 | 
			
		||||
        self.assertIsNotNone(data)
 | 
			
		||||
        self.assertIsNotNone(public_key)
 | 
			
		||||
        self.assertIsNotNone(public_key_fingerprint)
 | 
			
		||||
| 
						 | 
				
			
			@ -103,8 +109,9 @@ class IndexTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_get_index_from_jar_with_chars_to_be_stripped(self):
 | 
			
		||||
        fingerprint = 'NOOOO F4 9A F3 F1 1E FD DF 20 DF FD 70 F5 E3 11 7B 99 76 67 41 67 AD CA 28 0E 6B 19 32 A0 60 1B 26 F6'
 | 
			
		||||
        data, public_key, public_key_fingerprint = \
 | 
			
		||||
            fdroidserver.index.get_index_from_jar('repo/index-v1.jar', fingerprint)
 | 
			
		||||
        data, public_key, public_key_fingerprint = fdroidserver.index.get_index_from_jar(
 | 
			
		||||
            'repo/index-v1.jar', fingerprint
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    @patch('requests.head')
 | 
			
		||||
    def test_download_repo_index_same_etag(self, head):
 | 
			
		||||
| 
						 | 
				
			
			@ -243,13 +250,15 @@ class IndexTest(unittest.TestCase):
 | 
			
		|||
                pass
 | 
			
		||||
 | 
			
		||||
            fdroidserver.index.v1_sort_packages(
 | 
			
		||||
                i, fdroidserver.common.load_stats_fdroid_signing_key_fingerprints())
 | 
			
		||||
                i, fdroidserver.common.load_stats_fdroid_signing_key_fingerprints()
 | 
			
		||||
            )
 | 
			
		||||
            self.maxDiff = None
 | 
			
		||||
            self.assertEqual(json.dumps(i, indent=2), json.dumps(o, indent=2))
 | 
			
		||||
 | 
			
		||||
    def test_make_v0_repo_only(self):
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
 | 
			
		||||
                                       dir=self.tmpdir)
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(tmptestsdir)
 | 
			
		||||
        os.mkdir('repo')
 | 
			
		||||
        repo_icons_dir = os.path.join('repo', 'icons')
 | 
			
		||||
| 
						 | 
				
			
			@ -266,19 +275,24 @@ class IndexTest(unittest.TestCase):
 | 
			
		|||
        fdroidserver.common.config['repo_pubkey'] = 'ffffffffffffffffffffffffffffffffff'
 | 
			
		||||
        fdroidserver.index.make_v0({}, [], 'repo', repodict, requestsdict, {})
 | 
			
		||||
        self.assertTrue(os.path.isdir(repo_icons_dir))
 | 
			
		||||
        self.assertTrue(os.path.exists(os.path.join(repo_icons_dir,
 | 
			
		||||
                                                    fdroidserver.common.default_config['repo_icon'])))
 | 
			
		||||
        self.assertTrue(
 | 
			
		||||
            os.path.exists(
 | 
			
		||||
                os.path.join(
 | 
			
		||||
                    repo_icons_dir, fdroidserver.common.default_config['repo_icon']
 | 
			
		||||
                )
 | 
			
		||||
            )
 | 
			
		||||
        )
 | 
			
		||||
        self.assertTrue(os.path.exists(os.path.join('repo', 'index.xml')))
 | 
			
		||||
 | 
			
		||||
    def test_make_v0(self):
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
 | 
			
		||||
                                       dir=self.tmpdir)
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(tmptestsdir)
 | 
			
		||||
        os.mkdir('metadata')
 | 
			
		||||
        os.mkdir('repo')
 | 
			
		||||
        metadatafile = 'metadata/info.zwanenburg.caffeinetile.yml'
 | 
			
		||||
        shutil.copy(os.path.join(self.basedir, metadatafile),
 | 
			
		||||
                    metadatafile)
 | 
			
		||||
        shutil.copy(os.path.join(self.basedir, metadatafile), metadatafile)
 | 
			
		||||
        repo_icons_dir = os.path.join('repo', 'icons')
 | 
			
		||||
        self.assertFalse(os.path.isdir(repo_icons_dir))
 | 
			
		||||
        repodict = {
 | 
			
		||||
| 
						 | 
				
			
			@ -296,21 +310,14 @@ class IndexTest(unittest.TestCase):
 | 
			
		|||
        apk = {
 | 
			
		||||
            'hash': 'dbbdd7deadb038862f426b71efe4a64df8c3edf25d669e935f349510e16f65db',
 | 
			
		||||
            'hashType': 'sha256',
 | 
			
		||||
            'uses-permission': [
 | 
			
		||||
                [
 | 
			
		||||
                    'android.permission.WAKE_LOCK',
 | 
			
		||||
                    None
 | 
			
		||||
                ]
 | 
			
		||||
            ],
 | 
			
		||||
            'uses-permission': [['android.permission.WAKE_LOCK', None]],
 | 
			
		||||
            'uses-permission-sdk-23': [],
 | 
			
		||||
            'features': [],
 | 
			
		||||
            'icons_src': {
 | 
			
		||||
                '160': 'res/drawable/ic_coffee_on.xml',
 | 
			
		||||
                '-1': 'res/drawable/ic_coffee_on.xml'
 | 
			
		||||
            },
 | 
			
		||||
            'icons': {
 | 
			
		||||
                '160': 'info.zwanenburg.caffeinetile.4.xml'
 | 
			
		||||
                '-1': 'res/drawable/ic_coffee_on.xml',
 | 
			
		||||
            },
 | 
			
		||||
            'icons': {'160': 'info.zwanenburg.caffeinetile.4.xml'},
 | 
			
		||||
            'antiFeatures': [],
 | 
			
		||||
            'packageName': 'info.zwanenburg.caffeinetile',
 | 
			
		||||
            'versionCode': 4,
 | 
			
		||||
| 
						 | 
				
			
			@ -330,33 +337,45 @@ class IndexTest(unittest.TestCase):
 | 
			
		|||
        fdroidserver.common.config['make_current_version_link'] = True
 | 
			
		||||
        fdroidserver.index.make_v0(apps, [apk], 'repo', repodict, requestsdict, {})
 | 
			
		||||
        self.assertTrue(os.path.isdir(repo_icons_dir))
 | 
			
		||||
        self.assertTrue(os.path.exists(os.path.join(repo_icons_dir,
 | 
			
		||||
                                                    fdroidserver.common.default_config['repo_icon'])))
 | 
			
		||||
        self.assertTrue(
 | 
			
		||||
            os.path.exists(
 | 
			
		||||
                os.path.join(
 | 
			
		||||
                    repo_icons_dir, fdroidserver.common.default_config['repo_icon']
 | 
			
		||||
                )
 | 
			
		||||
            )
 | 
			
		||||
        )
 | 
			
		||||
        self.assertTrue(os.path.exists(os.path.join('repo', 'index.xml')))
 | 
			
		||||
 | 
			
		||||
    def test_get_mirror_service_urls(self):
 | 
			
		||||
        for url in [
 | 
			
		||||
                'git@github.com:foo/bar',
 | 
			
		||||
                'git@github.com:foo/bar.git',
 | 
			
		||||
                'https://github.com/foo/bar',
 | 
			
		||||
                'https://github.com/foo/bar.git',
 | 
			
		||||
            'git@github.com:foo/bar',
 | 
			
		||||
            'git@github.com:foo/bar.git',
 | 
			
		||||
            'https://github.com/foo/bar',
 | 
			
		||||
            'https://github.com/foo/bar.git',
 | 
			
		||||
        ]:
 | 
			
		||||
            self.assertEqual(['https://raw.githubusercontent.com/foo/bar/master/fdroid'],
 | 
			
		||||
                             fdroidserver.index.get_mirror_service_urls(url))
 | 
			
		||||
            self.assertEqual(
 | 
			
		||||
                ['https://raw.githubusercontent.com/foo/bar/master/fdroid'],
 | 
			
		||||
                fdroidserver.index.get_mirror_service_urls(url),
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        for url in [
 | 
			
		||||
                'git@gitlab.com:group/project',
 | 
			
		||||
                'git@gitlab.com:group/project.git',
 | 
			
		||||
                'https://gitlab.com/group/project',
 | 
			
		||||
                'https://gitlab.com/group/project.git',
 | 
			
		||||
            'git@gitlab.com:group/project',
 | 
			
		||||
            'git@gitlab.com:group/project.git',
 | 
			
		||||
            'https://gitlab.com/group/project',
 | 
			
		||||
            'https://gitlab.com/group/project.git',
 | 
			
		||||
        ]:
 | 
			
		||||
            self.assertEqual(['https://group.gitlab.io/project/fdroid',
 | 
			
		||||
                              'https://gitlab.com/group/project/-/raw/master/fdroid'],
 | 
			
		||||
                             fdroidserver.index.get_mirror_service_urls(url))
 | 
			
		||||
            self.assertEqual(
 | 
			
		||||
                [
 | 
			
		||||
                    'https://group.gitlab.io/project/fdroid',
 | 
			
		||||
                    'https://gitlab.com/group/project/-/raw/master/fdroid',
 | 
			
		||||
                ],
 | 
			
		||||
                fdroidserver.index.get_mirror_service_urls(url),
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    def test_make_website(self):
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
 | 
			
		||||
                                       dir=self.tmpdir)
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(tmptestsdir)
 | 
			
		||||
        os.mkdir('metadata')
 | 
			
		||||
        os.mkdir('repo')
 | 
			
		||||
| 
						 | 
				
			
			@ -396,21 +415,31 @@ class IndexTest(unittest.TestCase):
 | 
			
		|||
            self.assertEquals(css, pretty_css)
 | 
			
		||||
 | 
			
		||||
    def test_v1_sort_packages_with_invalid(self):
 | 
			
		||||
        i = [{'packageName': 'org.smssecure.smssecure',
 | 
			
		||||
              'apkName': 'smssecure-custom.fake',
 | 
			
		||||
              'signer': None,
 | 
			
		||||
              'versionCode': 11111}]
 | 
			
		||||
        i = [
 | 
			
		||||
            {
 | 
			
		||||
                'packageName': 'org.smssecure.smssecure',
 | 
			
		||||
                'apkName': 'smssecure-custom.fake',
 | 
			
		||||
                'signer': None,
 | 
			
		||||
                'versionCode': 11111,
 | 
			
		||||
            }
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
        fdroidserver.index.v1_sort_packages(
 | 
			
		||||
            i, fdroidserver.common.load_stats_fdroid_signing_key_fingerprints())
 | 
			
		||||
            i, fdroidserver.common.load_stats_fdroid_signing_key_fingerprints()
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (options, args) = parser.parse_args()
 | 
			
		||||
    Options.verbose = options.verbose
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,8 @@ import unittest
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -35,7 +36,9 @@ class InitTest(unittest.TestCase):
 | 
			
		|||
        fdroidserver.init.config = None
 | 
			
		||||
 | 
			
		||||
    def test_disable_in_config(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with open('config.yml', 'w') as fp:
 | 
			
		||||
            fp.write('keystore: NONE\n')
 | 
			
		||||
| 
						 | 
				
			
			@ -53,7 +56,9 @@ class InitTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_main_in_empty_dir(self):
 | 
			
		||||
        """Test that `fdroid init` will find apksigner and add it to the config"""
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
 | 
			
		||||
        shutil.copy(os.path.join(self.basedir, 'keystore.jks'), testdir)
 | 
			
		||||
| 
						 | 
				
			
			@ -74,8 +79,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (fdroidserver.init.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
 | 
			
		||||
    newSuite = unittest.TestSuite()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,7 +9,8 @@ import sys
 | 
			
		|||
import unittest
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -38,8 +39,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (fdroidserver.install.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
    fdroidserver.common.options = fdroidserver.install.options
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,7 +12,8 @@ import tempfile
 | 
			
		|||
import unittest
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -322,8 +323,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (fdroidserver.lint.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
    fdroidserver.common.options = fdroidserver.lint.options
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,7 +12,8 @@ from unittest import mock
 | 
			
		|||
from testcommon import TmpCwd, TmpPyPath
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -26,27 +27,31 @@ class MainTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_COMMANDS_check(self):
 | 
			
		||||
        """make sure the built in sub-command defs didn't change unintentionally"""
 | 
			
		||||
        self.assertListEqual([x for x in fdroidserver.__main__.COMMANDS.keys()],
 | 
			
		||||
                             ['build',
 | 
			
		||||
                              'init',
 | 
			
		||||
                              'publish',
 | 
			
		||||
                              'gpgsign',
 | 
			
		||||
                              'update',
 | 
			
		||||
                              'deploy',
 | 
			
		||||
                              'verify',
 | 
			
		||||
                              'checkupdates',
 | 
			
		||||
                              'import',
 | 
			
		||||
                              'install',
 | 
			
		||||
                              'readmeta',
 | 
			
		||||
                              'rewritemeta',
 | 
			
		||||
                              'lint',
 | 
			
		||||
                              'scanner',
 | 
			
		||||
                              'stats',
 | 
			
		||||
                              'signindex',
 | 
			
		||||
                              'btlog',
 | 
			
		||||
                              'signatures',
 | 
			
		||||
                              'nightly',
 | 
			
		||||
                              'mirror'])
 | 
			
		||||
        self.assertListEqual(
 | 
			
		||||
            [x for x in fdroidserver.__main__.COMMANDS.keys()],
 | 
			
		||||
            [
 | 
			
		||||
                'build',
 | 
			
		||||
                'init',
 | 
			
		||||
                'publish',
 | 
			
		||||
                'gpgsign',
 | 
			
		||||
                'update',
 | 
			
		||||
                'deploy',
 | 
			
		||||
                'verify',
 | 
			
		||||
                'checkupdates',
 | 
			
		||||
                'import',
 | 
			
		||||
                'install',
 | 
			
		||||
                'readmeta',
 | 
			
		||||
                'rewritemeta',
 | 
			
		||||
                'lint',
 | 
			
		||||
                'scanner',
 | 
			
		||||
                'stats',
 | 
			
		||||
                'signindex',
 | 
			
		||||
                'btlog',
 | 
			
		||||
                'signatures',
 | 
			
		||||
                'nightly',
 | 
			
		||||
                'mirror',
 | 
			
		||||
            ],
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_call_init(self):
 | 
			
		||||
        co = mock.Mock()
 | 
			
		||||
| 
						 | 
				
			
			@ -73,26 +78,34 @@ class MainTest(unittest.TestCase):
 | 
			
		|||
    def test_find_plugins(self):
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            with open('fdroid_testy1.py', 'w') as f:
 | 
			
		||||
                f.write(textwrap.dedent("""\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        """\
 | 
			
		||||
                        fdroid_summary = "ttt"
 | 
			
		||||
                        main = lambda: 'all good'"""))
 | 
			
		||||
                        main = lambda: 'all good'"""
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            with TmpPyPath(tmpdir):
 | 
			
		||||
                plugins = fdroidserver.__main__.find_plugins()
 | 
			
		||||
                self.assertIn('testy1', plugins.keys())
 | 
			
		||||
                self.assertEqual(plugins['testy1']['summary'], 'ttt')
 | 
			
		||||
                self.assertEqual(__import__(plugins['testy1']['name'],
 | 
			
		||||
                                            None,
 | 
			
		||||
                                            None,
 | 
			
		||||
                                            ['testy1'])
 | 
			
		||||
                                 .main(),
 | 
			
		||||
                                 'all good')
 | 
			
		||||
                self.assertEqual(
 | 
			
		||||
                    __import__(
 | 
			
		||||
                        plugins['testy1']['name'], None, None, ['testy1']
 | 
			
		||||
                    ).main(),
 | 
			
		||||
                    'all good',
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
    def test_main_plugin_lambda(self):
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            with open('fdroid_testy2.py', 'w') as f:
 | 
			
		||||
                f.write(textwrap.dedent("""\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        """\
 | 
			
		||||
                        fdroid_summary = "ttt"
 | 
			
		||||
                        main = lambda: print('all good')"""))
 | 
			
		||||
                        main = lambda: print('all good')"""
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            with TmpPyPath(tmpdir):
 | 
			
		||||
                with mock.patch('sys.argv', ['', 'testy2']):
 | 
			
		||||
                    with mock.patch('sys.exit') as exit_mock:
 | 
			
		||||
| 
						 | 
				
			
			@ -102,10 +115,14 @@ class MainTest(unittest.TestCase):
 | 
			
		|||
    def test_main_plugin_def(self):
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            with open('fdroid_testy3.py', 'w') as f:
 | 
			
		||||
                f.write(textwrap.dedent("""\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        """\
 | 
			
		||||
                        fdroid_summary = "ttt"
 | 
			
		||||
                        def main():
 | 
			
		||||
                            print('all good')"""))
 | 
			
		||||
                            print('all good')"""
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            with TmpPyPath(tmpdir):
 | 
			
		||||
                with mock.patch('sys.argv', ['', 'testy3']):
 | 
			
		||||
                    with mock.patch('sys.exit') as exit_mock:
 | 
			
		||||
| 
						 | 
				
			
			@ -116,10 +133,14 @@ class MainTest(unittest.TestCase):
 | 
			
		|||
        """making sure broken plugins get their exceptions through"""
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            with open('fdroid_testy4.py', 'w') as f:
 | 
			
		||||
                f.write(textwrap.dedent("""\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        """\
 | 
			
		||||
                        fdroid_summary = "ttt"
 | 
			
		||||
                        def main():
 | 
			
		||||
                            raise Exception("this plugin is broken")"""))
 | 
			
		||||
                            raise Exception("this plugin is broken")"""
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            with TmpPyPath(tmpdir):
 | 
			
		||||
                with mock.patch('sys.argv', ['', 'testy4']):
 | 
			
		||||
                    with self.assertRaisesRegex(Exception, "this plugin is broken"):
 | 
			
		||||
| 
						 | 
				
			
			@ -131,11 +152,15 @@ class MainTest(unittest.TestCase):
 | 
			
		|||
        """
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            with open('fdroid_testy5.py', 'w') as f:
 | 
			
		||||
                f.write(textwrap.dedent("""\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        """\
 | 
			
		||||
                        fdroid_summary = "ttt"
 | 
			
		||||
                        raise Exception("this plugin is malicious")
 | 
			
		||||
                        def main():
 | 
			
		||||
                            print("evil things")"""))
 | 
			
		||||
                            print("evil things")"""
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            with TmpPyPath(tmpdir):
 | 
			
		||||
                with mock.patch('sys.argv', ['', 'lint']):
 | 
			
		||||
                    with mock.patch('sys.exit') as exit_mock:
 | 
			
		||||
| 
						 | 
				
			
			@ -149,10 +174,14 @@ class MainTest(unittest.TestCase):
 | 
			
		|||
        """
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            with open('fdroid_signatures.py', 'w') as f:
 | 
			
		||||
                f.write(textwrap.dedent("""\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        """\
 | 
			
		||||
                        fdroid_summary = "ttt"
 | 
			
		||||
                        def main():
 | 
			
		||||
                            raise("plugin overrides don't get prevent!")"""))
 | 
			
		||||
                            raise("plugin overrides don't get prevent!")"""
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            with TmpPyPath(tmpdir):
 | 
			
		||||
                with mock.patch('sys.argv', ['', 'signatures']):
 | 
			
		||||
                    with mock.patch('sys.exit') as exit_mock:
 | 
			
		||||
| 
						 | 
				
			
			@ -162,49 +191,69 @@ class MainTest(unittest.TestCase):
 | 
			
		|||
                        self.assertEqual(exit_mock.call_count, 2)
 | 
			
		||||
 | 
			
		||||
    def test_preparse_plugin_lookup_bad_name(self):
 | 
			
		||||
        self.assertRaises(ValueError,
 | 
			
		||||
                          fdroidserver.__main__.preparse_plugin,
 | 
			
		||||
                          "some.package", "/non/existent/module/path")
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            ValueError,
 | 
			
		||||
            fdroidserver.__main__.preparse_plugin,
 | 
			
		||||
            "some.package",
 | 
			
		||||
            "/non/existent/module/path",
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_preparse_plugin_lookup_bad_path(self):
 | 
			
		||||
        self.assertRaises(ValueError,
 | 
			
		||||
                          fdroidserver.__main__.preparse_plugin,
 | 
			
		||||
                          "fake_module_name", "/non/existent/module/path")
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            ValueError,
 | 
			
		||||
            fdroidserver.__main__.preparse_plugin,
 | 
			
		||||
            "fake_module_name",
 | 
			
		||||
            "/non/existent/module/path",
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_preparse_plugin_lookup_summary_missing(self):
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            with open('fdroid_testy6.py', 'w') as f:
 | 
			
		||||
                f.write(textwrap.dedent("""\
 | 
			
		||||
                        main = lambda: print('all good')"""))
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        """\
 | 
			
		||||
                        main = lambda: print('all good')"""
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            with TmpPyPath(tmpdir):
 | 
			
		||||
                p = [x for x in pkgutil.iter_modules() if x[1].startswith('fdroid_')]
 | 
			
		||||
                module_dir = p[0][0].path
 | 
			
		||||
                module_name = p[0][1]
 | 
			
		||||
                self.assertRaises(NameError,
 | 
			
		||||
                                  fdroidserver.__main__.preparse_plugin,
 | 
			
		||||
                                  module_name, module_dir)
 | 
			
		||||
                self.assertRaises(
 | 
			
		||||
                    NameError,
 | 
			
		||||
                    fdroidserver.__main__.preparse_plugin,
 | 
			
		||||
                    module_name,
 | 
			
		||||
                    module_dir,
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
    def test_preparse_plugin_lookup_module_file(self):
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            with open('fdroid_testy7.py', 'w') as f:
 | 
			
		||||
                f.write(textwrap.dedent("""\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        """\
 | 
			
		||||
                        fdroid_summary = "ttt"
 | 
			
		||||
                        main = lambda: pritn('all good')"""))
 | 
			
		||||
                        main = lambda: pritn('all good')"""
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            with TmpPyPath(tmpdir):
 | 
			
		||||
                p = [x for x in pkgutil.iter_modules() if x[1].startswith('fdroid_')]
 | 
			
		||||
                module_path = p[0][0].path
 | 
			
		||||
                module_name = p[0][1]
 | 
			
		||||
                d = fdroidserver.__main__.preparse_plugin(module_name, module_path)
 | 
			
		||||
            self.assertDictEqual(d, {'name': 'fdroid_testy7',
 | 
			
		||||
                                     'summary': 'ttt'})
 | 
			
		||||
            self.assertDictEqual(d, {'name': 'fdroid_testy7', 'summary': 'ttt'})
 | 
			
		||||
 | 
			
		||||
    def test_preparse_plugin_lookup_module_dir(self):
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            os.mkdir(os.path.join(tmpdir, 'fdroid_testy8'))
 | 
			
		||||
            with open('fdroid_testy8/__main__.py', 'w') as f:
 | 
			
		||||
                f.write(textwrap.dedent("""\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        """\
 | 
			
		||||
                        fdroid_summary = "ttt"
 | 
			
		||||
                        main = lambda: print('all good')"""))
 | 
			
		||||
                        main = lambda: print('all good')"""
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            with open('fdroid_testy8/__init__.py', 'w') as f:
 | 
			
		||||
                pass
 | 
			
		||||
            with TmpPyPath(tmpdir):
 | 
			
		||||
| 
						 | 
				
			
			@ -212,16 +261,20 @@ class MainTest(unittest.TestCase):
 | 
			
		|||
                module_path = p[0][0].path
 | 
			
		||||
                module_name = p[0][1]
 | 
			
		||||
                d = fdroidserver.__main__.preparse_plugin(module_name, module_path)
 | 
			
		||||
            self.assertDictEqual(d, {'name': 'fdroid_testy8',
 | 
			
		||||
                                     'summary': 'ttt'})
 | 
			
		||||
            self.assertDictEqual(d, {'name': 'fdroid_testy8', 'summary': 'ttt'})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (common.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
 | 
			
		||||
    newSuite = unittest.TestSuite()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,7 +24,8 @@ except ImportError:
 | 
			
		|||
    from yaml import SafeLoader
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -134,8 +135,12 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        fdroidserver.metadata.warnings_action = None
 | 
			
		||||
 | 
			
		||||
        apps = fdroidserver.metadata.read_metadata()
 | 
			
		||||
        for appid in ('org.smssecure.smssecure', 'org.adaway',
 | 
			
		||||
                      'org.videolan.vlc', 'com.politedroid'):
 | 
			
		||||
        for appid in (
 | 
			
		||||
            'org.smssecure.smssecure',
 | 
			
		||||
            'org.adaway',
 | 
			
		||||
            'org.videolan.vlc',
 | 
			
		||||
            'com.politedroid',
 | 
			
		||||
        ):
 | 
			
		||||
            savepath = os.path.join('metadata', 'dump', appid + '.yaml')
 | 
			
		||||
            frommeta = dict(apps[appid])
 | 
			
		||||
            self.assertTrue(appid in apps)
 | 
			
		||||
| 
						 | 
				
			
			@ -149,7 +154,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
            #     yaml.dump(frommeta, f, default_flow_style=False)
 | 
			
		||||
 | 
			
		||||
    def test_rewrite_yaml_fakeotaupdate(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        fdroidserver.common.config = {'accepted_formats': ['yml']}
 | 
			
		||||
        fdroidserver.metadata.warnings_action = None
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -157,7 +164,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        allapps = fdroidserver.metadata.read_metadata()
 | 
			
		||||
        for appid, app in allapps.items():
 | 
			
		||||
            if appid == 'fake.ota.update':
 | 
			
		||||
                fdroidserver.metadata.write_metadata(os.path.join(testdir, appid + '.yml'), app)
 | 
			
		||||
                fdroidserver.metadata.write_metadata(
 | 
			
		||||
                    os.path.join(testdir, appid + '.yml'), app
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
        # assert rewrite result
 | 
			
		||||
        with open(os.path.join(testdir, 'fake.ota.update.yml'), 'r') as result:
 | 
			
		||||
| 
						 | 
				
			
			@ -166,14 +175,18 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
                self.assertEqual(result.read(), orig.read())
 | 
			
		||||
 | 
			
		||||
    def test_rewrite_yaml_fdroidclient(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        fdroidserver.common.config = {'accepted_formats': ['yml']}
 | 
			
		||||
 | 
			
		||||
        # rewrite metadata
 | 
			
		||||
        allapps = fdroidserver.metadata.read_metadata()
 | 
			
		||||
        for appid, app in allapps.items():
 | 
			
		||||
            if appid == 'org.fdroid.fdroid':
 | 
			
		||||
                fdroidserver.metadata.write_metadata(os.path.join(testdir, appid + '.yml'), app)
 | 
			
		||||
                fdroidserver.metadata.write_metadata(
 | 
			
		||||
                    os.path.join(testdir, appid + '.yml'), app
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
        # assert rewrite result
 | 
			
		||||
        with open(os.path.join(testdir, 'org.fdroid.fdroid.yml'), 'r') as result:
 | 
			
		||||
| 
						 | 
				
			
			@ -182,13 +195,17 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
                self.assertEqual(result.read(), orig.read())
 | 
			
		||||
 | 
			
		||||
    def test_rewrite_yaml_special_build_params(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        # rewrite metadata
 | 
			
		||||
        allapps = fdroidserver.metadata.read_metadata()
 | 
			
		||||
        for appid, app in allapps.items():
 | 
			
		||||
            if appid == 'app.with.special.build.params':
 | 
			
		||||
                fdroidserver.metadata.write_metadata(os.path.join(testdir, appid + '.yml'), app)
 | 
			
		||||
                fdroidserver.metadata.write_metadata(
 | 
			
		||||
                    os.path.join(testdir, appid + '.yml'), app
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
        # assert rewrite result
 | 
			
		||||
        with open(os.path.join(testdir, 'app.with.special.build.params.yml'), 'r') as result:
 | 
			
		||||
| 
						 | 
				
			
			@ -241,7 +258,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        self.assertEqual('1234567890', yamldata['Builds'][0]['commit'])
 | 
			
		||||
 | 
			
		||||
    def test_read_metadata_sort_by_time(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        metadatadir = os.path.join(testdir, 'metadata')
 | 
			
		||||
        os.makedirs(metadatadir)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -265,36 +284,50 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        self.assertEqual(randomlist, allappids)
 | 
			
		||||
 | 
			
		||||
    def test_parse_yaml_metadata_unknown_app_field(self):
 | 
			
		||||
        mf = io.StringIO(textwrap.dedent("""\
 | 
			
		||||
        mf = io.StringIO(
 | 
			
		||||
            textwrap.dedent(
 | 
			
		||||
                """\
 | 
			
		||||
            AutoName: F-Droid
 | 
			
		||||
            RepoType: git
 | 
			
		||||
            Builds: []
 | 
			
		||||
            bad: value"""))
 | 
			
		||||
            bad: value"""
 | 
			
		||||
            )
 | 
			
		||||
        )
 | 
			
		||||
        mf.name = 'mock_filename.yaml'
 | 
			
		||||
        with mock.patch('fdroidserver.metadata.warnings_action', 'error'):
 | 
			
		||||
            with self.assertRaises(MetaDataException):
 | 
			
		||||
                fdroidserver.metadata.parse_yaml_metadata(mf, {})
 | 
			
		||||
 | 
			
		||||
    def test_parse_yaml_metadata_unknown_build_flag(self):
 | 
			
		||||
        mf = io.StringIO(textwrap.dedent("""\
 | 
			
		||||
        mf = io.StringIO(
 | 
			
		||||
            textwrap.dedent(
 | 
			
		||||
                """\
 | 
			
		||||
            AutoName: F-Droid
 | 
			
		||||
            RepoType: git
 | 
			
		||||
            Builds:
 | 
			
		||||
              - bad: value"""))
 | 
			
		||||
              - bad: value"""
 | 
			
		||||
            )
 | 
			
		||||
        )
 | 
			
		||||
        mf.name = 'mock_filename.yaml'
 | 
			
		||||
        with mock.patch('fdroidserver.metadata.warnings_action', 'error'):
 | 
			
		||||
            with self.assertRaises(MetaDataException):
 | 
			
		||||
                fdroidserver.metadata.parse_yaml_metadata(mf, {})
 | 
			
		||||
 | 
			
		||||
    def test_parse_yaml_srclib_corrupt_file(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        srclibfile = os.path.join(testdir, 'srclib', 'mock.yml')
 | 
			
		||||
        os.mkdir(os.path.dirname(srclibfile))
 | 
			
		||||
        with open(srclibfile, 'w') as fp:
 | 
			
		||||
            fp.write(textwrap.dedent("""
 | 
			
		||||
            fp.write(
 | 
			
		||||
                textwrap.dedent(
 | 
			
		||||
                    """
 | 
			
		||||
            - RepoType: git
 | 
			
		||||
            - Repo: https://github.com/realm/realm-js.git
 | 
			
		||||
            """))
 | 
			
		||||
            """
 | 
			
		||||
                )
 | 
			
		||||
            )
 | 
			
		||||
        with mock.patch('fdroidserver.metadata.warnings_action', 'error'):
 | 
			
		||||
            with self.assertRaises(MetaDataException):
 | 
			
		||||
                fdroidserver.metadata.parse_yaml_srclib(srclibfile)
 | 
			
		||||
| 
						 | 
				
			
			@ -321,7 +354,10 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        fdroidserver.metadata.write_yaml(mf, app)
 | 
			
		||||
 | 
			
		||||
        mf.seek(0)
 | 
			
		||||
        self.assertEqual(mf.read(), textwrap.dedent("""\
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            mf.read(),
 | 
			
		||||
            textwrap.dedent(
 | 
			
		||||
                """\
 | 
			
		||||
            Categories:
 | 
			
		||||
              - None
 | 
			
		||||
            License: Unknown
 | 
			
		||||
| 
						 | 
				
			
			@ -341,10 +377,14 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
            AutoUpdateMode: None
 | 
			
		||||
            UpdateCheckMode: Tags
 | 
			
		||||
            """))
 | 
			
		||||
            """
 | 
			
		||||
            ),
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_parse_yaml_metadata_prebuild_list(self):
 | 
			
		||||
        mf = io.StringIO(textwrap.dedent("""\
 | 
			
		||||
        mf = io.StringIO(
 | 
			
		||||
            textwrap.dedent(
 | 
			
		||||
                """\
 | 
			
		||||
            AutoName: F-Droid
 | 
			
		||||
            RepoType: git
 | 
			
		||||
            Builds:
 | 
			
		||||
| 
						 | 
				
			
			@ -364,7 +404,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
                    - ./gradlew someSpecialTask
 | 
			
		||||
                    - sed -i 'd/that wrong config/' gradle.properties
 | 
			
		||||
                    - ./gradlew compile
 | 
			
		||||
            """))
 | 
			
		||||
            """
 | 
			
		||||
            )
 | 
			
		||||
        )
 | 
			
		||||
        mf.name = 'mock_filename.yaml'
 | 
			
		||||
        mf.seek(0)
 | 
			
		||||
        result = {}
 | 
			
		||||
| 
						 | 
				
			
			@ -386,7 +428,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
                                                           "./gradlew compile"}]})
 | 
			
		||||
 | 
			
		||||
    def test_parse_yaml_metadata_prebuild_strings(self):
 | 
			
		||||
        mf = io.StringIO(textwrap.dedent("""\
 | 
			
		||||
        mf = io.StringIO(
 | 
			
		||||
            textwrap.dedent(
 | 
			
		||||
                """\
 | 
			
		||||
            AutoName: F-Droid
 | 
			
		||||
            RepoType: git
 | 
			
		||||
            Builds:
 | 
			
		||||
| 
						 | 
				
			
			@ -398,7 +442,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
                  prebuild: npm something && echo 'important setting' >> /a/file
 | 
			
		||||
                  build: |-
 | 
			
		||||
                    ./gradlew someSpecialTask && sed -i 'd/that wrong config/' gradle.properties && ./gradlew compile
 | 
			
		||||
            """))
 | 
			
		||||
            """
 | 
			
		||||
            )
 | 
			
		||||
        )
 | 
			
		||||
        mf.name = 'mock_filename.yaml'
 | 
			
		||||
        mf.seek(0)
 | 
			
		||||
        result = {}
 | 
			
		||||
| 
						 | 
				
			
			@ -420,7 +466,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
                                                           "./gradlew compile"}]})
 | 
			
		||||
 | 
			
		||||
    def test_parse_yaml_metadata_prebuild_string(self):
 | 
			
		||||
        mf = io.StringIO(textwrap.dedent("""\
 | 
			
		||||
        mf = io.StringIO(
 | 
			
		||||
            textwrap.dedent(
 | 
			
		||||
                """\
 | 
			
		||||
            AutoName: F-Droid
 | 
			
		||||
            RepoType: git
 | 
			
		||||
            Builds:
 | 
			
		||||
| 
						 | 
				
			
			@ -428,7 +476,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
                  versionName: v0.1.0
 | 
			
		||||
                  prebuild: |-
 | 
			
		||||
                    a && b && sed -i 's,a,b,'
 | 
			
		||||
            """))
 | 
			
		||||
            """
 | 
			
		||||
            )
 | 
			
		||||
        )
 | 
			
		||||
        mf.name = 'mock_filename.yaml'
 | 
			
		||||
        mf.seek(0)
 | 
			
		||||
        result = {}
 | 
			
		||||
| 
						 | 
				
			
			@ -442,7 +492,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
                                                              "sed -i 's,a,b,'"}]})
 | 
			
		||||
 | 
			
		||||
    def test_parse_yaml_provides_should_be_ignored(self):
 | 
			
		||||
        mf = io.StringIO(textwrap.dedent("""\
 | 
			
		||||
        mf = io.StringIO(
 | 
			
		||||
            textwrap.dedent(
 | 
			
		||||
                """\
 | 
			
		||||
            Provides: this.is.deprecated
 | 
			
		||||
            AutoName: F-Droid
 | 
			
		||||
            RepoType: git
 | 
			
		||||
| 
						 | 
				
			
			@ -451,7 +503,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
                  versionName: v0.1.0
 | 
			
		||||
                  prebuild: |-
 | 
			
		||||
                    a && b && sed -i 's,a,b,'
 | 
			
		||||
            """))
 | 
			
		||||
            """
 | 
			
		||||
            )
 | 
			
		||||
        )
 | 
			
		||||
        mf.name = 'mock_filename.yaml'
 | 
			
		||||
        mf.seek(0)
 | 
			
		||||
        result = {}
 | 
			
		||||
| 
						 | 
				
			
			@ -475,7 +529,10 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        app['Builds'].append(build)
 | 
			
		||||
        fdroidserver.metadata.write_yaml(mf, app)
 | 
			
		||||
        mf.seek(0)
 | 
			
		||||
        self.assertEqual(mf.read(), textwrap.dedent("""\
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            mf.read(),
 | 
			
		||||
            textwrap.dedent(
 | 
			
		||||
                """\
 | 
			
		||||
            Categories:
 | 
			
		||||
              - None
 | 
			
		||||
            License: Unknown
 | 
			
		||||
| 
						 | 
				
			
			@ -490,7 +547,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
            AutoUpdateMode: None
 | 
			
		||||
            UpdateCheckMode: None
 | 
			
		||||
            """))
 | 
			
		||||
            """
 | 
			
		||||
            ),
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_write_yaml_1_line_scripts_as_list(self):
 | 
			
		||||
        mf = io.StringIO()
 | 
			
		||||
| 
						 | 
				
			
			@ -507,7 +566,10 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        app['Builds'].append(build)
 | 
			
		||||
        fdroidserver.metadata.write_yaml(mf, app)
 | 
			
		||||
        mf.seek(0)
 | 
			
		||||
        self.assertEqual(mf.read(), textwrap.dedent("""\
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            mf.read(),
 | 
			
		||||
            textwrap.dedent(
 | 
			
		||||
                """\
 | 
			
		||||
            Categories:
 | 
			
		||||
              - None
 | 
			
		||||
            License: Unknown
 | 
			
		||||
| 
						 | 
				
			
			@ -522,7 +584,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
            AutoUpdateMode: None
 | 
			
		||||
            UpdateCheckMode: None
 | 
			
		||||
            """))
 | 
			
		||||
            """
 | 
			
		||||
            ),
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_write_yaml_multiline_scripts_from_list(self):
 | 
			
		||||
        mf = io.StringIO()
 | 
			
		||||
| 
						 | 
				
			
			@ -545,7 +609,10 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        app['Builds'].append(build)
 | 
			
		||||
        fdroidserver.metadata.write_yaml(mf, app)
 | 
			
		||||
        mf.seek(0)
 | 
			
		||||
        self.assertEqual(mf.read(), textwrap.dedent("""\
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            mf.read(),
 | 
			
		||||
            textwrap.dedent(
 | 
			
		||||
                """\
 | 
			
		||||
            Categories:
 | 
			
		||||
              - None
 | 
			
		||||
            License: Unknown
 | 
			
		||||
| 
						 | 
				
			
			@ -570,7 +637,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
            AutoUpdateMode: None
 | 
			
		||||
            UpdateCheckMode: None
 | 
			
		||||
            """))
 | 
			
		||||
            """
 | 
			
		||||
            ),
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_write_yaml_multiline_scripts_from_string(self):
 | 
			
		||||
        mf = io.StringIO()
 | 
			
		||||
| 
						 | 
				
			
			@ -587,7 +656,10 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        app['Builds'].append(build)
 | 
			
		||||
        fdroidserver.metadata.write_yaml(mf, app)
 | 
			
		||||
        mf.seek(0)
 | 
			
		||||
        self.assertEqual(mf.read(), textwrap.dedent("""\
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            mf.read(),
 | 
			
		||||
            textwrap.dedent(
 | 
			
		||||
                """\
 | 
			
		||||
            Categories:
 | 
			
		||||
              - None
 | 
			
		||||
            License: Unknown
 | 
			
		||||
| 
						 | 
				
			
			@ -612,7 +684,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
            AutoUpdateMode: None
 | 
			
		||||
            UpdateCheckMode: None
 | 
			
		||||
            """))
 | 
			
		||||
            """
 | 
			
		||||
            ),
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_write_yaml_make_sure_provides_does_not_get_written(self):
 | 
			
		||||
        mf = io.StringIO()
 | 
			
		||||
| 
						 | 
				
			
			@ -627,7 +701,10 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        app['Builds'].append(build)
 | 
			
		||||
        fdroidserver.metadata.write_yaml(mf, app)
 | 
			
		||||
        mf.seek(0)
 | 
			
		||||
        self.assertEqual(mf.read(), textwrap.dedent("""\
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            mf.read(),
 | 
			
		||||
            textwrap.dedent(
 | 
			
		||||
                """\
 | 
			
		||||
            Categories:
 | 
			
		||||
              - None
 | 
			
		||||
            License: Unknown
 | 
			
		||||
| 
						 | 
				
			
			@ -640,7 +717,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
            AutoUpdateMode: None
 | 
			
		||||
            UpdateCheckMode: None
 | 
			
		||||
            """))
 | 
			
		||||
            """
 | 
			
		||||
            ),
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_parse_yaml_srclib_unknown_key(self):
 | 
			
		||||
        fdroidserver.metadata.warnings_action = 'error'
 | 
			
		||||
| 
						 | 
				
			
			@ -685,7 +764,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        fdroidserver.metadata.warnings_action = 'error'
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            with open('simple.yml', 'w', encoding='utf-8') as f:
 | 
			
		||||
                f.write(textwrap.dedent('''\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        '''\
 | 
			
		||||
                    # this should be simple
 | 
			
		||||
 | 
			
		||||
                    RepoType: git
 | 
			
		||||
| 
						 | 
				
			
			@ -695,7 +776,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
                    Subdir:
 | 
			
		||||
 | 
			
		||||
                    Prepare:
 | 
			
		||||
                    '''))
 | 
			
		||||
                    '''
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            srclib = fdroidserver.metadata.parse_yaml_srclib('simple.yml')
 | 
			
		||||
            self.assertDictEqual({'Repo': 'https://git.host/repo.git',
 | 
			
		||||
                                  'RepoType': 'git',
 | 
			
		||||
| 
						 | 
				
			
			@ -707,13 +790,17 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        fdroidserver.metadata.warnings_action = 'error'
 | 
			
		||||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            with open('Changelog-cketti.yml', 'w', encoding='utf-8') as f:
 | 
			
		||||
                f.write(textwrap.dedent('''\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        '''\
 | 
			
		||||
                    RepoType: git
 | 
			
		||||
                    Repo: https://github.com/cketti/ckChangeLog
 | 
			
		||||
 | 
			
		||||
                    Subdir: library,ckChangeLog/src/main
 | 
			
		||||
                    Prepare: "[ -f project.properties ] || echo 'source.dir=java' > ant.properties && echo -e 'android.library=true\\\\ntarget=android-19' > project.properties"
 | 
			
		||||
                    '''))
 | 
			
		||||
                    '''
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            srclib = fdroidserver.metadata.parse_yaml_srclib('Changelog-cketti.yml')
 | 
			
		||||
            self.assertDictEqual(srclib,
 | 
			
		||||
                                 {'Repo': 'https://github.com/cketti/ckChangeLog',
 | 
			
		||||
| 
						 | 
				
			
			@ -729,7 +816,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            os.mkdir('srclibs')
 | 
			
		||||
            with open('srclibs/with-list.yml', 'w', encoding='utf-8') as f:
 | 
			
		||||
                f.write(textwrap.dedent('''\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        '''\
 | 
			
		||||
                    # this should be simple
 | 
			
		||||
                    RepoType: git
 | 
			
		||||
                    Repo: https://git.host/repo.git
 | 
			
		||||
| 
						 | 
				
			
			@ -745,7 +834,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
                    Prepare:
 | 
			
		||||
                        There is a difference between knowing the path
 | 
			
		||||
                        and walking the path.
 | 
			
		||||
                    '''))
 | 
			
		||||
                    '''
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            fdroidserver.metadata.read_srclibs()
 | 
			
		||||
        self.maxDiff = None
 | 
			
		||||
        self.assertDictEqual(fdroidserver.metadata.srclibs,
 | 
			
		||||
| 
						 | 
				
			
			@ -767,7 +858,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            os.mkdir('srclibs')
 | 
			
		||||
            with open('srclibs/with-list.yml', 'w', encoding='utf-8') as f:
 | 
			
		||||
                f.write(textwrap.dedent('''\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        '''\
 | 
			
		||||
                    # this should be simple
 | 
			
		||||
                    RepoType: git
 | 
			
		||||
                    Repo: https://git.host/repo.git
 | 
			
		||||
| 
						 | 
				
			
			@ -782,7 +875,9 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
                     - But until we do, these people are still a part of that system and that makes them our enemy.
 | 
			
		||||
                     - You have to understand, most of these people are not ready to be unplugged.
 | 
			
		||||
                     - And many of them are so inert, so hopelessly dependent on the system that they will fight to protect it.
 | 
			
		||||
                    '''))
 | 
			
		||||
                    '''
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            fdroidserver.metadata.read_srclibs()
 | 
			
		||||
        self.maxDiff = None
 | 
			
		||||
        self.assertDictEqual(fdroidserver.metadata.srclibs,
 | 
			
		||||
| 
						 | 
				
			
			@ -804,19 +899,27 @@ class MetadataTest(unittest.TestCase):
 | 
			
		|||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            os.mkdir('srclibs')
 | 
			
		||||
            with open('srclibs/simple.yml', 'w', encoding='utf-8') as f:
 | 
			
		||||
                f.write(textwrap.dedent('''\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        '''\
 | 
			
		||||
                    RepoType: git
 | 
			
		||||
                    Repo: https://git.host/repo.git
 | 
			
		||||
                    '''))
 | 
			
		||||
                    '''
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            with open('srclibs/simple-wb.yml', 'w', encoding='utf-8') as f:
 | 
			
		||||
                f.write(textwrap.dedent('''\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        '''\
 | 
			
		||||
                    # this should be simple
 | 
			
		||||
                    RepoType: git
 | 
			
		||||
                    Repo: https://git.host/repo.git
 | 
			
		||||
 | 
			
		||||
                    Subdir:
 | 
			
		||||
                    Prepare:
 | 
			
		||||
                    '''))
 | 
			
		||||
                    '''
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            fdroidserver.metadata.read_srclibs()
 | 
			
		||||
        self.assertDictEqual(fdroidserver.metadata.srclibs,
 | 
			
		||||
                             {'simple-wb': {'RepoType': 'git',
 | 
			
		||||
| 
						 | 
				
			
			@ -833,8 +936,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
 | 
			
		||||
    newSuite = unittest.TestSuite()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,7 +23,8 @@ import textwrap
 | 
			
		|||
from unittest import mock
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -56,8 +57,9 @@ class PublishTest(unittest.TestCase):
 | 
			
		|||
        self.assertEqual('ee8807d2', publish.key_alias("org.schabi.newpipe"))
 | 
			
		||||
        self.assertEqual('b53c7e11', publish.key_alias("de.grobox.liberario"))
 | 
			
		||||
 | 
			
		||||
        publish.config = {'keyaliases': {'yep.app': '@org.org.org',
 | 
			
		||||
                                         'com.example.app': '1a2b3c4d'}}
 | 
			
		||||
        publish.config = {
 | 
			
		||||
            'keyaliases': {'yep.app': '@org.org.org', 'com.example.app': '1a2b3c4d'}
 | 
			
		||||
        }
 | 
			
		||||
        self.assertEqual('78688a0f', publish.key_alias('yep.app'))
 | 
			
		||||
        self.assertEqual('1a2b3c4d', publish.key_alias('com.example.app'))
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -69,11 +71,13 @@ class PublishTest(unittest.TestCase):
 | 
			
		|||
        publish.config['keypass'] = '123456'
 | 
			
		||||
        publish.config['keystore'] = 'dummy-keystore.jks'
 | 
			
		||||
 | 
			
		||||
        expected = {'78688a0f': '277655a6235bc6b0ef2d824396c51ba947f5ebc738c293d887e7083ff338af82',
 | 
			
		||||
                    'd2d51ff2': 'fa3f6a017541ee7fe797be084b1bcfbf92418a7589ef1f7fdeb46741b6d2e9c3',
 | 
			
		||||
                    'dc3b169e': '6ae5355157a47ddcc3834a71f57f6fb5a8c2621c8e0dc739e9ddf59f865e497c',
 | 
			
		||||
                    'a163ec9b': 'd34f678afbaa8f2fa6cc0edd6f0c2d1d2e2e9eb08bea521b24c740806016bff4',
 | 
			
		||||
                    'repokey': 'c58460800c7b250a619c30c13b07b7359a43e5af71a4352d86c58ae18c9f6d41'}
 | 
			
		||||
        expected = {
 | 
			
		||||
            '78688a0f': '277655a6235bc6b0ef2d824396c51ba947f5ebc738c293d887e7083ff338af82',
 | 
			
		||||
            'd2d51ff2': 'fa3f6a017541ee7fe797be084b1bcfbf92418a7589ef1f7fdeb46741b6d2e9c3',
 | 
			
		||||
            'dc3b169e': '6ae5355157a47ddcc3834a71f57f6fb5a8c2621c8e0dc739e9ddf59f865e497c',
 | 
			
		||||
            'a163ec9b': 'd34f678afbaa8f2fa6cc0edd6f0c2d1d2e2e9eb08bea521b24c740806016bff4',
 | 
			
		||||
            'repokey': 'c58460800c7b250a619c30c13b07b7359a43e5af71a4352d86c58ae18c9f6d41',
 | 
			
		||||
        }
 | 
			
		||||
        result = publish.read_fingerprints_from_keystore()
 | 
			
		||||
        self.maxDiff = None
 | 
			
		||||
        self.assertEqual(expected, result)
 | 
			
		||||
| 
						 | 
				
			
			@ -84,17 +88,20 @@ class PublishTest(unittest.TestCase):
 | 
			
		|||
        publish.config = common.config
 | 
			
		||||
        publish.config['keystorepass'] = '123456'
 | 
			
		||||
        publish.config['keypass'] = '123456'
 | 
			
		||||
        publish.config['keystore'] = os.path.join(os.getcwd(),
 | 
			
		||||
                                                  'dummy-keystore.jks')
 | 
			
		||||
        publish.config['keystore'] = os.path.join(os.getcwd(), 'dummy-keystore.jks')
 | 
			
		||||
        publish.config['repo_keyalias'] = 'repokey'
 | 
			
		||||
 | 
			
		||||
        appids = ['com.example.app',
 | 
			
		||||
                  'net.unavailable',
 | 
			
		||||
                  'org.test.testy',
 | 
			
		||||
                  'com.example.anotherapp',
 | 
			
		||||
                  'org.org.org']
 | 
			
		||||
        appids = [
 | 
			
		||||
            'com.example.app',
 | 
			
		||||
            'net.unavailable',
 | 
			
		||||
            'org.test.testy',
 | 
			
		||||
            'com.example.anotherapp',
 | 
			
		||||
            'org.org.org',
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        with open('config.py', 'w') as f:
 | 
			
		||||
            pass
 | 
			
		||||
| 
						 | 
				
			
			@ -114,15 +121,20 @@ class PublishTest(unittest.TestCase):
 | 
			
		|||
            },
 | 
			
		||||
            "org.test.testy": {
 | 
			
		||||
                "signer": "6ae5355157a47ddcc3834a71f57f6fb5a8c2621c8e0dc739e9ddf59f865e497c"
 | 
			
		||||
            }
 | 
			
		||||
            },
 | 
			
		||||
        }
 | 
			
		||||
        self.assertEqual(expected, common.load_stats_fdroid_signing_key_fingerprints())
 | 
			
		||||
 | 
			
		||||
        with open('config.py', 'r') as f:
 | 
			
		||||
            self.assertEqual(textwrap.dedent('''\
 | 
			
		||||
            self.assertEqual(
 | 
			
		||||
                textwrap.dedent(
 | 
			
		||||
                    '''\
 | 
			
		||||
 | 
			
		||||
                repo_key_sha256 = "c58460800c7b250a619c30c13b07b7359a43e5af71a4352d86c58ae18c9f6d41"
 | 
			
		||||
                '''), f.read())
 | 
			
		||||
                '''
 | 
			
		||||
                ),
 | 
			
		||||
                f.read(),
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    def test_store_and_load_fdroid_signing_key_fingerprints_with_missmatch(self):
 | 
			
		||||
        common.config = {}
 | 
			
		||||
| 
						 | 
				
			
			@ -130,12 +142,13 @@ class PublishTest(unittest.TestCase):
 | 
			
		|||
        publish.config = common.config
 | 
			
		||||
        publish.config['keystorepass'] = '123456'
 | 
			
		||||
        publish.config['keypass'] = '123456'
 | 
			
		||||
        publish.config['keystore'] = os.path.join(os.getcwd(),
 | 
			
		||||
                                                  'dummy-keystore.jks')
 | 
			
		||||
        publish.config['keystore'] = os.path.join(os.getcwd(), 'dummy-keystore.jks')
 | 
			
		||||
        publish.config['repo_keyalias'] = 'repokey'
 | 
			
		||||
        publish.config['repo_key_sha256'] = 'bad bad bad bad bad bad bad bad bad bad bad bad'
 | 
			
		||||
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        publish.store_stats_fdroid_signing_key_fingerprints({}, indent=2)
 | 
			
		||||
        with self.assertRaises(FDroidException):
 | 
			
		||||
| 
						 | 
				
			
			@ -149,7 +162,9 @@ class PublishTest(unittest.TestCase):
 | 
			
		|||
        publish.config['repo_keyalias'] = 'sova'
 | 
			
		||||
        publish.config['keystorepass'] = 'r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI='
 | 
			
		||||
        publish.config['keypass'] = 'r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI='
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        shutil.copy('keystore.jks', testdir)
 | 
			
		||||
        os.mkdir(os.path.join(testdir, 'repo'))
 | 
			
		||||
| 
						 | 
				
			
			@ -170,6 +185,7 @@ class PublishTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_check_for_key_collisions(self):
 | 
			
		||||
        from fdroidserver.metadata import App
 | 
			
		||||
 | 
			
		||||
        common.config = {}
 | 
			
		||||
        common.fill_config_defaults(common.config)
 | 
			
		||||
        publish.config = common.config
 | 
			
		||||
| 
						 | 
				
			
			@ -253,11 +269,12 @@ class PublishTest(unittest.TestCase):
 | 
			
		|||
                self.assertEqual(publish.config['keytool'], data['keytool'])
 | 
			
		||||
 | 
			
		||||
    def test_sign_then_implant_signature(self):
 | 
			
		||||
 | 
			
		||||
        class Options:
 | 
			
		||||
            verbose = False
 | 
			
		||||
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
 | 
			
		||||
        config = common.read_config(Options)
 | 
			
		||||
| 
						 | 
				
			
			@ -322,8 +339,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (common.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
 | 
			
		||||
    newSuite = unittest.TestSuite()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,7 +12,8 @@ from unittest import mock
 | 
			
		|||
from testcommon import TmpCwd
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -47,24 +48,34 @@ class RewriteMetaTest(unittest.TestCase):
 | 
			
		|||
            rewritemeta.main()
 | 
			
		||||
 | 
			
		||||
            with open('metadata/a.yml') as f:
 | 
			
		||||
                self.assertEqual(f.read(), textwrap.dedent('''\
 | 
			
		||||
                self.assertEqual(
 | 
			
		||||
                    f.read(),
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        '''\
 | 
			
		||||
                    License: Unknown
 | 
			
		||||
 | 
			
		||||
                    AutoName: a
 | 
			
		||||
 | 
			
		||||
                    AutoUpdateMode: None
 | 
			
		||||
                    UpdateCheckMode: None
 | 
			
		||||
                    '''))
 | 
			
		||||
                    '''
 | 
			
		||||
                    ),
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
            with open('metadata/b.yml') as f:
 | 
			
		||||
                self.assertEqual(f.read(), textwrap.dedent('''\
 | 
			
		||||
                self.assertEqual(
 | 
			
		||||
                    f.read(),
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        '''\
 | 
			
		||||
                    License: Unknown
 | 
			
		||||
 | 
			
		||||
                    AutoName: b
 | 
			
		||||
 | 
			
		||||
                    AutoUpdateMode: None
 | 
			
		||||
                    UpdateCheckMode: None
 | 
			
		||||
                    '''))
 | 
			
		||||
                    '''
 | 
			
		||||
                    ),
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
    def test_rewrite_scenario_yml_no_ruamel(self):
 | 
			
		||||
        sys.argv = ['rewritemeta', 'a']
 | 
			
		||||
| 
						 | 
				
			
			@ -81,16 +92,26 @@ class RewriteMetaTest(unittest.TestCase):
 | 
			
		|||
                    rewritemeta.main()
 | 
			
		||||
 | 
			
		||||
            with open('metadata/a.yml') as f:
 | 
			
		||||
                self.assertEqual(f.read(), textwrap.dedent('''\
 | 
			
		||||
                    AutoName: a'''))
 | 
			
		||||
                self.assertEqual(
 | 
			
		||||
                    f.read(),
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        '''\
 | 
			
		||||
                    AutoName: a'''
 | 
			
		||||
                    ),
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (common.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
 | 
			
		||||
    newSuite = unittest.TestSuite()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,7 +15,8 @@ import yaml
 | 
			
		|||
from unittest import mock
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -27,7 +28,6 @@ import fdroidserver.scanner
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
class ScannerTest(unittest.TestCase):
 | 
			
		||||
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        logging.basicConfig(level=logging.INFO)
 | 
			
		||||
        self.basedir = os.path.join(localmodule, 'tests')
 | 
			
		||||
| 
						 | 
				
			
			@ -53,8 +53,9 @@ class ScannerTest(unittest.TestCase):
 | 
			
		|||
            build = fdroidserver.metadata.Build()
 | 
			
		||||
            fatal_problems = fdroidserver.scanner.scan_source(d, build)
 | 
			
		||||
            should = projects.get(os.path.basename(d), 0)
 | 
			
		||||
            self.assertEqual(should, fatal_problems,
 | 
			
		||||
                             "%s should have %d errors!" % (d, should))
 | 
			
		||||
            self.assertEqual(
 | 
			
		||||
                should, fatal_problems, "%s should have %d errors!" % (d, should)
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    def test_get_gradle_compile_commands(self):
 | 
			
		||||
        test_files = [
 | 
			
		||||
| 
						 | 
				
			
			@ -85,13 +86,17 @@ class ScannerTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_scan_source_files_sneaky_maven(self):
 | 
			
		||||
        """Check for sneaking in banned maven repos"""
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        fdroidserver.scanner.config = None
 | 
			
		||||
        fdroidserver.scanner.options = mock.Mock()
 | 
			
		||||
        fdroidserver.scanner.options.json = True
 | 
			
		||||
        with open('build.gradle', 'w') as fp:
 | 
			
		||||
            fp.write(textwrap.dedent("""
 | 
			
		||||
            fp.write(
 | 
			
		||||
                textwrap.dedent(
 | 
			
		||||
                    """
 | 
			
		||||
                 maven {
 | 
			
		||||
                    "https://jitpack.io"
 | 
			
		||||
                    url 'https://maven.fabric.io/public'
 | 
			
		||||
| 
						 | 
				
			
			@ -100,7 +105,9 @@ class ScannerTest(unittest.TestCase):
 | 
			
		|||
                    "https://maven.google.com"
 | 
			
		||||
                    setUrl('https://evilcorp.com/maven')
 | 
			
		||||
                 }
 | 
			
		||||
            """))
 | 
			
		||||
            """
 | 
			
		||||
                )
 | 
			
		||||
            )
 | 
			
		||||
        count = fdroidserver.scanner.scan_source(testdir)
 | 
			
		||||
        self.assertEqual(2, count, 'there should be this many errors')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -111,7 +118,9 @@ class ScannerTest(unittest.TestCase):
 | 
			
		|||
        difference between absolute and relative paths.
 | 
			
		||||
 | 
			
		||||
        """
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        build_dir = os.path.join('build', 'fake.app')
 | 
			
		||||
        abs_build_dir = os.path.join(testdir, build_dir)
 | 
			
		||||
        os.makedirs(abs_build_dir, exist_ok=True)
 | 
			
		||||
| 
						 | 
				
			
			@ -130,21 +139,13 @@ class ScannerTest(unittest.TestCase):
 | 
			
		|||
            'static.a',
 | 
			
		||||
            'src/test/resources/classes.dex',
 | 
			
		||||
        ]
 | 
			
		||||
        remove = [
 | 
			
		||||
            'gradle-wrapper.jar',
 | 
			
		||||
            'gradlew',
 | 
			
		||||
            'gradlew.bat',
 | 
			
		||||
        ]
 | 
			
		||||
        remove = ['gradle-wrapper.jar', 'gradlew', 'gradlew.bat']
 | 
			
		||||
        os.makedirs('src/test/resources', exist_ok=True)
 | 
			
		||||
        for f in keep + remove:
 | 
			
		||||
            with open(f, 'w') as fp:
 | 
			
		||||
                fp.write('placeholder')
 | 
			
		||||
            self.assertTrue(os.path.exists(f))
 | 
			
		||||
        binaries = [
 | 
			
		||||
            'binary.out',
 | 
			
		||||
            'fake.png',
 | 
			
		||||
            'snippet.png',
 | 
			
		||||
        ]
 | 
			
		||||
        binaries = ['binary.out', 'fake.png', 'snippet.png']
 | 
			
		||||
        with open('binary.out', 'wb') as fp:
 | 
			
		||||
            fp.write(b'\x00\x00')
 | 
			
		||||
            fp.write(uuid.uuid4().bytes)
 | 
			
		||||
| 
						 | 
				
			
			@ -152,10 +153,12 @@ class ScannerTest(unittest.TestCase):
 | 
			
		|||
        os.chmod('fake.png', 0o755)
 | 
			
		||||
        os.system('ls -l binary.out')
 | 
			
		||||
        with open('snippet.png', 'wb') as fp:
 | 
			
		||||
            fp.write(b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x000\x00\x00'
 | 
			
		||||
                     b'\x000\x08\x06\x00\x00\x00W\x02\xf9\x87\x00\x00\x00\x04sB'
 | 
			
		||||
                     b'IT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00\tpHYs\x00\x00\n'
 | 
			
		||||
                     b'a\x00\x00\na\x01\xfc\xccJ%\x00\x00\x00\x19tEXtSoftware')
 | 
			
		||||
            fp.write(
 | 
			
		||||
                b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x000\x00\x00'
 | 
			
		||||
                b'\x000\x08\x06\x00\x00\x00W\x02\xf9\x87\x00\x00\x00\x04sB'
 | 
			
		||||
                b'IT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00\tpHYs\x00\x00\n'
 | 
			
		||||
                b'a\x00\x00\na\x01\xfc\xccJ%\x00\x00\x00\x19tEXtSoftware'
 | 
			
		||||
            )
 | 
			
		||||
        os.chmod('snippet.png', 0o755)
 | 
			
		||||
        os.system('ls -l fake.png')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -199,7 +202,9 @@ class ScannerTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_build_local_scanner(self):
 | 
			
		||||
        """`fdroid build` calls scanner functions, test them here"""
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
 | 
			
		||||
        config = dict()
 | 
			
		||||
| 
						 | 
				
			
			@ -229,12 +234,15 @@ class ScannerTest(unittest.TestCase):
 | 
			
		|||
            self.assertTrue(os.path.exists(f))
 | 
			
		||||
 | 
			
		||||
        with open('build.xml', 'w') as fp:
 | 
			
		||||
            fp.write(textwrap.dedent(
 | 
			
		||||
                """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 | 
			
		||||
            fp.write(
 | 
			
		||||
                textwrap.dedent(
 | 
			
		||||
                    """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 | 
			
		||||
                <project basedir="." default="clean" name="mockapp">
 | 
			
		||||
                <target name="release"/>
 | 
			
		||||
                <target name="clean"/>
 | 
			
		||||
                </project>"""))
 | 
			
		||||
                </project>"""
 | 
			
		||||
                )
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        def make_fake_apk(output, build):
 | 
			
		||||
            with open(build.output, 'w') as fp:
 | 
			
		||||
| 
						 | 
				
			
			@ -272,21 +280,27 @@ class ScannerTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_scan_gradle_file_with_multiple_problems(self):
 | 
			
		||||
        """Check that the scanner can handle scandelete with gradle files with multiple problems"""
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        fdroidserver.scanner.config = None
 | 
			
		||||
        fdroidserver.scanner.options = mock.Mock()
 | 
			
		||||
        build = fdroidserver.metadata.Build()
 | 
			
		||||
        build.scandelete = ['build.gradle']
 | 
			
		||||
        with open('build.gradle', 'w') as fp:
 | 
			
		||||
            fp.write(textwrap.dedent("""
 | 
			
		||||
            fp.write(
 | 
			
		||||
                textwrap.dedent(
 | 
			
		||||
                    """
 | 
			
		||||
                 maven {
 | 
			
		||||
                    url 'https://maven.fabric.io/public'
 | 
			
		||||
                 }
 | 
			
		||||
                 maven {
 | 
			
		||||
                    url 'https://evilcorp.com/maven'
 | 
			
		||||
                 }
 | 
			
		||||
            """))
 | 
			
		||||
            """
 | 
			
		||||
                )
 | 
			
		||||
            )
 | 
			
		||||
        count = fdroidserver.scanner.scan_source(testdir, build)
 | 
			
		||||
        self.assertFalse(os.path.exists("build.gradle"))
 | 
			
		||||
        self.assertEqual(0, count, 'there should be this many errors')
 | 
			
		||||
| 
						 | 
				
			
			@ -296,8 +310,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
 | 
			
		||||
    newSuite = unittest.TestSuite()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,7 +10,8 @@ import logging
 | 
			
		|||
from tempfile import TemporaryDirectory
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -20,7 +21,6 @@ from fdroidserver import common, signatures
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
class SignaturesTest(unittest.TestCase):
 | 
			
		||||
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        logging.basicConfig(level=logging.DEBUG)
 | 
			
		||||
        common.config = None
 | 
			
		||||
| 
						 | 
				
			
			@ -60,8 +60,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (common.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
 | 
			
		||||
    newSuite = unittest.TestSuite()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -43,7 +43,8 @@ except ImportError:
 | 
			
		|||
        from yaml import Loader as FullLoader
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -55,11 +56,7 @@ import fdroidserver.update
 | 
			
		|||
from fdroidserver.common import FDroidPopen
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
DONATION_FIELDS = (
 | 
			
		||||
    'Donate',
 | 
			
		||||
    'Liberapay',
 | 
			
		||||
    'OpenCollective',
 | 
			
		||||
)
 | 
			
		||||
DONATION_FIELDS = ('Donate', 'Liberapay', 'OpenCollective')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Options:
 | 
			
		||||
| 
						 | 
				
			
			@ -77,6 +74,7 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
        logging.getLogger('androguard.axml').setLevel(logging.INFO)
 | 
			
		||||
        logging.getLogger('androguard.core.api_specific_resources').setLevel(logging.INFO)
 | 
			
		||||
        from PIL import PngImagePlugin
 | 
			
		||||
 | 
			
		||||
        logging.getLogger(PngImagePlugin.__name__).setLevel(logging.INFO)
 | 
			
		||||
        self.basedir = os.path.join(localmodule, 'tests')
 | 
			
		||||
        self.tmpdir = os.path.abspath(os.path.join(self.basedir, '..', '.testfiles'))
 | 
			
		||||
| 
						 | 
				
			
			@ -114,12 +112,17 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
        shutil.copystat(testfile, cpfile)
 | 
			
		||||
 | 
			
		||||
        apps = dict()
 | 
			
		||||
        for packageName in ('info.guardianproject.urzip', 'org.videolan.vlc', 'obb.mainpatch.current',
 | 
			
		||||
                            'com.nextcloud.client', 'com.nextcloud.client.dev',
 | 
			
		||||
                            'eu.siacs.conversations'):
 | 
			
		||||
        for packageName in (
 | 
			
		||||
            'info.guardianproject.urzip',
 | 
			
		||||
            'org.videolan.vlc',
 | 
			
		||||
            'obb.mainpatch.current',
 | 
			
		||||
            'com.nextcloud.client',
 | 
			
		||||
            'com.nextcloud.client.dev',
 | 
			
		||||
            'eu.siacs.conversations',
 | 
			
		||||
        ):
 | 
			
		||||
            apps[packageName] = fdroidserver.metadata.App()
 | 
			
		||||
            apps[packageName]['id'] = packageName
 | 
			
		||||
            apps[packageName]['CurrentVersionCode'] = 0xcafebeef
 | 
			
		||||
            apps[packageName]['CurrentVersionCode'] = 0xCAFEBEEF
 | 
			
		||||
 | 
			
		||||
        apps['info.guardianproject.urzip']['CurrentVersionCode'] = 100
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -286,7 +289,7 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
        appid = 'info.guardianproject.checkey'
 | 
			
		||||
        testapps = {appid: copy.copy(apps[appid])}
 | 
			
		||||
        self.assertEqual('Checkey the app!', testapps[appid]['Name'])
 | 
			
		||||
        del(testapps[appid]['Name'])
 | 
			
		||||
        del (testapps[appid]['Name'])
 | 
			
		||||
        fdroidserver.update.insert_missing_app_names_from_apks(testapps, apks)
 | 
			
		||||
        self.assertIsNone(testapps[appid].get('Name'))
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -367,8 +370,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_insert_triple_t_2_metadata(self):
 | 
			
		||||
        packageName = 'org.piwigo.android'
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
 | 
			
		||||
                                       dir=self.tmpdir)
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.rmdir(tmptestsdir)
 | 
			
		||||
        shutil.copytree(os.path.join(self.basedir, 'triple-t-2'), tmptestsdir)
 | 
			
		||||
        os.chdir(tmptestsdir)
 | 
			
		||||
| 
						 | 
				
			
			@ -414,8 +418,7 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
        config = dict()
 | 
			
		||||
        fdroidserver.common.fill_config_defaults(config)
 | 
			
		||||
        fdroidserver.common.config = config
 | 
			
		||||
        p = FDroidPopen(['java', '-cp', 'getsig',
 | 
			
		||||
                         'getsig', apkfile])
 | 
			
		||||
        p = FDroidPopen(['java', '-cp', 'getsig', 'getsig', apkfile])
 | 
			
		||||
        sig = None
 | 
			
		||||
        for line in p.output.splitlines():
 | 
			
		||||
            if line.startswith('Result:'):
 | 
			
		||||
| 
						 | 
				
			
			@ -509,7 +512,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def testScanApksAndObbs(self):
 | 
			
		||||
        os.chdir(os.path.join(localmodule, 'tests'))
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        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, 'metadata'), 'metadata')
 | 
			
		||||
| 
						 | 
				
			
			@ -567,7 +572,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
    def test_apkcache_json(self):
 | 
			
		||||
        """test the migration from pickle to json"""
 | 
			
		||||
        os.chdir(os.path.join(localmodule, 'tests'))
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        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')
 | 
			
		||||
        config = dict()
 | 
			
		||||
| 
						 | 
				
			
			@ -608,7 +615,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
        fdroidserver.common.config = config
 | 
			
		||||
        fdroidserver.update.config = config
 | 
			
		||||
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        os.mkdir('repo')
 | 
			
		||||
        os.mkdir('stats')
 | 
			
		||||
| 
						 | 
				
			
			@ -625,8 +634,10 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
        self.assertEqual(filename, info['apkName'])
 | 
			
		||||
        self.assertEqual(datetime, type(info['added']))
 | 
			
		||||
        self.assertEqual(os.path.getsize(os.path.join('repo', filename)), info['size'])
 | 
			
		||||
        self.assertEqual('531190bdbc07e77d5577249949106f32dac7f62d38d66d66c3ae058be53a729d',
 | 
			
		||||
                         info['hash'])
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            '531190bdbc07e77d5577249949106f32dac7f62d38d66d66c3ae058be53a729d',
 | 
			
		||||
            info['hash'],
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_read_added_date_from_all_apks(self):
 | 
			
		||||
        config = dict()
 | 
			
		||||
| 
						 | 
				
			
			@ -770,7 +781,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
        fdroidserver.common.fill_config_defaults(config)
 | 
			
		||||
        fdroidserver.common.config = config
 | 
			
		||||
        fdroidserver.update.config = config
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        os.mkdir('repo')
 | 
			
		||||
        apkfile = 'repo/badzip_1.apk'
 | 
			
		||||
| 
						 | 
				
			
			@ -780,7 +793,6 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
            fdroidserver.update.scan_apk(apkfile)
 | 
			
		||||
 | 
			
		||||
    def test_process_apk(self):
 | 
			
		||||
 | 
			
		||||
        def _build_yaml_representer(dumper, data):
 | 
			
		||||
            '''Creates a YAML representation of a Build instance'''
 | 
			
		||||
            return dumper.represent_dict(data)
 | 
			
		||||
| 
						 | 
				
			
			@ -820,8 +832,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
            if apkName == '../org.dyndns.fules.ck_20.apk':
 | 
			
		||||
                self.assertEqual(apk['icon'], 'org.dyndns.fules.ck.20.png')
 | 
			
		||||
            for density in fdroidserver.update.screen_densities:
 | 
			
		||||
                icon_path = os.path.join(fdroidserver.update.get_icon_dir('repo', density),
 | 
			
		||||
                                         apk['icon'])
 | 
			
		||||
                icon_path = os.path.join(
 | 
			
		||||
                    fdroidserver.update.get_icon_dir('repo', density), apk['icon']
 | 
			
		||||
                )
 | 
			
		||||
                self.assertTrue(os.path.isfile(icon_path))
 | 
			
		||||
                self.assertTrue(os.path.getsize(icon_path) > 1)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -863,8 +876,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
        knownapks = fdroidserver.common.KnownApks()
 | 
			
		||||
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
 | 
			
		||||
                                       dir=self.tmpdir)
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        print('tmptestsdir', tmptestsdir)
 | 
			
		||||
        os.chdir(tmptestsdir)
 | 
			
		||||
        os.mkdir('repo')
 | 
			
		||||
| 
						 | 
				
			
			@ -873,7 +887,7 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
        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:
 | 
			
		||||
            shutil.copy(os.path.join(self.basedir, apkName),
 | 
			
		||||
                        os.path.join(tmptestsdir, 'repo'))
 | 
			
		||||
| 
						 | 
				
			
			@ -964,7 +978,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_translate_per_build_anti_features(self):
 | 
			
		||||
        os.chdir(os.path.join(localmodule, 'tests'))
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        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, 'metadata'), 'metadata')
 | 
			
		||||
| 
						 | 
				
			
			@ -995,8 +1011,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
        self.assertTrue(foundtest)
 | 
			
		||||
 | 
			
		||||
    def test_create_metadata_from_template(self):
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
 | 
			
		||||
                                       dir=self.tmpdir)
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        print('tmptestsdir', tmptestsdir)
 | 
			
		||||
        os.chdir(tmptestsdir)
 | 
			
		||||
        os.mkdir('repo')
 | 
			
		||||
| 
						 | 
				
			
			@ -1097,8 +1114,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
        assert icons_src == {}
 | 
			
		||||
 | 
			
		||||
    def test_strip_and_copy_image(self):
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
 | 
			
		||||
                                       dir=self.tmpdir)
 | 
			
		||||
        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')
 | 
			
		||||
        out_file = os.path.join(tmptestsdir, 'icon.png')
 | 
			
		||||
| 
						 | 
				
			
			@ -1115,7 +1133,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
 | 
			
		||||
            os.mkdir('metadata')
 | 
			
		||||
            with open('template.yml', 'w') as f:
 | 
			
		||||
                f.write(textwrap.dedent('''\
 | 
			
		||||
                f.write(
 | 
			
		||||
                    textwrap.dedent(
 | 
			
		||||
                        '''\
 | 
			
		||||
                    Disabled:
 | 
			
		||||
                    License:
 | 
			
		||||
                    AuthorName:
 | 
			
		||||
| 
						 | 
				
			
			@ -1149,51 +1169,60 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
                    CurrentVersion:
 | 
			
		||||
                    CurrentVersionCode:
 | 
			
		||||
                    NoSourceSince:
 | 
			
		||||
                    '''))
 | 
			
		||||
                    '''
 | 
			
		||||
                    )
 | 
			
		||||
                )
 | 
			
		||||
            fdroidserver.update.create_metadata_from_template(apk)
 | 
			
		||||
            with open(os.path.join('metadata', 'rocks.janicerand.yml')) as f:
 | 
			
		||||
                metadata_content = yaml.load(f, Loader=SafeLoader)
 | 
			
		||||
                self.maxDiff = None
 | 
			
		||||
                self.assertDictEqual(metadata_content,
 | 
			
		||||
                                     {'ArchivePolicy': '',
 | 
			
		||||
                                      'AuthorEmail': '',
 | 
			
		||||
                                      'AuthorName': '',
 | 
			
		||||
                                      'AuthorWebSite': '',
 | 
			
		||||
                                      'AutoName': 'rocks.janicerand',
 | 
			
		||||
                                      'AutoUpdateMode': '',
 | 
			
		||||
                                      'Binaries': '',
 | 
			
		||||
                                      'Bitcoin': '',
 | 
			
		||||
                                      'Builds': '',
 | 
			
		||||
                                      'Changelog': '',
 | 
			
		||||
                                      'CurrentVersion': '',
 | 
			
		||||
                                      'CurrentVersionCode': '',
 | 
			
		||||
                                      'Disabled': '',
 | 
			
		||||
                                      'Donate': '',
 | 
			
		||||
                                      'FlattrID': '',
 | 
			
		||||
                                      'IssueTracker': '',
 | 
			
		||||
                                      'LiberapayID': '',
 | 
			
		||||
                                      'License': '',
 | 
			
		||||
                                      'Litecoin': '',
 | 
			
		||||
                                      'Name': 'rocks.janicerand',
 | 
			
		||||
                                      'NoSourceSince': '',
 | 
			
		||||
                                      'Repo': '',
 | 
			
		||||
                                      'RepoType': '',
 | 
			
		||||
                                      'RequiresRoot': '',
 | 
			
		||||
                                      'SourceCode': '',
 | 
			
		||||
                                      'Summary': 'rocks.janicerand',
 | 
			
		||||
                                      'Translation': '',
 | 
			
		||||
                                      'UpdateCheckData': '',
 | 
			
		||||
                                      'UpdateCheckIgnore': '',
 | 
			
		||||
                                      'UpdateCheckMode': '',
 | 
			
		||||
                                      'UpdateCheckName': '',
 | 
			
		||||
                                      'VercodeOperation': '',
 | 
			
		||||
                                      'WebSite': ''})
 | 
			
		||||
                self.assertDictEqual(
 | 
			
		||||
                    metadata_content,
 | 
			
		||||
                    {
 | 
			
		||||
                        'ArchivePolicy': '',
 | 
			
		||||
                        'AuthorEmail': '',
 | 
			
		||||
                        'AuthorName': '',
 | 
			
		||||
                        'AuthorWebSite': '',
 | 
			
		||||
                        'AutoName': 'rocks.janicerand',
 | 
			
		||||
                        'AutoUpdateMode': '',
 | 
			
		||||
                        'Binaries': '',
 | 
			
		||||
                        'Bitcoin': '',
 | 
			
		||||
                        'Builds': '',
 | 
			
		||||
                        'Changelog': '',
 | 
			
		||||
                        'CurrentVersion': '',
 | 
			
		||||
                        'CurrentVersionCode': '',
 | 
			
		||||
                        'Disabled': '',
 | 
			
		||||
                        'Donate': '',
 | 
			
		||||
                        'FlattrID': '',
 | 
			
		||||
                        'IssueTracker': '',
 | 
			
		||||
                        'LiberapayID': '',
 | 
			
		||||
                        'License': '',
 | 
			
		||||
                        'Litecoin': '',
 | 
			
		||||
                        'Name': 'rocks.janicerand',
 | 
			
		||||
                        'NoSourceSince': '',
 | 
			
		||||
                        'Repo': '',
 | 
			
		||||
                        'RepoType': '',
 | 
			
		||||
                        'RequiresRoot': '',
 | 
			
		||||
                        'SourceCode': '',
 | 
			
		||||
                        'Summary': 'rocks.janicerand',
 | 
			
		||||
                        'Translation': '',
 | 
			
		||||
                        'UpdateCheckData': '',
 | 
			
		||||
                        'UpdateCheckIgnore': '',
 | 
			
		||||
                        'UpdateCheckMode': '',
 | 
			
		||||
                        'UpdateCheckName': '',
 | 
			
		||||
                        'VercodeOperation': '',
 | 
			
		||||
                        'WebSite': '',
 | 
			
		||||
                    },
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
    def test_insert_funding_yml_donation_links(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        os.mkdir('build')
 | 
			
		||||
        content = textwrap.dedent("""
 | 
			
		||||
        content = textwrap.dedent(
 | 
			
		||||
            """
 | 
			
		||||
            community_bridge: ''
 | 
			
		||||
            custom: [LINK1, LINK2]
 | 
			
		||||
            github: USERNAME
 | 
			
		||||
| 
						 | 
				
			
			@ -1203,7 +1232,8 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
            open_collective: USERNAME
 | 
			
		||||
            otechie: USERNAME
 | 
			
		||||
            patreon: USERNAME
 | 
			
		||||
        """)
 | 
			
		||||
        """
 | 
			
		||||
        )
 | 
			
		||||
        app = fdroidserver.metadata.App()
 | 
			
		||||
        app.id = 'fake.app.id'
 | 
			
		||||
        apps = {app.id: app}
 | 
			
		||||
| 
						 | 
				
			
			@ -1230,7 +1260,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
 | 
			
		||||
    def test_insert_funding_yml_donation_links_one_at_a_time(self):
 | 
			
		||||
        """Exercise the FUNDING.yml code one entry at a time"""
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        os.mkdir('build')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1242,7 +1274,8 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
        for field in DONATION_FIELDS:
 | 
			
		||||
            self.assertIsNone(app.get(field))
 | 
			
		||||
 | 
			
		||||
        content = textwrap.dedent("""
 | 
			
		||||
        content = textwrap.dedent(
 | 
			
		||||
            """
 | 
			
		||||
            community_bridge: 'blah-de-blah'
 | 
			
		||||
            github: USERNAME
 | 
			
		||||
            issuehunt: USERNAME
 | 
			
		||||
| 
						 | 
				
			
			@ -1250,7 +1283,8 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
            liberapay: USERNAME
 | 
			
		||||
            open_collective: USERNAME
 | 
			
		||||
            patreon: USERNAME
 | 
			
		||||
        """)
 | 
			
		||||
        """
 | 
			
		||||
        )
 | 
			
		||||
        for line in content.split('\n'):
 | 
			
		||||
            if not line:
 | 
			
		||||
                continue
 | 
			
		||||
| 
						 | 
				
			
			@ -1270,7 +1304,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
                    self.assertEqual(app.get('Donate', '').split('/')[-1], v)
 | 
			
		||||
 | 
			
		||||
    def test_insert_funding_yml_donation_links_with_corrupt_file(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        os.mkdir('build')
 | 
			
		||||
        app = fdroidserver.metadata.App()
 | 
			
		||||
| 
						 | 
				
			
			@ -1278,11 +1314,15 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
        apps = {app.id: app}
 | 
			
		||||
        os.mkdir(os.path.join('build', app.id))
 | 
			
		||||
        with open(os.path.join('build', app.id, 'FUNDING.yml'), 'w') as fp:
 | 
			
		||||
            fp.write(textwrap.dedent("""
 | 
			
		||||
            fp.write(
 | 
			
		||||
                textwrap.dedent(
 | 
			
		||||
                    """
 | 
			
		||||
                opencollective: foo
 | 
			
		||||
                custom: []
 | 
			
		||||
                liberapay: :
 | 
			
		||||
            """))
 | 
			
		||||
            """
 | 
			
		||||
                )
 | 
			
		||||
            )
 | 
			
		||||
        fdroidserver.update.insert_funding_yml_donation_links(apps)
 | 
			
		||||
        for field in DONATION_FIELDS:
 | 
			
		||||
            self.assertIsNone(app.get(field))
 | 
			
		||||
| 
						 | 
				
			
			@ -1311,8 +1351,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
        self.assertIsNotNone(fdroidserver.update.sanitize_funding_yml_entry(['first', 'second']))
 | 
			
		||||
 | 
			
		||||
    def test_set_localized_text_entry(self):
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
 | 
			
		||||
                                       dir=self.tmpdir)
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(tmptestsdir)
 | 
			
		||||
        config = dict()
 | 
			
		||||
        fdroidserver.common.fill_config_defaults(config)
 | 
			
		||||
| 
						 | 
				
			
			@ -1342,8 +1383,9 @@ class UpdateTest(unittest.TestCase):
 | 
			
		|||
            self.assertIsNone(app['localized'].get(locale, {}).get(key))
 | 
			
		||||
 | 
			
		||||
    def test_set_author_entry(self):
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name,
 | 
			
		||||
                                       dir=self.tmpdir)
 | 
			
		||||
        tmptestsdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(tmptestsdir)
 | 
			
		||||
        config = dict()
 | 
			
		||||
        fdroidserver.common.fill_config_defaults(config)
 | 
			
		||||
| 
						 | 
				
			
			@ -1411,8 +1453,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
 | 
			
		||||
    newSuite = unittest.TestSuite()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,8 @@ import unittest
 | 
			
		|||
from git import Repo
 | 
			
		||||
 | 
			
		||||
localmodule = os.path.realpath(
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
 | 
			
		||||
    os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
 | 
			
		||||
)
 | 
			
		||||
print('localmodule: ' + localmodule)
 | 
			
		||||
if localmodule not in sys.path:
 | 
			
		||||
    sys.path.insert(0, localmodule)
 | 
			
		||||
| 
						 | 
				
			
			@ -36,7 +37,9 @@ class VCSTest(unittest.TestCase):
 | 
			
		|||
        os.chdir(self.basedir)
 | 
			
		||||
 | 
			
		||||
    def test_remote_set_head_can_fail(self):
 | 
			
		||||
        testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
 | 
			
		||||
        testdir = tempfile.mkdtemp(
 | 
			
		||||
            prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
 | 
			
		||||
        )
 | 
			
		||||
        os.chdir(testdir)
 | 
			
		||||
        # First create an upstream repo with one commit
 | 
			
		||||
        upstream_repo = Repo.init("upstream_repo")
 | 
			
		||||
| 
						 | 
				
			
			@ -80,8 +83,13 @@ if __name__ == "__main__":
 | 
			
		|||
    os.chdir(os.path.dirname(__file__))
 | 
			
		||||
 | 
			
		||||
    parser = optparse.OptionParser()
 | 
			
		||||
    parser.add_option("-v", "--verbose", action="store_true", default=False,
 | 
			
		||||
                      help="Spew out even more information than normal")
 | 
			
		||||
    parser.add_option(
 | 
			
		||||
        "-v",
 | 
			
		||||
        "--verbose",
 | 
			
		||||
        action="store_true",
 | 
			
		||||
        default=False,
 | 
			
		||||
        help="Spew out even more information than normal",
 | 
			
		||||
    )
 | 
			
		||||
    (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
 | 
			
		||||
 | 
			
		||||
    newSuite = unittest.TestSuite()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue