1
0
mirror of https://github.com/quay/quay.git synced 2025-04-18 10:44:06 +03:00
quay/util/test/test_log_util.py
Kotakonda Sai Deekshith abcf94536b
chore: Filtering repeatPassword in debuglogs (PROJQUAY-8559) (#3659)
* Filtering repeatPassword in debuglogs

* updated test_log_util.py for format issues
2025-02-11 20:31:31 +05:30

60 lines
1.9 KiB
Python

import os
import pytest
from _init import CONF_DIR
from app import FILTERED_VALUES
from util.log import filter_logs, logfile_path
def test_filter_logs():
values = {
"user": {"password": "toto", "repeatPassword": "toto"},
"password": "toto",
"upstream_registry_username": "user",
"upstream_registry_password": "testpass",
"blob": "1234567890asdfewkqresfdsfewfdsfd",
"unfiltered": "foo",
}
filter_logs(values, FILTERED_VALUES)
assert values == {
"user": {"password": "[FILTERED]", "repeatPassword": "[FILTERED]"},
"password": "[FILTERED]",
"upstream_registry_username": "[FILTERED]",
"upstream_registry_password": "[FILTERED]",
"blob": "12345678",
"unfiltered": "foo",
}
@pytest.mark.parametrize(
"debug,jsonfmt,expected",
[
(False, False, os.path.join(CONF_DIR, "logging.conf")),
(False, True, os.path.join(CONF_DIR, "logging_json.conf")),
(True, False, os.path.join(CONF_DIR, "logging_debug.conf")),
(True, True, os.path.join(CONF_DIR, "logging_debug_json.conf")),
],
)
def test_logfile_path(debug, jsonfmt, expected, monkeypatch):
assert logfile_path(jsonfmt=jsonfmt, debug=debug) == expected
@pytest.mark.parametrize(
"debug,jsonfmt,expected",
[
("false", "false", os.path.join(CONF_DIR, "logging.conf")),
("false", "true", os.path.join(CONF_DIR, "logging_json.conf")),
("true", "false", os.path.join(CONF_DIR, "logging_debug.conf")),
("true", "true", os.path.join(CONF_DIR, "logging_debug_json.conf")),
],
)
def test_logfile_path_env(debug, jsonfmt, expected, monkeypatch):
monkeypatch.setenv("DEBUGLOG", debug)
monkeypatch.setenv("JSONLOG", jsonfmt)
assert logfile_path() == expected
def test_logfile_path_default():
assert logfile_path() == os.path.join(CONF_DIR, "logging.conf")