Server integrations / Paper and protocol tests (push) Failing after 20s
Server integrations / fabric / 1.20.1 (push) Failing after 11s
Server integrations / fabric / 1.21.1 (push) Failing after 14s
Server integrations / fabric / 26.1.2 (push) Failing after 17s
Server integrations / fabric / 26.2 (push) Failing after 12s
Server integrations / fabric / 26.3 (push) Failing after 6s
Server integrations / forge / 1.20.1 (push) Failing after 6s
Server integrations / forge / 1.21.1 (push) Failing after 8s
Server integrations / forge / 26.1.2 (push) Failing after 8s
Server integrations / forge / 26.2 (push) Failing after 8s
Server integrations / forge / 26.3 (push) Failing after 7s
CI / Web UIs (type-check + build) (panel/web) (push) Canceled after 0s
CI / Launcher (Windows build check) (push) Canceled after 2m53s
CI / Real installs (Mojang, Fabric, Quilt, Forge, NeoForge) (push) Canceled after 0s
CI / Docker image builds (push) Canceled after 0s
CI / Rust (fmt, clippy, tests) (push) Canceled after 1m22s
CI / Web UIs (type-check + build) (launcher) (push) Canceled after 1m27s
59 lines
3.1 KiB
Rust
59 lines
3.1 KiB
Rust
mod common;
|
|
use common::*;
|
|
|
|
fn tile(zoom: u8, x: i32, y: i32) -> Vec<u8> {
|
|
let png = [0x89, b'P', b'N', b'G', 0x0d, 0x0a, 0x1a, 0x0a, 1, 2, 3, 4];
|
|
let mut v = vec![zoom];
|
|
v.extend(x.to_be_bytes());
|
|
v.extend(y.to_be_bytes());
|
|
v.extend((png.len() as u32).to_be_bytes());
|
|
v.extend(png);
|
|
v
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn the_landing_page_decides_what_the_public_sees_of_the_map() {
|
|
let t = setup().await;
|
|
let admin = t.login("admin", "supersecret").await;
|
|
let (_, srv) = t.call("POST", "/api/admin/servers", Some(&admin), Some(json!({"name": "SMP", "instance_id": "smp"}))).await;
|
|
let key = srv["token"].as_str().unwrap().to_string();
|
|
assert_eq!(t.call_raw("POST", "/api/server/v1/map/tiles?dim=minecraft:overworld", Some(&key), tile(0, 0, 0)).await.0, StatusCode::OK);
|
|
t.call("POST", "/api/server/v1/map/players", Some(&key), Some(json!({"players": [{"uuid": "11111111-1111-1111-1111-111111111111", "name": "Steve", "dimension": "minecraft:overworld", "x": 1.0, "y": 64.0, "z": 2.0, "yaw": 0.0}]}))).await;
|
|
t.call("POST", "/api/server/v1/map/overlay", Some(&key), Some(json!({"claims": [{"id": "c"}], "pins": [{"id": "p"}]}))).await;
|
|
|
|
// No map section on the landing page: nothing is public.
|
|
assert_eq!(t.call("GET", "/api/v1/public/map/0", None, None).await.0, StatusCode::NOT_FOUND);
|
|
|
|
let landing = |opts: Value| json!({"blocks": [{"id": "m1", "type": "map", "enabled": true, "options": opts}]});
|
|
assert_eq!(t.call("PUT", "/api/admin/landing", Some(&admin), Some(landing(json!({"show_players": false})))).await.0, StatusCode::OK);
|
|
let (s, info) = t.call("GET", "/api/v1/public/map/0", None, None).await;
|
|
assert_eq!(s, StatusCode::OK, "{info}");
|
|
assert_eq!(info["ready"], true);
|
|
assert_eq!(info["layers"]["players"], false);
|
|
assert_eq!(info["layers"]["claims"], true);
|
|
// The tile key from the public info loads tiles without signing in.
|
|
let token = info["token"].as_str().unwrap();
|
|
let (s, png) = t.fetch(&format!("/api/map/{}/overworld/0/0/0.png?t={token}", info["server_id"])).await;
|
|
assert_eq!((s, png.len()), (StatusCode::OK, 12));
|
|
|
|
// Players stay hidden unless the admin turns them on.
|
|
let (_, o) = t.call("GET", "/api/v1/public/map/0/overlay", None, None).await;
|
|
assert_eq!(o["players"].as_array().unwrap().len(), 0);
|
|
assert_eq!(o["claims"].as_array().unwrap().len(), 1);
|
|
t.call("PUT", "/api/admin/landing", Some(&admin), Some(landing(json!({"show_players": true, "show_pins": false})))).await;
|
|
let (_, o) = t.call("GET", "/api/v1/public/map/0/overlay", None, None).await;
|
|
assert_eq!(o["players"][0]["name"], "Steve");
|
|
assert_eq!(o["pins"].as_array().unwrap().len(), 0);
|
|
|
|
// Another server's map isn't exposed, and turning the section off closes it.
|
|
assert_eq!(t.call("GET", "/api/v1/public/map/999", None, None).await.0, StatusCode::NOT_FOUND);
|
|
t.call(
|
|
"PUT",
|
|
"/api/admin/landing",
|
|
Some(&admin),
|
|
Some(json!({"blocks": [{"id": "m1", "type": "map", "enabled": false, "options": {}}]})),
|
|
)
|
|
.await;
|
|
assert_eq!(t.call("GET", "/api/v1/public/map/0", None, None).await.0, StatusCode::NOT_FOUND);
|
|
}
|