| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803 |
- """Integration tests for Authentication API endpoints.
- Tests the full request/response cycle for /api/v1/auth/ and /api/v1/users/ endpoints.
- """
- import pytest
- from httpx import AsyncClient
- class TestAuthStatusAPI:
- """Integration tests for /api/v1/auth/status endpoint."""
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_get_auth_status_disabled(self, async_client: AsyncClient):
- """Verify auth status returns disabled when not configured."""
- response = await async_client.get("/api/v1/auth/status")
- assert response.status_code == 200
- result = response.json()
- assert "auth_enabled" in result
- assert result["auth_enabled"] is False
- assert result["requires_setup"] is True
- class TestAuthSetupAPI:
- """Integration tests for /api/v1/auth/setup endpoint."""
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_setup_auth_disabled(self, async_client: AsyncClient):
- """Verify auth can be set up with auth disabled (no password required)."""
- response = await async_client.post(
- "/api/v1/auth/setup",
- json={"auth_enabled": False},
- )
- assert response.status_code == 200
- result = response.json()
- assert result["auth_enabled"] is False
- assert result["admin_created"] is False
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_setup_auth_enabled_requires_credentials(self, async_client: AsyncClient):
- """Verify enabling auth requires admin username and password."""
- response = await async_client.post(
- "/api/v1/auth/setup",
- json={"auth_enabled": True},
- )
- assert response.status_code == 400
- assert "Admin username and password are required" in response.json()["detail"]
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_setup_auth_enabled_with_credentials(self, async_client: AsyncClient):
- """Verify auth can be enabled with admin credentials."""
- response = await async_client.post(
- "/api/v1/auth/setup",
- json={
- "auth_enabled": True,
- "admin_username": "testadmin",
- "admin_password": "testpassword123",
- },
- )
- assert response.status_code == 200
- result = response.json()
- assert result["auth_enabled"] is True
- assert result["admin_created"] is True
- class TestAuthLoginAPI:
- """Integration tests for /api/v1/auth/login endpoint."""
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_login_auth_disabled(self, async_client: AsyncClient):
- """Verify login fails when auth is not enabled."""
- response = await async_client.post(
- "/api/v1/auth/login",
- json={"username": "admin", "password": "password"},
- )
- assert response.status_code == 400
- assert "Authentication is not enabled" in response.json()["detail"]
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_login_success(self, async_client: AsyncClient):
- """Verify login succeeds with valid credentials after setup."""
- # First enable auth
- await async_client.post(
- "/api/v1/auth/setup",
- json={
- "auth_enabled": True,
- "admin_username": "logintest",
- "admin_password": "loginpassword123",
- },
- )
- # Now login
- response = await async_client.post(
- "/api/v1/auth/login",
- json={"username": "logintest", "password": "loginpassword123"},
- )
- assert response.status_code == 200
- result = response.json()
- assert "access_token" in result
- assert result["token_type"] == "bearer"
- assert result["user"]["username"] == "logintest"
- assert result["user"]["role"] == "admin"
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_login_invalid_credentials(self, async_client: AsyncClient):
- """Verify login fails with invalid credentials."""
- # First enable auth
- await async_client.post(
- "/api/v1/auth/setup",
- json={
- "auth_enabled": True,
- "admin_username": "invalidtest",
- "admin_password": "correctpassword",
- },
- )
- # Try login with wrong password
- response = await async_client.post(
- "/api/v1/auth/login",
- json={"username": "invalidtest", "password": "wrongpassword"},
- )
- assert response.status_code == 401
- assert "Incorrect username or password" in response.json()["detail"]
- class TestAuthMeAPI:
- """Integration tests for /api/v1/auth/me endpoint."""
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_me_without_token(self, async_client: AsyncClient):
- """Verify /me fails without authentication token."""
- response = await async_client.get("/api/v1/auth/me")
- assert response.status_code == 401
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_me_with_valid_token(self, async_client: AsyncClient):
- """Verify /me returns user info with valid token."""
- # Setup and login
- await async_client.post(
- "/api/v1/auth/setup",
- json={
- "auth_enabled": True,
- "admin_username": "metest",
- "admin_password": "mepassword123",
- },
- )
- login_response = await async_client.post(
- "/api/v1/auth/login",
- json={"username": "metest", "password": "mepassword123"},
- )
- token = login_response.json()["access_token"]
- # Get current user
- response = await async_client.get(
- "/api/v1/auth/me",
- headers={"Authorization": f"Bearer {token}"},
- )
- assert response.status_code == 200
- result = response.json()
- assert result["username"] == "metest"
- assert result["role"] == "admin"
- assert result["is_active"] is True
- class TestUsersAPI:
- """Integration tests for /api/v1/users/ endpoints."""
- @pytest.fixture
- async def auth_token(self, async_client: AsyncClient):
- """Setup auth and return admin token."""
- await async_client.post(
- "/api/v1/auth/setup",
- json={
- "auth_enabled": True,
- "admin_username": "usersadmin",
- "admin_password": "adminpassword123",
- },
- )
- login_response = await async_client.post(
- "/api/v1/auth/login",
- json={"username": "usersadmin", "password": "adminpassword123"},
- )
- return login_response.json()["access_token"]
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_list_users_requires_auth(self, async_client: AsyncClient):
- """Verify listing users requires authentication when auth is enabled."""
- # First enable auth
- await async_client.post(
- "/api/v1/auth/setup",
- json={
- "auth_enabled": True,
- "admin_username": "authreqadmin",
- "admin_password": "adminpassword123",
- },
- )
- # Now try to list users without a token
- response = await async_client.get("/api/v1/users/")
- assert response.status_code == 401
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_list_users_as_admin(self, async_client: AsyncClient, auth_token: str):
- """Verify admin can list users."""
- response = await async_client.get(
- "/api/v1/users/",
- headers={"Authorization": f"Bearer {auth_token}"},
- )
- assert response.status_code == 200
- result = response.json()
- assert isinstance(result, list)
- assert len(result) >= 1 # At least the admin user
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_create_user(self, async_client: AsyncClient, auth_token: str):
- """Verify admin can create a new user."""
- response = await async_client.post(
- "/api/v1/users/",
- headers={"Authorization": f"Bearer {auth_token}"},
- json={
- "username": "newuser",
- "password": "newuserpassword",
- "role": "user",
- },
- )
- assert response.status_code == 201
- result = response.json()
- assert result["username"] == "newuser"
- assert result["role"] == "user"
- assert result["is_active"] is True
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_create_user_duplicate_username(self, async_client: AsyncClient, auth_token: str):
- """Verify creating user with duplicate username fails."""
- # Create first user
- await async_client.post(
- "/api/v1/users/",
- headers={"Authorization": f"Bearer {auth_token}"},
- json={
- "username": "duplicateuser",
- "password": "password123",
- "role": "user",
- },
- )
- # Try to create duplicate
- response = await async_client.post(
- "/api/v1/users/",
- headers={"Authorization": f"Bearer {auth_token}"},
- json={
- "username": "duplicateuser",
- "password": "password456",
- "role": "user",
- },
- )
- assert response.status_code == 400
- assert "Username already exists" in response.json()["detail"]
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_update_user(self, async_client: AsyncClient, auth_token: str):
- """Verify admin can update a user."""
- # Create user
- create_response = await async_client.post(
- "/api/v1/users/",
- headers={"Authorization": f"Bearer {auth_token}"},
- json={
- "username": "updateuser",
- "password": "password123",
- "role": "user",
- },
- )
- user_id = create_response.json()["id"]
- # Update user
- response = await async_client.patch(
- f"/api/v1/users/{user_id}",
- headers={"Authorization": f"Bearer {auth_token}"},
- json={"role": "admin"},
- )
- assert response.status_code == 200
- assert response.json()["role"] == "admin"
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_delete_user(self, async_client: AsyncClient, auth_token: str):
- """Verify admin can delete a user."""
- # Create user
- create_response = await async_client.post(
- "/api/v1/users/",
- headers={"Authorization": f"Bearer {auth_token}"},
- json={
- "username": "deleteuser",
- "password": "password123",
- "role": "user",
- },
- )
- user_id = create_response.json()["id"]
- # Delete user
- response = await async_client.delete(
- f"/api/v1/users/{user_id}",
- headers={"Authorization": f"Bearer {auth_token}"},
- )
- assert response.status_code == 204
- class TestAuthDisableAPI:
- """Integration tests for /api/v1/auth/disable endpoint."""
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_disable_auth(self, async_client: AsyncClient):
- """Verify admin can disable authentication."""
- # Setup auth
- await async_client.post(
- "/api/v1/auth/setup",
- json={
- "auth_enabled": True,
- "admin_username": "disableadmin",
- "admin_password": "adminpassword123",
- },
- )
- # Login to get token
- login_response = await async_client.post(
- "/api/v1/auth/login",
- json={"username": "disableadmin", "password": "adminpassword123"},
- )
- token = login_response.json()["access_token"]
- # Disable auth
- response = await async_client.post(
- "/api/v1/auth/disable",
- headers={"Authorization": f"Bearer {token}"},
- )
- assert response.status_code == 200
- assert response.json()["auth_enabled"] is False
- # Verify auth is now disabled
- status_response = await async_client.get("/api/v1/auth/status")
- assert status_response.json()["auth_enabled"] is False
- class TestGroupsAPI:
- """Integration tests for /api/v1/groups/ endpoints."""
- @pytest.fixture
- async def auth_token(self, async_client: AsyncClient):
- """Setup auth and return admin token."""
- await async_client.post(
- "/api/v1/auth/setup",
- json={
- "auth_enabled": True,
- "admin_username": "groupsadmin",
- "admin_password": "adminpassword123",
- },
- )
- login_response = await async_client.post(
- "/api/v1/auth/login",
- json={"username": "groupsadmin", "password": "adminpassword123"},
- )
- return login_response.json()["access_token"]
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_list_groups(self, async_client: AsyncClient, auth_token: str):
- """Verify listing groups returns default groups."""
- response = await async_client.get(
- "/api/v1/groups/",
- headers={"Authorization": f"Bearer {auth_token}"},
- )
- assert response.status_code == 200
- groups = response.json()
- assert isinstance(groups, list)
- # Should have default groups: Administrators, Operators, Viewers
- group_names = [g["name"] for g in groups]
- assert "Administrators" in group_names
- assert "Operators" in group_names
- assert "Viewers" in group_names
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_get_permissions(self, async_client: AsyncClient, auth_token: str):
- """Verify getting available permissions."""
- response = await async_client.get(
- "/api/v1/groups/permissions",
- headers={"Authorization": f"Bearer {auth_token}"},
- )
- assert response.status_code == 200
- permissions = response.json()
- assert isinstance(permissions, dict)
- # Should have permission categories
- assert "Printers" in permissions or len(permissions) > 0
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_create_group(self, async_client: AsyncClient, auth_token: str):
- """Verify creating a new group."""
- response = await async_client.post(
- "/api/v1/groups/",
- headers={"Authorization": f"Bearer {auth_token}"},
- json={
- "name": "Custom Group",
- "description": "A custom test group",
- "permissions": ["printers:read", "archives:read"],
- },
- )
- assert response.status_code == 201
- group = response.json()
- assert group["name"] == "Custom Group"
- assert group["description"] == "A custom test group"
- assert "printers:read" in group["permissions"]
- assert group["is_system"] is False
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_update_group(self, async_client: AsyncClient, auth_token: str):
- """Verify updating a group."""
- # Create a group first
- create_response = await async_client.post(
- "/api/v1/groups/",
- headers={"Authorization": f"Bearer {auth_token}"},
- json={
- "name": "Update Test Group",
- "permissions": ["printers:read"],
- },
- )
- group_id = create_response.json()["id"]
- # Update the group
- response = await async_client.patch(
- f"/api/v1/groups/{group_id}",
- headers={"Authorization": f"Bearer {auth_token}"},
- json={
- "description": "Updated description",
- "permissions": ["printers:read", "printers:control"],
- },
- )
- assert response.status_code == 200
- group = response.json()
- assert group["description"] == "Updated description"
- assert "printers:control" in group["permissions"]
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_cannot_delete_system_group(self, async_client: AsyncClient, auth_token: str):
- """Verify system groups cannot be deleted."""
- # Get the Administrators group
- list_response = await async_client.get(
- "/api/v1/groups/",
- headers={"Authorization": f"Bearer {auth_token}"},
- )
- admin_group = next(g for g in list_response.json() if g["name"] == "Administrators")
- # Try to delete it
- response = await async_client.delete(
- f"/api/v1/groups/{admin_group['id']}",
- headers={"Authorization": f"Bearer {auth_token}"},
- )
- assert response.status_code == 400
- assert "system group" in response.json()["detail"].lower()
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_delete_custom_group(self, async_client: AsyncClient, auth_token: str):
- """Verify custom groups can be deleted."""
- # Create a group
- create_response = await async_client.post(
- "/api/v1/groups/",
- headers={"Authorization": f"Bearer {auth_token}"},
- json={"name": "Delete Test Group"},
- )
- group_id = create_response.json()["id"]
- # Delete it
- response = await async_client.delete(
- f"/api/v1/groups/{group_id}",
- headers={"Authorization": f"Bearer {auth_token}"},
- )
- assert response.status_code == 204
- class TestUserGroupsAPI:
- """Integration tests for user-group assignments."""
- @pytest.fixture
- async def auth_token(self, async_client: AsyncClient):
- """Setup auth and return admin token."""
- await async_client.post(
- "/api/v1/auth/setup",
- json={
- "auth_enabled": True,
- "admin_username": "usergroupadmin",
- "admin_password": "adminpassword123",
- },
- )
- login_response = await async_client.post(
- "/api/v1/auth/login",
- json={"username": "usergroupadmin", "password": "adminpassword123"},
- )
- return login_response.json()["access_token"]
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_create_user_with_groups(self, async_client: AsyncClient, auth_token: str):
- """Verify creating a user with group assignments."""
- # Get Operators group ID
- groups_response = await async_client.get(
- "/api/v1/groups/",
- headers={"Authorization": f"Bearer {auth_token}"},
- )
- operators_group = next(g for g in groups_response.json() if g["name"] == "Operators")
- # Create user with group
- response = await async_client.post(
- "/api/v1/users/",
- headers={"Authorization": f"Bearer {auth_token}"},
- json={
- "username": "groupuser",
- "password": "password123",
- "group_ids": [operators_group["id"]],
- },
- )
- assert response.status_code == 201
- user = response.json()
- assert any(g["name"] == "Operators" for g in user["groups"])
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_add_user_to_group(self, async_client: AsyncClient, auth_token: str):
- """Verify adding a user to a group."""
- # Create a user
- user_response = await async_client.post(
- "/api/v1/users/",
- headers={"Authorization": f"Bearer {auth_token}"},
- json={"username": "addtogroup", "password": "password123"},
- )
- user_id = user_response.json()["id"]
- # Get Viewers group
- groups_response = await async_client.get(
- "/api/v1/groups/",
- headers={"Authorization": f"Bearer {auth_token}"},
- )
- viewers_group = next(g for g in groups_response.json() if g["name"] == "Viewers")
- # Add user to group
- response = await async_client.post(
- f"/api/v1/groups/{viewers_group['id']}/users/{user_id}",
- headers={"Authorization": f"Bearer {auth_token}"},
- )
- assert response.status_code == 204
- # Verify user is in group
- user_check = await async_client.get(
- f"/api/v1/users/{user_id}",
- headers={"Authorization": f"Bearer {auth_token}"},
- )
- assert any(g["name"] == "Viewers" for g in user_check.json()["groups"])
- class TestChangePasswordAPI:
- """Integration tests for /api/v1/users/me/change-password endpoint."""
- @pytest.fixture
- async def user_token(self, async_client: AsyncClient):
- """Setup auth and return regular user token."""
- # Enable auth with admin
- await async_client.post(
- "/api/v1/auth/setup",
- json={
- "auth_enabled": True,
- "admin_username": "pwchangeadmin",
- "admin_password": "adminpassword123",
- },
- )
- admin_login = await async_client.post(
- "/api/v1/auth/login",
- json={"username": "pwchangeadmin", "password": "adminpassword123"},
- )
- admin_token = admin_login.json()["access_token"]
- # Create a regular user
- await async_client.post(
- "/api/v1/users/",
- headers={"Authorization": f"Bearer {admin_token}"},
- json={"username": "pwchangeuser", "password": "oldpassword123"},
- )
- # Login as regular user
- user_login = await async_client.post(
- "/api/v1/auth/login",
- json={"username": "pwchangeuser", "password": "oldpassword123"},
- )
- return user_login.json()["access_token"]
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_change_password_success(self, async_client: AsyncClient, user_token: str):
- """Verify user can change their own password."""
- response = await async_client.post(
- "/api/v1/users/me/change-password",
- headers={"Authorization": f"Bearer {user_token}"},
- json={
- "current_password": "oldpassword123",
- "new_password": "newpassword456",
- },
- )
- assert response.status_code == 200
- assert "success" in response.json()["message"].lower()
- # Verify can login with new password
- login_response = await async_client.post(
- "/api/v1/auth/login",
- json={"username": "pwchangeuser", "password": "newpassword456"},
- )
- assert login_response.status_code == 200
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_change_password_wrong_current(self, async_client: AsyncClient, user_token: str):
- """Verify changing password fails with wrong current password."""
- response = await async_client.post(
- "/api/v1/users/me/change-password",
- headers={"Authorization": f"Bearer {user_token}"},
- json={
- "current_password": "wrongpassword",
- "new_password": "newpassword456",
- },
- )
- assert response.status_code == 400
- assert "incorrect" in response.json()["detail"].lower()
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_change_password_requires_auth(self, async_client: AsyncClient):
- """Verify changing password requires authentication."""
- response = await async_client.post(
- "/api/v1/users/me/change-password",
- json={
- "current_password": "oldpassword",
- "new_password": "newpassword",
- },
- )
- assert response.status_code == 401
- class TestAuthMiddlewarePublicRoutes:
- """Tests for auth middleware public route configuration.
- These routes must be accessible without authentication, even when auth is enabled,
- because browser elements like <img src> and <video src> don't send Authorization headers.
- """
- @pytest.fixture
- async def enabled_auth(self, async_client: AsyncClient):
- """Enable auth for testing middleware behavior."""
- await async_client.post(
- "/api/v1/auth/setup",
- json={
- "auth_enabled": True,
- "admin_username": "middlewareadmin",
- "admin_password": "adminpassword123",
- },
- )
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_auth_status_is_public(self, async_client: AsyncClient, enabled_auth):
- """Verify /api/v1/auth/status is accessible without auth."""
- response = await async_client.get("/api/v1/auth/status")
- assert response.status_code == 200
- assert "auth_enabled" in response.json()
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_auth_login_is_public(self, async_client: AsyncClient, enabled_auth):
- """Verify /api/v1/auth/login is accessible without auth."""
- response = await async_client.post(
- "/api/v1/auth/login",
- json={"username": "middlewareadmin", "password": "adminpassword123"},
- )
- # Should not return 401 (unauthorized) - it should either succeed or return
- # a different error (like 400 for wrong credentials)
- assert response.status_code != 401 or "token" in response.json()
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_auth_setup_is_public(self, async_client: AsyncClient):
- """Verify /api/v1/auth/setup is accessible without auth (needed for setup/recovery)."""
- # Don't enable auth first - test that setup endpoint itself is accessible
- response = await async_client.post(
- "/api/v1/auth/setup",
- json={"auth_enabled": False},
- )
- # Should not be 401
- assert response.status_code != 401
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_updates_version_is_public(self, async_client: AsyncClient, enabled_auth):
- """Verify /api/v1/updates/version is accessible without auth."""
- response = await async_client.get("/api/v1/updates/version")
- # Should not be 401
- assert response.status_code != 401
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_protected_route_requires_auth(self, async_client: AsyncClient, enabled_auth):
- """Verify non-public routes return 401 without token."""
- response = await async_client.get("/api/v1/printers/")
- assert response.status_code == 401
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_protected_route_works_with_token(self, async_client: AsyncClient, enabled_auth):
- """Verify non-public routes work with valid token."""
- # Login to get token
- login_response = await async_client.post(
- "/api/v1/auth/login",
- json={"username": "middlewareadmin", "password": "adminpassword123"},
- )
- token = login_response.json()["access_token"]
- # Access protected route
- response = await async_client.get(
- "/api/v1/printers/",
- headers={"Authorization": f"Bearer {token}"},
- )
- assert response.status_code == 200
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_advanced_auth_status_is_public(self, async_client: AsyncClient, enabled_auth):
- """Verify /api/v1/auth/advanced-auth/status is accessible without auth."""
- response = await async_client.get("/api/v1/auth/advanced-auth/status")
- # Should not be 401 (must be accessible for login page)
- assert response.status_code != 401
- # Should return valid response (200 with auth status)
- if response.status_code == 200:
- result = response.json()
- assert "advanced_auth_enabled" in result
- assert "smtp_configured" in result
- @pytest.mark.asyncio
- @pytest.mark.integration
- async def test_forgot_password_is_public(self, async_client: AsyncClient, enabled_auth):
- """Verify /api/v1/auth/forgot-password is accessible without auth."""
- response = await async_client.post(
- "/api/v1/auth/forgot-password",
- json={"email": "test@example.com"},
- )
- # Should not be 401 (must be accessible for password reset from login page)
- assert response.status_code != 401
- # Will likely be 400 (advanced auth not enabled) but that's okay -
- # the important thing is it's not blocked by auth middleware
- assert response.status_code in [200, 400]
|