Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion UnleashClient/clients/unleash_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,9 @@ def destroy(self) -> None:
def _redact_to_print_safely(value: Optional[str]) -> Optional[str]:
if not value:
return value
return f"{value[:6]}...{value[-3:]}"
prefix, separator, secret = value.rpartition(":")
redacted_secret = f"{secret[:6]}...{secret[-3:]}"
return f"{prefix}{separator}{redacted_secret}"

@staticmethod
def _get_fallback_value(
Expand Down
11 changes: 9 additions & 2 deletions tests/unit_tests/clients/test_unleash_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,15 @@ def test_redact_to_print_safely_truncates_middle():
assert api_key not in redacted


def test_redact_to_print_safely_keeps_environment_and_project_visible():
api_key = "production:default:abcdef1234567890ghijklmnop"
redacted = UnleashClient._redact_to_print_safely(api_key)
assert redacted == "production:default:abcdef...nop"
assert "abcdef1234567890ghijklmnop" not in redacted


def test_api_key_is_not_logged_in_plain_text_in_multiple_instances_warning(caplog):
api_key = "abcdef1234567890ghijklmnop"
api_key = "production:default:abcdef1234567890ghijklmnop"
client1 = UnleashClient(
URL,
APP_NAME,
Expand All @@ -1064,7 +1071,7 @@ def test_api_key_is_not_logged_in_plain_text_in_multiple_instances_warning(caplo

log_text = " ".join(str(r.msg) for r in caplog.records)
assert api_key not in log_text
assert "abcdef...nop" in log_text
assert "production:default:abcdef...nop" in log_text

client1.destroy()
client2.destroy()
Expand Down
Loading