Explorar o código

[desktop] Fix database passwords, stmp passwords, and secret keys scripts

This was missed by the test suite because we were explicitly
setting the *PASSWORD to None instead of the default value.
Erick Tryzelaar %!s(int64=10) %!d(string=hai) anos
pai
achega
01003a0

+ 5 - 5
desktop/core/src/desktop/conf.py

@@ -143,7 +143,7 @@ CHERRYPY_SERVER_THREADS = Config(
 SECRET_KEY = Config(
   key="secret_key",
   help=_("Used in hashing algorithms for sessions."),
-  default="")
+  default=None)
 
 SECRET_KEY_SCRIPT = Config(
   key="secret_key_script",
@@ -280,7 +280,7 @@ SMTP = ConfigSection(
       help=_("The password for the SMTP user."),
       type=str,
       private=True,
-      default=""
+      default=None,
     ),
 
     PASSWORD_SCRIPT = Config(
@@ -335,14 +335,14 @@ DATABASE = ConfigSection(
       help=_('Database password.'),
       private=True,
       type=str,
-      default='',
+      default=None,
     ),
     PASSWORD_SCRIPT=Config(
       key='password_script',
       help=_('Execute this script to produce the database password. This will be used when `password` is not set.'),
       private=True,
       type=coerce_password_from_script,
-      default='',
+      default=None,
     ),
     HOST=Config(
       key='host',
@@ -963,7 +963,7 @@ def config_validator(user):
   from desktop.lib import i18n
 
   res = []
-  if not SECRET_KEY.get():
+  if not get_secret_key():
     res.append((SECRET_KEY, unicode(_("Secret key should be configured as a random string. All sessions will be lost on restart"))))
 
   # Validate SSL setup

+ 4 - 2
desktop/core/src/desktop/settings.py

@@ -340,8 +340,10 @@ EMAIL_USE_TLS = desktop.conf.SMTP.USE_TLS.get()
 DEFAULT_FROM_EMAIL = desktop.conf.SMTP.DEFAULT_FROM.get()
 
 # Used for securely creating sessions. Should be unique and not shared with anybody. Changing auth backends will invalidate all open sessions.
-SECRET_KEY = desktop.conf.get_secret_key() + str(AUTHENTICATION_BACKENDS)
-if SECRET_KEY == "":
+SECRET_KEY = desktop.conf.get_secret_key()
+if SECRET_KEY:
+  SECRET_KEY += str(AUTHENTICATION_BACKENDS)
+else:
   import uuid
   SECRET_KEY = str(uuid.uuid4())
 

+ 0 - 3
desktop/core/src/desktop/tests.py

@@ -699,7 +699,6 @@ class BaseTestPasswordConfig(object):
   @nottest
   def run_test_read_password_from_script(self):
     resets = [
-      self.get_config_password().set_for_testing(None),
       self.get_config_password_script().set_for_testing(self.SCRIPT)
     ]
 
@@ -725,7 +724,6 @@ class BaseTestPasswordConfig(object):
   @nottest
   def run_test_password_script_raises_exception(self):
     resets = [
-      self.get_config_password().set_for_testing(None),
       self.get_config_password_script().set_for_testing(
           '%s -c "import sys; sys.exit(1)"' % sys.executable
       ),
@@ -738,7 +736,6 @@ class BaseTestPasswordConfig(object):
         reset()
 
     resets = [
-      self.get_config_password().set_for_testing(None),
       self.get_config_password_script().set_for_testing('/does-not-exist')
     ]