mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-03 01:35:22 +03:00
Add tests for special character handling
This commit is contained in:
parent
4902ba1e90
commit
7d17546aee
@ -2,12 +2,13 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from frigate.util import clean_camera_user_pass
|
||||
from frigate.util import clean_camera_user_pass, escape_special_characters
|
||||
|
||||
|
||||
class TestUserPassCleanup(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.rtsp_with_pass = "rtsp://user:password@192.168.0.2:554/live"
|
||||
self.rtsp_with_special_pass = "rtsp://user:password#$@@192.168.0.2:554/live"
|
||||
self.rtsp_no_pass = "rtsp://192.168.0.3:554/live"
|
||||
|
||||
def test_cleanup(self):
|
||||
@ -20,3 +21,13 @@ class TestUserPassCleanup(unittest.TestCase):
|
||||
"""Test that nothing changes when no user / pass are defined."""
|
||||
clean = clean_camera_user_pass(self.rtsp_no_pass)
|
||||
assert clean == self.rtsp_no_pass
|
||||
|
||||
def test_special_char_password(self):
|
||||
"""Test that special characters in pw are escaped, but not others."""
|
||||
escaped = escape_special_characters(self.rtsp_with_special_pass)
|
||||
assert escaped == "rtsp://user:password%23%24%40@192.168.0.2:554/live"
|
||||
|
||||
def test_no_special_char_password(self):
|
||||
"""Test that no change is made to path with no special characters."""
|
||||
escaped = escape_special_characters(self.rtsp_with_pass)
|
||||
assert escaped == self.rtsp_with_pass
|
||||
@ -633,7 +633,6 @@ def escape_special_characters(path: str) -> str:
|
||||
try:
|
||||
found = re.search(REGEX_CAMERA_USER_PASS, path).group(0)[:-1]
|
||||
pw = found[(found.index(":") + 1) :]
|
||||
logger.error(f"Found {found} and pw {pw}")
|
||||
return path.replace(pw, urllib.parse.quote_plus(pw))
|
||||
except AttributeError:
|
||||
# path does not have user:pass
|
||||
|
||||
Loading…
Reference in New Issue
Block a user