mirror of
https://github.com/block/buzz.git
synced 2026-11-24 18:21:59 +00:00
test(auth): bind route controls to exact outcomes and merged routers
Co-authored-by: Sarnow <1894dcbafaa4df1ac607a9bf879ac0b7d77fbccb0e0f4619ecc252c8adbad8a2@seiler-test.communities.public.builderlabstaging.xyz> Signed-off-by: Brad Seiler <seiler@squareup.com>
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
//!
|
||||
//! The route inventory is shared with `scripts/check-community-ban-route-inventory.py`.
|
||||
//! This ignored test uses a disposable local relay/PostgreSQL/MinIO stack and
|
||||
//! fresh tenant hosts and identities. GIF requests stop at malformed local
|
||||
//! input before any provider request; Git and workflow requests use absent
|
||||
//! fresh tenant hosts and identities. Run without BUZZ_KLIPY_API_KEY so GIF
|
||||
//! controls assert the disabled-provider response; Git and workflow requests use absent
|
||||
//! resources and must stop before subprocess or durable work.
|
||||
//!
|
||||
//! ```text
|
||||
@@ -252,7 +252,7 @@ fn route_path(row: &RouteRow, case: &str, actor: &Principal) -> String {
|
||||
|
||||
fn request_body(case: &str, actor: &Principal) -> Vec<u8> {
|
||||
match case {
|
||||
"events" => EventBuilder::new(Kind::TextNote, "community-ban route matrix")
|
||||
"events" => EventBuilder::new(Kind::Metadata, "{}")
|
||||
.sign_with_keys(&actor.keys)
|
||||
.expect("sign test message")
|
||||
.as_json()
|
||||
@@ -274,7 +274,9 @@ fn request_body(case: &str, actor: &Principal) -> Vec<u8> {
|
||||
"gif_search" | "gif_share" | "profile_search" | "invite_mint" | "buzz_read_state" => {
|
||||
b"{".to_vec()
|
||||
}
|
||||
"media_upload" => b"not an image file".to_vec(),
|
||||
"media_upload" => vec![
|
||||
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, b'J', b'F', b'I', b'F', 0,
|
||||
],
|
||||
"git_upload_pack" | "git_receive_pack" => Vec::new(),
|
||||
"git_default_post" => serde_json::to_vec(&serde_json::json!({
|
||||
"branch": "main",
|
||||
@@ -444,28 +446,78 @@ fn assert_ban_denial(
|
||||
}
|
||||
|
||||
fn assert_allowed_control(response_status: StatusCode, body: &str, route: &RouteRow, case: &str) {
|
||||
assert!(
|
||||
matches!(response_status.as_u16(), 200..=299 | 400 | 404 | 409 | 415 | 422),
|
||||
"{} {} case {case}: unbanned control must pass authentication and authorization, then reach the fixture's expected success or input/resource result; got {}: {body}",
|
||||
route.method,
|
||||
route.path,
|
||||
response_status
|
||||
);
|
||||
let denial_message = if route.id.starts_with("git_default_branch") {
|
||||
BANNED_MESSAGE
|
||||
} else if route.id.starts_with("git_") {
|
||||
"blocked: banned from this community"
|
||||
} else if route.id.starts_with("media_") {
|
||||
"relay membership required"
|
||||
} else {
|
||||
BANNED_MESSAGE
|
||||
let expected_status = match case {
|
||||
"events"
|
||||
| "moderation_command"
|
||||
| "query"
|
||||
| "count"
|
||||
| "buzz_sidebar"
|
||||
| "moderation_reports"
|
||||
| "moderation_owner_ban"
|
||||
| "moderation_audit"
|
||||
| "moderation_restricted" => StatusCode::OK,
|
||||
"profile_search" | "invite_mint" | "buzz_read_state" => StatusCode::BAD_REQUEST,
|
||||
// This isolated fixture runs without a GIF provider key.
|
||||
"gif_search" | "gif_share" | "workflow_runs" | "workflow_approvals" | "media_get"
|
||||
| "media_head" | "git_info_refs" | "git_upload_pack" | "git_receive_pack"
|
||||
| "git_default_get" | "git_default_post" => StatusCode::NOT_FOUND,
|
||||
"media_upload" => StatusCode::UNPROCESSABLE_ENTITY,
|
||||
_ => panic!("no positive-control contract for {case}"),
|
||||
};
|
||||
assert!(
|
||||
!body.contains(denial_message),
|
||||
"{} {} case {case}: allowed control must not receive a ban denial; body: {body}",
|
||||
route.method,
|
||||
route.path
|
||||
assert_eq!(
|
||||
response_status, expected_status,
|
||||
"{} {} case {case}: positive control reached an unexpected result: {body}",
|
||||
route.method, route.path
|
||||
);
|
||||
|
||||
if case == "media_head" {
|
||||
assert!(body.is_empty(), "HEAD must suppress the missing-blob body");
|
||||
return;
|
||||
}
|
||||
if matches!(
|
||||
case,
|
||||
"git_info_refs" | "git_upload_pack" | "git_receive_pack"
|
||||
) {
|
||||
assert_eq!(body, "repository not found");
|
||||
return;
|
||||
}
|
||||
let value: serde_json::Value = serde_json::from_str(body)
|
||||
.unwrap_or_else(|error| panic!("case {case}: expected JSON, got {body}: {error}"));
|
||||
match case {
|
||||
"events" | "moderation_command" => {
|
||||
assert_eq!(value["accepted"], true, "case {case}: {body}");
|
||||
assert!(value["event_id"].as_str().is_some_and(|id| id.len() == 64));
|
||||
}
|
||||
"query"
|
||||
| "moderation_reports"
|
||||
| "moderation_owner_ban"
|
||||
| "moderation_audit"
|
||||
| "moderation_restricted" => assert!(value.is_array(), "case {case}: {body}"),
|
||||
"count" => assert!(value["count"].as_u64().is_some(), "count response: {body}"),
|
||||
"buzz_sidebar" => {
|
||||
assert!(value["channels"].is_array(), "sidebar response: {body}");
|
||||
assert!(value.get("next_cursor").is_some());
|
||||
}
|
||||
"buzz_read_state" => {
|
||||
assert_eq!(value["error"]["code"], "invalid_request");
|
||||
assert!(value["error"]["request_id"].as_str().is_some());
|
||||
}
|
||||
_ => {
|
||||
let expected_error = match case {
|
||||
"profile_search" => "invalid profile search JSON",
|
||||
"invite_mint" => {
|
||||
"invalid invite JSON: EOF while parsing an object at line 1 column 1"
|
||||
}
|
||||
"gif_search" | "gif_share" => "GIF search is not configured",
|
||||
"workflow_runs" | "workflow_approvals" => "workflow not found",
|
||||
"media_get" => "not found",
|
||||
"media_upload" => "invalid image data",
|
||||
"git_default_get" | "git_default_post" => "repository not found",
|
||||
_ => unreachable!(),
|
||||
};
|
||||
assert_eq!(value["error"], expected_error, "case {case}: {body}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn principal<'a>(name: &str, principals: &[&'a Principal]) -> &'a Principal {
|
||||
@@ -538,6 +590,19 @@ async fn community_http_ban_matrix() {
|
||||
keys: Keys::generate(),
|
||||
nip_oa_tag: None,
|
||||
};
|
||||
let clear_member_agent_keys = Keys::generate();
|
||||
let clear_member_agent = Principal {
|
||||
name: "clear-member-agent",
|
||||
nip_oa_tag: Some(
|
||||
buzz_sdk::nip_oa::compute_auth_tag(
|
||||
&clear_member.keys,
|
||||
&clear_member_agent_keys.public_key(),
|
||||
"",
|
||||
)
|
||||
.expect("sign clear ordinary-owner agent proof"),
|
||||
),
|
||||
keys: clear_member_agent_keys,
|
||||
};
|
||||
let clear_admin = Principal {
|
||||
name: "admin",
|
||||
keys: Keys::generate(),
|
||||
@@ -574,6 +639,7 @@ async fn community_http_ban_matrix() {
|
||||
let banned = [&banned_member, &banned_admin, &banned_agent];
|
||||
let controls = [
|
||||
&clear_member,
|
||||
&clear_member_agent,
|
||||
&clear_admin,
|
||||
&clear_owner,
|
||||
&clear_moderator_agent,
|
||||
@@ -600,11 +666,18 @@ async fn community_http_ban_matrix() {
|
||||
"moderation_owner_ban" => "clear-moderator-agent",
|
||||
_ => route.control.as_str(),
|
||||
};
|
||||
let control = principal(control_name, &controls);
|
||||
let response = send_route_request(&client, &route, case, control, &host).await;
|
||||
let status = response.status();
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
assert_allowed_control(status, &body, &route, case);
|
||||
let control_names = if control_name == "member" {
|
||||
vec!["member", "clear-member-agent"]
|
||||
} else {
|
||||
vec![control_name]
|
||||
};
|
||||
for name in control_names {
|
||||
let control = principal(name, &controls);
|
||||
let response = send_route_request(&client, &route, case, control, &host).await;
|
||||
let status = response.status();
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
assert_allowed_control(status, &body, &route, case);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,3 +18,7 @@ ingest_owner_ban crates/buzz-relay/src/handlers/ingest.rs owner_ban_blocks_every
|
||||
moderation_owner_ban crates/buzz-relay/src/api/bridge.rs moderation_read_honors_fresh_and_stored_banned_agent_owners postgres-ci moderation_owner_ban_auth_time_and_stored_link
|
||||
timeout_admin_denial crates/buzz-test-client/tests/regression_relay_admin_ban_gate.rs banned_and_timed_out_admins_are_refused_but_unrestricted_admin_can_administer relay-e2e timed_out_admin_relay_admin_denial
|
||||
http_tenant_isolation crates/buzz-test-client/tests/community_ban_routes.rs ban_is_scoped_to_host_resolved_community relay-e2e http_ban_tenant_isolation
|
||||
invite_restricted_claim crates/buzz-relay/src/api/invites/postgres_tests/restriction_tests.rs signed_nonmember_claims_reject_restrictions_without_consuming_invite postgres-ci restricted_nonmember_claim_never_consumes_invite
|
||||
workflow_owner_ban crates/buzz-relay/src/api/bridge/workflow_webhook_postgres_tests.rs webhook_admission_enforces_owner_ban_tenant_scope_and_lookup_failure postgres-ci webhook_owner_ban_tenant_scope_and_fail_closed_lookup
|
||||
durable_live_revalidation crates/buzz-relay/src/state.rs missed_member_owner_ban_and_first_owner_link_revoke_root_audio_sessions postgres-ci missed_fanout_member_and_owner_revocation
|
||||
token_owner_revalidation crates/buzz-relay/src/state.rs token_owner_admission_survives_scan_with_nip_oa_disabled_until_owner_removal postgres-ci nip_fi_owner_admission_matches_live_scan
|
||||
|
||||
|
@@ -29,12 +29,12 @@ join_policy relay GET /api/join-policy public_metadata not_applicable not_applic
|
||||
join_policy_terms relay GET /api/join-policy/terms public_metadata not_applicable not_applicable:public_metadata classified -
|
||||
join_policy_privacy relay GET /api/join-policy/privacy public_metadata not_applicable not_applicable:public_metadata classified -
|
||||
invite_accept_policy relay POST /api/invites/accept-policy pre_membership_anonymous exempt not_applicable:no_authenticated_principal classified -
|
||||
invite_claim relay POST /api/invites/claim pre_membership_nip98 exempt enforce pending:BUZZ-268 BUZZ-268
|
||||
invite_claim relay POST /api/invites/claim pre_membership_nip98 exempt enforce pg:signed_nonmember_claims_reject_restrictions_without_consuming_invite -
|
||||
nip_fi_disconnect relay POST /api/nip-fi/disconnect internal_nip_fi not_applicable not_applicable:internal_auth_plane classified -
|
||||
moderation_reports relay GET /moderation/reports community_nip98 community enforce matrix:moderation_reports+moderation_owner_ban admin
|
||||
moderation_audit relay GET /moderation/audit community_nip98 community enforce matrix:moderation_audit+moderation_owner_ban admin
|
||||
moderation_restricted relay GET /moderation/restricted community_nip98 community enforce matrix:moderation_restricted+moderation_owner_ban admin
|
||||
workflow_webhook relay POST /hooks/{id} workflow_webhook_secret not_applicable enforce pending:BUZZ-272 BUZZ-272
|
||||
workflow_webhook relay POST /hooks/{id} workflow_webhook_secret not_applicable enforce pg:webhook_admission_enforces_owner_ban_tenant_scope_and_lookup_failure -
|
||||
mesh_demo_echo relay POST /_mesh/demo/echo testbed_internal not_applicable not_applicable:testbed_only classified -
|
||||
huddle_audio relay GET /huddle/{channel_id}/audio community_nip42 community enforce pg:audio_join_rejects_community_banned_member+audio_join_rejects_banned_admin+audio_join_rejects_banned_owner_agent -
|
||||
media_upload relay PUT /upload community_blossom community enforce matrix:media_upload member
|
||||
|
||||
|
Reference in New Issue
Block a user