Skip to content

Commit 6630960

Browse files
committed
using fixed lenght for masked settings
1 parent cc48582 commit 6630960

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/scrapy_settings_log/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def spider_closed(self, spider):
5959
]
6060
regex_list = settings.get("MASKED_SENSITIVE_SETTINGS_REGEX_LIST", default_regexes)
6161
for reg in regex_list:
62-
updated_settings = {k: '*'*len(v) if v else v for k, v in settings.items() if re.match(reg, k)}
62+
updated_settings = {k: '**********' if v else v for k, v in settings.items() if re.match(reg, k)}
6363
settings = {**settings, **updated_settings}
6464

6565
self.output_settings(settings, spider)

tests/test_code.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ 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-
assert '"SHUB_APIKEY": "*************"' in caplog.text
122-
assert '"shub_apikey": "*************"' in caplog.text
123-
assert '"api_key": "*************"' in caplog.text
121+
assert '"SHUB_APIKEY": "**********"' in caplog.text
122+
assert '"shub_apikey": "**********"' in caplog.text
123+
assert '"api_key": "**********"' in caplog.text
124124
assert 'apikey_value' not in caplog.text
125125

126126

@@ -151,8 +151,8 @@ def test_log_all_should_not_return_aws_secret_key_value_by_default(caplog):
151151
with caplog.at_level(logging.INFO):
152152
logger.spider_closed(spider)
153153

154-
assert '"AWS_SECRET_ACCESS_KEY": "*************"' in caplog.text
155-
assert '"aws_secret_access_key": "*************"' in caplog.text
154+
assert '"AWS_SECRET_ACCESS_KEY": "**********"' in caplog.text
155+
assert '"aws_secret_access_key": "**********"' in caplog.text
156156
assert 'secret_value' not in caplog.text
157157

158158

@@ -168,8 +168,8 @@ def test_log_all_should_not_return_password_value_by_default(caplog):
168168
with caplog.at_level(logging.INFO):
169169
logger.spider_closed(spider)
170170

171-
assert '"test_password": "*************"' in caplog.text
172-
assert '"PASSWORD_TEST": "*************"' in caplog.text
171+
assert '"test_password": "**********"' in caplog.text
172+
assert '"PASSWORD_TEST": "**********"' in caplog.text
173173
assert 'secret_value' not in caplog.text
174174

175175

@@ -187,5 +187,5 @@ def test_log_all_should_return_only_the_custom_regex_data_masked_if_MASKED_SENSI
187187
logger.spider_closed(spider)
188188

189189
assert 'apikey_value1' in caplog.text
190-
assert '"apppppppikey": "*****************"' in caplog.text
190+
assert '"apppppppikey": "**********"' in caplog.text
191191
assert 'some_random_value' not in caplog.text

0 commit comments

Comments
 (0)