From e86bedb223c28e1926fa1af0b05c74f594ca0c0c Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 2 Jun 2020 17:29:59 +0200 Subject: [PATCH] Prevent possible secret values to show up in deprecation logs (#36368) Co-authored-by: Martin Hjelmare --- homeassistant/helpers/config_validation.py | 26 ++++++++++----------- tests/helpers/test_config_validation.py | 27 +++++++++------------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index 32121958b03..c24adc76597 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -657,30 +657,30 @@ def deprecated( if replacement_key and invalidation_version: warning = ( - "The '{key}' option (with value '{value}') is" - " deprecated, please replace it with '{replacement_key}'." + "The '{key}' option is deprecated," + " please replace it with '{replacement_key}'." " This option will become invalid in version" " {invalidation_version}" ) elif replacement_key: warning = ( - "The '{key}' option (with value '{value}') is" - " deprecated, please replace it with '{replacement_key}'" + "The '{key}' option is deprecated," + " please replace it with '{replacement_key}'" ) elif invalidation_version: warning = ( - "The '{key}' option (with value '{value}') is" - " deprecated, please remove it from your configuration." + "The '{key}' option is deprecated," + " please remove it from your configuration." " This option will become invalid in version" " {invalidation_version}" ) else: warning = ( - "The '{key}' option (with value '{value}') is" - " deprecated, please remove it from your configuration" + "The '{key}' option is deprecated," + " please remove it from your configuration" ) - def check_for_invalid_version(value: Optional[Any]) -> None: + def check_for_invalid_version() -> None: """Raise error if current version has reached invalidation.""" if not invalidation_version: return @@ -689,7 +689,6 @@ def deprecated( raise vol.Invalid( warning.format( key=key, - value=value, replacement_key=replacement_key, invalidation_version=invalidation_version, ) @@ -698,19 +697,20 @@ def deprecated( def validator(config: Dict) -> Dict: """Check if key is in config and log warning.""" if key in config: - value = config[key] - check_for_invalid_version(value) + check_for_invalid_version() KeywordStyleAdapter(logging.getLogger(module_name)).warning( warning, key=key, - value=value, replacement_key=replacement_key, invalidation_version=invalidation_version, ) + + value = config[key] if replacement_key: config.pop(key) else: value = default + keys = [key] if replacement_key: keys.append(replacement_key) diff --git a/tests/helpers/test_config_validation.py b/tests/helpers/test_config_validation.py index 72eb61bbacb..d0f19f356ae 100644 --- a/tests/helpers/test_config_validation.py +++ b/tests/helpers/test_config_validation.py @@ -548,8 +548,7 @@ def test_deprecated_with_no_optionals(caplog, schema): "homeassistant.helpers.config_validation", ] assert ( - "The 'mars' option (with value 'True') is deprecated, " - "please remove it from your configuration" + "The 'mars' option is deprecated, please remove it from your configuration" ) in caplog.text assert test_data == output @@ -582,8 +581,7 @@ def test_deprecated_with_replacement_key(caplog, schema): output = deprecated_schema(test_data.copy()) assert len(caplog.records) == 1 assert ( - "The 'mars' option (with value 'True') is deprecated, " - "please replace it with 'jupiter'" + "The 'mars' option is deprecated, please replace it with 'jupiter'" ) in caplog.text assert {"jupiter": True} == output @@ -617,7 +615,7 @@ def test_deprecated_with_invalidation_version(caplog, schema, version): ) message = ( - "The 'mars' option (with value 'True') is deprecated, " + "The 'mars' option is deprecated, " "please remove it from your configuration. " "This option will become invalid in version 1.0.0" ) @@ -643,7 +641,7 @@ def test_deprecated_with_invalidation_version(caplog, schema, version): with pytest.raises(vol.MultipleInvalid) as exc_info: invalidated_schema(test_data) assert str(exc_info.value) == ( - "The 'mars' option (with value 'True') is deprecated, " + "The 'mars' option is deprecated, " "please remove it from your configuration. This option will " "become invalid in version 0.1.0" ) @@ -671,7 +669,7 @@ def test_deprecated_with_replacement_key_and_invalidation_version( ) warning = ( - "The 'mars' option (with value 'True') is deprecated, " + "The 'mars' option is deprecated, " "please replace it with 'jupiter'. This option will become " "invalid in version 1.0.0" ) @@ -703,7 +701,7 @@ def test_deprecated_with_replacement_key_and_invalidation_version( with pytest.raises(vol.MultipleInvalid) as exc_info: invalidated_schema(test_data) assert str(exc_info.value) == ( - "The 'mars' option (with value 'True') is deprecated, " + "The 'mars' option is deprecated, " "please replace it with 'jupiter'. This option will become " "invalid in version 0.1.0" ) @@ -725,8 +723,7 @@ def test_deprecated_with_default(caplog, schema): assert len(caplog.records) == 1 assert caplog.records[0].name == __name__ assert ( - "The 'mars' option (with value 'True') is deprecated, " - "please remove it from your configuration" + "The 'mars' option is deprecated, please remove it from your configuration" ) in caplog.text assert test_data == output @@ -759,8 +756,7 @@ def test_deprecated_with_replacement_key_and_default(caplog, schema): output = deprecated_schema(test_data.copy()) assert len(caplog.records) == 1 assert ( - "The 'mars' option (with value 'True') is deprecated, " - "please replace it with 'jupiter'" + "The 'mars' option is deprecated, please replace it with 'jupiter'" ) in caplog.text assert {"jupiter": True} == output @@ -792,8 +788,7 @@ def test_deprecated_with_replacement_key_and_default(caplog, schema): output = deprecated_schema_with_default(test_data.copy()) assert len(caplog.records) == 1 assert ( - "The 'mars' option (with value 'True') is deprecated, " - "please replace it with 'jupiter'" + "The 'mars' option is deprecated, please replace it with 'jupiter'" ) in caplog.text assert {"jupiter": True} == output @@ -828,7 +823,7 @@ def test_deprecated_with_replacement_key_invalidation_version_default( output = deprecated_schema(test_data.copy()) assert len(caplog.records) == 1 assert ( - "The 'mars' option (with value 'True') is deprecated, " + "The 'mars' option is deprecated, " "please replace it with 'jupiter'. This option will become " "invalid in version 1.0.0" ) in caplog.text @@ -855,7 +850,7 @@ def test_deprecated_with_replacement_key_invalidation_version_default( with pytest.raises(vol.MultipleInvalid) as exc_info: invalidated_schema(test_data) assert str(exc_info.value) == ( - "The 'mars' option (with value 'True') is deprecated, " + "The 'mars' option is deprecated, " "please replace it with 'jupiter'. This option will become " "invalid in version 0.1.0" )