Compare commits

...

4 Commits

Author SHA1 Message Date
aclist
525de56036 feat: redact user id in logs
Some checks failed
Mirror to Codeberg / mirror-to-codeberg (push) Has been cancelled
2026-07-24 01:13:00 +09:00
aclist
7edb66c311 chore: distinguish between api and web tests 2026-07-24 01:05:01 +09:00
aclist
dc2a635d2f chore: add typehints to test 2026-07-24 01:04:41 +09:00
aclist
8528300851 chore: update crc tests 2026-07-24 01:01:39 +09:00
5 changed files with 39 additions and 5 deletions

View File

@ -4,8 +4,9 @@ from typing import Literal
api_filter = r"(.*&key=)([^&]*)(.*)" api_filter = r"(.*&key=)([^&]*)(.*)"
home_filter = r"(/home/)([^\s'\/]*)(.*)" home_filter = r"(/home/)([^\s'\/]*)(.*)"
user_filter = r"(.*Steam/userdata/)([^/]*)(.*)"
REDACTED = r"\1REDACTED\3" REDACTED = r"\1REDACTED\3"
REDACTION_PATTERNS = [api_filter, home_filter] REDACTION_PATTERNS = [api_filter, home_filter, user_filter]
def redact_home(text: str) -> str: def redact_home(text: str) -> str:

View File

@ -114,4 +114,5 @@ markers = [
"post_install: requires a completed installation", "post_install: requires a completed installation",
"redact: log redaction mechanisms", "redact: log redaction mechanisms",
"slow: long-running tests", "slow: long-running tests",
"webtest: depends on remote endpoint",
] ]

View File

@ -37,6 +37,14 @@ class RecordsListHandler(logging.Handler):
"Error in directory: '/home/SENSITIVE_USERNAME'", "Error in directory: '/home/SENSITIVE_USERNAME'",
"Error in directory: '/home/REDACTED'", "Error in directory: '/home/REDACTED'",
), ),
(
"User directory: /home/user/.local/share/Steam/userdata/999999/grid",
"User directory: /home/REDACTED/.local/share/Steam/userdata/REDACTED/grid",
),
(
"User directory: /drive/.local/share/Steam/userdata/999999",
"User directory: /drive/.local/share/Steam/userdata/REDACTED",
),
], ],
) )
def test_log_redaction(log_error: str, expect: str) -> None: def test_log_redaction(log_error: str, expect: str) -> None:

View File

@ -4,7 +4,7 @@ from dzgui.config.query import get_config
from dzgui.config.xdg import get_xdg_paths, parse_filepaths from dzgui.config.xdg import get_xdg_paths, parse_filepaths
from dzgui.api import probe from dzgui.api import probe
pytestmark = pytest.mark.apitest pytestmark = pytest.mark.webtest
@pytest.fixture @pytest.fixture

View File

@ -38,14 +38,14 @@ def dummy_app() -> None:
return d return d
def test_wrap_exe(dummy_app) -> None: def test_wrap_exe(dummy_app: dict[str, str]) -> None:
s = Shortcuts(Path("")) s = Shortcuts(Path(""))
s.add_shortcut(*dummy_app.values()) s.add_shortcut(*dummy_app.values())
assert s.shortcuts["shortcuts"]["0"]["Exe"][0] == '"' assert s.shortcuts["shortcuts"]["0"]["Exe"][0] == '"'
assert s.shortcuts["shortcuts"]["0"]["Exe"][-1] == '"' assert s.shortcuts["shortcuts"]["0"]["Exe"][-1] == '"'
def test_add_shortcut(dummy_app) -> None: def test_add_shortcut(dummy_app: dict[str, str]) -> None:
s = Shortcuts(Path("")) s = Shortcuts(Path(""))
s.add_shortcut(*dummy_app.values()) s.add_shortcut(*dummy_app.values())
new = s.shortcuts["shortcuts"] new = s.shortcuts["shortcuts"]
@ -56,7 +56,7 @@ def test_add_shortcut(dummy_app) -> None:
assert new[ind][k] == v assert new[ind][k] == v
def test_save_shortcut(dummy_app) -> None: def test_save_shortcut(dummy_app: dict[str, str]) -> None:
s = Shortcuts(Path("")) s = Shortcuts(Path(""))
s.add_shortcut(*dummy_app.values()) s.add_shortcut(*dummy_app.values())
with tempfile.NamedTemporaryFile() as f: with tempfile.NamedTemporaryFile() as f:
@ -65,3 +65,27 @@ def test_save_shortcut(dummy_app) -> None:
s.save_shortcuts() s.save_shortcuts()
s._load_shortcuts(tmp) s._load_shortcuts(tmp)
assert len(s.shortcuts["shortcuts"]) == 1 assert len(s.shortcuts["shortcuts"]) == 1
def test_shortcut_crc(dummy_app: dict[str, str]) -> None:
s = Shortcuts(Path(""))
s.add_shortcut(*dummy_app.values())
for key in s.shortcuts["shortcuts"].keys():
entry = s.shortcuts["shortcuts"][key]
name = entry["AppName"]
exe = entry["Exe"]
uid = name + exe
bpid = s.gen_bpid(uid)
assert entry["appid"] & 0xFFFFFFFF == bpid
def test_reverse_crc(dummy_app: dict[str, str]) -> None:
s = Shortcuts(Path(""))
s.add_shortcut(*dummy_app.values())
for key in s.shortcuts["shortcuts"].keys():
entry = s.shortcuts["shortcuts"][key]
name = entry["AppName"]
exe = entry["Exe"]
uid = name + exe
bpid = s.gen_bpid(uid)
assert s.find_appname_by_unsigned_id(bpid) == name