mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
buzz-db: pin upsert reference-check precedence on an existing workflow
For an existing workflow ID, a different valid owner or channel still returns AccessDenied, while a missing owner or channel returns NotFound before the overwrite check. Neither attempt changes the stored row. Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Luke Tornquist <tornquist@squareup.com>
This commit is contained in:
@@ -180,6 +180,51 @@ async fn upsert_workflow_rejects_missing_owner_or_channel_without_foreign_keys()
|
|||||||
.expect("valid parents");
|
.expect("valid parents");
|
||||||
}
|
}
|
||||||
assert_eq!(count(&db, "workflows", community).await, 1);
|
assert_eq!(count(&db, "workflows", community).await, 1);
|
||||||
|
|
||||||
|
// An existing ID: a different valid owner or channel is the overwrite
|
||||||
|
// boundary (`AccessDenied`); a missing owner or channel fails the reference
|
||||||
|
// check first (`NotFound`). Neither attempt touches the stored row.
|
||||||
|
let other_owner = [0x22; 32];
|
||||||
|
ensure_user(&db.pool, community, &other_owner)
|
||||||
|
.await
|
||||||
|
.expect("other owner");
|
||||||
|
let other_channel = new_channel(&db, community, &owner).await;
|
||||||
|
let overwrite = |channel: Option<Uuid>, owner: [u8; 32]| {
|
||||||
|
let pool = db.pool.clone();
|
||||||
|
async move {
|
||||||
|
upsert_workflow(
|
||||||
|
&pool,
|
||||||
|
community,
|
||||||
|
id,
|
||||||
|
channel,
|
||||||
|
&owner,
|
||||||
|
"hijack",
|
||||||
|
r#"{"trigger":{"on":"manual"},"steps":[{"id":"x"}]}"#,
|
||||||
|
&[1; 32],
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for (label, result) in [
|
||||||
|
("other owner", overwrite(Some(channel), other_owner).await),
|
||||||
|
("other channel", overwrite(Some(other_channel), owner).await),
|
||||||
|
] {
|
||||||
|
assert!(
|
||||||
|
matches!(result, Err(DbError::AccessDenied(_))),
|
||||||
|
"{label}: expected AccessDenied, got {result:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
assert_not_found(overwrite(Some(channel), [0x23; 32]).await, "owner");
|
||||||
|
assert_not_found(overwrite(Some(Uuid::new_v4()), owner).await, "channel");
|
||||||
|
|
||||||
|
let stored = get_workflow(&db.pool, community, id)
|
||||||
|
.await
|
||||||
|
.expect("stored workflow");
|
||||||
|
assert_eq!(stored.owner_pubkey, owner.to_vec());
|
||||||
|
assert_eq!(stored.channel_id, Some(channel));
|
||||||
|
assert_eq!(stored.name, "wf");
|
||||||
|
assert_eq!(stored.definition_hash, vec![0; 32]);
|
||||||
|
assert_eq!(count(&db, "workflows", community).await, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
Reference in New Issue
Block a user