Clients take a flow's id or key: one resolver in the SDK, id first, explicit id:/key:, a warning for reads and a refusal for changes when a name means two flows, deleted flows found by their last key; sync creates by POST, retries a create race through the drift checks and reports the id; MCP gets create_flow and resolves every flow argument with the caller's token; displays show flow_name; an engine from before ids is named as such
This commit is contained in:
@@ -264,6 +264,13 @@ def test_an_agent_cannot_write_code_its_person_may_not(
|
||||
).json()
|
||||
assert me["is_superuser"] is False
|
||||
token = mcp_token(uuid.UUID(me["id"]), agent)
|
||||
# One they may create: the tool only reaches the route for a listed flow.
|
||||
flows = f"{settings.API_V1_STR}/flows"
|
||||
made = client.post(
|
||||
f"{flows}/", headers=normal_user_token_headers, json={"name": "agent_gate"}
|
||||
)
|
||||
assert made.status_code == 201, made.text
|
||||
flow_id = made.json()["definition"]["id"]
|
||||
|
||||
async def block(http: httpx.AsyncClient) -> httpx.Response:
|
||||
return await http.post(
|
||||
@@ -272,11 +279,14 @@ def test_an_agent_cannot_write_code_its_person_may_not(
|
||||
token,
|
||||
"tools/call",
|
||||
name="save_node_source",
|
||||
arguments={"name": "any", "node_id": "fn", "code": "import os"},
|
||||
arguments={"flow": "agent_gate", "node_id": "fn", "code": "import os"},
|
||||
),
|
||||
)
|
||||
|
||||
answer = json.loads(over_mcp(block).json()["result"]["content"][0]["text"])
|
||||
try:
|
||||
answer = json.loads(over_mcp(block).json()["result"]["content"][0]["text"])
|
||||
finally:
|
||||
client.delete(f"{flows}/{flow_id}", headers=normal_user_token_headers)
|
||||
assert answer == {"error": CODE_IS_SUPERUSERS, "status": 403}
|
||||
|
||||
|
||||
|
||||
@@ -6,38 +6,80 @@ import httpx
|
||||
|
||||
from fluksio.mcp import server
|
||||
|
||||
#: What the engine lists: the grandfathered `heating`, now keyed `warmth`, and
|
||||
#: the later flow that took its old key.
|
||||
LISTED = [{"id": "heating", "name": "warmth"}, {"id": "f_heat0000", "name": "heating"}]
|
||||
|
||||
def test_a_name_cannot_climb_out_of_its_route() -> None:
|
||||
"""httpx resolves ``..``, so ``save_flow("../ai/config")`` was ``PUT /ai/config``.
|
||||
|
||||
A prompt-injected assistant acting for a superuser could repoint the
|
||||
provider that way while the stored key stayed.
|
||||
"""
|
||||
def _calls(*tools) -> list[str]:
|
||||
"""What the tools sent past the flow listing, run against a recording
|
||||
engine."""
|
||||
seen: list[str] = []
|
||||
|
||||
def record(request: httpx.Request) -> httpx.Response:
|
||||
if request.url.path == "/api/v1/flows/" and request.method == "GET":
|
||||
return httpx.Response(200, json={"data": LISTED, "count": len(LISTED)})
|
||||
seen.append(f"{request.method} {request.url.raw_path.decode()}")
|
||||
return httpx.Response(200, json={})
|
||||
|
||||
async def calls() -> None:
|
||||
async def calls() -> list:
|
||||
previous = server._client
|
||||
mock = httpx.AsyncClient(
|
||||
transport=httpx.MockTransport(record), base_url="http://test"
|
||||
)
|
||||
server.set_client(mock)
|
||||
try:
|
||||
await server.save_flow("../ai/config", {})
|
||||
await server.delete_flow("..")
|
||||
await server.get_node_source("..", "../source")
|
||||
return [await tool() for tool in tools]
|
||||
finally:
|
||||
server.set_client(previous)
|
||||
await mock.aclose()
|
||||
|
||||
asyncio.run(calls())
|
||||
answers = asyncio.run(calls())
|
||||
return seen + [answer for answer in answers if answer != {}]
|
||||
|
||||
|
||||
def test_a_name_cannot_climb_out_of_its_route() -> None:
|
||||
"""httpx resolves ``..``, so ``save_flow("../ai/config")`` was ``PUT /ai/config``.
|
||||
|
||||
A prompt-injected assistant acting for a superuser could repoint the
|
||||
provider that way while the stored key stayed. A flow is now only ever a
|
||||
listed one, and what follows it is still one segment.
|
||||
"""
|
||||
seen = _calls(
|
||||
lambda: server.save_flow("../ai/config", {}),
|
||||
lambda: server.get_node_source("f_heat0000", "../source"),
|
||||
)
|
||||
|
||||
assert seen == [
|
||||
"PUT /api/v1/flows/%2E%2E%2Fai%2Fconfig",
|
||||
"DELETE /api/v1/flows/%2E%2E",
|
||||
"GET /api/v1/flows/%2E%2E/nodes/%2E%2E%2Fsource/source",
|
||||
"GET /api/v1/flows/f_heat0000/nodes/%2E%2E%2Fsource/source",
|
||||
{"error": "No flow with the id or key '../ai/config'."},
|
||||
]
|
||||
|
||||
|
||||
def test_a_flow_argument_goes_through_the_resolver() -> None:
|
||||
"""Id first; a read of a name two flows answer to says so, a change of
|
||||
it is refused, and the explicit forms say which."""
|
||||
seen = _calls(
|
||||
lambda: server.get_flow("heating"),
|
||||
lambda: server.delete_flow("heating"),
|
||||
lambda: server.delete_flow("key:heating"),
|
||||
lambda: server.get_flow("warmth"),
|
||||
)
|
||||
|
||||
warning = (
|
||||
"'heating' is the id of 'warmth' and the key of 'f_heat0000'. "
|
||||
"Using the id. Pass key:heating for the other."
|
||||
)
|
||||
refusal = (
|
||||
"'heating' is the id of 'warmth' and the key of 'f_heat0000'. "
|
||||
"Pass id:heating or key:heating."
|
||||
)
|
||||
assert seen == [
|
||||
"GET /api/v1/flows/heating",
|
||||
"DELETE /api/v1/flows/f_heat0000",
|
||||
"GET /api/v1/flows/heating",
|
||||
{"warning": warning},
|
||||
{"error": refusal},
|
||||
]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user