Skip to content

Commit c5c2b6e

Browse files
gnikonorovBeyondEvil
authored andcommitted
Allow for redacting of environment table values (pytest-dev#431)
* Add untested change * Add tests * Add documentation * Add the changelog entry * remove debug code from test * Change wording of documentation
1 parent 72cede0 commit c5c2b6e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Version History
1717

1818
* Thanks to `@gnikonorov <https://github.com/gnikonorov>`_ for the PR
1919

20+
* Implement :code:`environment_table_redact_list` to allow for redaction of environment table values. (`#233 <https://github.com/pytest-dev/pytest-html/issues/233>`_)
21+
22+
* Thanks to `@fenchu <https://github.com/fenchu>`_ for reporting and `@gnikonorov <https://github.com/gnikonorov>`_ for the PR
23+
2024
3.1.1 (2020-12-13)
2125
~~~~~~~~~~~~~~~~~~
2226

src/pytest_html/html_report.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import datetime
33
import json
44
import os
5+
import re
56
import time
67
from collections import defaultdict
78
from collections import OrderedDict
@@ -226,6 +227,10 @@ def _generate_environment(self, config):
226227

227228
for key in keys:
228229
value = metadata[key]
230+
if self._is_redactable_environment_variable(key, config):
231+
black_box_ascii_value = 0x2593
232+
value = "".join(chr(black_box_ascii_value) for char in str(value))
233+
229234
if isinstance(value, str) and value.startswith("http"):
230235
value = html.a(value, href=value, target="_blank")
231236
elif isinstance(value, (list, tuple, set)):
@@ -239,6 +244,14 @@ def _generate_environment(self, config):
239244
environment.append(html.table(rows, id="environment"))
240245
return environment
241246

247+
def _is_redactable_environment_variable(self, environment_variable, config):
248+
redactable_regexes = config.getini("environment_table_redact_list")
249+
for redactable_regex in redactable_regexes:
250+
if re.match(redactable_regex, environment_variable):
251+
return True
252+
253+
return False
254+
242255
def _save_report(self, report_content):
243256
dir_name = os.path.dirname(self.logfile)
244257
assets_dir = os.path.join(dir_name, "assets")

0 commit comments

Comments
 (0)