@@ -118,8 +118,6 @@ def test_log_all_should_not_return_apikey_value_by_default(caplog):
118118 with caplog .at_level (logging .INFO ):
119119 logger .spider_closed (spider )
120120
121- # won't check specifics here as the default settings
122- # can vary with scrapy versions - presence is enough
123121 assert '"APIKEY": "*************"' in caplog .text
124122 assert '"apikey": "*************"' in caplog .text
125123 assert '"api_key": "*************"' in caplog .text
@@ -138,8 +136,6 @@ def test_log_all_should_return_apikey_value_if_MASKED_SENSITIVE_SETTINGS_ENABLED
138136 with caplog .at_level (logging .INFO ):
139137 logger .spider_closed (spider )
140138
141- # won't check specifics here as the default settings
142- # can vary with scrapy versions - presence is enough
143139 assert '"APIKEY": "apikey_value"' in caplog .text
144140
145141
@@ -155,8 +151,24 @@ def test_log_all_should_not_return_aws_secret_key_value_by_default(caplog):
155151 with caplog .at_level (logging .INFO ):
156152 logger .spider_closed (spider )
157153
158- # won't check specifics here as the default settings
159- # can vary with scrapy versions - presence is enough
160154 assert '"AWS_SECRET_ACCESS_KEY": "*************"' in caplog .text
161155 assert '"aws_secret_access_key": "*************"' in caplog .text
162- assert 'secret_value' not in caplog .text
156+ assert 'secret_value' not in caplog .text
157+
158+
159+ def test_log_all_should_return_only_the_custom_regex_data_masked_if_MASKED_SENSITIVE_SETTINGS_REGEX_LIST_configured (caplog ):
160+ settings = {
161+ "SETTINGS_LOGGING_ENABLED" : True ,
162+ "MASKED_SENSITIVE_SETTINGS_REGEX_LIST" : ["apppppppikey" ],
163+ "APIKEY" : 'apikey_value1' ,
164+ "apppppppikey" : 'some_random_value' ,
165+ }
166+
167+ spider = MockSpider (settings )
168+ logger = SpiderSettingsLogging ()
169+ with caplog .at_level (logging .INFO ):
170+ logger .spider_closed (spider )
171+
172+ assert 'apikey_value1' in caplog .text
173+ assert '"apppppppikey": "*****************"' in caplog .text
174+ assert 'some_random_value' not in caplog .text
0 commit comments