Skip to content

Commit 8670e64

Browse files
Rename function.
1 parent 3442288 commit 8670e64

3 files changed

Lines changed: 20 additions & 16 deletions

File tree

django/cohiva/tests/test_utils_strings.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
from django.test import TestCase
22

3-
from cohiva.utils.strings import remove_secrets_from_uri
3+
from cohiva.utils.strings import sanitize_log_message
44

55

66
class UtilsStringsTestCase(TestCase):
7-
def test_remove_secrets_from_uri_no_uri(self):
7+
def test_sanitize_log_message_no_uri(self):
88
text = "Normal text without URI"
9-
safe_text = remove_secrets_from_uri(text)
9+
safe_text = sanitize_log_message(text)
1010
self.assertEqual(safe_text, text)
1111

12-
def test_remove_secrets_from_uri_no_password(self):
12+
def test_sanitize_log_message_uri_without_password(self):
1313
text = "Normal text without URI but no password https://user@host/path?bla=1 more text"
14-
safe_text = remove_secrets_from_uri(text)
14+
safe_text = sanitize_log_message(text)
1515
self.assertEqual(safe_text, text)
1616

17-
def test_remove_secrets_from_uri_https(self):
18-
safe_text = remove_secrets_from_uri("https://user:_SECRET_@host")
17+
def test_sanitize_log_message_uri_https(self):
18+
safe_text = sanitize_log_message("https://user:_SECRET_@host")
1919
self.assertEqual(safe_text, "https://user:******@host")
2020

21-
def test_remove_secrets_from_uri_https_with_text(self):
22-
safe_text = remove_secrets_from_uri("Text https://user:_SECRET_@host more text")
21+
def test_sanitize_log_message_uri_https_with_text(self):
22+
safe_text = sanitize_log_message("Text https://user:_SECRET_@host more text")
2323
self.assertEqual(safe_text, "Text https://user:******@host more text")
2424

25-
def test_remove_secrets_from_uri_mysql(self):
26-
safe_text = remove_secrets_from_uri("Text mysql://user:_SECRET_@host more text")
25+
def test_sanitize_log_message_uri_mysql(self):
26+
safe_text = sanitize_log_message("Text mysql://user:_SECRET_@host more text")
2727
self.assertEqual(safe_text, "Text mysql://user:******@host more text")
2828

29-
def test_remove_secrets_from_uri_multiple(self):
29+
def test_sanitize_log_message_multiple_uris(self):
3030
text = (
3131
"Text https://user:_SECRET_@host more text "
3232
"mysql://user:_SECRET_@host/path/to/?query=1 more text"
3333
)
34-
safe_text = remove_secrets_from_uri(text)
34+
safe_text = sanitize_log_message(text)
3535
self.assertEqual(
3636
safe_text,
3737
(

django/cohiva/utils/strings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ def pluralize(count, singular, plural):
77
return f"{count} {plural}"
88

99

10-
def remove_secrets_from_uri(text: str):
10+
def sanitize_log_message(text: str):
11+
return _sanitize_uris(text)
12+
13+
14+
def _sanitize_uris(text: str):
1115
pattern = (
1216
r"\b(?P<protocol>[a-zA-Z][a-zA-Z0-9+.-]*)://"
1317
r"(?P<username>[^:@/\s]+):(?P<password>[^@/\s]+)@"

django/finance/accounting/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from django.conf import settings
55

6-
from cohiva.utils.strings import remove_secrets_from_uri
6+
from cohiva.utils.strings import sanitize_log_message
77
from finance.accounting import CashctrlBook, DummyBook, GnucashBook
88

99
logger = logging.getLogger("finance_accounting")
@@ -120,7 +120,7 @@ def __enter__(self) -> CashctrlBook | GnucashBook | DummyBook | None:
120120
self.backend_obj = self.backend_class(self.backend_label, self.db_id)
121121
return self.backend_obj
122122
except Exception as e:
123-
error_msg = remove_secrets_from_uri(str(e))
123+
error_msg = sanitize_log_message(str(e))
124124
logger.error(
125125
f"Couldn't initialize accounting backend {self.backend_class}: {error_msg}"
126126
)

0 commit comments

Comments
 (0)