mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-26 09:30:37 +00:00
test_runner: redact passwords from log messages (#2434)
This commit is contained in:
committed by
GitHub
parent
1a8c8b04d7
commit
59d04ab66a
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user