From f46e99a5c49789b7a56351c6f3c98f7b93cee289 Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Tue, 30 Jun 2020 02:47:53 +0200 Subject: [PATCH] test for #796 The extlib test is in build because it tests the interaction between prepare_source with a later scan as it is run from build.py --- tests/build.TestCase | 35 +++++++++++++++++++++++++++++++++++ tests/scanner.TestCase | 1 + 2 files changed, 36 insertions(+) diff --git a/tests/build.TestCase b/tests/build.TestCase index 183f6661..875e83e6 100755 --- a/tests/build.TestCase +++ b/tests/build.TestCase @@ -23,6 +23,7 @@ if localmodule not in sys.path: import fdroidserver.build import fdroidserver.common import fdroidserver.metadata +import fdroidserver.scanner class BuildTest(unittest.TestCase): @@ -198,6 +199,40 @@ class BuildTest(unittest.TestCase): self.assertFalse(os.path.exists('gen')) 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) + os.chdir(testdir) + os.mkdir("build") + + config = dict() + config['sdk_path'] = os.getenv('ANDROID_HOME') + config['ndk_paths'] = {'r10d': os.getenv('ANDROID_NDK_HOME')} + config['build_tools'] = 'FAKE_BUILD_TOOLS_VERSION' + fdroidserver.common.config = config + app = fdroidserver.metadata.App() + app.id = 'com.gpl.rpg.AndorsTrail' + build = fdroidserver.metadata.Build() + build.commit = 'master' + build.androidupdate = ['no'] + build.extlibs = ['android/android-support-v4r11.jar'] + 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') + + class FakeVcs(): + # no need to change to the correct commit here + def gotorevision(self, rev, refresh=True): + pass + + def getsrclib(self): + return None + + 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") + if __name__ == "__main__": os.chdir(os.path.dirname(__file__)) diff --git a/tests/scanner.TestCase b/tests/scanner.TestCase index 2dbfbbba..4636a4eb 100755 --- a/tests/scanner.TestCase +++ b/tests/scanner.TestCase @@ -271,6 +271,7 @@ class ScannerTest(unittest.TestCase): self.assertEqual(len(data), len(urls), 'each data example should produce a URL') + if __name__ == "__main__": os.chdir(os.path.dirname(__file__))