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
9 changes: 8 additions & 1 deletion dbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@


class DbSyncError(Exception):
pass
default_print_password = "password='*****'"

def __init__(self, message):
# escaped password
message = re.sub(r'password=[\"\'].+[\"\'](?=\s)', self.default_print_password, message)
# not escaped password
message = re.sub(r'password=\S+', self.default_print_password, message)
super().__init__(message)


def _add_quotes_to_schema_name(schema: str) -> str:
Expand Down
21 changes: 21 additions & 0 deletions test/test_dbsyncerror.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest

from dbsync import DbSyncError


@pytest.mark.parametrize("password", ['password=\"my_secret password 8417\\.\"',
'password=\'my_secret password\'',
"password=my_secret_password84189./+-"
])
def test_DbSyncError_password_print(password: str):
host = "host=\"localhost\""
user = "user=user"

conn_string = f"{user} {password} {host}"

with pytest.raises(DbSyncError) as err:
raise DbSyncError(conn_string)
assert password not in str(err)
assert user in str(err)
assert host in str(err)
assert DbSyncError.default_print_password in str(err.value)