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
21 localmodule = os.path.realpath(
22 os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
23 print('localmodule: ' + localmodule)
24 if localmodule not in sys.path:
25 sys.path.insert(0, localmodule)
27 from fdroidserver import publish
28 from fdroidserver import common
29 from fdroidserver.exception import FDroidException
32 class PublishTest(unittest.TestCase):
33 '''fdroidserver/publish.py'''
35 def test_key_alias(self):
37 self.assertEqual('a163ec9b', publish.key_alias('com.example.app'))
38 self.assertEqual('d2d51ff2', publish.key_alias('com.example.anotherapp'))
39 self.assertEqual('dc3b169e', publish.key_alias('org.test.testy'))
40 self.assertEqual('78688a0f', publish.key_alias('org.org.org'))
42 publish.config = {'keyaliases': {'yep.app': '@org.org.org',
43 'com.example.app': '1a2b3c4d'}}
44 self.assertEqual('78688a0f', publish.key_alias('yep.app'))
45 self.assertEqual('1a2b3c4d', publish.key_alias('com.example.app'))
47 def test_read_fingerprints_from_keystore(self):
49 common.fill_config_defaults(common.config)
50 publish.config = common.config
51 publish.config['keystorepass'] = '123456'
52 publish.config['keypass'] = '123456'
53 publish.config['keystore'] = 'dummy-keystore.jks'
55 expected = {'78688a0f': '277655a6235bc6b0ef2d824396c51ba947f5ebc738c293d887e7083ff338af82',
56 'd2d51ff2': 'fa3f6a017541ee7fe797be084b1bcfbf92418a7589ef1f7fdeb46741b6d2e9c3',
57 'dc3b169e': '6ae5355157a47ddcc3834a71f57f6fb5a8c2621c8e0dc739e9ddf59f865e497c',
58 'a163ec9b': 'd34f678afbaa8f2fa6cc0edd6f0c2d1d2e2e9eb08bea521b24c740806016bff4',
59 'repokey': 'c58460800c7b250a619c30c13b07b7359a43e5af71a4352d86c58ae18c9f6d41'}
60 result = publish.read_fingerprints_from_keystore()
62 self.assertEqual(expected, result)
64 def test_store_and_load_fdroid_signing_key_fingerprints(self):
66 common.fill_config_defaults(common.config)
67 publish.config = common.config
68 publish.config['keystorepass'] = '123456'
69 publish.config['keypass'] = '123456'
70 publish.config['keystore'] = os.path.join(os.getcwd(),
72 publish.config['repo_keyalias'] = 'repokey'
74 appids = ['com.example.app',
77 'com.example.anotherapp',
80 with tempfile.TemporaryDirectory() as tmpdir:
81 orig_cwd = os.getcwd()
84 with open('config.py', 'w') as f:
87 publish.store_stats_fdroid_signing_key_fingerprints(appids, indent=2)
91 "com.example.anotherapp": {
92 "signer": "fa3f6a017541ee7fe797be084b1bcfbf92418a7589ef1f7fdeb46741b6d2e9c3"
95 "signer": "d34f678afbaa8f2fa6cc0edd6f0c2d1d2e2e9eb08bea521b24c740806016bff4"
98 "signer": "277655a6235bc6b0ef2d824396c51ba947f5ebc738c293d887e7083ff338af82"
101 "signer": "6ae5355157a47ddcc3834a71f57f6fb5a8c2621c8e0dc739e9ddf59f865e497c"
104 self.assertEqual(expected, common.load_stats_fdroid_signing_key_fingerprints())
106 with open('config.py', 'r') as f:
107 self.assertEqual(textwrap.dedent('''\
109 repo_key_sha256 = "c58460800c7b250a619c30c13b07b7359a43e5af71a4352d86c58ae18c9f6d41"
114 def test_store_and_load_fdroid_signing_key_fingerprints_with_missmatch(self):
116 common.fill_config_defaults(common.config)
117 publish.config = common.config
118 publish.config['keystorepass'] = '123456'
119 publish.config['keypass'] = '123456'
120 publish.config['keystore'] = os.path.join(os.getcwd(),
121 'dummy-keystore.jks')
122 publish.config['repo_keyalias'] = 'repokey'
123 publish.config['repo_key_sha256'] = 'bad bad bad bad bad bad bad bad bad bad bad bad'
125 with tempfile.TemporaryDirectory() as tmpdir:
126 orig_cwd = os.getcwd()
129 publish.store_stats_fdroid_signing_key_fingerprints({}, indent=2)
130 with self.assertRaises(FDroidException):
131 common.load_stats_fdroid_signing_key_fingerprints()
136 if __name__ == "__main__":
137 if os.path.basename(os.getcwd()) != 'tests' and os.path.isdir('tests'):
140 parser = optparse.OptionParser()
141 parser.add_option("-v", "--verbose", action="store_true", default=False,
142 help="Spew out even more information than normal")
143 (common.options, args) = parser.parse_args(['--verbose'])
145 newSuite = unittest.TestSuite()
146 newSuite.addTest(unittest.makeSuite(PublishTest))
147 unittest.main(failfast=False)