Cargo fmt
Browse files at this commit2bf64d3133e61a8fff66a1ae86dddddba6844872Parent: 1b12ff7- style
- cargo fmt
8 changed files +211 -67
- src/ai/protocol.rs +6 -3
- src/ai/server.rs +11 -4
- src/state.rs +7 -2
- src/web/builder.rs +11 -8
- tests/ai_bridge.rs +37 -8
- tests/ai_protocol.rs +40 -16
- tests/builder_api.rs +87 -24
- tests/spec_bounds.rs +12 -2
src/ai/protocol.rsmodified+6 -3
| @@ -536,11 +536,14 @@ mod tests { | ||
| 536 | 536 | })) |
| 537 | 537 | .unwrap(); |
| 538 | 538 | assert_eq!(bare.on_behalf_of, None); |
| 539 | - assert!(serde_json::from_value::<BlobRequest>(json!({ "id": "01J", "school": "demo" })) | |
| 540 | - .is_err()); | |
| 539 | + assert!( | |
| 540 | + serde_json::from_value::<BlobRequest>(json!({ "id": "01J", "school": "demo" })) | |
| 541 | + .is_err() | |
| 542 | + ); | |
| 541 | 543 | // The school is required here too. |
| 542 | 544 | assert!( |
| 543 | - serde_json::from_value::<BlobRequest>(json!({ "id": "01J", "file": "01FILE" })).is_err() | |
| 545 | + serde_json::from_value::<BlobRequest>(json!({ "id": "01J", "file": "01FILE" })) | |
| 546 | + .is_err() | |
| 544 | 547 | ); |
| 545 | 548 | // And the two shapes never parse as each other. |
| 546 | 549 | assert!( |
src/ai/server.rsmodified+11 -4
| @@ -24,11 +24,11 @@ use crate::constant::{ | ||
| 24 | 24 | REQUEST_TIMEOUT_SECS, |
| 25 | 25 | }; |
| 26 | 26 | use crate::database::Database; |
| 27 | -use crate::error::AppError; | |
| 28 | 27 | use crate::domain::course::Course; |
| 29 | 28 | use crate::domain::course_note::CourseNote; |
| 30 | 29 | use crate::domain::course_note_file::{CourseNoteFile, CourseNoteFileId}; |
| 31 | 30 | use crate::domain::user::{User, UserId}; |
| 31 | +use crate::error::AppError; | |
| 32 | 32 | use crate::state::DbHealth; |
| 33 | 33 | use crate::tenant::{Slug, Tenants}; |
| 34 | 34 | use crate::web::blob_path; |
| @@ -75,8 +75,12 @@ impl ApiHandle { | ||
| 75 | 75 | /// switched off — a service that retries the first two forever learns |
| 76 | 76 | /// nothing, while the third is worth retrying later. |
| 77 | 77 | async fn school(&self, school: &str) -> Result<(Slug, Database), (&'static str, String)> { |
| 78 | - let slug = Slug::try_new(school) | |
| 79 | - .map_err(|err| ("malformed", format!("`{school}` is not a school slug: {err}")))?; | |
| 78 | + let slug = Slug::try_new(school).map_err(|err| { | |
| 79 | + ( | |
| 80 | + "malformed", | |
| 81 | + format!("`{school}` is not a school slug: {err}"), | |
| 82 | + ) | |
| 83 | + })?; | |
| 80 | 84 | let db = self.tenants.get(&slug).await.map_err(|err| match err { |
| 81 | 85 | AppError::Unauthorized => ( |
| 82 | 86 | "unknown_school", |
| @@ -600,7 +604,10 @@ async fn open_blob( | ||
| 600 | 604 | /// never trusted from the frame: a service holding a stale id must not act as a |
| 601 | 605 | /// user who has since been deleted or demoted, nor as a same-named user of |
| 602 | 606 | /// another school. With nobody named the principal is the synthetic `ai` role. |
| 603 | -async fn principal(db: &Database, on_behalf_of: Option<&str>) -> Result<User, (&'static str, String)> { | |
| 607 | +async fn principal( | |
| 608 | + db: &Database, | |
| 609 | + on_behalf_of: Option<&str>, | |
| 610 | +) -> Result<User, (&'static str, String)> { | |
| 604 | 611 | let Some(who) = on_behalf_of else { |
| 605 | 612 | return Ok(User::ai_principal()); |
| 606 | 613 | }; |
src/state.rsmodified+7 -2
| @@ -173,7 +173,9 @@ impl BoardHub { | ||
| 173 | 173 | pub fn publish(&self, slug: &Slug, board: &str, frame: String) { |
| 174 | 174 | let sender = { |
| 175 | 175 | let boards = self.0.lock().expect("board hub lock"); |
| 176 | - boards.get(&scoped_key(slug, board)).map(|room| room.0.clone()) | |
| 176 | + boards | |
| 177 | + .get(&scoped_key(slug, board)) | |
| 178 | + .map(|room| room.0.clone()) | |
| 177 | 179 | }; |
| 178 | 180 | if let Some(sender) = sender { |
| 179 | 181 | let _ = sender.send(frame); |
| @@ -239,7 +241,10 @@ mod tests { | ||
| 239 | 241 | let mut in_b = hub.subscribe(&b, "board-1"); |
| 240 | 242 | |
| 241 | 243 | hub.publish(&a, "board-1", "alpha stroke".to_string()); |
| 242 | - assert_eq!(in_a.recv().await.expect("alpha's own stroke"), "alpha stroke"); | |
| 244 | + assert_eq!( | |
| 245 | + in_a.recv().await.expect("alpha's own stroke"), | |
| 246 | + "alpha stroke" | |
| 247 | + ); | |
| 243 | 248 | assert!( |
| 244 | 249 | in_b.try_recv().is_err(), |
| 245 | 250 | "beta's board must not hear alpha's stroke" |
src/web/builder.rsmodified+11 -8
| @@ -206,11 +206,7 @@ async fn builder_login( | ||
| 206 | 206 | let password = Password::try_new(&req.password).map_err(|_| AppError::Unauthorized)?; |
| 207 | 207 | let builder = match Builder::find_by_username(req.username.trim(), control).await? { |
| 208 | 208 | Some(builder) => { |
| 209 | - if !builder | |
| 210 | - .get_password_hash() | |
| 211 | - .verify_async(&password) | |
| 212 | - .await | |
| 213 | - { | |
| 209 | + if !builder.get_password_hash().verify_async(&password).await { | |
| 214 | 210 | return Err(AppError::Unauthorized); |
| 215 | 211 | } |
| 216 | 212 | builder |
| @@ -401,14 +397,18 @@ async fn update_school( | ||
| 401 | 397 | let control = st.tenants.control(); |
| 402 | 398 | // An empty patch on an unknown school is still a 404, so the existence |
| 403 | 399 | // check is not left to whichever field happened to be present. |
| 404 | - School::read(&slug, control).await?.ok_or(AppError::NotFound)?; | |
| 400 | + School::read(&slug, control) | |
| 401 | + .await? | |
| 402 | + .ok_or(AppError::NotFound)?; | |
| 405 | 403 | if let Some(name) = name { |
| 406 | 404 | School::update_name(&slug, &name, control).await?; |
| 407 | 405 | } |
| 408 | 406 | if let Some(status) = status { |
| 409 | 407 | st.tenants.set_status(&slug, status).await?; |
| 410 | 408 | } |
| 411 | - let school = School::read(&slug, control).await?.ok_or(AppError::NotFound)?; | |
| 409 | + let school = School::read(&slug, control) | |
| 410 | + .await? | |
| 411 | + .ok_or(AppError::NotFound)?; | |
| 412 | 412 | Ok(Json(SchoolResponse::new(&school))) |
| 413 | 413 | } |
| 414 | 414 | |
| @@ -445,7 +445,10 @@ async fn delete_school( | ||
| 445 | 445 | if let Err(err) = tokio::fs::remove_dir_all(&dir).await |
| 446 | 446 | && err.kind() != std::io::ErrorKind::NotFound |
| 447 | 447 | { |
| 448 | - tracing::warn!("failed to remove the files of {slug} at {}: {err}", dir.display()); | |
| 448 | + tracing::warn!( | |
| 449 | + "failed to remove the files of {slug} at {}: {err}", | |
| 450 | + dir.display() | |
| 451 | + ); | |
| 449 | 452 | } |
| 450 | 453 | Ok(StatusCode::NO_CONTENT) |
| 451 | 454 | } |
tests/ai_bridge.rsmodified+37 -8
| @@ -332,7 +332,11 @@ async fn concurrent_requests_share_one_connection_without_blocking_each_other() | ||
| 332 | 332 | |
| 333 | 333 | let calls = (0..N).map(|i| { |
| 334 | 334 | let bridge = bridge.clone(); |
| 335 | - tokio::spawn(async move { bridge.dispatch(&demo(), "ocr.extract", json!({ "n": i })).await }) | |
| 335 | + tokio::spawn(async move { | |
| 336 | + bridge | |
| 337 | + .dispatch(&demo(), "ocr.extract", json!({ "n": i })) | |
| 338 | + .await | |
| 339 | + }) | |
| 336 | 340 | }); |
| 337 | 341 | let answers = futures_util::future::join_all(calls).await; |
| 338 | 342 | |
| @@ -356,8 +360,14 @@ async fn requests_route_to_the_service_declaring_the_capability() { | ||
| 356 | 360 | let grader = connect_service(&bridge, hello("grader", &["grade.essay"]), Behaviour::Echo).await; |
| 357 | 361 | await_workers(&bridge, 2).await; |
| 358 | 362 | |
| 359 | - bridge.dispatch(&demo(), "grade.essay", json!("text")).await.unwrap(); | |
| 360 | - bridge.dispatch(&demo(), "ocr.extract", json!("png")).await.unwrap(); | |
| 363 | + bridge | |
| 364 | + .dispatch(&demo(), "grade.essay", json!("text")) | |
| 365 | + .await | |
| 366 | + .unwrap(); | |
| 367 | + bridge | |
| 368 | + .dispatch(&demo(), "ocr.extract", json!("png")) | |
| 369 | + .await | |
| 370 | + .unwrap(); | |
| 361 | 371 | |
| 362 | 372 | assert_eq!(ocr.seen().len(), 1, "ocr only saw its own capability"); |
| 363 | 373 | assert_eq!(ocr.seen()[0].capability, "ocr.extract"); |
| @@ -572,7 +582,12 @@ async fn a_silent_service_times_out_and_gives_the_slot_back() { | ||
| 572 | 582 | // An abandoned request must not leak the worker's capacity. |
| 573 | 583 | assert_eq!(bridge.workers()[0].inflight, 0); |
| 574 | 584 | // And the worker is immediately usable again. |
| 575 | - assert!(bridge.dispatch(&demo(), "ocr.extract", json!(null)).await.is_err()); | |
| 585 | + assert!( | |
| 586 | + bridge | |
| 587 | + .dispatch(&demo(), "ocr.extract", json!(null)) | |
| 588 | + .await | |
| 589 | + .is_err() | |
| 590 | + ); | |
| 576 | 591 | } |
| 577 | 592 | |
| 578 | 593 | #[tokio::test] |
| @@ -593,7 +608,12 @@ async fn a_per_call_timeout_overrides_the_default() { | ||
| 593 | 608 | )); |
| 594 | 609 | // ...but a capability known to be slow can ask for more. |
| 595 | 610 | let answer = bridge |
| 596 | - .dispatch_with_timeout(&demo(), "ocr.extract", json!("slow"), Duration::from_secs(5)) | |
| 611 | + .dispatch_with_timeout( | |
| 612 | + &demo(), | |
| 613 | + "ocr.extract", | |
| 614 | + json!("slow"), | |
| 615 | + Duration::from_secs(5), | |
| 616 | + ) | |
| 597 | 617 | .await |
| 598 | 618 | .expect("the longer deadline held"); |
| 599 | 619 | assert_eq!(answer["echo"], "slow"); |
| @@ -667,7 +687,10 @@ async fn a_disconnected_service_is_deregistered() { | ||
| 667 | 687 | let bridge = bridge().await; |
| 668 | 688 | let service = connect_service(&bridge, hello("ocr", &["ocr.extract"]), Behaviour::Echo).await; |
| 669 | 689 | await_workers(&bridge, 1).await; |
| 670 | - bridge.dispatch(&demo(), "ocr.extract", json!(null)).await.unwrap(); | |
| 690 | + bridge | |
| 691 | + .dispatch(&demo(), "ocr.extract", json!(null)) | |
| 692 | + .await | |
| 693 | + .unwrap(); | |
| 671 | 694 | |
| 672 | 695 | service.conn.close(0u32.into(), b"service shutting down"); |
| 673 | 696 | drop(service); |
| @@ -715,7 +738,10 @@ async fn losing_one_service_leaves_the_other_serving() { | ||
| 715 | 738 | await_workers(&bridge, 1).await; |
| 716 | 739 | |
| 717 | 740 | for _ in 0..4 { |
| 718 | - bridge.dispatch(&demo(), "ocr.extract", json!("x")).await.unwrap(); | |
| 741 | + bridge | |
| 742 | + .dispatch(&demo(), "ocr.extract", json!("x")) | |
| 743 | + .await | |
| 744 | + .unwrap(); | |
| 719 | 745 | } |
| 720 | 746 | assert_eq!( |
| 721 | 747 | survivor.seen().len(), |
| @@ -1795,7 +1821,10 @@ async fn a_course_note_is_indexed_and_its_output_stored_with_its_sources() { | ||
| 1795 | 1821 | // The service saw the note itself, under the documented capability. |
| 1796 | 1822 | let seen = service.seen(); |
| 1797 | 1823 | assert_eq!(seen[0].capability, AI_RAG_INDEX_CAPABILITY); |
| 1798 | - assert_eq!(seen[0].school, DEMO_SLUG, "the frame names the caller's school"); | |
| 1824 | + assert_eq!( | |
| 1825 | + seen[0].school, DEMO_SLUG, | |
| 1826 | + "the frame names the caller's school" | |
| 1827 | + ); | |
| 1799 | 1828 | assert_eq!(seen[0].payload["course_note"], note); |
| 1800 | 1829 | assert_eq!(seen[0].payload["title"], "Bölüm 3"); |
| 1801 | 1830 | assert_eq!(seen[0].payload["content"], "özet"); |
tests/ai_protocol.rsmodified+40 -16
| @@ -553,7 +553,8 @@ async fn the_request_frame_carries_exactly_the_published_keys() { | ||
| 553 | 553 | let id = request["id"].as_str().unwrap().to_string(); |
| 554 | 554 | raw::answer( |
| 555 | 555 | send, |
| 556 | - format!(r#"{{"status":"ok","id":"{id}","school":"{SCHOOL}","payload":{{"text":"hi"}}}}"#).as_bytes(), | |
| 556 | + format!(r#"{{"status":"ok","id":"{id}","school":"{SCHOOL}","payload":{{"text":"hi"}}}}"#) | |
| 557 | + .as_bytes(), | |
| 557 | 558 | ) |
| 558 | 559 | .await; |
| 559 | 560 | let answer = call.await.unwrap().expect("dispatch succeeded"); |
| @@ -714,7 +715,8 @@ async fn each_request_gets_its_own_stream_and_answers_may_come_back_in_any_order | ||
| 714 | 715 | let n = request["payload"]["n"].clone(); |
| 715 | 716 | raw::answer( |
| 716 | 717 | send, |
| 717 | - format!(r#"{{"status":"ok","id":"{id}","school":"{SCHOOL}","payload":{{"n":{n}}}}}"#).as_bytes(), | |
| 718 | + format!(r#"{{"status":"ok","id":"{id}","school":"{SCHOOL}","payload":{{"n":{n}}}}}"#) | |
| 719 | + .as_bytes(), | |
| 718 | 720 | ) |
| 719 | 721 | .await; |
| 720 | 722 | } |
| @@ -912,7 +914,8 @@ async fn several_raw_services_serve_one_capability_together() { | ||
| 912 | 914 | let n = request["payload"]["n"].clone(); |
| 913 | 915 | raw::answer( |
| 914 | 916 | send, |
| 915 | - format!(r#"{{"status":"ok","id":"{id}","school":"{SCHOOL}","payload":{n}}}"#).as_bytes(), | |
| 917 | + format!(r#"{{"status":"ok","id":"{id}","school":"{SCHOOL}","payload":{n}}}"#) | |
| 918 | + .as_bytes(), | |
| 916 | 919 | ) |
| 917 | 920 | .await; |
| 918 | 921 | } |
| @@ -1006,7 +1009,10 @@ async fn a_chat_request_names_the_askers_school_role() { | ||
| 1006 | 1009 | let id = request["id"].as_str().expect("trace id").to_string(); |
| 1007 | 1010 | raw::answer( |
| 1008 | 1011 | send, |
| 1009 | - format!(r#"{{"status":"ok","id":"{id}","school":"{SCHOOL}","payload":{{"text":"F = ma"}}}}"#).as_bytes(), | |
| 1012 | + format!( | |
| 1013 | + r#"{{"status":"ok","id":"{id}","school":"{SCHOOL}","payload":{{"text":"F = ma"}}}}"# | |
| 1014 | + ) | |
| 1015 | + .as_bytes(), | |
| 1010 | 1016 | ) |
| 1011 | 1017 | .await; |
| 1012 | 1018 | } |
| @@ -1118,9 +1124,13 @@ async fn the_api_refusal_frame_carries_exactly_the_published_keys_and_codes() { | ||
| 1118 | 1124 | ), |
| 1119 | 1125 | ( |
| 1120 | 1126 | "unknown_user", |
| 1121 | - r#"{"id":"t5","school":"demo","path":"/auth/me","on_behalf_of":"nobodyatall"}"#.to_string(), | |
| 1127 | + r#"{"id":"t5","school":"demo","path":"/auth/me","on_behalf_of":"nobodyatall"}"# | |
| 1128 | + .to_string(), | |
| 1129 | + ), | |
| 1130 | + ( | |
| 1131 | + "malformed", | |
| 1132 | + r#"{"id":"t6","school":"demo","path":42}"#.to_string(), | |
| 1122 | 1133 | ), |
| 1123 | - ("malformed", r#"{"id":"t6","school":"demo","path":42}"#.to_string()), | |
| 1124 | 1134 | // A frame that names no school at all: required, never defaulted. |
| 1125 | 1135 | ("malformed", r#"{"id":"t7","path":"/auth/me"}"#.to_string()), |
| 1126 | 1136 | // A string that is no slug — the service's own bug, not a missing |
| @@ -1173,8 +1183,10 @@ async fn an_api_read_answers_a_named_user_with_that_users_own_data() { | ||
| 1173 | 1183 | |
| 1174 | 1184 | let (answer, _) = raw::api_read( |
| 1175 | 1185 | &service.conn, |
| 1176 | - format!(r#"{{"id":"tme","school":"{SCHOOL}","path":"/auth/me","on_behalf_of":"{student}"}}"#) | |
| 1177 | - .as_bytes(), | |
| 1186 | + format!( | |
| 1187 | + r#"{{"id":"tme","school":"{SCHOOL}","path":"/auth/me","on_behalf_of":"{student}"}}"# | |
| 1188 | + ) | |
| 1189 | + .as_bytes(), | |
| 1178 | 1190 | ) |
| 1179 | 1191 | .await; |
| 1180 | 1192 | assert_eq!(answer["outcome"], "ok", "{answer}"); |
| @@ -1204,7 +1216,10 @@ async fn two_schools(bridge: &AiBridge) -> (axum::Router, Tenants, String, Strin | ||
| 1204 | 1216 | let beta_cookie = common::login_as_school(&app, &beta_db, "beta", "ayse", "student").await; |
| 1205 | 1217 | let demo_ayse = common::me_id(&app, &demo_cookie).await; |
| 1206 | 1218 | let beta_ayse = common::me_id(&app, &beta_cookie).await; |
| 1207 | - assert_ne!(demo_ayse, beta_ayse, "two schools, two separate `ayse` rows"); | |
| 1219 | + assert_ne!( | |
| 1220 | + demo_ayse, beta_ayse, | |
| 1221 | + "two schools, two separate `ayse` rows" | |
| 1222 | + ); | |
| 1208 | 1223 | (app, tenants, demo_ayse, beta_ayse) |
| 1209 | 1224 | } |
| 1210 | 1225 | |
| @@ -1222,8 +1237,10 @@ async fn an_api_read_answers_out_of_the_school_the_frame_named() { | ||
| 1222 | 1237 | for (school, who) in [("demo", &demo_ayse), ("beta", &beta_ayse)] { |
| 1223 | 1238 | let (answer, _) = raw::api_read( |
| 1224 | 1239 | &service.conn, |
| 1225 | - format!(r#"{{"id":"t-own","school":"{school}","path":"/auth/me","on_behalf_of":"{who}"}}"#) | |
| 1226 | - .as_bytes(), | |
| 1240 | + format!( | |
| 1241 | + r#"{{"id":"t-own","school":"{school}","path":"/auth/me","on_behalf_of":"{who}"}}"# | |
| 1242 | + ) | |
| 1243 | + .as_bytes(), | |
| 1227 | 1244 | ) |
| 1228 | 1245 | .await; |
| 1229 | 1246 | assert_eq!(answer["outcome"], "ok", "{answer}"); |
| @@ -1272,7 +1289,10 @@ async fn a_suspended_school_is_refused_with_its_own_code() { | ||
| 1272 | 1289 | let (answer, _) = raw::api_read(&service.conn, read.as_bytes()).await; |
| 1273 | 1290 | assert_eq!(answer["outcome"], "err", "{answer}"); |
| 1274 | 1291 | assert_eq!(answer["code"], "school_suspended", "{answer}"); |
| 1275 | - assert_eq!(answer["school"], "beta", "the refusal names the school back"); | |
| 1292 | + assert_eq!( | |
| 1293 | + answer["school"], "beta", | |
| 1294 | + "the refusal names the school back" | |
| 1295 | + ); | |
| 1276 | 1296 | assert_eq!(answer["id"], "t-susp"); |
| 1277 | 1297 | |
| 1278 | 1298 | // The demo school is untouched by its neighbour's suspension. |
| @@ -1295,8 +1315,10 @@ async fn a_blob_read_names_its_school_too() { | ||
| 1295 | 1315 | |
| 1296 | 1316 | let (header, _, body) = raw::blob_read( |
| 1297 | 1317 | &service.conn, |
| 1298 | - format!(r#"{{"id":"t-b1","school":"{SCHOOL}","file":"{file}","on_behalf_of":"{student}"}}"#) | |
| 1299 | - .as_bytes(), | |
| 1318 | + format!( | |
| 1319 | + r#"{{"id":"t-b1","school":"{SCHOOL}","file":"{file}","on_behalf_of":"{student}"}}"# | |
| 1320 | + ) | |
| 1321 | + .as_bytes(), | |
| 1300 | 1322 | ) |
| 1301 | 1323 | .await; |
| 1302 | 1324 | assert_eq!(header["status"], "ok", "{header}"); |
| @@ -1459,8 +1481,10 @@ async fn an_api_read_still_answers_on_the_shared_client_stream_path() { | ||
| 1459 | 1481 | |
| 1460 | 1482 | let (answer, _) = raw::api_read( |
| 1461 | 1483 | &service.conn, |
| 1462 | - format!(r#"{{"id":"t-api","school":"{SCHOOL}","path":"/auth/me","on_behalf_of":"{student}"}}"#) | |
| 1463 | - .as_bytes(), | |
| 1484 | + format!( | |
| 1485 | + r#"{{"id":"t-api","school":"{SCHOOL}","path":"/auth/me","on_behalf_of":"{student}"}}"# | |
| 1486 | + ) | |
| 1487 | + .as_bytes(), | |
| 1464 | 1488 | ) |
| 1465 | 1489 | .await; |
| 1466 | 1490 | assert_eq!(answer["outcome"], "ok", "{answer}"); |
tests/builder_api.rsmodified+87 -24
| @@ -164,7 +164,10 @@ async fn creating_a_school_seeds_an_admin_who_can_log_in() { | ||
| 164 | 164 | ); |
| 165 | 165 | let me = send(&app, "GET", "/auth/me", Some(&cookie), None).await; |
| 166 | 166 | assert_eq!(me.status, StatusCode::OK); |
| 167 | - assert_eq!(me.body["role"], "admin", "the seed is an admin, not a student"); | |
| 167 | + assert_eq!( | |
| 168 | + me.body["role"], "admin", | |
| 169 | + "the seed is an admin, not a student" | |
| 170 | + ); | |
| 168 | 171 | |
| 169 | 172 | // The slug is the identity: a second school may not take it. |
| 170 | 173 | assert_eq!( |
| @@ -187,9 +190,15 @@ async fn creating_a_school_seeds_an_admin_who_can_log_in() { | ||
| 187 | 190 | ); |
| 188 | 191 | // …and nothing was left behind by the refusal. |
| 189 | 192 | assert_eq!( |
| 190 | - send(&app, "GET", &format!("/schools/{bad}"), Some(&builder), None) | |
| 191 | - .await | |
| 192 | - .status, | |
| 193 | + send( | |
| 194 | + &app, | |
| 195 | + "GET", | |
| 196 | + &format!("/schools/{bad}"), | |
| 197 | + Some(&builder), | |
| 198 | + None | |
| 199 | + ) | |
| 200 | + .await | |
| 201 | + .status, | |
| 193 | 202 | StatusCode::NOT_FOUND, |
| 194 | 203 | "slug {bad:?} left a school behind" |
| 195 | 204 | ); |
| @@ -220,7 +229,9 @@ async fn a_suspension_closes_the_school_and_a_resume_reopens_it() { | ||
| 220 | 229 | let (app, _db, _tenants) = deployment().await; |
| 221 | 230 | let builder = builder_login(&app).await; |
| 222 | 231 | assert_eq!( |
| 223 | - create_school(&app, &builder, "beta", "secret1").await.status, | |
| 232 | + create_school(&app, &builder, "beta", "secret1") | |
| 233 | + .await | |
| 234 | + .status, | |
| 224 | 235 | StatusCode::CREATED |
| 225 | 236 | ); |
| 226 | 237 | |
| @@ -302,7 +313,9 @@ async fn a_suspension_closes_the_school_and_a_resume_reopens_it() { | ||
| 302 | 313 | "a suspended school refuses login" |
| 303 | 314 | ); |
| 304 | 315 | assert_eq!( |
| 305 | - send(&app, "GET", "/auth/me", Some(&live), None).await.status, | |
| 316 | + send(&app, "GET", "/auth/me", Some(&live), None) | |
| 317 | + .await | |
| 318 | + .status, | |
| 306 | 319 | StatusCode::FORBIDDEN, |
| 307 | 320 | "…and the cookie it had already issued, on its very next call" |
| 308 | 321 | ); |
| @@ -336,7 +349,9 @@ async fn a_suspension_closes_the_school_and_a_resume_reopens_it() { | ||
| 336 | 349 | ) |
| 337 | 350 | .await; |
| 338 | 351 | assert_eq!( |
| 339 | - send(&app, "GET", "/auth/me", Some(&live), None).await.status, | |
| 352 | + send(&app, "GET", "/auth/me", Some(&live), None) | |
| 353 | + .await | |
| 354 | + .status, | |
| 340 | 355 | StatusCode::OK, |
| 341 | 356 | "resuming restores the very same session" |
| 342 | 357 | ); |
| @@ -374,7 +389,11 @@ async fn resetting_an_admin_password_revokes_the_old_credential_and_its_sessions | ||
| 374 | 389 | .unwrap(); |
| 375 | 390 | hezarfen_backend::domain::user::User::create( |
| 376 | 391 | Username::try_new("veli").unwrap(), |
| 377 | - Password::try_new("secret1").unwrap().hash_async().await.unwrap(), | |
| 392 | + Password::try_new("secret1") | |
| 393 | + .unwrap() | |
| 394 | + .hash_async() | |
| 395 | + .await | |
| 396 | + .unwrap(), | |
| 378 | 397 | &gamma_db, |
| 379 | 398 | ) |
| 380 | 399 | .await |
| @@ -632,8 +651,8 @@ async fn probe_hostile_slug_segments_never_delete_anything() { | ||
| 632 | 651 | "Demo", |
| 633 | 652 | "control", |
| 634 | 653 | "builder", |
| 635 | - "%C4%B1demo", // dotless i, non-ascii | |
| 636 | - "d%E2%80%8Bemo", // zero-width space | |
| 654 | + "%C4%B1demo", // dotless i, non-ascii | |
| 655 | + "d%E2%80%8Bemo", // zero-width space | |
| 637 | 656 | "de%20mo", |
| 638 | 657 | "a", |
| 639 | 658 | "-lead", |
| @@ -675,12 +694,25 @@ async fn probe_hostile_slug_segments_never_delete_anything() { | ||
| 675 | 694 | // Also the empty segment, which is a different route shape entirely. |
| 676 | 695 | for method in ["GET", "DELETE", "PATCH"] { |
| 677 | 696 | let res = send(&app, method, "/schools/", Some(&builder), None).await; |
| 678 | - assert!(!res.status.is_success() || method == "GET", "{method} /schools/ -> {}", res.status); | |
| 697 | + assert!( | |
| 698 | + !res.status.is_success() || method == "GET", | |
| 699 | + "{method} /schools/ -> {}", | |
| 700 | + res.status | |
| 701 | + ); | |
| 679 | 702 | } |
| 680 | 703 | |
| 681 | - assert!(keep_dir.join("keep.bin").exists(), "a bystander school lost its bytes"); | |
| 682 | - assert!(root_canary.exists(), "the FILES_PATH root canary was deleted"); | |
| 683 | - assert!(outside_file.exists(), "a file outside FILES_PATH was deleted"); | |
| 704 | + assert!( | |
| 705 | + keep_dir.join("keep.bin").exists(), | |
| 706 | + "a bystander school lost its bytes" | |
| 707 | + ); | |
| 708 | + assert!( | |
| 709 | + root_canary.exists(), | |
| 710 | + "the FILES_PATH root canary was deleted" | |
| 711 | + ); | |
| 712 | + assert!( | |
| 713 | + outside_file.exists(), | |
| 714 | + "a file outside FILES_PATH was deleted" | |
| 715 | + ); | |
| 684 | 716 | assert!( |
| 685 | 717 | files_dir().exists() && outside.path().exists(), |
| 686 | 718 | "a directory root was removed" |
| @@ -784,7 +816,14 @@ async fn probe_remote_mode_database_statements_execute_for_every_accepted_slug() | ||
| 784 | 816 | let mut broken: Vec<String> = Vec::new(); |
| 785 | 817 | |
| 786 | 818 | for raw in [ |
| 787 | - "demo", "abc", "ata-koleji", "x-y", "trail-", "2024school", "12345", "a1", | |
| 819 | + "demo", | |
| 820 | + "abc", | |
| 821 | + "ata-koleji", | |
| 822 | + "x-y", | |
| 823 | + "trail-", | |
| 824 | + "2024school", | |
| 825 | + "12345", | |
| 826 | + "a1", | |
| 788 | 827 | ] { |
| 789 | 828 | let Ok(slug) = Slug::try_new(raw) else { |
| 790 | 829 | continue; |
| @@ -820,8 +859,23 @@ async fn probe_remote_mode_database_statements_execute_for_every_accepted_slug() | ||
| 820 | 859 | #[tokio::test] |
| 821 | 860 | async fn probe_slug_accept_set_and_published_reserved_list() { |
| 822 | 861 | for bad in [ |
| 823 | - "control", "builder", "Demo", "DEMO", "..", "", "a", "-lead", "de mo", "de.mo", "de_mo", | |
| 824 | - "demo/", "demo\\", "٢٣demo", "démo", "demo\u{200b}", "demo\n", | |
| 862 | + "control", | |
| 863 | + "builder", | |
| 864 | + "Demo", | |
| 865 | + "DEMO", | |
| 866 | + "..", | |
| 867 | + "", | |
| 868 | + "a", | |
| 869 | + "-lead", | |
| 870 | + "de mo", | |
| 871 | + "de.mo", | |
| 872 | + "de_mo", | |
| 873 | + "demo/", | |
| 874 | + "demo\\", | |
| 875 | + "٢٣demo", | |
| 876 | + "démo", | |
| 877 | + "demo\u{200b}", | |
| 878 | + "demo\n", | |
| 825 | 879 | // 33 characters |
| 826 | 880 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", |
| 827 | 881 | ] { |
| @@ -831,7 +885,10 @@ async fn probe_slug_accept_set_and_published_reserved_list() { | ||
| 831 | 885 | ); |
| 832 | 886 | } |
| 833 | 887 | for good in ["ab", "demo", "a1", "2024", "ata-koleji"] { |
| 834 | - assert!(Slug::try_new(good).is_ok(), "Slug::try_new rejected {good:?}"); | |
| 888 | + assert!( | |
| 889 | + Slug::try_new(good).is_ok(), | |
| 890 | + "Slug::try_new rejected {good:?}" | |
| 891 | + ); | |
| 835 | 892 | } |
| 836 | 893 | // Documented boundary: a trailing hyphen IS accepted today. |
| 837 | 894 | assert!( |
| @@ -971,7 +1028,9 @@ async fn probe_admin_targets_and_reset_revokes_all_sessions() { | ||
| 971 | 1028 | assert_eq!(reset.status, StatusCode::NO_CONTENT); |
| 972 | 1029 | for (n, cookie) in [(1, &s1), (2, &s2)] { |
| 973 | 1030 | assert_eq!( |
| 974 | - send(&app, "GET", "/auth/me", Some(cookie), None).await.status, | |
| 1031 | + send(&app, "GET", "/auth/me", Some(cookie), None) | |
| 1032 | + .await | |
| 1033 | + .status, | |
| 975 | 1034 | StatusCode::UNAUTHORIZED, |
| 976 | 1035 | "session {n} survived the password reset" |
| 977 | 1036 | ); |
| @@ -1036,9 +1095,7 @@ async fn probe_builder_session_hygiene() { | ||
| 1036 | 1095 | let builder = builder_login(&app).await; |
| 1037 | 1096 | let student = login(&app, "veli").await; |
| 1038 | 1097 | |
| 1039 | - let builder_token = builder | |
| 1040 | - .trim_start_matches("session=builder.") | |
| 1041 | - .to_string(); | |
| 1098 | + let builder_token = builder.trim_start_matches("session=builder.").to_string(); | |
| 1042 | 1099 | let student_token = cookie_token(&student).to_string(); |
| 1043 | 1100 | |
| 1044 | 1101 | // The builder's own token, worn as a school cookie. |
| @@ -1116,7 +1173,9 @@ async fn probe_builder_session_hygiene() { | ||
| 1116 | 1173 | ); |
| 1117 | 1174 | // Logout is idempotent and safe without a cookie. |
| 1118 | 1175 | assert_eq!( |
| 1119 | - send(&app, "POST", "/builder/logout", None, None).await.status, | |
| 1176 | + send(&app, "POST", "/builder/logout", None, None) | |
| 1177 | + .await | |
| 1178 | + .status, | |
| 1120 | 1179 | StatusCode::NO_CONTENT |
| 1121 | 1180 | ); |
| 1122 | 1181 | } |
| @@ -1283,7 +1342,11 @@ async fn probe_remote_deployment_creates_and_deletes_a_hyphenated_school() { | ||
| 1283 | 1342 | login.status, |
| 1284 | 1343 | ); |
| 1285 | 1344 | assert_eq!(retry.status, StatusCode::CONFLICT, "a made school is taken"); |
| 1286 | - assert_eq!(login.status, StatusCode::OK, "the admin logs into the hyphenated school"); | |
| 1345 | + assert_eq!( | |
| 1346 | + login.status, | |
| 1347 | + StatusCode::OK, | |
| 1348 | + "the admin logs into the hyphenated school" | |
| 1349 | + ); | |
| 1287 | 1350 | assert_eq!(deleted.status, StatusCode::NO_CONTENT); |
| 1288 | 1351 | assert!(!listed(&after_delete.body)); |
| 1289 | 1352 | assert_eq!( |
tests/spec_bounds.rsmodified+12 -2
| @@ -64,8 +64,18 @@ fn expectations() -> Vec<(&'static str, &'static str, &'static str, i64)> { | ||
| 64 | 64 | // --- builder (the vendor surface) --- |
| 65 | 65 | ("CreateSchool", "slug", "minLength", MIN_SLUG_LEN as i64), |
| 66 | 66 | ("CreateSchool", "slug", "maxLength", MAX_SLUG_LEN as i64), |
| 67 | - ("CreateSchool", "name", "maxLength", MAX_SCHOOL_NAME_LEN as i64), | |
| 68 | - ("UpdateSchool", "name", "maxLength", MAX_SCHOOL_NAME_LEN as i64), | |
| 67 | + ( | |
| 68 | + "CreateSchool", | |
| 69 | + "name", | |
| 70 | + "maxLength", | |
| 71 | + MAX_SCHOOL_NAME_LEN as i64, | |
| 72 | + ), | |
| 73 | + ( | |
| 74 | + "UpdateSchool", | |
| 75 | + "name", | |
| 76 | + "maxLength", | |
| 77 | + MAX_SCHOOL_NAME_LEN as i64, | |
| 78 | + ), | |
| 69 | 79 | ( |
| 70 | 80 | "CreateSchool", |
| 71 | 81 | "admin_username", |