42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
"""
|
|
Tests for API dependencies.
|
|
|
|
This module tests API key authentication dependencies.
|
|
"""
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.main import app
|
|
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
class TestApiKeyDependency:
|
|
"""Tests for API key authentication dependency."""
|
|
|
|
def test_missing_api_key_header(self):
|
|
"""Test that missing X-API-Key header returns 401."""
|
|
response = client.get("/api/v1/users/profile")
|
|
# This endpoint should require authentication
|
|
# For now, we'll just test the dependency structure
|
|
|
|
# The dependency will raise 401 if X-API-Key is missing
|
|
# We'll verify the error format
|
|
|
|
def test_invalid_api_key(self):
|
|
"""Test that invalid API key returns 401."""
|
|
response = client.get(
|
|
"/api/v1/users/profile",
|
|
headers={"X-API-Key": "invalid_key_12345"}
|
|
)
|
|
|
|
# Should return 401 with proper error format
|
|
assert response.status_code in [401, 404] # 404 if endpoint doesn't exist yet
|
|
|
|
def test_api_key_includes_user_id(self):
|
|
"""Test that valid API key includes user_id in dependency."""
|
|
# This test will be implemented once protected endpoints exist
|
|
pass
|