the Settings Connection card shows the mirror's stand: issuer and client id from config — the secret is never read into the render path — and a green Connected dot while the /directory/live stream is open, amber Reconnecting while the loop waits out a backoff, with the last roster event and last full pass aging quietly beside; DirectoryHealth is a mutex and four instants written by the stream task and read on render, and the card rides the profile section where every signed-in member already is
Browse files at this commite11a598638a5bc1f834c9324987a7778365cd0efParent: 2571bb38 changed files +308 -7
- crates/iz-web/Cargo.toml +1 -1
- crates/iz-web/src/directory.rs +99 -0
- crates/iz-web/src/i18n.rs +27 -0
- crates/iz-web/src/lib.rs +1 -0
- crates/iz-web/src/main.rs +25 -6
- crates/iz-web/src/settings.rs +56 -0
- crates/iz-web/tests/http.rs +67 -0
- style/main.scss +32 -0
crates/iz-web/Cargo.tomlmodified+1 -1
| @@ -28,6 +28,7 @@ time.workspace = true | |||
| 28 | thiserror.workspace = true | 28 | thiserror.workspace = true |
| 29 | tokio = { workspace = true } | 29 | tokio = { workspace = true } |
| 30 | async-trait = "0.1.92" | 30 | async-trait = "0.1.92" |
| 31 | +parking_lot = "0.12" | ||
| 31 | # The live stream is built with `futures_util::stream::unfold`; topcoat does | 32 | # The live stream is built with `futures_util::stream::unfold`; topcoat does |
| 32 | # not re-export the futures traits, so this is named directly. | 33 | # not re-export the futures traits, so this is named directly. |
| 33 | futures-util = { version = "0.3", default-features = false } | 34 | futures-util = { version = "0.3", default-features = false } |
| @@ -63,4 +64,3 @@ http = "1.5" | |||
| 63 | http-body-util = "0.1" | 64 | http-body-util = "0.1" |
| 64 | ulid = { workspace = true } | 65 | ulid = { workspace = true } |
| 65 | iz-client = { workspace = true, features = ["test-seam"] } | 66 | iz-client = { workspace = true, features = ["test-seam"] } |
| 66 | -parking_lot = "0.12" | ||
crates/iz-web/src/directory.rsadded+99 -0
| @@ -0,0 +1,99 @@ | |||
| 1 | +//! How the identity mirror stands against im — the facts the Settings | ||
| 2 | +//! Connection card renders. The mirror task writes; the page reads. | ||
| 3 | +//! | ||
| 4 | +//! Deliberately dumb: one mutex over four plain fields, because the card | ||
| 5 | +//! renders once per view and the stream updates a few times a minute. The | ||
| 6 | +//! client id and issuer are public by OIDC design; the client secret never | ||
| 7 | +//! comes near this struct, so the render path cannot leak what it was never | ||
| 8 | +//! given. | ||
| 9 | + | ||
| 10 | +use std::sync::Arc; | ||
| 11 | +use std::time::{Duration, Instant}; | ||
| 12 | + | ||
| 13 | +use parking_lot::Mutex; | ||
| 14 | +use topcoat::context::{Cx, try_app_context}; | ||
| 15 | + | ||
| 16 | +/// The mirror's health, shared between the stream task and the renderer. | ||
| 17 | +#[derive(Clone, Default)] | ||
| 18 | +pub struct DirectoryHealth(Arc<Mutex<Inner>>); | ||
| 19 | + | ||
| 20 | +#[derive(Default)] | ||
| 21 | +struct Inner { | ||
| 22 | + /// The `/directory/live` stream is open. | ||
| 23 | + connected: bool, | ||
| 24 | + opened_at: Option<Instant>, | ||
| 25 | + event_at: Option<Instant>, | ||
| 26 | + pass_at: Option<Instant>, | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +/// One rendered view of [`DirectoryHealth`]: the state word the card shows | ||
| 30 | +/// and the ages behind the two quiet facts. | ||
| 31 | +#[derive(Clone, Copy)] | ||
| 32 | +pub struct Snapshot { | ||
| 33 | + pub connected: bool, | ||
| 34 | + pub event_age: Option<Duration>, | ||
| 35 | + pub pass_age: Option<Duration>, | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +impl DirectoryHealth { | ||
| 39 | + pub fn new() -> Self { | ||
| 40 | + Self::default() | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + /// The stream opened (or reopened): the card may say Connected. | ||
| 44 | + pub fn connected(&self) { | ||
| 45 | + let mut inner = self.0.lock(); | ||
| 46 | + inner.connected = true; | ||
| 47 | + inner.opened_at = Some(Instant::now()); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + /// The stream ended or im refused it: the card says Reconnecting until | ||
| 51 | + /// the next full pass opens a fresh one. | ||
| 52 | + pub fn reconnecting(&self) { | ||
| 53 | + self.0.lock().connected = false; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + /// A Profile event came off the stream. | ||
| 57 | + pub fn event(&self) { | ||
| 58 | + self.0.lock().event_at = Some(Instant::now()); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + /// A full roster pass finished — the stream's boot replay, a resync | ||
| 62 | + /// after a drop, or the watchdog beat's pass. | ||
| 63 | + pub fn pass(&self) { | ||
| 64 | + self.0.lock().pass_at = Some(Instant::now()); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + pub fn snapshot(&self) -> Snapshot { | ||
| 68 | + let inner = self.0.lock(); | ||
| 69 | + let now = Instant::now(); | ||
| 70 | + Snapshot { | ||
| 71 | + connected: inner.connected, | ||
| 72 | + event_age: inner.event_at.map(|at| now.saturating_duration_since(at)), | ||
| 73 | + pass_age: inner.pass_at.map(|at| now.saturating_duration_since(at)), | ||
| 74 | + } | ||
| 75 | + } | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +/// The health `main.rs` registers on the router beside the directory | ||
| 79 | +/// client it describes. | ||
| 80 | +pub fn health(cx: &Cx) -> &DirectoryHealth { | ||
| 81 | + try_app_context::<DirectoryHealth>(cx) | ||
| 82 | + .expect("the directory health was registered on the router") | ||
| 83 | +} | ||
| 84 | + | ||
| 85 | +/// The stream's age in whole seconds, as the card prints it — a short | ||
| 86 | +/// number with its unit, the same shape in every language. | ||
| 87 | +pub fn age_text(age: Option<Duration>) -> String { | ||
| 88 | + match age { | ||
| 89 | + Some(age) => { | ||
| 90 | + let secs = age.as_secs(); | ||
| 91 | + if secs >= 60 { | ||
| 92 | + format!("{}m", secs / 60) | ||
| 93 | + } else { | ||
| 94 | + format!("{secs}s") | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | + None => String::new(), | ||
| 98 | + } | ||
| 99 | +} | ||
crates/iz-web/src/i18n.rsmodified+27 -0
| @@ -122,6 +122,15 @@ pub enum Key { | |||
| 122 | 122 | ||
| 123 | // settings.rs | 123 | // settings.rs |
| 124 | YourProfile, | 124 | YourProfile, |
| 125 | + Connection, | ||
| 126 | + ConnectionIssuer, | ||
| 127 | + ConnectionClientId, | ||
| 128 | + ConnectionStream, | ||
| 129 | + ConnectionConnected, | ||
| 130 | + ConnectionReconnecting, | ||
| 131 | + ConnectionLastEvent, | ||
| 132 | + ConnectionLastPass, | ||
| 133 | + ConnectionNever, | ||
| 125 | EmailLabel, | 134 | EmailLabel, |
| 126 | TimezoneLabel, | 135 | TimezoneLabel, |
| 127 | ThemeLabel, | 136 | ThemeLabel, |
| @@ -539,6 +548,24 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 539 | 548 | ||
| 540 | (YourProfile, En) => "Your profile", | 549 | (YourProfile, En) => "Your profile", |
| 541 | (YourProfile, Tr) => "Profilin", | 550 | (YourProfile, Tr) => "Profilin", |
| 551 | + (Connection, En) => "Connection", | ||
| 552 | + (Connection, Tr) => "Bağlantı", | ||
| 553 | + (ConnectionIssuer, En) => "Issuer", | ||
| 554 | + (ConnectionIssuer, Tr) => "Sağlayıcı", | ||
| 555 | + (ConnectionClientId, En) => "Client ID", | ||
| 556 | + (ConnectionClientId, Tr) => "İstemci kimliği", | ||
| 557 | + (ConnectionStream, En) => "Directory stream", | ||
| 558 | + (ConnectionStream, Tr) => "Dizin akışı", | ||
| 559 | + (ConnectionConnected, En) => "Connected", | ||
| 560 | + (ConnectionConnected, Tr) => "Bağlı", | ||
| 561 | + (ConnectionReconnecting, En) => "Reconnecting", | ||
| 562 | + (ConnectionReconnecting, Tr) => "Yeniden bağlanıyor", | ||
| 563 | + (ConnectionLastEvent, En) => "Last roster event", | ||
| 564 | + (ConnectionLastEvent, Tr) => "Son dizin olayı", | ||
| 565 | + (ConnectionLastPass, En) => "Last full pass", | ||
| 566 | + (ConnectionLastPass, Tr) => "Son tam geçiş", | ||
| 567 | + (ConnectionNever, En) => "never", | ||
| 568 | + (ConnectionNever, Tr) => "hiç", | ||
| 542 | (EmailLabel, En) => "EMAIL", | 569 | (EmailLabel, En) => "EMAIL", |
| 543 | (EmailLabel, Tr) => "E-POSTA", | 570 | (EmailLabel, Tr) => "E-POSTA", |
| 544 | (TimezoneLabel, En) => "TIMEZONE", | 571 | (TimezoneLabel, En) => "TIMEZONE", |
crates/iz-web/src/lib.rsmodified+1 -0
| @@ -6,6 +6,7 @@ | |||
| 6 | pub mod avatar; | 6 | pub mod avatar; |
| 7 | pub mod board; | 7 | pub mod board; |
| 8 | pub mod detail; | 8 | pub mod detail; |
| 9 | +pub mod directory; | ||
| 9 | pub mod dropdown; | 10 | pub mod dropdown; |
| 10 | pub mod files; | 11 | pub mod files; |
| 11 | pub mod i18n; | 12 | pub mod i18n; |
crates/iz-web/src/main.rsmodified+25 -6
| @@ -134,7 +134,10 @@ async fn main() { | |||
| 134 | // The shared identity directory: the same issuer and Basic pair the OIDC | 134 | // The shared identity directory: the same issuer and Basic pair the OIDC |
| 135 | // side holds, pointed at im's roster. One HTTP pool inside, cheap to | 135 | // side holds, pointed at im's roster. One HTTP pool inside, cheap to |
| 136 | // clone — the avatar route reaches it through the router context below, | 136 | // clone — the avatar route reaches it through the router context below, |
| 137 | - // and the two mirror tasks carry their own handles. | 137 | + // and the two mirror tasks carry their own handles. The health beside |
| 138 | + // it is what the Settings Connection card renders: the mirror writes, | ||
| 139 | + // the page reads. | ||
| 140 | + let health = iz_web::directory::DirectoryHealth::new(); | ||
| 138 | let directory = im_client::directory::DirectoryClient::new( | 141 | let directory = im_client::directory::DirectoryClient::new( |
| 139 | config.oidc.issuer.clone(), | 142 | config.oidc.issuer.clone(), |
| 140 | config.oidc.client_id.clone(), | 143 | config.oidc.client_id.clone(), |
| @@ -167,8 +170,9 @@ async fn main() { | |||
| 167 | directory.clone(), | 170 | directory.clone(), |
| 168 | iz_client::IzClient::new(oidc.clone()), | 171 | iz_client::IzClient::new(oidc.clone()), |
| 169 | config.base_url.clone(), | 172 | config.base_url.clone(), |
| 173 | + health.clone(), | ||
| 170 | )); | 174 | )); |
| 171 | - tokio::spawn(directory_stream(store.clone(), directory.clone())); | 175 | + tokio::spawn(directory_stream(store.clone(), directory.clone(), health.clone())); |
| 172 | // Told when the process is stopping, so the live streams end instead of | 176 | // Told when the process is stopping, so the live streams end instead of |
| 173 | // being waited out. See `iz_web::live::Shutdown`. | 177 | // being waited out. See `iz_web::live::Shutdown`. |
| 174 | let (stop, stopping) = tokio::sync::watch::channel(false); | 178 | let (stop, stopping) = tokio::sync::watch::channel(false); |
| @@ -186,6 +190,7 @@ async fn main() { | |||
| 186 | ) | 190 | ) |
| 187 | .app_context(store.clone()) | 191 | .app_context(store.clone()) |
| 188 | .app_context(directory) | 192 | .app_context(directory) |
| 193 | + .app_context(health) | ||
| 189 | .app_context(iz_client::LogoutBack(Arc::new(iz_web::server::logout_back))) | 194 | .app_context(iz_client::LogoutBack(Arc::new(iz_web::server::logout_back))) |
| 190 | .app_context(config.clone()) | 195 | .app_context(config.clone()) |
| 191 | .app_context(iz_web::live::LiveWindow(std::time::Duration::from_secs( | 196 | .app_context(iz_web::live::LiveWindow(std::time::Duration::from_secs( |
| @@ -347,13 +352,14 @@ async fn directory_sync( | |||
| 347 | directory: im_client::directory::DirectoryClient, | 352 | directory: im_client::directory::DirectoryClient, |
| 348 | client: iz_client::IzClient, | 353 | client: iz_client::IzClient, |
| 349 | configured_url: String, | 354 | configured_url: String, |
| 355 | + health: iz_web::directory::DirectoryHealth, | ||
| 350 | ) { | 356 | ) { |
| 351 | // An address that never arrives would otherwise say so every beat, | 357 | // An address that never arrives would otherwise say so every beat, |
| 352 | // five minutes apart, forever. It is one deployment fact, so it is | 358 | // five minutes apart, forever. It is one deployment fact, so it is |
| 353 | // said once and the mirror goes on without it. | 359 | // said once and the mirror goes on without it. |
| 354 | let mut said_no_address = false; | 360 | let mut said_no_address = false; |
| 355 | loop { | 361 | loop { |
| 356 | - mirror_directory(&store, &directory).await; | 362 | + mirror_directory(&store, &directory, &health).await; |
| 357 | // Before asking for the family, this app files itself in it, so a | 363 | // Before asking for the family, this app files itself in it, so a |
| 358 | // deployment appears in everyone's switcher without an admin | 364 | // deployment appears in everyone's switcher without an admin |
| 359 | // typing its address. Resolved per beat in the order a sign-out | 365 | // typing its address. Resolved per beat in the order a sign-out |
| @@ -400,16 +406,19 @@ async fn directory_sync( | |||
| 400 | 406 | ||
| 401 | /// One full pass of im's roster through the member rows: every entry | 407 | /// One full pass of im's roster through the member rows: every entry |
| 402 | /// through [`iz_core::store::Store::sync_member`], which announces only | 408 | /// through [`iz_core::store::Store::sync_member`], which announces only |
| 403 | -/// the rows that actually changed. | 409 | +/// the rows that actually changed. A pass that landed also stamps the |
| 410 | +/// Connection card's "last full pass". | ||
| 404 | async fn mirror_directory( | 411 | async fn mirror_directory( |
| 405 | store: &Arc<dyn iz_core::store::Store>, | 412 | store: &Arc<dyn iz_core::store::Store>, |
| 406 | directory: &im_client::directory::DirectoryClient, | 413 | directory: &im_client::directory::DirectoryClient, |
| 414 | + health: &iz_web::directory::DirectoryHealth, | ||
| 407 | ) { | 415 | ) { |
| 408 | match directory.directory().await { | 416 | match directory.directory().await { |
| 409 | Ok(members) => { | 417 | Ok(members) => { |
| 410 | for member in members { | 418 | for member in members { |
| 411 | apply_member(store, &member).await; | 419 | apply_member(store, &member).await; |
| 412 | } | 420 | } |
| 421 | + health.pass(); | ||
| 413 | } | 422 | } |
| 414 | Err(problem) => { | 423 | Err(problem) => { |
| 415 | eprintln!("directory sync: im did not answer ({problem}); keeping the rows there are") | 424 | eprintln!("directory sync: im did not answer ({problem}); keeping the rows there are") |
| @@ -441,37 +450,47 @@ async fn apply_member( | |||
| 441 | /// closing — wait out a backoff that doubles from one second to thirty, | 450 | /// closing — wait out a backoff that doubles from one second to thirty, |
| 442 | /// replay a full pass (the resync that heals whatever the dead stream | 451 | /// replay a full pass (the resync that heals whatever the dead stream |
| 443 | /// carried or dropped), and redial. A stream error inside the body is the | 452 | /// carried or dropped), and redial. A stream error inside the body is the |
| 444 | -/// same exit as a clean close: the pass below is what converges. | 453 | +/// same exit as a clean close: the pass below is what converges. The |
| 454 | +/// Connection card reads its state from the same marks this loop leaves: | ||
| 455 | +/// Connected from the open stream and each event, Reconnecting from every | ||
| 456 | +/// exit in between. | ||
| 445 | async fn directory_stream( | 457 | async fn directory_stream( |
| 446 | store: Arc<dyn iz_core::store::Store>, | 458 | store: Arc<dyn iz_core::store::Store>, |
| 447 | directory: im_client::directory::DirectoryClient, | 459 | directory: im_client::directory::DirectoryClient, |
| 460 | + health: iz_web::directory::DirectoryHealth, | ||
| 448 | ) { | 461 | ) { |
| 449 | let mut backoff = std::time::Duration::from_secs(1); | 462 | let mut backoff = std::time::Duration::from_secs(1); |
| 450 | loop { | 463 | loop { |
| 451 | - mirror_directory(&store, &directory).await; | 464 | + mirror_directory(&store, &directory, &health).await; |
| 452 | match directory.open_stream().await { | 465 | match directory.open_stream().await { |
| 453 | Ok(mut stream) => { | 466 | Ok(mut stream) => { |
| 467 | + health.connected(); | ||
| 454 | backoff = std::time::Duration::from_secs(1); | 468 | backoff = std::time::Duration::from_secs(1); |
| 455 | while let Some(event) = stream.next().await { | 469 | while let Some(event) = stream.next().await { |
| 456 | match event { | 470 | match event { |
| 457 | Ok(im_client::directory::DirectoryEvent::Profile(member)) => { | 471 | Ok(im_client::directory::DirectoryEvent::Profile(member)) => { |
| 472 | + health.event(); | ||
| 458 | apply_member(&store, &member).await; | 473 | apply_member(&store, &member).await; |
| 459 | } | 474 | } |
| 460 | Err(problem) => { | 475 | Err(problem) => { |
| 461 | eprintln!("directory stream: {problem}; re-listing"); | 476 | eprintln!("directory stream: {problem}; re-listing"); |
| 477 | + health.reconnecting(); | ||
| 462 | break; | 478 | break; |
| 463 | } | 479 | } |
| 464 | } | 480 | } |
| 465 | } | 481 | } |
| 482 | + health.reconnecting(); | ||
| 466 | } | 483 | } |
| 467 | Err(problem) => { | 484 | Err(problem) => { |
| 468 | eprintln!("directory stream: im did not answer ({problem})"); | 485 | eprintln!("directory stream: im did not answer ({problem})"); |
| 486 | + health.reconnecting(); | ||
| 469 | } | 487 | } |
| 470 | } | 488 | } |
| 471 | tokio::time::sleep(backoff).await; | 489 | tokio::time::sleep(backoff).await; |
| 472 | backoff = (backoff * 2).min(std::time::Duration::from_secs(30)); | 490 | backoff = (backoff * 2).min(std::time::Duration::from_secs(30)); |
| 473 | } | 491 | } |
| 474 | } | 492 | } |
| 493 | + | ||
| 475 | /// Waits for something to happen to the mail queue specifically. | 494 | /// Waits for something to happen to the mail queue specifically. |
| 476 | /// | 495 | /// |
| 477 | /// The channel carries every topic, and the sweep cares about one. Filtering | 496 | /// The channel carries every topic, and the sweep cares about one. Filtering |
crates/iz-web/src/settings.rsmodified+56 -0
| @@ -929,6 +929,48 @@ async fn send_message( | |||
| 929 | // Page | 929 | // Page |
| 930 | // --------------------------------------------------------------------------- | 930 | // --------------------------------------------------------------------------- |
| 931 | 931 | ||
| 932 | + | ||
| 933 | +/// The Connection card's body: who im is, as whom iz introduces itself, | ||
| 934 | +/// and whether the live identity feed is open at this moment. Read from | ||
| 935 | +/// the config and the mirror's health only — the client secret is not | ||
| 936 | +/// read here, so no render path can carry it. | ||
| 937 | +async fn connection_card(cx: &Cx, lang: Lang) -> Result { | ||
| 938 | + let oidc = &config(cx).oidc; | ||
| 939 | + let snap = crate::directory::health(cx).snapshot(); | ||
| 940 | + let (state_word, state_class) = if snap.connected { | ||
| 941 | + (t(lang, Key::ConnectionConnected), "connection-on") | ||
| 942 | + } else { | ||
| 943 | + (t(lang, Key::ConnectionReconnecting), "connection-wait") | ||
| 944 | + }; | ||
| 945 | + let event_age = crate::directory::age_text(snap.event_age); | ||
| 946 | + let pass_age = crate::directory::age_text(snap.pass_age); | ||
| 947 | + let never = t(lang, Key::ConnectionNever).to_string(); | ||
| 948 | + let event_line = if event_age.is_empty() { | ||
| 949 | + never.clone() | ||
| 950 | + } else { | ||
| 951 | + format!("{event_age} ago") | ||
| 952 | + }; | ||
| 953 | + let pass_line = if pass_age.is_empty() { never } else { format!("{pass_age} ago") }; | ||
| 954 | + view! { | ||
| 955 | + cx => | ||
| 956 | + <dl class="connection-facts"> | ||
| 957 | + <dt>(t(lang, Key::ConnectionIssuer))</dt> | ||
| 958 | + <dd class="connection-fact">(oidc.issuer.clone())</dd> | ||
| 959 | + <dt>(t(lang, Key::ConnectionClientId))</dt> | ||
| 960 | + <dd class="connection-fact">(oidc.client_id.clone())</dd> | ||
| 961 | + <dt>(t(lang, Key::ConnectionStream))</dt> | ||
| 962 | + <dd class="connection-fact"> | ||
| 963 | + <span class=(format!("connection-dot {state_class}"))></span> | ||
| 964 | + (state_word) | ||
| 965 | + </dd> | ||
| 966 | + <dt>(t(lang, Key::ConnectionLastEvent))</dt> | ||
| 967 | + <dd class="connection-fact">(event_line)</dd> | ||
| 968 | + <dt>(t(lang, Key::ConnectionLastPass))</dt> | ||
| 969 | + <dd class="connection-fact">(pass_line)</dd> | ||
| 970 | + </dl> | ||
| 971 | + } | ||
| 972 | +} | ||
| 973 | + | ||
| 932 | /// One row of the member list, as an admin may see it. Identity is im's to | 974 | /// One row of the member list, as an admin may see it. Identity is im's to |
| 933 | /// vouch — the row carries no password and no link token, only what the | 975 | /// vouch — the row carries no password and no link token, only what the |
| 934 | /// workspace itself decides: the role and whether the account is disabled. | 976 | /// workspace itself decides: the role and whether the account is disabled. |
| @@ -1324,6 +1366,20 @@ async fn settings_page(cx: &Cx) -> Result { | |||
| 1324 | </div> | 1366 | </div> |
| 1325 | </form> | 1367 | </form> |
| 1326 | </section> | 1368 | </section> |
| 1369 | + | ||
| 1370 | + // The identity mirror's stand, for every signed-in member: | ||
| 1371 | + // who iz trusts and as whom, and whether the live feed from | ||
| 1372 | + // im is open right now. Read-only — the issuer and client id | ||
| 1373 | + // are public by OIDC design, and the client secret is never | ||
| 1374 | + // read into this page at all. | ||
| 1375 | + <section class="panel" id="connection"> | ||
| 1376 | + <div class="panel-head"> | ||
| 1377 | + <h2 class="panel-title">(t(lang, Key::Connection))</h2> | ||
| 1378 | + </div> | ||
| 1379 | + <div class="panel-body"> | ||
| 1380 | + (connection_card(cx, lang).await?) | ||
| 1381 | + </div> | ||
| 1382 | + </section> | ||
| 1327 | } | 1383 | } |
| 1328 | 1384 | ||
| 1329 | if section == Section::Outgoing && let Some(sender) = &sender { | 1385 | if section == Section::Outgoing && let Some(sender) = &sender { |
crates/iz-web/tests/http.rsmodified+67 -0
| @@ -273,6 +273,9 @@ struct App { | |||
| 273 | store: Arc<dyn Store>, | 273 | store: Arc<dyn Store>, |
| 274 | client: iz_client::Config, | 274 | client: iz_client::Config, |
| 275 | fake: FakeIm, | 275 | fake: FakeIm, |
| 276 | + /// What the Settings Connection card renders: poked by hand in tests | ||
| 277 | + /// the way the mirror task pokes it in the process. | ||
| 278 | + health: iz_web::directory::DirectoryHealth, | ||
| 276 | /// Stands in for Ctrl+C. Held so a test can stop this router the way the | 279 | /// Stands in for Ctrl+C. Held so a test can stop this router the way the |
| 277 | /// process stops the real one. | 280 | /// process stops the real one. |
| 278 | stop: tokio::sync::watch::Sender<bool>, | 281 | stop: tokio::sync::watch::Sender<bool>, |
| @@ -333,6 +336,7 @@ impl App { | |||
| 333 | cookie_name: "iz_session".to_string(), | 336 | cookie_name: "iz_session".to_string(), |
| 334 | cookie_key: [7u8; 32], | 337 | cookie_key: [7u8; 32], |
| 335 | }; | 338 | }; |
| 339 | + let health = iz_web::directory::DirectoryHealth::new(); | ||
| 336 | let (stop, stopping) = tokio::sync::watch::channel(false); | 340 | let (stop, stopping) = tokio::sync::watch::channel(false); |
| 337 | let router = iz_client::mount( | 341 | let router = iz_client::mount( |
| 338 | Router::builder() | 342 | Router::builder() |
| @@ -354,6 +358,7 @@ impl App { | |||
| 354 | "iz-test", | 358 | "iz-test", |
| 355 | "s3cr3t", | 359 | "s3cr3t", |
| 356 | )) | 360 | )) |
| 361 | + .app_context(health.clone()) | ||
| 357 | .app_context(iz_client::LogoutBack(Arc::new( | 362 | .app_context(iz_client::LogoutBack(Arc::new( |
| 358 | iz_web::server::logout_back, | 363 | iz_web::server::logout_back, |
| 359 | ))) | 364 | ))) |
| @@ -368,6 +373,7 @@ impl App { | |||
| 368 | store, | 373 | store, |
| 369 | client, | 374 | client, |
| 370 | fake, | 375 | fake, |
| 376 | + health, | ||
| 371 | stop, | 377 | stop, |
| 372 | } | 378 | } |
| 373 | } | 379 | } |
| @@ -421,6 +427,7 @@ impl App { | |||
| 421 | cookie_name: "iz_session".to_string(), | 427 | cookie_name: "iz_session".to_string(), |
| 422 | cookie_key: [7u8; 32], | 428 | cookie_key: [7u8; 32], |
| 423 | }; | 429 | }; |
| 430 | + let health = iz_web::directory::DirectoryHealth::new(); | ||
| 424 | let (stop, stopping) = tokio::sync::watch::channel(false); | 431 | let (stop, stopping) = tokio::sync::watch::channel(false); |
| 425 | let router = iz_client::mount( | 432 | let router = iz_client::mount( |
| 426 | Router::builder() | 433 | Router::builder() |
| @@ -442,6 +449,7 @@ impl App { | |||
| 442 | "iz-test", | 449 | "iz-test", |
| 443 | "s3cr3t", | 450 | "s3cr3t", |
| 444 | )) | 451 | )) |
| 452 | + .app_context(health.clone()) | ||
| 445 | .app_context(iz_client::LogoutBack(Arc::new( | 453 | .app_context(iz_client::LogoutBack(Arc::new( |
| 446 | iz_web::server::logout_back, | 454 | iz_web::server::logout_back, |
| 447 | ))) | 455 | ))) |
| @@ -456,6 +464,7 @@ impl App { | |||
| 456 | store, | 464 | store, |
| 457 | client, | 465 | client, |
| 458 | fake, | 466 | fake, |
| 467 | + health, | ||
| 459 | stop, | 468 | stop, |
| 460 | } | 469 | } |
| 461 | } | 470 | } |
| @@ -5325,6 +5334,64 @@ async fn the_board_carries_the_avatar_fallback_script() { | |||
| 5325 | "avatars without the fallback script show the broken-image box: {html}" | 5334 | "avatars without the fallback script show the broken-image box: {html}" |
| 5326 | ); | 5335 | ); |
| 5327 | } | 5336 | } |
| 5337 | + | ||
| 5338 | +// --------------------------------------------------------------------------- | ||
| 5339 | +// Connection card: the identity mirror's stand, on every member's Settings | ||
| 5340 | +// --------------------------------------------------------------------------- | ||
| 5341 | + | ||
| 5342 | +/// The card names the provider and the app's public id, and says Connected | ||
| 5343 | +/// while the mirror's health holds an open stream. The client secret is | ||
| 5344 | +/// nowhere on the page — it must not even be read into the render path. | ||
| 5345 | +#[tokio::test] | ||
| 5346 | +async fn the_connection_card_names_its_provider_without_its_secret() { | ||
| 5347 | + let app = App::open().await; | ||
| 5348 | + let admin = admin(&app).await; | ||
| 5349 | + app.health.connected(); | ||
| 5350 | + app.health.event(); | ||
| 5351 | + app.health.pass(); | ||
| 5352 | + | ||
| 5353 | + let page = app.get("/settings", Some(&admin)).await; | ||
| 5354 | + assert_eq!(page.status.as_u16(), 200); | ||
| 5355 | + let html = String::from_utf8(page.bytes).unwrap(); | ||
| 5356 | + assert!(html.contains("id=\"connection\""), "no Connection card: {html}"); | ||
| 5357 | + assert!( | ||
| 5358 | + html.contains("iz-test:s3cr3t") == false, | ||
| 5359 | + "the client secret leaked onto the page: {html}" | ||
| 5360 | + ); | ||
| 5361 | + assert!( | ||
| 5362 | + !html.contains("s3cr3t"), | ||
| 5363 | + "the client secret leaked onto the page: {html}" | ||
| 5364 | + ); | ||
| 5365 | + assert!( | ||
| 5366 | + html.contains("iz-test"), | ||
| 5367 | + "the client id is the card's public fact: {html}" | ||
| 5368 | + ); | ||
| 5369 | + assert!( | ||
| 5370 | + html.contains("Connected"), | ||
| 5371 | + "an open stream says Connected: {html}" | ||
| 5372 | + ); | ||
| 5373 | +} | ||
| 5374 | + | ||
| 5375 | +/// Between passes — before the first stream opens, or after one died — | ||
| 5376 | +/// the card says Reconnecting, and still carries the public facts without | ||
| 5377 | +/// the secret. | ||
| 5378 | +#[tokio::test] | ||
| 5379 | +async fn the_connection_card_says_reconnecting_while_the_stream_is_down() { | ||
| 5380 | + let app = App::open().await; | ||
| 5381 | + let admin = admin(&app).await; | ||
| 5382 | + | ||
| 5383 | + let page = app.get("/settings", Some(&admin)).await; | ||
| 5384 | + assert_eq!(page.status.as_u16(), 200); | ||
| 5385 | + let html = String::from_utf8(page.bytes).unwrap(); | ||
| 5386 | + assert!( | ||
| 5387 | + html.contains("Reconnecting"), | ||
| 5388 | + "a stream that never opened says Reconnecting: {html}" | ||
| 5389 | + ); | ||
| 5390 | + assert!( | ||
| 5391 | + html.contains("iz-test") && !html.contains("s3cr3t"), | ||
| 5392 | + "the card names the client without the secret: {html}" | ||
| 5393 | + ); | ||
| 5394 | +} | ||
| 5328 | /// Polls the store until a `Rule` send for `rule_id` addressed to `recipient` | 5395 | /// Polls the store until a `Rule` send for `rule_id` addressed to `recipient` |
| 5329 | /// exists beyond the `already` count — the engine runs off the request in a | 5396 | /// exists beyond the `already` count — the engine runs off the request in a |
| 5330 | /// spawned task, so the row is not there yet when the triggering call | 5397 | /// spawned task, so the row is not there yet when the triggering call |
style/main.scssmodified+32 -0
| @@ -4365,3 +4365,35 @@ input[type="radio"] { | |||
| 4365 | // their columns stack instead of squeezing into slivers. | 4365 | // their columns stack instead of squeezing into slivers. |
| 4366 | .field-row { flex-wrap: wrap; } | 4366 | .field-row { flex-wrap: wrap; } |
| 4367 | } | 4367 | } |
| 4368 | + | ||
| 4369 | +// The Settings Connection card: the identity mirror's stand, as facts and a | ||
| 4370 | +// state dot — green while the /directory/live stream is open, amber while | ||
| 4371 | +// iz waits out a reconnection. | ||
| 4372 | +.connection-facts { | ||
| 4373 | + display: grid; | ||
| 4374 | + grid-template-columns: max-content 1fr; | ||
| 4375 | + gap: 0.4rem 1.5rem; | ||
| 4376 | + margin: 0; | ||
| 4377 | + | ||
| 4378 | + dt { | ||
| 4379 | + font-weight: 600; | ||
| 4380 | + white-space: nowrap; | ||
| 4381 | + } | ||
| 4382 | +} | ||
| 4383 | + | ||
| 4384 | +.connection-dot { | ||
| 4385 | + display: inline-block; | ||
| 4386 | + width: 0.55rem; | ||
| 4387 | + height: 0.55rem; | ||
| 4388 | + border-radius: 50%; | ||
| 4389 | + margin-right: 0.4rem; | ||
| 4390 | + vertical-align: baseline; | ||
| 4391 | + | ||
| 4392 | + &.connection-on { | ||
| 4393 | + background: #2e9e5b; | ||
| 4394 | + } | ||
| 4395 | + | ||
| 4396 | + &.connection-wait { | ||
| 4397 | + background: #d99a26; | ||
| 4398 | + } | ||
| 4399 | +} | ||