@@ -103,3 +103,60 @@ class CustomClass:
103103 logger .spider_closed (spider )
104104
105105 assert '{"DUMMY_CUSTOM_CLASS": {"CustomClass": "/foo/bar"}}' in caplog .text
106+
107+
108+ def test_log_all_should_not_return_apikey_value_by_default (caplog ):
109+ settings = {
110+ "SETTINGS_LOGGING_ENABLED" : True ,
111+ "APIKEY" : 'apikey_value1' ,
112+ "apikey" : 'apikey_value2' ,
113+ "api_key" : 'apikey_value3' ,
114+ }
115+
116+ spider = MockSpider (settings )
117+ logger = SpiderSettingsLogging ()
118+ with caplog .at_level (logging .INFO ):
119+ logger .spider_closed (spider )
120+
121+ # won't check specifics here as the default settings
122+ # can vary with scrapy versions - presence is enough
123+ assert '"APIKEY": "*************"' in caplog .text
124+ assert '"apikey": "*************"' in caplog .text
125+ assert '"api_key": "*************"' in caplog .text
126+ assert 'apikey_value' not in caplog .text
127+
128+
129+ def test_log_all_should_return_apikey_value_if_MASKED_SENSITIVE_SETTINGS_ENABLED_is_false (caplog ):
130+ settings = {
131+ "SETTINGS_LOGGING_ENABLED" : True ,
132+ "APIKEY" : 'apikey_value' ,
133+ "MASKED_SENSITIVE_SETTINGS_ENABLED" : False ,
134+ }
135+
136+ spider = MockSpider (settings )
137+ logger = SpiderSettingsLogging ()
138+ with caplog .at_level (logging .INFO ):
139+ logger .spider_closed (spider )
140+
141+ # won't check specifics here as the default settings
142+ # can vary with scrapy versions - presence is enough
143+ assert '"APIKEY": "apikey_value"' in caplog .text
144+
145+
146+ def test_log_all_should_not_return_aws_secret_key_value_by_default (caplog ):
147+ settings = {
148+ "SETTINGS_LOGGING_ENABLED" : True ,
149+ "AWS_SECRET_ACCESS_KEY" : 'secret_value1' ,
150+ "aws_secret_access_key" : 'secret_value2' ,
151+ }
152+
153+ spider = MockSpider (settings )
154+ logger = SpiderSettingsLogging ()
155+ with caplog .at_level (logging .INFO ):
156+ logger .spider_closed (spider )
157+
158+ # won't check specifics here as the default settings
159+ # can vary with scrapy versions - presence is enough
160+ assert '"AWS_SECRET_ACCESS_KEY": "*************"' in caplog .text
161+ assert '"aws_secret_access_key": "*************"' in caplog .text
162+ assert 'secret_value' not in caplog .text
0 commit comments