From 23d8a4599cd4702accfbd69956e6f9598fe70816 Mon Sep 17 00:00:00 2001 From: Daniel Hofbauer Date: Wed, 18 Nov 2026 12:37:03 +0100 Subject: [PATCH] fix(connections): test XYZ templates with a sample tile - Distinguish a missing sample from a usable tile. - Name XYZ connections from their host and warn about path keys. - Follow up on #2368; part of #2356. --- crates/engine/src/cmd/connections.rs | 54 +++++++++---- crates/engine/src/connection_tile_test.rs | 68 ++++++++++++++++ crates/engine/src/connections.rs | 14 +++- crates/engine/src/tests.rs | 94 +++++++++++++++++++---- crates/tiles/src/template.rs | 16 ++++ crates/ui-egui/src/connectionui.rs | 59 +++++++++++--- docs/user-guide/data.md | 32 +++++--- 7 files changed, 285 insertions(+), 52 deletions(-) create mode 100644 crates/engine/src/connection_tile_test.rs diff --git a/crates/engine/src/cmd/connections.rs b/crates/engine/src/cmd/connections.rs index 21ae1f5bf0..afc50a3824 100644 --- a/crates/engine/src/cmd/connections.rs +++ b/crates/engine/src/cmd/connections.rs @@ -6,6 +6,7 @@ use std::collections::BTreeMap; use serde_json::{Value, json}; use super::{b, ps}; +use crate::connections::tile_test::{self, Sample}; use crate::connections::{Connection, DATABASE_KINDS, DESKTOP_ONLY, KINDS}; use crate::render::rustgis_tiles::{arcgis_token, s3, stac}; use crate::s3_keys as keys; @@ -65,7 +66,7 @@ pub fn commands() -> Vec { ), C::new("connection.forgetPassword", "Forget Saved Password", "Home › Add › Data Sources", forget_password).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Reserved)).view().params(r#"{"id": "a database connection's id or name"}"#), C::new("connection.test", "Test Connection", "Home › Add › Data Sources", test).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Reserved)).view().params( - r#"{"id"?: "a connection's id or name", "kind"?: "postgres"|"mysql"|"sqlserver"|"service"|"wms"|"wmts"|"wfs"|"wcs"|"ogcapi"|"arcgis"|"csw"|"stac"|"s3", "name"?: text, "group"?: text, "address"?: text, "options"?: "an unsaved connection, as connection.new (when no id)", "auth"?: text, "user"?: text, "keyName"?: "as connection.new (when no id)", "password"?: "for a named database, authentication refusal restores prior session credentials; a later listing failure keeps the new password; never persisted. A saved web service's: as connection.login (logs in first)", "apiKey"?: "a saved web service's, as connection.login (logs in first)", "allowInsecure"?: "as connection.login", "accessKeyId"?: text, "secretAccessKey"?: text, "sessionToken"?: "as connection.login (logs in first)", "probe"?: "true: only the address the test reads, {fetch} (null for databases, which their driver tests)", "answer"?: "non-database kinds only: what that address returned, when the app fetched it (no network request then); databases ignore answer and test through their driver"}"#, + r#"{"id"?: "a connection's id or name", "kind"?: "postgres"|"mysql"|"sqlserver"|"service"|"wms"|"wmts"|"wfs"|"wcs"|"ogcapi"|"arcgis"|"csw"|"stac"|"s3", "name"?: text, "group"?: text, "address"?: text, "options"?: "an unsaved connection, as connection.new (when no id)", "auth"?: text, "user"?: text, "keyName"?: "as connection.new (when no id)", "password"?: "for a named database, authentication refusal restores prior session credentials; a later listing failure keeps the new password; never persisted. A saved web service's: as connection.login (logs in first)", "apiKey"?: "a saved web service's, as connection.login (logs in first)", "allowInsecure"?: "as connection.login", "accessKeyId"?: text, "secretAccessKey"?: text, "sessionToken"?: "as connection.login (logs in first)", "probe"?: "true: only the address the test reads, {fetch} (null for databases), with tile: {zoom, vector} for an XYZ sample", "answer"?: "fetched service or catalogue text, parsed without a request; not used for XYZ tiles or databases"} (a direct XYZ test returns result: {kind: \"xyz\", tile: [z,x,y], status: \"received\" or \"missing\"}; missing is not a pass)"#, ), C::new("connection.browse", "Browse Connection", "Home › Add › Data Sources", browse::browse).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Reserved).with(crate::policy::Effect::Files)).view().params( r#"{"id": "a connection's id or name", "node"?: "a child's node, as a listing gives it (the connection's top level when absent)", "probe"?: "true: only the address this level reads, {fetch} (null: read without a fetch, or by the database driver); an S3 connection logs in first, as connection.test does", "answer"?: "what that address returned, when the app fetched it", "documents"?: [{"url": "a further document a listing asked for (next)", "text": "its answer"}]} → {connection, node, children: [{key, name, what, detail?, node? (browse it), children? (listed already), add? {command, params}: the command that adds it}], truncated?, matched?, notes?, service? {url, type}, next? (fetch it, then ask again with answer and documents)}. Database roots list schemas; open a schema node to list its tables."#, @@ -271,6 +272,9 @@ fn shown_stripped(s: &mut Session, c: &Connection, stripped: bool, given: &str, out["strippedParameters"] = json!(names); } } + if web::is_service(c) && tile_test::is_template(&c.address) && tile_test::has_path_key(&c.address) { + s.notify_text(NoticeText::format(tile_test::PATH_KEY_WARNING, []), false); + } out } @@ -1217,19 +1221,8 @@ fn answered(s: &mut Session, c: &Connection, text: &str) -> CmdResult { fn test(s: &mut Session, p: &Value) -> CmdResult { let c = tested(s, p)?; - let service = web::is_service(&c); - // XYZ addresses name individual tiles, not a document the service test can read. - if service { - let address = c.address.split('#').next().unwrap_or_default(); - if (address.contains("{z}") || address.contains("{zoom}")) - && address.contains("{x}") - && (address.contains("{y}") || address.contains("{-y}")) - { - return Err(crate::connections::XYZ_TEST.into()); - } - } // An unsaved web service reads anonymously, whatever saved connection shares its origin. - let anonymous = service && c.id.is_empty(); + let anonymous = web::is_service(&c) && c.id.is_empty(); web::anonymously(s, anonymous, |s| test_connection(s, p, c)).unwrap_or_else(|_| Err("connection.test failed unexpectedly".into())) } @@ -1266,6 +1259,11 @@ fn test_connection(s: &mut Session, p: &Value, c: Connection) -> CmdResult { if !c.id.is_empty() { out["connection"] = json!(c.id); } + if web::is_service(&c) + && let Some(sample) = Sample::for_address(&c.address) + { + return test_xyz(s, p, &c, out, sample); + } if b(p, "probe").unwrap_or(false) { out["fetch"] = json!(probe_url(s, &c)?); return Ok(out); @@ -1310,3 +1308,33 @@ fn test_connection(s: &mut Session, p: &Value, c: Connection) -> CmdResult { out["result"] = result; Ok(out) } + +fn test_xyz(s: &mut Session, p: &Value, c: &Connection, mut out: Value, sample: Sample) -> CmdResult { + use crate::render::rustgis_tiles::logins; + let url = sample.address(&c.address)?; + if !c.auth.is_empty() && logins::origin(&url) != crate::connections::login_origin(c) { + return Err(tile_test::OTHER_ORIGIN.into()); + } + let url = web::request(s, (!c.id.is_empty()).then_some(c.id.as_str()), &url)?; + if b(p, "probe").unwrap_or(false) { + out["fetch"] = json!(url); + out["tile"] = json!(sample); + return Ok(out); + } + if p.get("answer").is_some() { + return Err(tile_test::TEXT_ANSWER.into()); + } + #[cfg(target_arch = "wasm32")] + return Err("An XYZ sample tile must be fetched by the app.".into()); + #[cfg(not(target_arch = "wasm32"))] + { + use crate::render::rustgis_tiles::cache; + let answer = cache::download_blocking_omitting_within(&url, cache::MAX_BYTES, cache::BLOCKING_TIMEOUT, &[404]); + let status = match sample.check(answer)? { + tile_test::Outcome::Received => "received", + tile_test::Outcome::Missing => "missing", + }; + out["result"] = json!({"kind":"xyz","tile":[sample.zoom,0,0],"status":status}); + Ok(out) + } +} diff --git a/crates/engine/src/connection_tile_test.rs b/crates/engine/src/connection_tile_test.rs new file mode 100644 index 0000000000..722cfc5fee --- /dev/null +++ b/crates/engine/src/connection_tile_test.rs @@ -0,0 +1,68 @@ +//! One bounded tile download for Test Connection, shared by the engine and the app. + +use crate::render::rustgis_tiles::{address, cache, template}; +use rustgis_map::tiles::TileKind; +use serde::{Deserialize, Serialize}; + +pub const NOT_TILE: &str = "The server answered, but the response is not a usable tile."; +pub const UNEXPANDED: &str = "The tile URL has an unsupported placeholder."; +pub const OTHER_ORIGIN: &str = "The sample tile changes the connection's origin. Use a concrete hostname to test with a saved login."; +pub const TEXT_ANSWER: &str = "An XYZ test needs a tile response, not a text answer."; +pub const PATH_KEY_WARNING: &str = "An API key in the URL path is saved as typed, not in the credential store."; + +/// An XYZ template the connection test recognises, not just a URL with a subdomain placeholder. +pub fn is_template(url: &str) -> bool { + template::xyz_sample_zoom(url).is_some() +} + +/// A nonempty `;key=…` path parameter, as used by Koordinates. Query keys have their own handling. +pub fn has_path_key(url: &str) -> bool { + let Some((_, at)) = url.split_once("://") else { return false }; + let Some((_, path)) = at.split(['?', '#']).next().unwrap_or_default().split_once('/') else { return false }; + path.split('/').any(|segment| { + segment.split(';').skip(1).any(|param| param.split_once('=').is_some_and(|(k, v)| k.eq_ignore_ascii_case("key") && !v.is_empty())) + }) +} + +#[derive(Clone, Copy, Deserialize, Serialize)] +pub struct Sample { + pub zoom: u8, + pub vector: bool, +} + +impl Sample { + pub(crate) fn for_address(url: &str) -> Option { + Some(Self { zoom: template::xyz_sample_zoom(url)?, vector: TileKind::guess(url) == TileKind::Vector }) + } + + pub(crate) fn address(self, url: &str) -> Result { + let template = url.split('#').next().unwrap_or_default(); + let url = template::expand(template, template::TileId { z: self.zoom, x: 0, y: 0 }, 256, false, &[]); + if url.contains(['{', '}']) { + return Err(UNEXPANDED.into()); + } + address::check(&url, Some(template))?; + Ok(url) + } + + /// A successful HTTP response is a pass only if the data actually decodes as a tile. + /// The transport supplies an empty body for 204; neither that nor a 404 is a pass. + pub fn check(self, response: Result, String>) -> Result { + match response { + Ok(bytes) if bytes.is_empty() => Ok(Outcome::Missing), + Err(e) if matches!(cache::http_status(&e), Some(204 | 404)) => Ok(Outcome::Missing), + Ok(bytes) => { + let want = if self.vector { cache::Want::Vector } else { cache::Want::Image }; + cache::decode(&bytes, want).map_err(|_| NOT_TILE.to_string())?; + Ok(Outcome::Received) + } + Err(e) => Err(e), + } + } +} + +#[derive(Clone, Copy)] +pub enum Outcome { + Received, + Missing, +} diff --git a/crates/engine/src/connections.rs b/crates/engine/src/connections.rs index 9985b089b8..2cbd66150f 100644 --- a/crates/engine/src/connections.rs +++ b/crates/engine/src/connections.rs @@ -10,6 +10,9 @@ use serde_json::{Map, Value, json}; use crate::sources::{self, Sources}; +#[path = "connection_tile_test.rs"] +pub mod tile_test; + /// The desktop preference saved connections are kept under. pub const PREF: &str = "connections"; /// The version of that preference this RustGIS reads and writes. One from a newer RustGIS isn't @@ -58,7 +61,6 @@ pub const SERVICE_AUTH: &[&str] = &["none", "basic", "header", "query", "arcgis" pub const WEB: &str = "web"; pub const S3_CREDENTIALS: &[&str] = &["keys", "profile", "environment", "none"]; pub const DESKTOP_ONLY: &str = "database connections are used by the desktop app"; -pub const XYZ_TEST: &str = "This is an XYZ tile URL template, not a service endpoint. Use Add Tile Layer to add it to the map."; /// Whether a serialized flag is off (so it is left out). fn is_false(value: &bool) -> bool { @@ -509,7 +511,15 @@ pub fn clean(mut c: Connection) -> Result<(Connection, bool), String> { let stripped = clean_login(&mut c)? || stripped; c.name = name_text(&c.name); if c.name.is_empty() { - c.name = if c.kind == "s3" && c.address.is_empty() { "AWS S3".into() } else { sources::default_name(&c.address) }; + c.name = if c.kind == "s3" && c.address.is_empty() { + "AWS S3".into() + } else if SERVICE_KINDS.contains(&c.kind.as_str()) && tile_test::is_template(&c.address) { + login_origin(&c) + .and_then(|origin| origin.split_once("://").map(|(_, host)| host.trim_start_matches("{s}.").chars().take(80).collect())) + .unwrap_or_else(|| "XYZ tiles".into()) + } else { + sources::default_name(&c.address) + }; } c.group = name_text(&c.group); if c.kind != "s3" { diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 20412f21e3..5b538c0bcf 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -31876,28 +31876,90 @@ fn connections_s3_rename_cannot_inherit_a_destination_session() { } #[test] -fn connection_test_rejects_xyz_templates() { - let mut s = Session::new(Project::default()); - for (kind, address) in [ - ("service", "http://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}"), - ("wmts", "https://tiles.example/{z}/{x}/{y}.png"), - ("wcs", "https://tiles.example/{z}/{x}/{y}.png"), - ("ogcapi", "https://tiles.example/tile.png?z={z}&x={x}&y={y}"), - ("service", "https://tiles.example/{zoom}/{x}/{-y}.png"), +fn connection_test_expands_xyz_templates() { + let mut s = Session::new(Project::default()); + for (kind, address, expected, zoom) in [ + ("service", "https://tiles.example/vt/lyrs=s&x={x}&y={y}&z={z}", "https://tiles.example/vt/lyrs=s&x=0&y=0&z=0", 0), + ("wmts", "https://tiles.example/{z}/{x}/{y}.png", "https://tiles.example/0/0/0.png", 0), + ("ogcapi", "https://tiles.example/tile.png?z={z}&x={x}&y={y}", "https://tiles.example/tile.png?z=0&x=0&y=0", 0), + ("service", "https://{s}.tiles.example/{zoom}/{x}/{-y}.png", "https://a.tiles.example/0/0/0.png", 0), + ("service", "https://tiles.example/{q}.jpg", "https://tiles.example/0.jpg", 1), + ("service", "https://tiles.example/tile.jpg?tile={quadkey}", "https://tiles.example/tile.jpg?tile=0", 1), ] { - let error = s.run("connection.test", &json!({"kind":kind,"address":address,"probe":true})).unwrap_err(); - assert!(error.contains("XYZ tile URL template") && error.contains("Add Tile Layer"), "{kind}: {error}"); + let result = s.run("connection.test", &json!({"kind":kind,"address":address,"probe":true})).unwrap(); + assert_eq!(result["fetch"], expected, "{kind}"); + assert_eq!(result["tile"]["zoom"], zoom); } - - let saved = - s.run("connection.new", &json!({"kind":"service","name":"Tiles","address":"https://tiles.example/{z}/{x}/{y}.png"})).unwrap(); - let error = s.run("connection.test", &json!({"id":saved["id"],"answer":"{}"})).unwrap_err(); - assert!(error.contains("Add Tile Layer"), "{error}"); - let ordinary = json!({"kind":"ogcapi","address":"https://tiles.example/collections#{z}/{x}/{y}","probe":true}); assert_eq!(s.run("connection.test", &ordinary).unwrap()["fetch"], "https://tiles.example/collections?f=json"); } +#[test] +fn connection_xyz_default_name_and_path_key_notice() { + let mut s = Session::new(Project::default()); + let mark = s.notice_mark(); + let url = "https://tiles.example/{z}/{x}/{y}.png"; + let added = s.run("connection.new", &json!({"kind":"service","address":url})).unwrap(); + assert_eq!(added["name"], "tiles.example"); + assert!(s.notices_since(mark).is_empty()); + let with_key = "https://tiles.example/services;key=fixture/tiles/{z}/{x}/{y}.png"; + let added = s.run("connection.new", &json!({"kind":"service","address":with_key,"name":"Relief"})).unwrap(); + assert_eq!(added["name"], "Relief"); + assert_eq!(added["address"], with_key); + assert!(s.notices_since(mark).iter().any(|n| n.text.contains("URL path is saved as typed") && !n.text.contains("fixture"))); +} + +#[cfg(not(target_arch = "wasm32"))] +#[test] +fn connection_test_fetches_one_xyz_tile_with_the_selected_login() { + use std::io::{BufRead, BufReader, Write}; + use std::net::TcpListener; + use std::time::Duration; + + let png = tiny_skia::Pixmap::new(1, 1).unwrap().encode_png().unwrap(); + for (status, body, expected) in [ + ("200 OK", png.as_slice(), Ok("received")), + ("204 No Content", &[][..], Ok("missing")), + ("404 Not Found", &[][..], Ok("missing")), + ("401 Unauthorized", &[][..], Err("http status: 401")), + ("200 OK", b"Login required", Err("not a usable tile")), + ] { + let listener = TcpListener::bind("127.0.0.1:0").unwrap(); + let port = listener.local_addr().unwrap().port(); + let body = body.to_vec(); + let server = std::thread::spawn(move || { + let (stream, _) = listener.accept().unwrap(); + stream.set_read_timeout(Some(Duration::from_secs(5))).unwrap(); + let mut reader = BufReader::new(stream); + let mut request = String::new(); + reader.read_line(&mut request).unwrap(); + let mut line = String::new(); + while reader.read_line(&mut line).unwrap() != 0 && line != "\r\n" { + line.clear(); + } + let mut stream = reader.into_inner(); + write!(stream, "HTTP/1.1 {status}\r\nContent-Length: {}\r\nConnection: close\r\n\r\n", body.len()).unwrap(); + stream.write_all(&body).unwrap(); + request + }); + let mut s = Session::new(Project::default()); + let url = format!("http://127.0.0.1:{port}/services;key=xyz-path-fixture/{{z}}/{{x}}/{{y}}.png"); + let c = s.run("connection.new", &json!({"kind":"service","address":url,"auth":"query","keyName":"rg_xyz_key"})).unwrap(); + let params = json!({"id":c["id"],"apiKey":"sample+key","allowInsecure":true}); + let result = s.run("connection.test", ¶ms); + match expected { + Ok(expected) => assert_eq!(result.unwrap()["result"], json!({"kind":"xyz","tile":[0,0,0],"status":expected})), + Err(expected) => { + let error = result.unwrap_err(); + assert!(error.contains(expected) && !error.contains("sample") && !error.contains("xyz-path-fixture"), "{error}"); + let history = s.diagnostics.report(rustgis_data::diagnostics::Filter::All); + assert!(history.contains(expected) && !history.contains("xyz-path-fixture"), "{history}"); + } + } + assert_eq!(server.join().unwrap(), "GET /services;key=xyz-path-fixture/0/0/0.png?rg_xyz_key=sample%2Bkey HTTP/1.1\r\n"); + } +} + #[test] fn connection_test_probes_and_answers() { #[cfg(not(target_arch = "wasm32"))] diff --git a/crates/tiles/src/template.rs b/crates/tiles/src/template.rs index 8e77330e70..87bd639bc5 100644 --- a/crates/tiles/src/template.rs +++ b/crates/tiles/src/template.rs @@ -141,6 +141,22 @@ pub fn style_zoom(m_per_px: f64) -> f32 { if z.is_finite() { z.clamp(0.0, 24.0) as f32 } else { 0.0 } } +/// Recognises XYZ coordinates or a quadkey in the path or query, not in the fragment. +/// The root tile has an empty quadkey, so sample the first child for those templates. +pub fn xyz_sample_zoom(template: &str) -> Option { + let template = template.split('#').next().unwrap_or_default(); + if template.contains("{q}") || template.contains("{quadkey}") { + Some(1) + } else if (template.contains("{z}") || template.contains("{zoom}")) + && template.contains("{x}") + && (template.contains("{y}") || template.contains("{-y}")) + { + Some(0) + } else { + None + } +} + /// Fills in a tile address template: `{z}`, `{x}`, `{y}`, `{-y}` (rows from the south), `{s}` /// (one of `subdomains`, chosen by the tile), `{switch:a,b,c}`, `{q}`/`{quadkey}`, /// `{bbox-epsg-3857}` (a WMS box), `{width}`/`{height}`, `{r}` (dropped) and `{ratio}` (1). diff --git a/crates/ui-egui/src/connectionui.rs b/crates/ui-egui/src/connectionui.rs index 376a3fbf89..9d85ef94ec 100644 --- a/crates/ui-egui/src/connectionui.rs +++ b/crates/ui-egui/src/connectionui.rs @@ -2,6 +2,7 @@ //! web probes, and explicit saved-connection choices for project sources. use egui::vec2; +use rustgis_engine::connections::tile_test::{self, Outcome, Sample}; use rustgis_engine::connections::{ Connection, DATABASE_KINDS, LoginReason, LoginRequest, SERVICE_KINDS as WEB_KINDS, WEB, database_key, database_label, login_origin, }; @@ -50,7 +51,7 @@ pub struct State { pub access_key: String, pub secret_key: String, pub session_token: String, - pub test: Option<(Value, Slot, String>>, TestContext)>, + pub test: Option<(Value, Slot>, TestContext)>, /// The form was opened to log in (Log In…): Save logs in even with no secret typed, /// using the connection's existing session login (or saved DB/S3 credentials). pub login: bool, @@ -62,6 +63,11 @@ pub struct State { pub resolving: Option<(String, String)>, } +pub enum TestAnswer { + Document(Vec), + Tile(Sample, Outcome), +} + /// A token generation this form started: the connection it is for, and whether the form's Test /// follows it (a Test never keeps the token past this session). pub struct Generating { @@ -139,9 +145,9 @@ pub(crate) fn translated(e: &str) -> String { web::UNSAVED => tl!("Save the connection first: a login belongs to a saved connection."), web::NO_ORIGIN => tl!("The connection's address has no http:// or https:// origin a login can go to."), web::SAVE_BEFORE_TEST => tl!("Save changes before testing this connection."), - rustgis_engine::connections::XYZ_TEST => { - tl!("This is an XYZ tile URL template, not a service endpoint. Use Add Tile Layer to add it to the map.") - } + tile_test::NOT_TILE => tl!("The server answered, but the response is not a usable tile."), + tile_test::UNEXPANDED => tl!("The tile URL has an unsupported placeholder."), + tile_test::OTHER_ORIGIN => tl!("The sample tile changes the connection's origin. Use a concrete hostname to test with a saved login."), web::NOT_THIS_SESSION => tl!("This request's login does not belong to this session."), web::CHOOSE_CONNECTION => tl!("Several saved connections match this address. Choose a connection explicitly."), web::NO_SUCH_CONNECTION => tl!("No saved web-service connection with this id."), @@ -621,9 +627,27 @@ pub fn start_test(app: &mut RustGisApp) { } let status = tl!("Testing…"); let context = TestContext { opened: app.session.opened, form: definition(&app.ui.connection), status, _login: login }; - let slot: Slot, String>> = Slot::default(); - let land = slot.clone(); - cache::download(&url, Box::new(move |r| *land.lock().unwrap_or_else(|e| e.into_inner()) = Some(r))); + let slot: Slot> = Slot::default(); + if let Ok(sample) = serde_json::from_value::(v["tile"].clone()) { + let land = std::sync::Arc::downgrade(&slot); + let watch = land.clone(); + cache::with_still(std::sync::Arc::new(move || watch.strong_count() != 0), || { + cache::download_limited_omitting( + &url, + cache::MAX_BYTES, + &[404], + Box::new(move |r| { + if let Some(land) = land.upgrade() { + let outcome = sample.check(r).map(|outcome| TestAnswer::Tile(sample, outcome)); + *land.lock().unwrap_or_else(|e| e.into_inner()) = Some(outcome); + } + }), + ); + }); + } else { + let land = slot.clone(); + cache::download(&url, Box::new(move |r| *land.lock().unwrap_or_else(|e| e.into_inner()) = Some(r.map(TestAnswer::Document)))); + } app.ui.connection.test = Some((q, slot, context)); app.dialogs.info = Some(status.into()); } @@ -826,7 +850,7 @@ pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { let Some((mut q, _, _context)) = app.ui.connection.test.take() else { return }; app.dialogs.info = None; match result { - Ok(bytes) => { + Ok(TestAnswer::Document(bytes)) => { q["answer"] = json!(String::from_utf8_lossy(&bytes)); let kind = q["kind"].as_str().unwrap_or("").to_owned(); match app.run("connection.test", q) { @@ -834,7 +858,19 @@ pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { Err(e) => app.dialogs.error = Some(rustgis_engine::render::rustgis_tiles::logins::scrub(&e)), } } - Err(e) => app.dialogs.error = Some(rustgis_engine::render::rustgis_tiles::logins::scrub(&e)), + Ok(TestAnswer::Tile(sample, outcome)) => { + let zoom = sample.zoom.to_string(); + match outcome { + Outcome::Received => app.dialogs.info = Some(i18n::fmt("Received tile {z}/0/0.", &[("z", &zoom)])), + Outcome::Missing => { + app.dialogs.error = Some(i18n::fmt( + "Server reachable, but no tile at {z}/0/0. Check the address and the layer's zoom range.", + &[("z", &zoom)], + )); + } + } + } + Err(e) => app.dialogs.error = Some(logins::scrub(&translated(&e))), } } @@ -1259,6 +1295,11 @@ pub fn dialog(app: &mut RustGisApp, ui: &mut egui::Ui) -> bool { .changed(); ui.end_row(); if service { + if tile_test::is_template(&st.address) && tile_test::has_path_key(&st.address) { + ui.label(""); + ui.label(egui::RichText::new(tl!("An API key in the URL path is saved as typed, not in the credential store.")).small()); + ui.end_row(); + } ui.label(egui::RichText::new(tl!("Login")).strong()); ui.label(""); ui.end_row(); diff --git a/docs/user-guide/data.md b/docs/user-guide/data.md index b7ce6691fe..eb9e1d3ec6 100644 --- a/docs/user-guide/data.md +++ b/docs/user-guide/data.md @@ -972,11 +972,11 @@ server must also allow browser requests (CORS). In the pane, **New Connection ▾** and **Edit…** let you set the name, group and address; **Home › Add › Add Data › New Connection** opens the same form for a chosen kind. Leave a new -connection's name blank to derive it from the address. **Test** checks the form without saving -it: web-service, catalogue, STAC and S3 requests run in the background on both desktop and web; -database tests run synchronously on desktop. The web app doesn't offer database kinds for new -connections; saved database rows remain visible but cannot be opened or tested there. Earth -Search and Planetary Computer remain available under **Library**. +connection's name blank to derive it from the address (the host for an XYZ template). **Test** +checks the form without saving it. Web-service, catalogue, STAC and S3 requests run in the +background on both desktop and web; database tests run synchronously on desktop. The web app +doesn't offer database kinds for new connections; saved database rows remain visible but cannot +be opened or tested there. Earth Search and Planetary Computer remain available under **Library**. For a new web-service connection, enter its Basic password or header/query API key to test it before saving. The test uses only the entered login, not a saved service login or an S3 session login @@ -1030,13 +1030,21 @@ Database connections are used on the desktop only. S3 options are `region`, `buc `connection.test` lists the endpoint's tables, layers, records, collections or buckets. It also accepts an unsaved definition (`kind`, `address`, `name`, `group`, `options`) instead of `id`. With `probe: true`, it returns the secret-free address to fetch (`fetch: null` for -databases). For non-database kinds, pass that response text as `answer` with the same definition -to parse it without a network request. Database kinds ignore `answer` and test through their -driver. An anonymous S3 test needs at least one named bucket. - -**Test** does not send service requests to XYZ URL templates with tile coordinates -(`{z}/{x}/{y}`, also `{zoom}` or `{-y}`). To add one to the map, use -**Home › Add › Basemap › Add Tile Layer…** (`map.addTiles`) instead. +databases). For service documents, pass the response text as `answer` with the same definition +to parse it without a network request. Do not pass `answer` for an XYZ tile; database kinds ignore +`answer` and test through their driver. An anonymous S3 test needs at least one named bucket. + +**Test** recognises XYZ coordinates (`{z}/{x}/{y}`, also `{zoom}` and `{-y}`) and quadkeys +(`{q}` or `{quadkey}`) in the address. It fills in the URL (including `{s}` when present) and +fetches one tile instead of requesting capabilities: `0/0/0`, or `1/0/0` for a quadkey because +the root tile has an empty key. A missing tile (HTTP 404 or an empty response) is not a pass: +check the URL and the layer's zoom range. A direct `connection.test` returns +`result: {kind: "xyz", tile: [z,x,y], status: "received"|"missing"}`; a probe returns `fetch` +and the sample's `tile: {zoom, vector}`. **Test** does not add a layer. Use +**Home › Add › Basemap › Add Tile Layer…** (`map.addTiles`) to add the template to the map. +An API key embedded in a `;key=…` path component is saved as typed, not in the credential +store. If the provider supports a query or header login, keep the key out of the address and +use the connection's login instead. `connection.browse` lists what a connection offers, a level at a time: database roots list the schemas returned by their provider; opening a schema lists its spatial tables. Services list their