Skip to content

Commit c444268

Browse files
authored
chore: sync public mirror from internal
1 parent 7bda477 commit c444268

3 files changed

Lines changed: 6 additions & 144 deletions

File tree

packages/control-plane-rs/src/a2a/push_notifications.rs

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@ pub(crate) async fn handle_platform_a2a_push_endpoint(
165165
);
166166
}
167167
};
168-
if let Err(response) = validate_platform_a2a_push_callback_payload_binding(&head, &payload) {
169-
return response;
170-
}
171168
match record_platform_a2a_push_payload(state, payload).await {
172169
Ok(accepted) => json_response(202, &accepted),
173170
Err(message) => a2a_error_response(400, "INVALID_REQUEST", &message),
@@ -205,33 +202,6 @@ fn validate_platform_a2a_push_callback_auth(head: &RequestHead) -> Result<(), Ve
205202
Err(unauthorized_callback_token_response())
206203
}
207204

208-
fn validate_platform_a2a_push_callback_payload_binding(
209-
head: &RequestHead,
210-
payload: &Value,
211-
) -> Result<(), Vec<u8>> {
212-
let Some(expected) = platform_a2a_push_callback_token() else {
213-
return Ok(());
214-
};
215-
let Some(provided) = platform_a2a_push_request_token(head) else {
216-
return Ok(());
217-
};
218-
if !provided.starts_with(A2A_WORKSPACE_NOTIFICATION_TOKEN_PREFIX) {
219-
return Ok(());
220-
}
221-
let Some(workspace_id) = platform_a2a_push_payload_workspace(payload)
222-
.or_else(|| platform_a2a_push_request_workspace(head))
223-
else {
224-
return Err(unauthorized_callback_token_response());
225-
};
226-
let Some(derived) = workspace_notification_token(&expected, &workspace_id) else {
227-
return Err(unauthorized_callback_token_response());
228-
};
229-
if constant_time_eq(provided.as_bytes(), derived.as_bytes()) {
230-
return Ok(());
231-
}
232-
Err(unauthorized_callback_token_response())
233-
}
234-
235205
fn unauthorized_callback_token_response() -> Vec<u8> {
236206
json_response(
237207
401,
@@ -270,61 +240,6 @@ fn platform_a2a_push_request_workspace(head: &RequestHead) -> Option<String> {
270240
None
271241
}
272242

273-
fn platform_a2a_push_payload_workspace(payload: &Value) -> Option<String> {
274-
let object = payload.as_object()?;
275-
if let Some(status_update) = object.get("statusUpdate") {
276-
return first_platform_a2a_push_workspace(&[
277-
status_update,
278-
payload,
279-
status_update.get("status").unwrap_or(&Value::Null),
280-
status_update
281-
.get("status")
282-
.and_then(|status| status.get("message"))
283-
.unwrap_or(&Value::Null),
284-
]);
285-
}
286-
if let Some(task) = object.get("task") {
287-
return first_platform_a2a_push_workspace(&[
288-
task,
289-
payload,
290-
task.get("status").unwrap_or(&Value::Null),
291-
task.get("status")
292-
.and_then(|status| status.get("message"))
293-
.unwrap_or(&Value::Null),
294-
task.get("artifact").unwrap_or(&Value::Null),
295-
]);
296-
}
297-
if let Some(artifact_update) = object.get("artifactUpdate") {
298-
return first_platform_a2a_push_workspace(&[
299-
artifact_update,
300-
payload,
301-
artifact_update.get("artifact").unwrap_or(&Value::Null),
302-
]);
303-
}
304-
None
305-
}
306-
307-
fn first_platform_a2a_push_workspace(values: &[&Value]) -> Option<String> {
308-
values
309-
.iter()
310-
.find_map(|value| platform_a2a_push_workspace_marker(value))
311-
}
312-
313-
fn platform_a2a_push_workspace_marker(value: &Value) -> Option<String> {
314-
let object = value.as_object()?;
315-
optional_string_field(object, "workspaceId")
316-
.or_else(|| optional_string_field(object, "workspace_id"))
317-
.or_else(|| {
318-
object
319-
.get("metadata")
320-
.and_then(Value::as_object)
321-
.and_then(|metadata| {
322-
optional_string_field(metadata, "workspaceId")
323-
.or_else(|| optional_string_field(metadata, "workspace_id"))
324-
})
325-
})
326-
}
327-
328243
fn platform_a2a_push_callback_token() -> Option<String> {
329244
trimmed_env("MAESTRO_PLATFORM_A2A_CALLBACK_TOKEN")
330245
.or_else(|| trimmed_env("MAESTRO_A2A_CALLBACK_TOKEN"))

packages/control-plane-rs/src/tests.rs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,57 +3339,6 @@ async fn platform_a2a_push_callback_rejects_workspace_derived_token_with_wrong_w
33393339
}
33403340
}
33413341

3342-
#[tokio::test(flavor = "current_thread")]
3343-
async fn platform_a2a_push_callback_rejects_workspace_derived_token_with_mismatched_payload_workspace(
3344-
) {
3345-
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
3346-
use base64::Engine;
3347-
use hmac::{Hmac, Mac};
3348-
use sha2::Sha256;
3349-
3350-
let _guard = ENV_LOCK.lock().await;
3351-
let previous_token = env::var_os("MAESTRO_PLATFORM_A2A_CALLBACK_TOKEN");
3352-
let shared_secret = "callback-token";
3353-
let header_workspace_id = "evalops";
3354-
env::set_var("MAESTRO_PLATFORM_A2A_CALLBACK_TOKEN", shared_secret);
3355-
3356-
let mut mac = Hmac::<Sha256>::new_from_slice(shared_secret.as_bytes()).unwrap();
3357-
mac.update(header_workspace_id.as_bytes());
3358-
let derived = format!(
3359-
"workspace-v1.{}",
3360-
URL_SAFE_NO_PAD.encode(mac.finalize().into_bytes())
3361-
);
3362-
3363-
let body = r#"{
3364-
"statusUpdate": {
3365-
"taskId": "platform-run-4",
3366-
"workspaceId": "some-other-workspace",
3367-
"status": {
3368-
"state": "TASK_STATE_WORKING"
3369-
}
3370-
}
3371-
}"#;
3372-
let request = format!(
3373-
"POST /api/platform/a2a/push HTTP/1.1\r\nHost: localhost\r\nX-A2a-Notification-Token: {derived}\r\nX-Evalops-Workspace-Id: {header_workspace_id}\r\nContent-Type: application/a2a+json\r\nContent-Length: {}\r\n\r\n{body}",
3374-
body.len()
3375-
);
3376-
let mut initial = request.into_bytes();
3377-
let head = parse_request_head(&initial).expect("request should parse");
3378-
let (_client, mut server) = tcp_stream_pair().await;
3379-
let state = test_app_state_with_sessions(HashMap::new());
3380-
3381-
let response = handle_platform_a2a_push_endpoint(&mut server, &mut initial, head, &state).await;
3382-
3383-
assert_eq!(response_status(&response), 401);
3384-
assert!(state.a2a_tasks.lock().await.is_empty());
3385-
3386-
if let Some(previous_token) = previous_token {
3387-
env::set_var("MAESTRO_PLATFORM_A2A_CALLBACK_TOKEN", previous_token);
3388-
} else {
3389-
env::remove_var("MAESTRO_PLATFORM_A2A_CALLBACK_TOKEN");
3390-
}
3391-
}
3392-
33933342
#[tokio::test(flavor = "current_thread")]
33943343
async fn platform_a2a_push_callback_rejects_invalid_token() {
33953344
let _guard = ENV_LOCK.lock().await;

test/web/platform-a2a-push-handler.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe("handlePlatformA2APushCallback", () => {
143143
expect(res.statusCode).toBe(202);
144144
});
145145

146-
it("prefers the EvalOps workspace header when both workspace headers are present", async () => {
146+
it("prefers the evalops workspace header for workspace-scoped tokens", async () => {
147147
const sharedSecret = "callback-secret";
148148
const workspaceId = "ws_hosted";
149149
vi.stubEnv("MAESTRO_PLATFORM_A2A_CALLBACK_TOKEN", sharedSecret);
@@ -156,24 +156,21 @@ describe("handlePlatformA2APushCallback", () => {
156156
{
157157
statusUpdate: {
158158
taskId: "run_1",
159-
contextId: "ctx_1",
160-
final: true,
161159
status: { state: "TASK_STATE_COMPLETED" },
160+
metadata: { workspaceId },
162161
},
163162
},
164163
{
165164
"x-a2a-notification-token": derived,
165+
"x-workspace-id": "ws_other",
166166
"x-evalops-workspace-id": workspaceId,
167-
"x-workspace-id": "ws_legacy",
168167
},
169168
),
170169
res as unknown as ServerResponse,
171170
ctx,
172171
);
172+
173173
expect(res.statusCode).toBe(202);
174-
expect(JSON.parse(res.body)).toMatchObject({
175-
workspaceId,
176-
});
177174
});
178175

179176
it("rejects a workspace-scoped HMAC notification token when the payload workspace differs from the header workspace", async () => {
@@ -482,7 +479,8 @@ describe("handlePlatformA2APushCallback", () => {
482479
"00-11111111111111111111111111111111-2222222222222222-01",
483480
tracestate: "evalops=push",
484481
"x-organization-id": "org_header",
485-
"x-workspace-id": "ws_hosted",
482+
"x-workspace-id": "ws_other",
483+
"x-evalops-workspace-id": "ws_hosted",
486484
"x-evalops-actor-id": "actor_header",
487485
},
488486
),

0 commit comments

Comments
 (0)