2017-09-06 15:54:16 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import inspect
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
import hashlib
|
|
|
|
import logging
|
|
|
|
from tempfile import TemporaryDirectory
|
|
|
|
|
|
|
|
localmodule = os.path.realpath(
|
2021-06-07 11:49:21 +02:00
|
|
|
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
|
|
|
|
)
|
2017-09-06 15:54:16 +02:00
|
|
|
print('localmodule: ' + localmodule)
|
|
|
|
if localmodule not in sys.path:
|
|
|
|
sys.path.insert(0, localmodule)
|
|
|
|
|
|
|
|
from testcommon import TmpCwd
|
|
|
|
from fdroidserver import common, signatures
|
|
|
|
|
|
|
|
|
|
|
|
class SignaturesTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
common.config = None
|
2024-05-08 16:26:46 +02:00
|
|
|
config = common.read_config()
|
2017-09-06 15:54:16 +02:00
|
|
|
config['jarsigner'] = common.find_sdk_tools_cmd('jarsigner')
|
|
|
|
config['verbose'] = True
|
|
|
|
common.config = config
|
|
|
|
|
|
|
|
def test_main(self):
|
|
|
|
|
|
|
|
# option fixture class:
|
|
|
|
class OptionsFixture:
|
|
|
|
APK = [os.path.abspath(os.path.join('repo', 'com.politedroid_3.apk'))]
|
|
|
|
|
|
|
|
with TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
|
2018-05-14 14:07:40 +02:00
|
|
|
signatures.extract(OptionsFixture())
|
2017-09-06 15:54:16 +02:00
|
|
|
|
|
|
|
# check if extracted signatures are where they are supposed to be
|
|
|
|
# also verify weather if extracted file contian what they should
|
|
|
|
filesAndHashes = (
|
|
|
|
(os.path.join('metadata', 'com.politedroid', 'signatures', '3', 'MANIFEST.MF'),
|
|
|
|
'7dcd83f0c41a75457fd2311bf3c4578f80d684362d74ba8dc52838d353f31cf2'),
|
|
|
|
(os.path.join('metadata', 'com.politedroid', 'signatures', '3', 'RELEASE.RSA'),
|
|
|
|
'883ef3d5a6e0bf69d2a58d9e255a7930f08a49abc38e216ed054943c99c8fdb4'),
|
|
|
|
(os.path.join('metadata', 'com.politedroid', 'signatures', '3', 'RELEASE.SF'),
|
|
|
|
'99fbb3211ef5d7c1253f3a7ad4836eadc9905103ce6a75916c40de2831958284'),
|
|
|
|
)
|
|
|
|
for path, checksum in filesAndHashes:
|
2018-08-06 22:13:40 +02:00
|
|
|
self.assertTrue(os.path.isfile(path),
|
|
|
|
msg="check whether '{path}' was extracted "
|
|
|
|
"correctly.".format(path=path))
|
2017-09-06 15:54:16 +02:00
|
|
|
with open(path, 'rb') as f:
|
|
|
|
self.assertEqual(hashlib.sha256(f.read()).hexdigest(), checksum)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-08-14 10:34:13 +02:00
|
|
|
os.chdir(os.path.dirname(__file__))
|
|
|
|
|
2024-05-02 14:08:28 +02:00
|
|
|
import argparse
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
2021-06-07 11:49:21 +02:00
|
|
|
"-v",
|
|
|
|
"--verbose",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Spew out even more information than normal",
|
|
|
|
)
|
2024-05-08 16:26:46 +02:00
|
|
|
common.options = common.parse_args(parser)
|
2017-09-06 15:54:16 +02:00
|
|
|
|
|
|
|
newSuite = unittest.TestSuite()
|
|
|
|
newSuite.addTest(unittest.makeSuite(SignaturesTest))
|
2017-10-20 11:51:59 +02:00
|
|
|
unittest.main(failfast=False)
|