42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
import pytest
|
|
from fastapi import HTTPException
|
|
|
|
from app.auth.mock_auth import mock_get_user_from_token, mock_initiate_auth
|
|
from app.models.auth import CognitoUser
|
|
|
|
|
|
def test_mock_get_user_from_token_success():
|
|
"""Test successful token validation returns expected user"""
|
|
user = mock_get_user_from_token("testuser")
|
|
assert isinstance(user, CognitoUser)
|
|
assert user.username == "testuser"
|
|
assert user.roles == ["admin"]
|
|
|
|
|
|
def test_mock_get_user_from_token_invalid():
|
|
"""Test invalid token raises expected exception"""
|
|
with pytest.raises(HTTPException) as exc_info:
|
|
mock_get_user_from_token("invalid_token")
|
|
|
|
assert exc_info.value.status_code == 401
|
|
assert exc_info.value.detail == "Invalid mock token - use 'testuser'"
|
|
|
|
|
|
def test_mock_initiate_auth():
|
|
"""Test mock authentication returns expected token response"""
|
|
result = mock_initiate_auth("any_user", "any_password")
|
|
|
|
assert isinstance(result, dict)
|
|
assert result["AccessToken"] == "testuser"
|
|
assert result["ExpiresIn"] == 3600
|
|
assert result["TokenType"] == "Bearer"
|
|
|
|
|
|
def test_mock_initiate_auth_different_credentials():
|
|
"""Test mock authentication works with any credentials"""
|
|
result1 = mock_initiate_auth("user1", "pass1")
|
|
result2 = mock_initiate_auth("user2", "pass2")
|
|
|
|
# Should return same mock token regardless of credentials
|
|
assert result1 == result2
|