feat(api): Implement JWT utility functions and configuration
This commit is contained in:
24
tests/api/test_utils.py
Normal file
24
tests/api/test_utils.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from datetime import timedelta
|
||||
from ea_chatbot.api.utils import create_access_token, decode_access_token
|
||||
|
||||
def test_create_and_decode_access_token():
|
||||
"""Test that a token can be created and then decoded."""
|
||||
data = {"sub": "test@example.com", "user_id": "123"}
|
||||
token = create_access_token(data)
|
||||
|
||||
decoded = decode_access_token(token)
|
||||
assert decoded["sub"] == data["sub"]
|
||||
assert decoded["user_id"] == data["user_id"]
|
||||
assert "exp" in decoded
|
||||
|
||||
def test_decode_invalid_token():
|
||||
"""Test that an invalid token returns None."""
|
||||
assert decode_access_token("invalid-token") is None
|
||||
|
||||
def test_expired_token():
|
||||
"""Test that an expired token returns None."""
|
||||
data = {"sub": "test@example.com"}
|
||||
# Create a token that expired 1 minute ago
|
||||
token = create_access_token(data, expires_delta=timedelta(minutes=-1))
|
||||
|
||||
assert decode_access_token(token) is None
|
||||
Reference in New Issue
Block a user