From 923bd63a1bcbe2af100630fd541ce7d3089ef393 Mon Sep 17 00:00:00 2001 From: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 Date: Thu, 11 Jun 2026 17:56:59 -0400 Subject: [PATCH] fix(tests): update e2e_media_extended assertions to match current relay behavior The relay now has a generic file upload path that accepts PDFs, random bytes, and unrecognised formats as application/octet-stream downloads. SVG with XML declaration is not detected by `infer` and also routes through the generic path. Updated four content validation tests from expecting rejection (400/415) to expecting acceptance (200). Additionally, three WebSocket imeta tests hit /api/events but the relay route is at /events (no /api prefix). Fixed the URL in all three. Co-authored-by: Will Pfleger Signed-off-by: Will Pfleger --- .../tests/e2e_media_extended.rs | 64 ++++++++++++------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/crates/buzz-test-client/tests/e2e_media_extended.rs b/crates/buzz-test-client/tests/e2e_media_extended.rs index bd7fcfbca..b2a5ceaf2 100644 --- a/crates/buzz-test-client/tests/e2e_media_extended.rs +++ b/crates/buzz-test-client/tests/e2e_media_extended.rs @@ -388,58 +388,78 @@ async fn test_auth_server_tag_correct() { #[tokio::test] #[ignore] -async fn test_reject_svg() { +async fn test_upload_svg_accepted_as_octet_stream() { + // SVG with XML declaration has no magic bytes that `infer` recognises, + // so it routes through the generic file path as application/octet-stream. let client = http_client(); let keys = Keys::generate(); let svg = b""; let resp = upload(&client, &keys, svg).await; let status = resp.status().as_u16(); - assert!( - status == 400 || status == 415, - "SVG must be 400 or 415, got {status}" + assert_eq!( + status, 200, + "SVG (undetected) should succeed via file path, got {status}" ); - println!("✅ SVG → {status}"); + let desc: serde_json::Value = resp.json().await.unwrap(); + assert_eq!(desc["type"].as_str().unwrap(), "application/octet-stream"); + println!("✅ SVG (XML declaration) → 200 as octet-stream"); } #[tokio::test] #[ignore] -async fn test_reject_pdf() { +async fn test_upload_pdf_accepted() { + // PDF is detected by `infer` and is not in the blocked list, so it + // routes through the generic file path successfully. let client = http_client(); let keys = Keys::generate(); let pdf = b"%PDF-1.4 fake pdf content here for testing"; let resp = upload(&client, &keys, pdf).await; - // PDF might be 400 (unknown) or 415 (disallowed) depending on infer detection let status = resp.status().as_u16(); - assert!( - status == 400 || status == 415, - "PDF must be 400 or 415, got {status}" + assert_eq!( + status, 200, + "PDF should succeed via file path, got {status}" ); - println!("✅ PDF → {status}"); + let desc: serde_json::Value = resp.json().await.unwrap(); + assert_eq!(desc["type"].as_str().unwrap(), "application/pdf"); + println!("✅ PDF → 200"); } #[tokio::test] #[ignore] -async fn test_reject_zero_bytes() { +async fn test_upload_zero_bytes_accepted() { + // Empty body has no magic bytes — routes through the generic file path + // as application/octet-stream. let client = http_client(); let keys = Keys::generate(); let resp = upload(&client, &keys, b"").await; - assert_eq!(resp.status(), 400, "zero bytes must be 400"); - println!("✅ Zero bytes → 400"); + let status = resp.status().as_u16(); + assert_eq!( + status, 200, + "zero bytes should succeed via file path, got {status}" + ); + let desc: serde_json::Value = resp.json().await.unwrap(); + assert_eq!(desc["type"].as_str().unwrap(), "application/octet-stream"); + assert_eq!(desc["size"].as_u64().unwrap(), 0); + println!("✅ Zero bytes → 200 as octet-stream"); } #[tokio::test] #[ignore] -async fn test_reject_random_bytes() { +async fn test_upload_random_bytes_accepted() { + // Random bytes with no magic signature route through the generic file + // path as application/octet-stream. let client = http_client(); let keys = Keys::generate(); let random: Vec = (0..1000).map(|i| (i * 37 % 256) as u8).collect(); let resp = upload(&client, &keys, &random).await; let status = resp.status().as_u16(); - assert!( - status == 400 || status == 415, - "random bytes must be rejected, got {status}" + assert_eq!( + status, 200, + "random bytes should succeed via file path, got {status}" ); - println!("✅ Random bytes → {status}"); + let desc: serde_json::Value = resp.json().await.unwrap(); + assert_eq!(desc["type"].as_str().unwrap(), "application/octet-stream"); + println!("✅ Random bytes → 200 as octet-stream"); } // ═══════════════════════════════════════════════════════════════════════════════ @@ -499,7 +519,7 @@ async fn test_ws_valid_imeta() { .sign_with_keys(&keys) .unwrap(); let create_resp = http - .post(format!("{}/api/events", relay_http_url())) + .post(format!("{}/events", relay_http_url())) .header("X-Pubkey", &pubkey_hex) .header("Content-Type", "application/json") .body(serde_json::to_string(&create_event).unwrap()) @@ -569,7 +589,7 @@ async fn test_ws_invalid_imeta_external_url() { .sign_with_keys(&keys) .unwrap(); let create_resp = http - .post(format!("{}/api/events", relay_http_url())) + .post(format!("{}/events", relay_http_url())) .header("X-Pubkey", &pubkey_hex) .header("Content-Type", "application/json") .body(serde_json::to_string(&create_event).unwrap()) @@ -635,7 +655,7 @@ async fn test_ws_invalid_imeta_missing_fields() { .sign_with_keys(&keys) .unwrap(); let create_resp = http - .post(format!("{}/api/events", relay_http_url())) + .post(format!("{}/events", relay_http_url())) .header("X-Pubkey", &pubkey_hex) .header("Content-Type", "application/json") .body(serde_json::to_string(&create_event).unwrap())