Skip to content

Commit 4ef7473

Browse files
committed
feat(add scan-csv api route):
1 parent 0987f05 commit 4ef7473

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

agentic_security/integrations/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
class IntegrationProto(Protocol):
66
def __init__(
77
self, prompt_groups: list, tools_inbox: asyncio.Queue, opts: dict = {}
8-
): ...
8+
):
9+
...
910

10-
async def apply(self) -> list: ...
11+
async def apply(self) -> list:
12+
...

agentic_security/routes/scan.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime
22

3-
from fastapi import APIRouter, BackgroundTasks, HTTPException
3+
from fastapi import APIRouter, BackgroundTasks, File, HTTPException, Query, UploadFile
44
from fastapi.responses import StreamingResponse
55

66
from ..core.app import get_stop_event, get_tools_inbox, set_current_run
@@ -52,3 +52,28 @@ async def scan(scan_parameters: Scan, background_tasks: BackgroundTasks):
5252
async def stop_scan():
5353
get_stop_event().set()
5454
return {"status": "Scan stopped"}
55+
56+
57+
@router.post("/scan-csv")
58+
async def scan_csv(
59+
background_tasks: BackgroundTasks,
60+
file: UploadFile = File(...),
61+
llmSpec: UploadFile = File(...),
62+
optimize: bool = Query(False),
63+
maxBudget: int = Query(10_000),
64+
enableMultiStepAttack: bool = Query(False),
65+
):
66+
# TODO: content dataset to fuzzer
67+
content = await file.read()
68+
llm_spec = await llmSpec.read()
69+
70+
scan_parameters = Scan(
71+
llmSpec=llm_spec,
72+
optimize=optimize,
73+
maxBudget=1000,
74+
enableMultiStepAttack=enableMultiStepAttack,
75+
)
76+
77+
return StreamingResponse(
78+
streaming_response_generator(scan_parameters), media_type="application/json"
79+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import agentic_security.test_spec_assets as test_spec_assets
2+
from agentic_security.routes.scan import router
3+
from fastapi.testclient import TestClient
4+
5+
client = TestClient(router)
6+
7+
8+
def test_upload_csv_and_run():
9+
# Create a sample CSV content
10+
csv_content = "id,prompt\nspec1,value1\nspec2,value3"
11+
# Send a POST request to the /upload-csv endpoint
12+
response = client.post(
13+
"/scan-csv?optimize=false&enableMultiStepAttack=false&maxBudget=1000",
14+
files={
15+
"file": ("test.csv", csv_content, "text/csv"),
16+
"llmSpec": ("spec.txt", test_spec_assets.SAMPLE_SPEC, "text/plain"),
17+
},
18+
)
19+
20+
assert response.status_code == 200
21+
assert "Scan completed." in response.text

0 commit comments

Comments
 (0)