Skip to content

Commit 4fae20b

Browse files
committed
Add new UTs for whitespace
1 parent b30214e commit 4fae20b

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

tests/unit/test_sensitive_item_removal.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ def test_pwd_removal_preserve_context(regexes, config_line, anon_line):
623623
assert anon_line == replace_matching_item(regexes, config_line, pwd_lookup, SALT)
624624

625625

626-
@pytest.mark.parametrize("whitespace", [" ", "\t", "\n", " \t\n"])
626+
@pytest.mark.parametrize("whitespace", [" ", " ", "\t", "\n", " \t\n"])
627627
def test_pwd_removal_preserve_leading_whitespace(regexes, whitespace):
628628
"""Test leading whitespace is preserved in config lines."""
629629
config_line = "{whitespace}{line}".format(
@@ -634,7 +634,7 @@ def test_pwd_removal_preserve_leading_whitespace(regexes, whitespace):
634634
assert processed_line.startswith(whitespace)
635635

636636

637-
@pytest.mark.parametrize("whitespace", [" ", "\t", "\n", " \t\n"])
637+
@pytest.mark.parametrize("whitespace", [" ", " ", "\t", "\n", " \t\n"])
638638
def test_pwd_removal_preserve_trailing_whitespace(regexes, whitespace):
639639
"""Test trailing whitespace is preserved in config lines."""
640640
config_line = "{line}{whitespace}".format(
@@ -645,6 +645,43 @@ def test_pwd_removal_preserve_trailing_whitespace(regexes, whitespace):
645645
assert processed_line.endswith(whitespace)
646646

647647

648+
@pytest.mark.parametrize("whitespace", [" ", " ", " ", " "])
649+
def test_pwd_removal_preserve_single_inline_whitespace(regexes, whitespace):
650+
"""Test single inline whitespace is preserved in config lines."""
651+
line = "password secret"
652+
config_line = f"{line}{whitespace}{line}"
653+
pwd_lookup = {}
654+
processed_line = replace_matching_item(regexes, config_line, pwd_lookup, SALT)
655+
assert processed_line == f"{line}{whitespace}{line}"
656+
657+
658+
@pytest.mark.parametrize("whitespace", [" ", " ", " ", " "])
659+
def test_pwd_removal_preserve_multiple_inline_whitespace(regexes, whitespace):
660+
"""Test multiple inline whitespace is preserved in config lines."""
661+
line = "password secret"
662+
config_line = f"{line}{whitespace}{line}{whitespace}{line}"
663+
pwd_lookup = {}
664+
processed_line = replace_matching_item(regexes, config_line, pwd_lookup, SALT)
665+
assert processed_line == f"{line}{whitespace}{line}{whitespace}{line}"
666+
667+
668+
@pytest.mark.parametrize(
669+
"ws1, ws2",
670+
[
671+
(" ", " "),
672+
(" ", " "),
673+
(" .", " "),
674+
],
675+
)
676+
def test_pwd_removal_preserve_different_inline_whitespace(regexes, ws1, ws2):
677+
"""Test different inline whitespace sizes are preserved in config lines."""
678+
line = "password secret"
679+
config_line = f"{line}{ws1}{line}{ws2}{line}"
680+
pwd_lookup = {}
681+
processed_line = replace_matching_item(regexes, config_line, pwd_lookup, SALT)
682+
assert processed_line == f"{line}{ws1}{line}{ws2}{line}"
683+
684+
648685
@pytest.mark.parametrize("config_line,sensitive_text", sensitive_lines)
649686
@pytest.mark.parametrize(
650687
"prepend_text",

0 commit comments

Comments
 (0)