-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_logging.py
More file actions
executable file
·30 lines (22 loc) · 1.16 KB
/
Copy pathtest_logging.py
File metadata and controls
executable file
·30 lines (22 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Tests for local diagnostic logging."""
from tempfile import TemporaryDirectory
from openbox_logging import configure_logging, diagnostic_log_path, read_diagnostic_log, redact
def test_redaction():
assert "secret-token" not in redact("token=secret-token password: hunter2")
assert "<redacted>" in redact('{"api_key":"secret-token"}')
assert "hunter2" not in redact("{'password': 'hunter2'}")
assert "secret-token" not in redact("Authorization: Bearer secret-token")
assert "retroach-key-abc" not in redact("RA key= retroach-key-abc")
assert "retroach-key-abc" not in redact("RA API KEY= retroach-key-abc")
assert "igdb-secret" not in redact("client_secret= igdb-secret")
assert "igdb-secret" not in redact('{"client_secret": "igdb-secret"}')
def test_file_logging():
with TemporaryDirectory() as directory:
logger = configure_logging(directory)
logger.debug("Diagnostic test message")
assert diagnostic_log_path(directory).is_file()
assert "Diagnostic test message" in read_diagnostic_log(directory)
if __name__ == "__main__":
test_redaction()
test_file_logging()
print("logging self-test: ok")