39 lines
1.3 KiB
Rust
39 lines
1.3 KiB
Rust
mod common;
|
|
|
|
use common::{announce_test_file, test_server};
|
|
|
|
#[tokio::test]
|
|
async fn stats_reflects_files() {
|
|
let server = test_server();
|
|
announce_test_file(&server, "a.ogg", "audio", &"a1".repeat(32)).await;
|
|
announce_test_file(&server, "b.ogg", "audio", &"a2".repeat(32)).await;
|
|
announce_test_file(&server, "c.pdf", "document", &"a3".repeat(32)).await;
|
|
let res = server.get("/api/v1/stats").await;
|
|
assert_eq!(res.status_code(), 200);
|
|
let body = res.json::<serde_json::Value>();
|
|
assert_eq!(body["files"], 3);
|
|
assert_eq!(body["total_bytes"], 300);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn announce_rate_limited() {
|
|
let server = test_server();
|
|
// 10 por segundo no RateLimiter padrão; dispara 12
|
|
let mut last_status = axum::http::StatusCode::OK;
|
|
for i in 0..12 {
|
|
let res = server.post("/api/v1/announce")
|
|
.json(&serde_json::json!({
|
|
"peer_id": "ral",
|
|
"name": format!("f{i}.ogg"),
|
|
"description": "",
|
|
"type": "audio",
|
|
"extension": "ogg",
|
|
"size_bytes": 10,
|
|
"hash": format!("{:02x}", i).repeat(32),
|
|
"license": "authored"
|
|
}))
|
|
.await;
|
|
last_status = res.status_code();
|
|
}
|
|
assert_eq!(last_status, axum::http::StatusCode::BAD_REQUEST);
|
|
} |