mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-02 20:15:24 +02:00
API security hardening (#571)
* Enhance security and safety around user update API - Prevent a regular user from promoting themself to admin - Prevent an admin from demoting themself - Refactor token fixture to admin + regular user tokens * Restrict user CRUD API to admins * Secure admin API routes * Refactor APIrouter into Admin/UserAPIRouter * Secure theme routes * Make 'all recipes' routes public * Secure favorite routes * Remove redundant checks * Fix public routes mistakenly flagged user routes * Make webhooks changeable only by admin * Allow users to create categories and tags * Address lint issues
This commit is contained in:
parent
f5faff66d3
commit
6320ba7ec5
43 changed files with 456 additions and 347 deletions
|
@ -6,15 +6,15 @@ from tests.app_routes import AppRoutes
|
|||
|
||||
|
||||
@fixture
|
||||
def long_live_token(api_client: TestClient, api_routes: AppRoutes, token):
|
||||
response = api_client.post(api_routes.users_api_tokens, json={"name": "Test Fixture Token"}, headers=token)
|
||||
def long_live_token(api_client: TestClient, api_routes: AppRoutes, admin_token):
|
||||
response = api_client.post(api_routes.users_api_tokens, json={"name": "Test Fixture Token"}, headers=admin_token)
|
||||
assert response.status_code == 201
|
||||
|
||||
return {"Authorization": f"Bearer {json.loads(response.text).get('token')}"}
|
||||
|
||||
|
||||
def test_api_token_creation(api_client: TestClient, api_routes: AppRoutes, token):
|
||||
response = api_client.post(api_routes.users_api_tokens, json={"name": "Test API Token"}, headers=token)
|
||||
def test_api_token_creation(api_client: TestClient, api_routes: AppRoutes, admin_token):
|
||||
response = api_client.post(api_routes.users_api_tokens, json={"name": "Test API Token"}, headers=admin_token)
|
||||
assert response.status_code == 201
|
||||
|
||||
|
||||
|
@ -24,9 +24,9 @@ def test_use_token(api_client: TestClient, api_routes: AppRoutes, long_live_toke
|
|||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_delete_token(api_client: TestClient, api_routes: AppRoutes, token):
|
||||
response = api_client.delete(api_routes.users_api_tokens_token_id(1), headers=token)
|
||||
def test_delete_token(api_client: TestClient, api_routes: AppRoutes, admin_token):
|
||||
response = api_client.delete(api_routes.users_api_tokens_token_id(1), headers=admin_token)
|
||||
assert response.status_code == 200
|
||||
|
||||
response = api_client.delete(api_routes.users_api_tokens_token_id(2), headers=token)
|
||||
response = api_client.delete(api_routes.users_api_tokens_token_id(2), headers=admin_token)
|
||||
assert response.status_code == 200
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue