From 04c1a7babc81798f9f9141128c6e52453959c817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20HUBSCHER?= Date: Thu, 24 Sep 2015 16:29:35 +0200 Subject: [PATCH] @ametaireau review. --- syncto/__init__.py | 6 +++++- syncto/tests/support.py | 1 + syncto/tests/test_functional.py | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/syncto/__init__.py b/syncto/__init__.py index f858b0e..0b103cd 100644 --- a/syncto/__init__.py +++ b/syncto/__init__.py @@ -18,7 +18,7 @@ CLIENT_STATE_HEADER = 'X-Client-State' DEFAULT_SETTINGS = { - 'syncto.cache_hmac_secret': 'This is not a secret', + 'syncto.cache_hmac_secret': None, 'syncto.cache_credentials_ttl_seconds': 300 } @@ -26,6 +26,10 @@ def main(global_config, **settings): config = Configurator(settings=settings) + if 'syncto.cache_hmac_secret' not in settings: + raise ValueError( + "Please configure the `syncto.cache_hmac_secret` settings.") + cliquet.initialize(config, __version__, default_settings=DEFAULT_SETTINGS) config.scan("syncto.views") return config.make_wsgi_app() diff --git a/syncto/tests/support.py b/syncto/tests/support.py index bddfedd..ed0ebfc 100644 --- a/syncto/tests/support.py +++ b/syncto/tests/support.py @@ -28,6 +28,7 @@ def get_app_settings(self, additional_settings=None): settings['cliquet.storage_backend'] = 'cliquet.storage.memory' settings['cliquet.permission_backend'] = 'cliquet.permission.memory' settings['cliquet.userid_hmac_secret'] = "this is not a secret" + settings['syncto.cache_hmac_secret'] = 'This is not a secret' if additional_settings is not None: settings.update(additional_settings) diff --git a/syncto/tests/test_functional.py b/syncto/tests/test_functional.py index bf1698c..b281406 100644 --- a/syncto/tests/test_functional.py +++ b/syncto/tests/test_functional.py @@ -6,6 +6,7 @@ from cliquet.tests.support import FormattedErrorMixin from requests.exceptions import HTTPError from syncto import AUTHORIZATION_HEADER, CLIENT_STATE_HEADER +from syncto import main as testapp from .support import BaseWebTest, unittest @@ -20,6 +21,17 @@ } +class SettingsMissingTest(BaseWebTest, unittest.TestCase): + def __init__(self, *args, **kwargs): + super(unittest.TestCase, self).__init__(*args, **kwargs) + + def test_syncto_cache_hmac_secret_missing(self): + settings = self.get_app_settings() + # Remove the mandatory settings we want to test + del settings['syncto.cache_hmac_secret'] + self.assertRaises(ValueError, testapp, {}, **settings) + + class FunctionalTest(FormattedErrorMixin, BaseWebTest, unittest.TestCase): def __init__(self, *args, **kwargs):