feat: implement 5 QA-driven security and quality proposals
Implemented proposals from comprehensive QA review: 1. extend-csrf-protection - Add POST to CSRF protected methods in frontend - Global CSRF middleware for all state-changing operations - Update tests with CSRF token fixtures 2. tighten-cors-websocket-security - Replace wildcard CORS with explicit method/header lists - Disable query parameter auth in production (code 4002) - Add per-user WebSocket connection limit (max 5, code 4005) 3. shorten-jwt-expiry - Reduce JWT expiry from 7 days to 60 minutes - Add refresh token support with 7-day expiry - Implement token rotation on refresh - Frontend auto-refresh when token near expiry (<5 min) 4. fix-frontend-quality - Add React.lazy() code splitting for all pages - Fix useCallback dependency arrays (Dashboard, Comments) - Add localStorage data validation in AuthContext - Complete i18n for AttachmentUpload component 5. enhance-backend-validation - Add SecurityAuditMiddleware for access denied logging - Add ErrorSanitizerMiddleware for production error messages - Protect /health/detailed with admin authentication - Add input length validation (comment 5000, desc 10000) All 521 backend tests passing. Frontend builds successfully. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -39,7 +39,7 @@ class TestCustomFieldsCRUD:
|
||||
db.commit()
|
||||
return project
|
||||
|
||||
def test_create_text_field(self, client, db, admin_token):
|
||||
def test_create_text_field(self, client, db, auth_headers):
|
||||
"""Test creating a text custom field."""
|
||||
project = self.setup_project(db, "00000000-0000-0000-0000-000000000001")
|
||||
|
||||
@@ -50,7 +50,7 @@ class TestCustomFieldsCRUD:
|
||||
"field_type": "text",
|
||||
"is_required": False,
|
||||
},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 201
|
||||
@@ -59,7 +59,7 @@ class TestCustomFieldsCRUD:
|
||||
assert data["field_type"] == "text"
|
||||
assert data["is_required"] is False
|
||||
|
||||
def test_create_number_field(self, client, db, admin_token):
|
||||
def test_create_number_field(self, client, db, auth_headers):
|
||||
"""Test creating a number custom field."""
|
||||
project = self.setup_project(db, "00000000-0000-0000-0000-000000000001")
|
||||
|
||||
@@ -70,7 +70,7 @@ class TestCustomFieldsCRUD:
|
||||
"field_type": "number",
|
||||
"is_required": True,
|
||||
},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 201
|
||||
@@ -79,7 +79,7 @@ class TestCustomFieldsCRUD:
|
||||
assert data["field_type"] == "number"
|
||||
assert data["is_required"] is True
|
||||
|
||||
def test_create_dropdown_field(self, client, db, admin_token):
|
||||
def test_create_dropdown_field(self, client, db, auth_headers):
|
||||
"""Test creating a dropdown custom field."""
|
||||
project = self.setup_project(db, "00000000-0000-0000-0000-000000000001")
|
||||
|
||||
@@ -91,7 +91,7 @@ class TestCustomFieldsCRUD:
|
||||
"options": ["Frontend", "Backend", "Database", "API"],
|
||||
"is_required": False,
|
||||
},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 201
|
||||
@@ -100,7 +100,7 @@ class TestCustomFieldsCRUD:
|
||||
assert data["field_type"] == "dropdown"
|
||||
assert data["options"] == ["Frontend", "Backend", "Database", "API"]
|
||||
|
||||
def test_create_dropdown_field_without_options_fails(self, client, db, admin_token):
|
||||
def test_create_dropdown_field_without_options_fails(self, client, db, auth_headers):
|
||||
"""Test that creating a dropdown field without options fails."""
|
||||
project = self.setup_project(db, "00000000-0000-0000-0000-000000000001")
|
||||
|
||||
@@ -111,12 +111,12 @@ class TestCustomFieldsCRUD:
|
||||
"field_type": "dropdown",
|
||||
"options": [],
|
||||
},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 422 # Validation error
|
||||
|
||||
def test_create_formula_field(self, client, db, admin_token):
|
||||
def test_create_formula_field(self, client, db, auth_headers):
|
||||
"""Test creating a formula custom field."""
|
||||
project = self.setup_project(db, "00000000-0000-0000-0000-000000000001")
|
||||
|
||||
@@ -127,7 +127,7 @@ class TestCustomFieldsCRUD:
|
||||
"name": "hours_worked",
|
||||
"field_type": "number",
|
||||
},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
# Create formula field
|
||||
@@ -138,7 +138,7 @@ class TestCustomFieldsCRUD:
|
||||
"field_type": "formula",
|
||||
"formula": "{time_spent} / {original_estimate} * 100",
|
||||
},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 201
|
||||
@@ -147,7 +147,7 @@ class TestCustomFieldsCRUD:
|
||||
assert data["field_type"] == "formula"
|
||||
assert "{time_spent}" in data["formula"]
|
||||
|
||||
def test_list_custom_fields(self, client, db, admin_token):
|
||||
def test_list_custom_fields(self, client, db, auth_headers):
|
||||
"""Test listing custom fields for a project."""
|
||||
project = self.setup_project(db, "00000000-0000-0000-0000-000000000001")
|
||||
|
||||
@@ -155,17 +155,17 @@ class TestCustomFieldsCRUD:
|
||||
client.post(
|
||||
f"/api/projects/{project.id}/custom-fields",
|
||||
json={"name": "Field 1", "field_type": "text"},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
client.post(
|
||||
f"/api/projects/{project.id}/custom-fields",
|
||||
json={"name": "Field 2", "field_type": "number"},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
f"/api/projects/{project.id}/custom-fields",
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -173,7 +173,7 @@ class TestCustomFieldsCRUD:
|
||||
assert data["total"] == 2
|
||||
assert len(data["fields"]) == 2
|
||||
|
||||
def test_update_custom_field(self, client, db, admin_token):
|
||||
def test_update_custom_field(self, client, db, auth_headers):
|
||||
"""Test updating a custom field."""
|
||||
project = self.setup_project(db, "00000000-0000-0000-0000-000000000001")
|
||||
|
||||
@@ -181,7 +181,7 @@ class TestCustomFieldsCRUD:
|
||||
create_response = client.post(
|
||||
f"/api/projects/{project.id}/custom-fields",
|
||||
json={"name": "Original Name", "field_type": "text"},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
field_id = create_response.json()["id"]
|
||||
|
||||
@@ -189,7 +189,7 @@ class TestCustomFieldsCRUD:
|
||||
response = client.put(
|
||||
f"/api/custom-fields/{field_id}",
|
||||
json={"name": "Updated Name", "is_required": True},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -197,7 +197,7 @@ class TestCustomFieldsCRUD:
|
||||
assert data["name"] == "Updated Name"
|
||||
assert data["is_required"] is True
|
||||
|
||||
def test_delete_custom_field(self, client, db, admin_token):
|
||||
def test_delete_custom_field(self, client, db, auth_headers):
|
||||
"""Test deleting a custom field."""
|
||||
project = self.setup_project(db, "00000000-0000-0000-0000-000000000001")
|
||||
|
||||
@@ -205,14 +205,14 @@ class TestCustomFieldsCRUD:
|
||||
create_response = client.post(
|
||||
f"/api/projects/{project.id}/custom-fields",
|
||||
json={"name": "To Delete", "field_type": "text"},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
field_id = create_response.json()["id"]
|
||||
|
||||
# Delete it
|
||||
response = client.delete(
|
||||
f"/api/custom-fields/{field_id}",
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 204
|
||||
@@ -220,11 +220,11 @@ class TestCustomFieldsCRUD:
|
||||
# Verify it's gone
|
||||
get_response = client.get(
|
||||
f"/api/custom-fields/{field_id}",
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert get_response.status_code == 404
|
||||
|
||||
def test_max_fields_limit(self, client, db, admin_token):
|
||||
def test_max_fields_limit(self, client, db, auth_headers):
|
||||
"""Test that maximum 20 custom fields per project is enforced."""
|
||||
project = self.setup_project(db, "00000000-0000-0000-0000-000000000001")
|
||||
|
||||
@@ -233,7 +233,7 @@ class TestCustomFieldsCRUD:
|
||||
response = client.post(
|
||||
f"/api/projects/{project.id}/custom-fields",
|
||||
json={"name": f"Field {i}", "field_type": "text"},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code == 201
|
||||
|
||||
@@ -241,12 +241,12 @@ class TestCustomFieldsCRUD:
|
||||
response = client.post(
|
||||
f"/api/projects/{project.id}/custom-fields",
|
||||
json={"name": "Field 21", "field_type": "text"},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code == 400
|
||||
assert "Maximum" in response.json()["detail"]
|
||||
|
||||
def test_duplicate_name_rejected(self, client, db, admin_token):
|
||||
def test_duplicate_name_rejected(self, client, db, auth_headers):
|
||||
"""Test that duplicate field names are rejected."""
|
||||
project = self.setup_project(db, "00000000-0000-0000-0000-000000000001")
|
||||
|
||||
@@ -254,14 +254,14 @@ class TestCustomFieldsCRUD:
|
||||
client.post(
|
||||
f"/api/projects/{project.id}/custom-fields",
|
||||
json={"name": "Unique Name", "field_type": "text"},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
# Try to create another with same name
|
||||
response = client.post(
|
||||
f"/api/projects/{project.id}/custom-fields",
|
||||
json={"name": "Unique Name", "field_type": "number"},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code == 400
|
||||
assert "already exists" in response.json()["detail"]
|
||||
@@ -311,7 +311,7 @@ class TestFormulaService:
|
||||
class TestCustomValuesWithTasks:
|
||||
"""Test custom values integration with tasks."""
|
||||
|
||||
def setup_project_with_fields(self, db, client, admin_token, owner_id: str):
|
||||
def setup_project_with_fields(self, db, client, auth_headers, owner_id: str):
|
||||
"""Create a project with custom fields for testing."""
|
||||
space = Space(
|
||||
id="test-space-002",
|
||||
@@ -342,23 +342,23 @@ class TestCustomValuesWithTasks:
|
||||
text_response = client.post(
|
||||
f"/api/projects/{project.id}/custom-fields",
|
||||
json={"name": "sprint_number", "field_type": "text"},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
text_field_id = text_response.json()["id"]
|
||||
|
||||
number_response = client.post(
|
||||
f"/api/projects/{project.id}/custom-fields",
|
||||
json={"name": "story_points", "field_type": "number"},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
number_field_id = number_response.json()["id"]
|
||||
|
||||
return project, text_field_id, number_field_id
|
||||
|
||||
def test_create_task_with_custom_values(self, client, db, admin_token):
|
||||
def test_create_task_with_custom_values(self, client, db, auth_headers):
|
||||
"""Test creating a task with custom values."""
|
||||
project, text_field_id, number_field_id = self.setup_project_with_fields(
|
||||
db, client, admin_token, "00000000-0000-0000-0000-000000000001"
|
||||
db, client, auth_headers, "00000000-0000-0000-0000-000000000001"
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
@@ -370,15 +370,15 @@ class TestCustomValuesWithTasks:
|
||||
{"field_id": number_field_id, "value": "8"},
|
||||
],
|
||||
},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 201
|
||||
|
||||
def test_get_task_includes_custom_values(self, client, db, admin_token):
|
||||
def test_get_task_includes_custom_values(self, client, db, auth_headers):
|
||||
"""Test that getting a task includes custom values."""
|
||||
project, text_field_id, number_field_id = self.setup_project_with_fields(
|
||||
db, client, admin_token, "00000000-0000-0000-0000-000000000001"
|
||||
db, client, auth_headers, "00000000-0000-0000-0000-000000000001"
|
||||
)
|
||||
|
||||
# Create task with custom values
|
||||
@@ -391,14 +391,14 @@ class TestCustomValuesWithTasks:
|
||||
{"field_id": number_field_id, "value": "8"},
|
||||
],
|
||||
},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
task_id = create_response.json()["id"]
|
||||
|
||||
# Get task and check custom values
|
||||
get_response = client.get(
|
||||
f"/api/tasks/{task_id}",
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
assert get_response.status_code == 200
|
||||
@@ -406,10 +406,10 @@ class TestCustomValuesWithTasks:
|
||||
assert data["custom_values"] is not None
|
||||
assert len(data["custom_values"]) >= 2
|
||||
|
||||
def test_update_task_custom_values(self, client, db, admin_token):
|
||||
def test_update_task_custom_values(self, client, db, auth_headers):
|
||||
"""Test updating custom values on a task."""
|
||||
project, text_field_id, number_field_id = self.setup_project_with_fields(
|
||||
db, client, admin_token, "00000000-0000-0000-0000-000000000001"
|
||||
db, client, auth_headers, "00000000-0000-0000-0000-000000000001"
|
||||
)
|
||||
|
||||
# Create task
|
||||
@@ -421,7 +421,7 @@ class TestCustomValuesWithTasks:
|
||||
{"field_id": text_field_id, "value": "Sprint 5"},
|
||||
],
|
||||
},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
task_id = create_response.json()["id"]
|
||||
|
||||
@@ -434,7 +434,7 @@ class TestCustomValuesWithTasks:
|
||||
{"field_id": number_field_id, "value": "13"},
|
||||
],
|
||||
},
|
||||
headers={"Authorization": f"Bearer {admin_token}"},
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
assert update_response.status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user