fix(workbench): proxy workspace writes through cloud web
This commit is contained in:
@@ -42,7 +42,12 @@ export function isCloudApiProxyRoute(method, pathname) {
|
||||
GET_PROXY_PREFIXES.some((prefix) => normalizedPath.startsWith(prefix));
|
||||
}
|
||||
if (normalizedMethod === "POST") {
|
||||
return POST_PROXY_ROUTES.has(normalizedPath) || isDevicePodPostProxyRoute(normalizedPath);
|
||||
return POST_PROXY_ROUTES.has(normalizedPath) ||
|
||||
isDevicePodPostProxyRoute(normalizedPath) ||
|
||||
isWorkbenchWorkspaceWriteProxyRoute(normalizedMethod, normalizedPath);
|
||||
}
|
||||
if (normalizedMethod === "PATCH" || normalizedMethod === "PUT") {
|
||||
return isWorkbenchWorkspaceWriteProxyRoute(normalizedMethod, normalizedPath);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -56,6 +61,14 @@ function isDevicePodPostProxyRoute(pathname) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isWorkbenchWorkspaceWriteProxyRoute(method, pathname) {
|
||||
const parts = pathname.split("/").filter(Boolean);
|
||||
if (parts.length < 4 || parts[0] !== "v1" || parts[1] !== "workbench" || parts[2] !== "workspace") return false;
|
||||
if ((method === "PATCH" || method === "PUT") && parts.length === 4) return true;
|
||||
if (method === "POST" && parts.length === 5) return parts[4] === "select-conversation" || parts[4] === "reset";
|
||||
return false;
|
||||
}
|
||||
|
||||
function isPublicCodeAgentPollRoute(method, pathname) {
|
||||
return method === "GET" && (
|
||||
pathname.startsWith("/v1/agent/chat/result/") ||
|
||||
|
||||
@@ -56,3 +56,36 @@ test("cloud web proxies only supported authenticated device-pod write routes", (
|
||||
routeKey: "POST /v1/device-pods/D601-F103-V2/jobs/job_1/output"
|
||||
});
|
||||
});
|
||||
|
||||
test("cloud web proxies authenticated account workbench write routes", () => {
|
||||
assert.deepEqual(cloudWebProxyRoutePolicy("PATCH", "/v1/workbench/workspace/ws_default"), {
|
||||
proxy: true,
|
||||
authRequired: true,
|
||||
publicRoute: false,
|
||||
routeKey: "PATCH /v1/workbench/workspace/ws_default"
|
||||
});
|
||||
assert.deepEqual(cloudWebProxyRoutePolicy("PUT", "/v1/workbench/workspace/ws_default"), {
|
||||
proxy: true,
|
||||
authRequired: true,
|
||||
publicRoute: false,
|
||||
routeKey: "PUT /v1/workbench/workspace/ws_default"
|
||||
});
|
||||
assert.deepEqual(cloudWebProxyRoutePolicy("POST", "/v1/workbench/workspace/ws_default/select-conversation"), {
|
||||
proxy: true,
|
||||
authRequired: true,
|
||||
publicRoute: false,
|
||||
routeKey: "POST /v1/workbench/workspace/ws_default/select-conversation"
|
||||
});
|
||||
assert.deepEqual(cloudWebProxyRoutePolicy("POST", "/v1/workbench/workspace/ws_default/reset"), {
|
||||
proxy: true,
|
||||
authRequired: true,
|
||||
publicRoute: false,
|
||||
routeKey: "POST /v1/workbench/workspace/ws_default/reset"
|
||||
});
|
||||
assert.deepEqual(cloudWebProxyRoutePolicy("POST", "/v1/workbench/workspace/ws_default/events"), {
|
||||
proxy: false,
|
||||
authRequired: false,
|
||||
publicRoute: false,
|
||||
routeKey: "POST /v1/workbench/workspace/ws_default/events"
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user