10 from tempfile import TemporaryDirectory
12 localmodule = os.path.realpath(
13 os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
14 print('localmodule: ' + localmodule)
15 if localmodule not in sys.path:
16 sys.path.insert(0, localmodule)
18 from testcommon import TmpCwd
19 from fdroidserver import common, signatures
22 class SignaturesTest(unittest.TestCase):
25 logging.basicConfig(level=logging.DEBUG)
27 config = common.read_config(common.options)
28 config['jarsigner'] = common.find_sdk_tools_cmd('jarsigner')
29 config['verbose'] = True
30 common.config = config
34 # option fixture class:
36 APK = [os.path.abspath(os.path.join('repo', 'com.politedroid_3.apk'))]
38 with TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
39 signatures.extract(common.config, OptionsFixture())
41 # check if extracted signatures are where they are supposed to be
42 # also verify weather if extracted file contian what they should
44 (os.path.join('metadata', 'com.politedroid', 'signatures', '3', 'MANIFEST.MF'),
45 '7dcd83f0c41a75457fd2311bf3c4578f80d684362d74ba8dc52838d353f31cf2'),
46 (os.path.join('metadata', 'com.politedroid', 'signatures', '3', 'RELEASE.RSA'),
47 '883ef3d5a6e0bf69d2a58d9e255a7930f08a49abc38e216ed054943c99c8fdb4'),
48 (os.path.join('metadata', 'com.politedroid', 'signatures', '3', 'RELEASE.SF'),
49 '99fbb3211ef5d7c1253f3a7ad4836eadc9905103ce6a75916c40de2831958284'),
51 for path, checksum in filesAndHashes:
52 self.assertTrue(os.path.isfile(path))
53 with open(path, 'rb') as f:
54 self.assertEqual(hashlib.sha256(f.read()).hexdigest(), checksum)
57 if __name__ == "__main__":
58 parser = optparse.OptionParser()
59 parser.add_option("-v", "--verbose", action="store_true", default=False,
60 help="Spew out even more information than normal")
61 (common.options, args) = parser.parse_args(['--verbose'])
63 newSuite = unittest.TestSuite()
64 newSuite.addTest(unittest.makeSuite(SignaturesTest))
65 unittest.main(failfast=False)