mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-14 11:10:30 +03:00
publish: factor out the signing key creation into a method
This commit is contained in:
parent
7813a17cf8
commit
a114c73c2d
2 changed files with 65 additions and 27 deletions
|
|
@ -11,6 +11,7 @@
|
|||
#
|
||||
|
||||
import inspect
|
||||
import jks, jks.util
|
||||
import logging
|
||||
import optparse
|
||||
import os
|
||||
|
|
@ -190,6 +191,32 @@ class PublishTest(unittest.TestCase):
|
|||
allaliases = publish.check_for_key_collisions(allapps)
|
||||
self.assertEqual(len(randomappids), len(allaliases))
|
||||
|
||||
def test_create_key_if_not_existing(self):
|
||||
common.config = {}
|
||||
common.fill_config_defaults(common.config)
|
||||
publish.config = common.config
|
||||
publish.config['keystorepass'] = '123456'
|
||||
publish.config['keypass'] = '654321'
|
||||
publish.config['keystore'] = "keystore.jks"
|
||||
publish.config['keydname'] = 'CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US'
|
||||
testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
|
||||
os.chdir(testdir)
|
||||
keystore = jks.KeyStore.new("jks", [])
|
||||
keystore.save(publish.config['keystore'], publish.config['keystorepass'])
|
||||
|
||||
self.assertTrue(publish.create_key_if_not_existing("newalias"))
|
||||
# The second time we try that, a new key should not be created
|
||||
self.assertFalse(publish.create_key_if_not_existing("newalias"))
|
||||
self.assertTrue(publish.create_key_if_not_existing("anotheralias"))
|
||||
|
||||
keystore = jks.KeyStore.load(publish.config['keystore'], publish.config['keystorepass'])
|
||||
self.assertCountEqual(keystore.private_keys, ["newalias", "anotheralias"])
|
||||
for alias, pk in keystore.private_keys.items():
|
||||
self.assertFalse(pk.is_decrypted())
|
||||
pk.decrypt(publish.config['keypass'])
|
||||
self.assertTrue(pk.is_decrypted())
|
||||
self.assertEqual(jks.util.RSA_ENCRYPTION_OID, pk.algorithm_oid)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.chdir(os.path.dirname(__file__))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue