Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkst-pieter committed Dec 4, 2024
1 parent c032506 commit 5360398
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
21 changes: 9 additions & 12 deletions canarytokens/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,28 +525,25 @@ class WindowsFakeFSTokenRequest(TokenRequest):

@validator("windows_fake_fs_root")
def check_process_name(value: str):
_value = value.strip()
invalid_chars = r'[<>:"/\\|?*]'
drive_pattern = r"^[A-Za-z]:[\\/]"

if not re.match(drive_pattern, value):
if not re.match(drive_pattern, _value):
raise ValueError(
f"windows_fake_fs_root does not have a drive letter specified. Given: {value}"
f"windows_fake_fs_root does not have a drive letter specified. Given: {_value}"
)

folder_path = re.sub(drive_pattern, "", value, 1)
folder_path = re.sub(drive_pattern, "", _value, 1)
if re.search(invalid_chars, folder_path):
raise ValueError(
f"windows_fake_fs_root contains invalid Windows Path Characters. Given: {value}"
)
if value.endswith(" "):
raise ValueError(
f"windows_fake_fs_root cannot end with a space. Given: {value}"
f"windows_fake_fs_root contains invalid Windows Path Characters. Given: {_value}"
)
if value.endswith("."):
if _value.endswith("."):
raise ValueError(
f"windows_fake_fs_root cannot end with a fullstop. Given: {value}"
f"windows_fake_fs_root cannot end with a fullstop. Given: {_value}"
)
return value

return _value


class CCTokenRequest(TokenRequest):
Expand Down
11 changes: 5 additions & 6 deletions tests/integration/test_windows_fake_fs_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ def test_windows_fake_fs_token_fires(
)

stats = get_stats_from_webhook(webhook_receiver, token=token_info.token)
if stats is not None:
# Check that what was sent to the webhook is consistent.
assert len(stats) == expected_hits
assert stats[0]["memo"] == memo
_ = TokenAlertDetailGeneric(**stats[0])
assert stats is not None
# Check that what was sent to the webhook is consistent.
assert len(stats) == expected_hits
assert stats[0]["memo"] == memo
_ = TokenAlertDetailGeneric(**stats[0])

# Check that the returned history has a single hit.
resp = get_token_history(token_info=token_info, version=version)
Expand Down Expand Up @@ -109,7 +109,6 @@ def test_windows_fake_fs_token_fires(
],
"windows_fake_fs_root contains invalid Windows Path Characters.",
),
([r"C:\Testing "], "windows_fake_fs_root cannot end with a space."),
([r"C:\Testing."], "windows_fake_fs_root cannot end with a fullstop."),
([r"Testing"], "windows_fake_fs_root does not have a drive letter specified."),
],
Expand Down

0 comments on commit 5360398

Please sign in to comment.