chiark / gitweb /
better error message in publish when repo_key is not set
authorMichael Pöhn <michael.poehn@fsfe.org>
Mon, 16 Oct 2017 16:11:57 +0000 (18:11 +0200)
committerMichael Pöhn <michael.poehn@fsfe.org>
Tue, 17 Oct 2017 20:10:39 +0000 (22:10 +0200)
fdroidserver/common.py
fdroidserver/index.py
fdroidserver/publish.py
tests/common.TestCase

index 8e580971d085b50d87eccc919d620e26c02edfbe..5f18f3b76451a3029e25743ce4b4cb69afb61dd0 100644 (file)
@@ -302,6 +302,30 @@ def read_config(opts, config_file='config.py'):
     return config
 
 
+def assert_config_keystore(config):
+    """Check weather keystore is configured correctly and raise exception if not."""
+
+    nosigningkey = False
+    if 'repo_keyalias' not in config:
+        nosigningkey = True
+        logging.critical(_("'repo_keyalias' not found in config.py!"))
+    if 'keystore' not in config:
+        nosigningkey = True
+        logging.critical(_("'keystore' not found in config.py!"))
+    elif not os.path.exists(config['keystore']):
+        nosigningkey = True
+        logging.critical("'" + config['keystore'] + "' does not exist!")
+    if 'keystorepass' not in config:
+        nosigningkey = True
+        logging.critical(_("'keystorepass' not found in config.py!"))
+    if 'keypass' not in config:
+        nosigningkey = True
+        logging.critical(_("'keypass' not found in config.py!"))
+    if nosigningkey:
+        raise FDroidException("This command requires a signing key, " +
+                              "you can create one using: fdroid update --create-key")
+
+
 def find_sdk_tools_cmd(cmd):
     '''find a working path to a tool from the Android SDK'''
 
index 0e23060c9fde7fae7db9d9e110d6fbc8def7bc84..d013b319754b083772e56e67004476be8a66e27c 100644 (file)
@@ -63,26 +63,8 @@ def make(apps, sortedids, apks, repodir, archive):
             return "fdroid.app:" + appid, apps[appid].Name
         raise MetaDataException("Cannot resolve app id " + appid)
 
-    nosigningkey = False
     if not common.options.nosign:
-        if 'repo_keyalias' not in common.config:
-            nosigningkey = True
-            logging.critical(_("'repo_keyalias' not found in config.py!"))
-        if 'keystore' not in common.config:
-            nosigningkey = True
-            logging.critical(_("'keystore' not found in config.py!"))
-        if 'keystorepass' not in common.config:
-            nosigningkey = True
-            logging.critical(_("'keystorepass' not found in config.py!"))
-        if 'keypass' not in common.config:
-            nosigningkey = True
-            logging.critical(_("'keypass' not found in config.py!"))
-        if not os.path.exists(common.config['keystore']):
-            nosigningkey = True
-            logging.critical("'" + common.config['keystore'] + "' does not exist!")
-        if nosigningkey:
-            raise FDroidException("`fdroid update` requires a signing key, " +
-                                  "you can create one using: fdroid update --create-key")
+        common.assert_config_keystore(common.config)
 
     repodict = collections.OrderedDict()
     repodict['timestamp'] = datetime.utcnow()
index 4bdb8fb1a6498a313c4f8394e44a7b280962f0e6..431d2aefa0f562395bc3966ceaa75c3afd074fce 100644 (file)
@@ -157,6 +157,8 @@ def main():
         logging.critical(_('Java JDK not found! Install in standard location or set java_paths!'))
         sys.exit(1)
 
+    common.assert_config_keystore(config)
+
     log_dir = 'logs'
     if not os.path.isdir(log_dir):
         logging.info(_("Creating log directory"))
index a09c948bb4618d8e4dea9fd8b92b26fd2887b162..3a10b7bba03417ddf812cd5d30cd17c254f46db8 100755 (executable)
@@ -25,6 +25,7 @@ if localmodule not in sys.path:
 import fdroidserver.signindex
 import fdroidserver.common
 import fdroidserver.metadata
+from testcommon import TmpCwd
 from fdroidserver.exception import FDroidException
 
 
@@ -39,6 +40,20 @@ class CommonTest(unittest.TestCase):
             os.makedirs(self.tmpdir)
         os.chdir(self.basedir)
 
+    def test_assert_config_keystore(self):
+        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
+            with self.assertRaises(FDroidException):
+                fdroidserver.common.assert_config_keystore({})
+
+        with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
+            c = {'repo_keyalias': 'localhost',
+                 'keystore': 'keystore.jks',
+                 'keystorepass': '12345',
+                 'keypass': '12345'}
+            with open('keystore.jks', 'w'):
+                pass
+            fdroidserver.common.assert_config_keystore(c)
+
     def _set_build_tools(self):
         build_tools = os.path.join(fdroidserver.common.config['sdk_path'], 'build-tools')
         if os.path.exists(build_tools):