feat: 完善 N7 智能座舱交互与控制链路

This commit is contained in:
vee
2026-09-07 15:34:59 +08:00
parent 32d179143f
commit c96970f068
100 changed files with 30088 additions and 1174 deletions
+34
View File
@@ -7,6 +7,8 @@ from cognitive_agent.auth import (
SessionCodec,
SlidingWindowLimiter,
hash_password,
is_json_content_type,
origin_matches_host,
verify_password,
)
@@ -53,6 +55,38 @@ class AuthenticationUnitTests(unittest.TestCase):
self.assertEqual(limiter.retry_after("client", now=120), 40)
self.assertEqual(limiter.retry_after("client", now=161), 0)
def test_json_content_type_is_exact_but_allows_parameters(self) -> None:
self.assertTrue(is_json_content_type("application/json"))
self.assertTrue(is_json_content_type("Application/JSON; charset=utf-8"))
self.assertFalse(is_json_content_type("text/plain"))
self.assertFalse(is_json_content_type("application/problem+json"))
self.assertFalse(is_json_content_type(""))
def test_origin_match_uses_scheme_host_and_effective_port(self) -> None:
self.assertTrue(
origin_matches_host("http://127.0.0.1:8000", "127.0.0.1:8000", "http")
)
self.assertTrue(origin_matches_host("http://example.test", "EXAMPLE.test:80", "http"))
self.assertTrue(origin_matches_host("http://[::1]:8000", "[::1]:8000", "http"))
self.assertFalse(
origin_matches_host("http://localhost:8000", "127.0.0.1:8000", "http")
)
self.assertFalse(
origin_matches_host("https://127.0.0.1:8000", "127.0.0.1:8000", "http")
)
self.assertFalse(
origin_matches_host("http://127.0.0.1:8001", "127.0.0.1:8000", "http")
)
self.assertFalse(origin_matches_host("null", "127.0.0.1:8000", "http"))
self.assertFalse(
origin_matches_host(
"http://127.0.0.1:8000/extra",
"127.0.0.1:8000",
"http",
)
)
if __name__ == "__main__":
unittest.main()