From 8bde6e70dcf923db2ad3ce0dcd78ac350ecaaca2 Mon Sep 17 00:00:00 2001 From: Cory Francis Myers Date: Wed, 7 Feb 2024 17:17:24 -0800 Subject: [PATCH] fix(SecureDropConfig): pass "env" for inferring debug mode The interactions among our "env" and "DEBUG" and Flask's "ENV" and "DEBUG" are not ideal, but refactoring them is well beyond the scope of this fix. --- securedrop/sdconfig.py | 5 +++++ securedrop/tests/test_config.py | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/securedrop/sdconfig.py b/securedrop/sdconfig.py index 4dd55c23a5..725c41dc4e 100644 --- a/securedrop/sdconfig.py +++ b/securedrop/sdconfig.py @@ -71,6 +71,8 @@ class SecureDropConfig: RQ_WORKER_NAME: str + env: str = "prod" + @property def TEMP_DIR(self) -> Path: # We use a directory under the SECUREDROP_DATA_ROOT instead of `/tmp` because @@ -115,6 +117,8 @@ def _parse_config_from_file(config_module_name: str) -> SecureDropConfig: config_from_local_file, "SCRYPT_PARAMS", dict(N=2**14, r=8, p=1) ) + env = getattr(config_from_local_file, "env", "prod") + try: final_securedrop_root = Path(config_from_local_file.SECUREDROP_ROOT) except AttributeError: @@ -188,6 +192,7 @@ def _parse_config_from_file(config_module_name: str) -> SecureDropConfig: ) return SecureDropConfig( + env=env, JOURNALIST_APP_FLASK_CONFIG_CLS=parsed_journ_flask_config, SOURCE_APP_FLASK_CONFIG_CLS=parsed_source_flask_config, GPG_KEY_DIR=final_gpg_key_dir, diff --git a/securedrop/tests/test_config.py b/securedrop/tests/test_config.py index 724a873d4c..925072647e 100644 --- a/securedrop/tests/test_config.py +++ b/securedrop/tests/test_config.py @@ -19,8 +19,12 @@ def test_parse_current_config(): try: current_config_file.write_text(current_sample_config.read_text()) - # When trying to parse it, it succeeds - assert _parse_config_from_file(f"tests.{current_config_module}") + # When trying to parse it, it succeeds... + parsed_config = _parse_config_from_file(f"tests.{current_config_module}") + assert parsed_config + + # ...and has one of our `env` values rather than one of Flask's: + assert parsed_config.env in ["prod", "dev", "test"] finally: current_config_file.unlink(missing_ok=True)