4 # command which created the keystore used in this test case:
6 # $ for ALIAS in 'repokey a163ec9b d2d51ff2 dc3b169e 78688a0f'; \
7 # do keytool -genkey -keystore dummy-keystore.jks \
8 # -alias $ALIAS -keyalg 'RSA' -keysize '2048' \
9 # -validity '10000' -storepass 123456 \
10 # -keypass 123456 -dname 'CN=test, OU=F-Droid'; done
22 localmodule = os.path.realpath(
23 os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
24 print('localmodule: ' + localmodule)
25 if localmodule not in sys.path:
26 sys.path.insert(0, localmodule)
28 from fdroidserver import publish
29 from fdroidserver import common
30 from fdroidserver.exception import FDroidException
33 class PublishTest(unittest.TestCase):
34 '''fdroidserver/publish.py'''
37 logging.basicConfig(level=logging.DEBUG)
38 self.basedir = os.path.join(localmodule, 'tests')
39 self.tmpdir = os.path.abspath(os.path.join(self.basedir, '..', '.testfiles'))
40 if not os.path.exists(self.tmpdir):
41 os.makedirs(self.tmpdir)
42 os.chdir(self.basedir)
44 def test_key_alias(self):
46 self.assertEqual('a163ec9b', publish.key_alias('com.example.app'))
47 self.assertEqual('d2d51ff2', publish.key_alias('com.example.anotherapp'))
48 self.assertEqual('dc3b169e', publish.key_alias('org.test.testy'))
49 self.assertEqual('78688a0f', publish.key_alias('org.org.org'))
51 publish.config = {'keyaliases': {'yep.app': '@org.org.org',
52 'com.example.app': '1a2b3c4d'}}
53 self.assertEqual('78688a0f', publish.key_alias('yep.app'))
54 self.assertEqual('1a2b3c4d', publish.key_alias('com.example.app'))
56 def test_read_fingerprints_from_keystore(self):
58 common.fill_config_defaults(common.config)
59 publish.config = common.config
60 publish.config['keystorepass'] = '123456'
61 publish.config['keypass'] = '123456'
62 publish.config['keystore'] = 'dummy-keystore.jks'
64 expected = {'78688a0f': '277655a6235bc6b0ef2d824396c51ba947f5ebc738c293d887e7083ff338af82',
65 'd2d51ff2': 'fa3f6a017541ee7fe797be084b1bcfbf92418a7589ef1f7fdeb46741b6d2e9c3',
66 'dc3b169e': '6ae5355157a47ddcc3834a71f57f6fb5a8c2621c8e0dc739e9ddf59f865e497c',
67 'a163ec9b': 'd34f678afbaa8f2fa6cc0edd6f0c2d1d2e2e9eb08bea521b24c740806016bff4',
68 'repokey': 'c58460800c7b250a619c30c13b07b7359a43e5af71a4352d86c58ae18c9f6d41'}
69 result = publish.read_fingerprints_from_keystore()
71 self.assertEqual(expected, result)
73 def test_store_and_load_fdroid_signing_key_fingerprints(self):
75 common.fill_config_defaults(common.config)
76 publish.config = common.config
77 publish.config['keystorepass'] = '123456'
78 publish.config['keypass'] = '123456'
79 publish.config['keystore'] = os.path.join(os.getcwd(),
81 publish.config['repo_keyalias'] = 'repokey'
83 appids = ['com.example.app',
86 'com.example.anotherapp',
89 testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
91 with open('config.py', 'w') as f:
94 publish.store_stats_fdroid_signing_key_fingerprints(appids, indent=2)
98 "com.example.anotherapp": {
99 "signer": "fa3f6a017541ee7fe797be084b1bcfbf92418a7589ef1f7fdeb46741b6d2e9c3"
102 "signer": "d34f678afbaa8f2fa6cc0edd6f0c2d1d2e2e9eb08bea521b24c740806016bff4"
105 "signer": "277655a6235bc6b0ef2d824396c51ba947f5ebc738c293d887e7083ff338af82"
108 "signer": "6ae5355157a47ddcc3834a71f57f6fb5a8c2621c8e0dc739e9ddf59f865e497c"
111 self.assertEqual(expected, common.load_stats_fdroid_signing_key_fingerprints())
113 with open('config.py', 'r') as f:
114 self.assertEqual(textwrap.dedent('''\
116 repo_key_sha256 = "c58460800c7b250a619c30c13b07b7359a43e5af71a4352d86c58ae18c9f6d41"
119 def test_store_and_load_fdroid_signing_key_fingerprints_with_missmatch(self):
121 common.fill_config_defaults(common.config)
122 publish.config = common.config
123 publish.config['keystorepass'] = '123456'
124 publish.config['keypass'] = '123456'
125 publish.config['keystore'] = os.path.join(os.getcwd(),
126 'dummy-keystore.jks')
127 publish.config['repo_keyalias'] = 'repokey'
128 publish.config['repo_key_sha256'] = 'bad bad bad bad bad bad bad bad bad bad bad bad'
130 testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
132 publish.store_stats_fdroid_signing_key_fingerprints({}, indent=2)
133 with self.assertRaises(FDroidException):
134 common.load_stats_fdroid_signing_key_fingerprints()
137 if __name__ == "__main__":
138 parser = optparse.OptionParser()
139 parser.add_option("-v", "--verbose", action="store_true", default=False,
140 help="Spew out even more information than normal")
141 (common.options, args) = parser.parse_args(['--verbose'])
143 newSuite = unittest.TestSuite()
144 newSuite.addTest(unittest.makeSuite(PublishTest))
145 unittest.main(failfast=False)