test_runner: redact passwords from log messages (#2434)

This commit is contained in:
Alexander Bayandin
2022-09-13 18:24:11 +01:00
committed by GitHub
parent 1a8c8b04d7
commit 59d04ab66a
2 changed files with 15 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
import logging
import logging.config
import re
"""
This file configures logging to use in python tests.
@@ -29,6 +30,17 @@ LOGGING = {
}
class PasswordFilter(logging.Filter):
"""Filter out password from logs."""
# Good enough to filter our passwords produced by PgProtocol.connstr
FILTER = re.compile(r"(\s*)password=[^\s]+(\s*)")
def filter(self, record: logging.LogRecord) -> bool:
record.msg = self.FILTER.sub(r"\1password=<hidden>\2", str(record.msg))
return True
def getLogger(name="root") -> logging.Logger:
"""Method to get logger for tests.
@@ -38,5 +50,6 @@ def getLogger(name="root") -> logging.Logger:
# default logger for tests
log = getLogger()
log.addFilter(PasswordFilter())
logging.config.dictConfig(LOGGING)

View File

@@ -125,7 +125,8 @@ def pytest_configure(config):
if env_neon_bin:
neon_binpath = env_neon_bin
else:
neon_binpath = os.path.join(base_dir, "target/debug")
build_type = os.environ.get("BUILD_TYPE", "debug")
neon_binpath = os.path.join(base_dir, "target", build_type)
log.info(f"neon_binpath is {neon_binpath}")
if not os.path.exists(os.path.join(neon_binpath, "pageserver")):
raise Exception('neon binaries not found at "{}"'.format(neon_binpath))