2022-11-02 13:00:54 +01:00
|
|
|
"""Test camera user and password cleanup."""
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
2023-07-06 16:28:50 +02:00
|
|
|
from frigate.util.builtin import clean_camera_user_pass, escape_special_characters
|
2022-11-02 13:00:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestUserPassCleanup(unittest.TestCase):
|
|
|
|
def setUp(self) -> None:
|
|
|
|
self.rtsp_with_pass = "rtsp://user:password@192.168.0.2:554/live"
|
2022-11-06 03:42:32 +01:00
|
|
|
self.rtsp_with_special_pass = (
|
|
|
|
"rtsp://user:password`~!@#$%^&*()-_;',.<>:\"\{\}\[\]@@192.168.0.2:554/live"
|
|
|
|
)
|
2022-11-02 13:00:54 +01:00
|
|
|
self.rtsp_no_pass = "rtsp://192.168.0.3:554/live"
|
|
|
|
|
|
|
|
def test_cleanup(self):
|
|
|
|
"""Test that user / pass are cleaned up."""
|
|
|
|
clean = clean_camera_user_pass(self.rtsp_with_pass)
|
|
|
|
assert clean != self.rtsp_with_pass
|
|
|
|
assert "user:password" not in clean
|
|
|
|
|
|
|
|
def test_no_cleanup(self):
|
|
|
|
"""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)
|
2022-11-06 03:42:32 +01:00
|
|
|
assert (
|
|
|
|
escaped
|
|
|
|
== "rtsp://user:password%60~%21%40%23%24%25%5E%26%2A%28%29-_%3B%27%2C.%3C%3E%3A%22%5C%7B%5C%7D%5C%5B%5C%5D%40@192.168.0.2:554/live"
|
|
|
|
)
|
2022-11-02 13:00:54 +01:00
|
|
|
|
|
|
|
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
|
2023-03-21 23:21:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestUserPassMasking(unittest.TestCase):
|
|
|
|
def setUp(self) -> None:
|
|
|
|
self.rtsp_log_message = "Did you mean file:rtsp://user:password@192.168.1.3:554"
|
|
|
|
|
|
|
|
def test_rtsp_in_log_message(self):
|
2024-02-17 23:01:50 +01:00
|
|
|
"""Test that the rtsp url in a log message is escaped."""
|
2023-03-21 23:21:37 +01:00
|
|
|
escaped = clean_camera_user_pass(self.rtsp_log_message)
|
|
|
|
print(f"The escaped is {escaped}")
|
|
|
|
assert escaped == "Did you mean file:rtsp://*:*@192.168.1.3:554"
|