- Updated test cases in `test_auth_endpoints.py` to ensure consistent formatting and style. - Enhanced `test_socket_endpoints.py` with consistent parameter formatting and improved readability. - Cleaned up `conftest.py` by ensuring consistent parameter formatting in fixtures. - Added comprehensive tests for API token dependencies in `test_api_token_dependencies.py`. - Refactored `test_auth_service.py` to maintain consistent parameter formatting. - Cleaned up `test_oauth_service.py` by removing unnecessary imports. - Improved `test_socket_service.py` with consistent formatting and readability. - Enhanced `test_cookies.py` by ensuring consistent formatting and readability. - Introduced new tests for token utilities in `test_token_utils.py` to validate token generation and expiration logic.
24 lines
668 B
Python
24 lines
668 B
Python
"""Cookie parsing utilities for WebSocket authentication."""
|
|
|
|
|
|
|
|
def parse_cookies(cookie_header: str) -> dict[str, str]:
|
|
"""Parse HTTP cookie header into a dictionary."""
|
|
cookies = {}
|
|
if not cookie_header:
|
|
return cookies
|
|
|
|
for cookie in cookie_header.split(";"):
|
|
cookie = cookie.strip()
|
|
if "=" in cookie:
|
|
name, value = cookie.split("=", 1)
|
|
cookies[name.strip()] = value.strip()
|
|
|
|
return cookies
|
|
|
|
|
|
def extract_access_token_from_cookies(cookie_header: str) -> str | None:
|
|
"""Extract access token from HTTP cookies."""
|
|
cookies = parse_cookies(cookie_header)
|
|
return cookies.get("access_token")
|