diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-10 17:03:29 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-10 17:03:29 +0000 |
| commit | 6c6d677f35756445ccc7a1ce06d231e567254f58 (patch) | |
| tree | 4421b8989e8bd392203ac54b6544d37ae2d038ff /tests/sync | |
| parent | cbed48d5a20b646a5bcc23e907d6163a3a8d36c5 (diff) | |
test(sync): add rejection test for announcements without clone tags
Diffstat (limited to 'tests/sync')
| -rw-r--r-- | tests/sync/bootstrap.rs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/sync/bootstrap.rs b/tests/sync/bootstrap.rs index 62a8fa5..506a262 100644 --- a/tests/sync/bootstrap.rs +++ b/tests/sync/bootstrap.rs | |||
| @@ -212,4 +212,93 @@ async fn test_relay_replays_events_after_restart() { | |||
| 212 | "After restart sync result: {} (may be false due to domain change)", | 212 | "After restart sync result: {} (may be false due to domain change)", |
| 213 | synced_after_restart | 213 | synced_after_restart |
| 214 | ); | 214 | ); |
| 215 | } | ||
| 216 | |||
| 217 | /// Test 4: Rejection - announcement not listing relay should NOT sync | ||
| 218 | /// | ||
| 219 | /// Scenario: | ||
| 220 | /// 1. relay_a (source), relay_b (sync from relay_a) | ||
| 221 | /// 2. Create announcement listing ONLY relay_a domain | ||
| 222 | /// 3. Send to relay_a | ||
| 223 | /// 4. Verify NOT synced to relay_b (write policy rejects) | ||
| 224 | /// | ||
| 225 | /// This tests that the relay's write policy correctly rejects events | ||
| 226 | /// that don't list its domain in the clone tag. | ||
| 227 | #[tokio::test] | ||
| 228 | async fn test_announcement_not_listing_relay_is_not_synced() { | ||
| 229 | // 1. Start source relay (relay_a) | ||
| 230 | let relay_a = TestRelay::start().await; | ||
| 231 | println!( | ||
| 232 | "relay_a started at {} (domain: {})", | ||
| 233 | relay_a.url(), | ||
| 234 | relay_a.domain() | ||
| 235 | ); | ||
| 236 | |||
| 237 | // 2. Start syncing relay (relay_b) configured to sync from relay_a | ||
| 238 | let relay_b = TestRelay::start_with_sync(Some(relay_a.url().into())).await; | ||
| 239 | println!( | ||
| 240 | "relay_b started at {} (domain: {})", | ||
| 241 | relay_b.url(), | ||
| 242 | relay_b.domain() | ||
| 243 | ); | ||
| 244 | |||
| 245 | // 3. Create test keys | ||
| 246 | let keys = Keys::generate(); | ||
| 247 | |||
| 248 | // 4. Wait for relay_b's sync connection to establish | ||
| 249 | tokio::time::sleep(Duration::from_secs(1)).await; | ||
| 250 | |||
| 251 | // 5. Create a repository announcement that lists ONLY relay_a | ||
| 252 | // This should NOT sync to relay_b because relay_b's write policy | ||
| 253 | // will reject events that don't list its domain | ||
| 254 | let announcement = create_repo_announcement( | ||
| 255 | &keys, | ||
| 256 | &[&relay_a.domain()], // Only relay_a, NOT relay_b | ||
| 257 | "test-repo-rejection", | ||
| 258 | ); | ||
| 259 | let announcement_id = announcement.id; | ||
| 260 | |||
| 261 | println!( | ||
| 262 | "Created announcement {} (kind {}) - lists ONLY relay_a", | ||
| 263 | announcement_id, | ||
| 264 | announcement.kind.as_u16() | ||
| 265 | ); | ||
| 266 | for tag in announcement.tags.iter() { | ||
| 267 | println!(" Tag: {:?}", tag.as_slice()); | ||
| 268 | } | ||
| 269 | |||
| 270 | // 6. Send announcement to relay_a | ||
| 271 | let client_a = TestClient::new(relay_a.url(), keys.clone()) | ||
| 272 | .await | ||
| 273 | .expect("Failed to connect to relay_a"); | ||
| 274 | |||
| 275 | client_a | ||
| 276 | .send_event(&announcement) | ||
| 277 | .await | ||
| 278 | .expect("Failed to send announcement to relay_a"); | ||
| 279 | println!("Announcement sent to relay_a"); | ||
| 280 | |||
| 281 | client_a.disconnect().await; | ||
| 282 | |||
| 283 | // 7. Wait for potential sync attempt | ||
| 284 | // Give enough time for sync to complete if it were to happen | ||
| 285 | tokio::time::sleep(Duration::from_secs(3)).await; | ||
| 286 | |||
| 287 | // 8. Verify announcement did NOT sync to relay_b | ||
| 288 | let filter = Filter::new() | ||
| 289 | .kind(Kind::Custom(KIND_REPOSITORY_STATE)) | ||
| 290 | .author(keys.public_key()); | ||
| 291 | |||
| 292 | let synced = wait_for_event_on_relay(relay_b.url(), filter, Duration::from_secs(2)).await; | ||
| 293 | |||
| 294 | // 9. Cleanup | ||
| 295 | relay_b.stop().await; | ||
| 296 | relay_a.stop().await; | ||
| 297 | |||
| 298 | assert!( | ||
| 299 | !synced, | ||
| 300 | "Announcement {} should NOT have synced to relay_b because it doesn't list relay_b's domain", | ||
| 301 | announcement_id | ||
| 302 | ); | ||
| 303 | println!("SUCCESS: Announcement was correctly rejected by relay_b (not synced)"); | ||
| 215 | } \ No newline at end of file | 304 | } \ No newline at end of file |