| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | use std::{net::SocketAddr, path::Path}; |
| 21 | |
| 22 | use steid::{ |
| 23 | application::{AppConfig, is_claimed, mint_reset_for_handle}, |
| 24 | domain::{SetupToken, repository::OrgRepository}, |
| 25 | infrastructure::{ |
| 26 | app, database, |
| 27 | repository::{SqliteOrgRepo, SqlitePasswordResetRepo, SqliteUserRepo}, |
| 28 | }, |
| 29 | }; |
| 30 | use tempfile::TempDir; |
| 31 | use tokio::{net::TcpListener, sync::oneshot, task::JoinHandle}; |
| 32 | use topcoat::asset::AssetBundle; |
| 33 | |
| 34 | |
| 35 | |
| 36 | struct Instance { |
| 37 | base: String, |
| 38 | |
| 39 | setup_token: String, |
| 40 | |
| 41 | config: AppConfig, |
| 42 | |
| 43 | pool: sqlx::SqlitePool, |
| 44 | |
| 45 | _dir: TempDir, |
| 46 | stop: Option<oneshot::Sender<()>>, |
| 47 | serving: Option<JoinHandle<()>>, |
| 48 | } |
| 49 | |
| 50 | impl Instance { |
| 51 | |
| 52 | fn url(&self, path: &str) -> String { |
| 53 | format!("{}{path}", self.base) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | impl Drop for Instance { |
| 58 | fn drop(&mut self) { |
| 59 | |
| 60 | |
| 61 | |
| 62 | if let Some(stop) = self.stop.take() { |
| 63 | let _ = stop.send(()); |
| 64 | } |
| 65 | if let Some(serving) = self.serving.take() { |
| 66 | serving.abort(); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | |
| 72 | async fn boot() -> Instance { |
| 73 | boot_with(None).await |
| 74 | } |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | async fn boot_with_owner(handle: &str, email: &str) -> Instance { |
| 84 | boot_with(Some((handle.to_owned(), email.to_owned()))).await |
| 85 | } |
| 86 | |
| 87 | async fn boot_with(owner: Option<(String, String)>) -> Instance { |
| 88 | let dir = tempfile::tempdir().expect("a temp dir"); |
| 89 | let config = config_in(dir.path(), owner.clone()); |
| 90 | |
| 91 | let pool = database::connect(&config.database_url) |
| 92 | .await |
| 93 | .expect("the database opens"); |
| 94 | |
| 95 | |
| 96 | |
| 97 | let seeded = app::seed_owner_on_boot(&config, &pool) |
| 98 | .await |
| 99 | .expect("the configured owner is created"); |
| 100 | assert_eq!( |
| 101 | seeded.is_some(), |
| 102 | owner.is_some(), |
| 103 | "a configured owner must actually be created" |
| 104 | ); |
| 105 | |
| 106 | let token = SetupToken::generate(); |
| 107 | let setup_token = token.reveal().to_owned(); |
| 108 | let setup = if seeded.is_some() { None } else { Some(token) }; |
| 109 | |
| 110 | let router = app::build(config.clone(), pool.clone(), assets(), setup) |
| 111 | .await |
| 112 | .build(); |
| 113 | |
| 114 | |
| 115 | |
| 116 | let listener = TcpListener::bind("127.0.0.1:0").await.expect("a port"); |
| 117 | let addr: SocketAddr = listener.local_addr().expect("the address it got"); |
| 118 | |
| 119 | let (stop, stopped) = oneshot::channel(); |
| 120 | let serving = tokio::spawn(async move { |
| 121 | let _ = topcoat::serve_until(listener, router, async { |
| 122 | let _ = stopped.await; |
| 123 | }) |
| 124 | .await; |
| 125 | }); |
| 126 | |
| 127 | Instance { |
| 128 | base: format!("http://{addr}"), |
| 129 | setup_token, |
| 130 | config, |
| 131 | pool, |
| 132 | _dir: dir, |
| 133 | stop: Some(stop), |
| 134 | serving: Some(serving), |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | |
| 139 | fn config_in(dir: &Path, owner: Option<(String, String)>) -> AppConfig { |
| 140 | let data_dir = dir.join("data"); |
| 141 | std::fs::create_dir_all(&data_dir).expect("mkdir"); |
| 142 | |
| 143 | AppConfig { |
| 144 | database_url: format!("sqlite:{}?mode=rwc", dir.join("steid.db").display()), |
| 145 | data_dir, |
| 146 | |
| 147 | |
| 148 | |
| 149 | insecure_cookies: false, |
| 150 | allow_private_webhooks: false, |
| 151 | trusted_proxy: false, |
| 152 | |
| 153 | |
| 154 | operator_token: None, |
| 155 | setup_token: None, |
| 156 | backup_marker: None, |
| 157 | smtp_url: None, |
| 158 | mail_from: None, |
| 159 | |
| 160 | |
| 161 | owner_email: owner.as_ref().map(|(_, email)| email.clone()), |
| 162 | owner_handle: owner.as_ref().map(|(handle, _)| handle.clone()), |
| 163 | owner_org: None, |
| 164 | owner_org_name: None, |
| 165 | public_url: None, |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | fn assets() -> AssetBundle { |
| 178 | |
| 179 | |
| 180 | let dir = Box::leak(Box::new(tempfile::tempdir().expect("a temp dir"))); |
| 181 | std::fs::write( |
| 182 | dir.path().join("manifest.toml"), |
| 183 | "version = 1\nassets = []\n", |
| 184 | ) |
| 185 | .expect("the manifest is written"); |
| 186 | |
| 187 | AssetBundle::load_dir(dir.path()).expect("an empty bundle loads") |
| 188 | } |
| 189 | |
| 190 | |
| 191 | struct Answer { |
| 192 | status: u16, |
| 193 | headers: Vec<(String, String)>, |
| 194 | body: String, |
| 195 | } |
| 196 | |
| 197 | impl Answer { |
| 198 | |
| 199 | fn header(&self, name: &str) -> Option<&str> { |
| 200 | self.headers |
| 201 | .iter() |
| 202 | .find(|(key, _)| key.eq_ignore_ascii_case(name)) |
| 203 | .map(|(_, value)| value.as_str()) |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | async fn request(url: String, body: Option<(&str, String)>, extra: &[(&str, &str)]) -> Answer { |
| 219 | let body = body.map(|(content_type, body)| (content_type.to_owned(), body)); |
| 220 | let extra: Vec<(String, String)> = extra |
| 221 | .iter() |
| 222 | .map(|(name, value)| ((*name).to_owned(), (*value).to_owned())) |
| 223 | .collect(); |
| 224 | |
| 225 | tokio::task::spawn_blocking(move || { |
| 226 | let agent = ureq::Agent::config_builder() |
| 227 | |
| 228 | |
| 229 | |
| 230 | .http_status_as_error(false) |
| 231 | .max_redirects(0) |
| 232 | .build() |
| 233 | .new_agent(); |
| 234 | |
| 235 | let mut response = match body { |
| 236 | Some((content_type, body)) => { |
| 237 | let mut post = agent.post(&url).header("content-type", &content_type); |
| 238 | for (name, value) in &extra { |
| 239 | post = post.header(name, value); |
| 240 | } |
| 241 | post.send(&body).expect("the request completes") |
| 242 | } |
| 243 | None => agent.get(&url).call().expect("the request completes"), |
| 244 | }; |
| 245 | |
| 246 | let status = response.status().as_u16(); |
| 247 | let headers = response |
| 248 | .headers() |
| 249 | .iter() |
| 250 | .map(|(name, value)| { |
| 251 | ( |
| 252 | name.as_str().to_owned(), |
| 253 | String::from_utf8_lossy(value.as_bytes()).into_owned(), |
| 254 | ) |
| 255 | }) |
| 256 | .collect(); |
| 257 | let body = response.body_mut().read_to_string().unwrap_or_default(); |
| 258 | |
| 259 | Answer { |
| 260 | status, |
| 261 | headers, |
| 262 | body, |
| 263 | } |
| 264 | }) |
| 265 | .await |
| 266 | .expect("the blocking thread finishes") |
| 267 | } |
| 268 | |
| 269 | async fn get(instance: &Instance, path: &str) -> Answer { |
| 270 | request(instance.url(path), None, &[]).await |
| 271 | } |
| 272 | |
| 273 | |
| 274 | |
| 275 | async fn post_form(instance: &Instance, path: &str, body: &str) -> Answer { |
| 276 | post_form_with(instance, path, body, &[]).await |
| 277 | } |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | async fn post_form_from_page(instance: &Instance, path: &str, body: &str) -> Answer { |
| 284 | post_form_with(instance, path, body, &[("sec-fetch-site", "same-origin")]).await |
| 285 | } |
| 286 | |
| 287 | async fn post_form_with( |
| 288 | instance: &Instance, |
| 289 | path: &str, |
| 290 | body: &str, |
| 291 | headers: &[(&str, &str)], |
| 292 | ) -> Answer { |
| 293 | request( |
| 294 | instance.url(path), |
| 295 | Some(("application/x-www-form-urlencoded", body.to_owned())), |
| 296 | headers, |
| 297 | ) |
| 298 | .await |
| 299 | } |
| 300 | |
| 301 | async fn post_json(instance: &Instance, path: &str, body: String) -> Answer { |
| 302 | request(instance.url(path), Some(("application/json", body)), &[]).await |
| 303 | } |
| 304 | |
| 305 | |
| 306 | fn sets_a_session(answer: &Answer) -> bool { |
| 307 | answer |
| 308 | .header("set-cookie") |
| 309 | .is_some_and(|cookie| cookie.to_ascii_lowercase().contains("session")) |
| 310 | } |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | async fn claim(instance: &Instance) { |
| 318 | let body = format!( |
| 319 | r#"{{"setup_token":"{}","email":"ada@example.com","handle":"ada","password":"a-long-enough-password"}}"#, |
| 320 | instance.setup_token |
| 321 | ); |
| 322 | |
| 323 | let answer = post_json(instance, "/api/setup", body).await; |
| 324 | |
| 325 | assert_eq!(answer.status, 201, "the claim was refused: {}", answer.body); |
| 326 | assert!( |
| 327 | answer.body.contains("\"handle\":\"ada\""), |
| 328 | "{}", |
| 329 | answer.body |
| 330 | ); |
| 331 | } |
| 332 | |
| 333 | #[tokio::test] |
| 334 | async fn an_instance_boots_and_can_be_claimed_without_a_browser() { |
| 335 | let instance = boot().await; |
| 336 | |
| 337 | let before = get(&instance, "/api/instance").await; |
| 338 | assert_eq!(before.status, 200); |
| 339 | assert_eq!(before.body.trim(), r#"{"claimed":false}"#); |
| 340 | |
| 341 | claim(&instance).await; |
| 342 | |
| 343 | let after = get(&instance, "/api/instance").await; |
| 344 | assert_eq!(after.status, 200); |
| 345 | assert_eq!(after.body.trim(), r#"{"claimed":true}"#); |
| 346 | } |
| 347 | |
| 348 | #[tokio::test] |
| 349 | async fn an_instance_given_an_owner_in_its_configuration_boots_claimed() { |
| 350 | |
| 351 | |
| 352 | let instance = boot_with_owner("ada", "ada@example.com").await; |
| 353 | |
| 354 | let answer = get(&instance, "/api/instance").await; |
| 355 | |
| 356 | assert_eq!(answer.status, 200); |
| 357 | assert_eq!(answer.body.trim(), r#"{"claimed":true}"#); |
| 358 | } |
| 359 | |
| 360 | #[tokio::test] |
| 361 | async fn a_boot_seeded_instance_cannot_be_claimed_by_anyone() { |
| 362 | |
| 363 | |
| 364 | let instance = boot_with_owner("ada", "ada@example.com").await; |
| 365 | |
| 366 | let over_json = post_json( |
| 367 | &instance, |
| 368 | "/api/setup", |
| 369 | format!( |
| 370 | r#"{{"setup_token":"{}","email":"eve@example.com","handle":"eve","password":"a-long-enough-password"}}"#, |
| 371 | instance.setup_token |
| 372 | ), |
| 373 | ) |
| 374 | .await; |
| 375 | assert_ne!( |
| 376 | over_json.status, 201, |
| 377 | "the claim went through: {}", |
| 378 | over_json.body |
| 379 | ); |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | let over_form = post_form( |
| 385 | &instance, |
| 386 | "/auth/setup", |
| 387 | &format!( |
| 388 | "token={}&handle=eve&email=eve@example.com&password=a-long-enough-password", |
| 389 | instance.setup_token |
| 390 | ), |
| 391 | ) |
| 392 | .await; |
| 393 | assert_eq!(over_form.status, 303); |
| 394 | assert_eq!(over_form.header("location"), Some("/")); |
| 395 | |
| 396 | assert_eq!( |
| 397 | get(&instance, "/api/instance").await.body.trim(), |
| 398 | r#"{"claimed":true}"#, |
| 399 | "and nobody became the owner" |
| 400 | ); |
| 401 | } |
| 402 | |
| 403 | #[tokio::test] |
| 404 | async fn a_refused_organisation_is_refused_again_on_the_next_boot() { |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | let dir = tempfile::tempdir().expect("a temp dir"); |
| 410 | let config = AppConfig { |
| 411 | owner_org: Some("admin".to_owned()), |
| 412 | ..config_in( |
| 413 | dir.path(), |
| 414 | Some(("ada".to_owned(), "ada@example.com".to_owned())), |
| 415 | ) |
| 416 | }; |
| 417 | |
| 418 | for boot in ["first", "second"] { |
| 419 | |
| 420 | let pool = database::connect(&config.database_url) |
| 421 | .await |
| 422 | .expect("the database opens"); |
| 423 | |
| 424 | let error = app::seed_owner_on_boot(&config, &pool) |
| 425 | .await |
| 426 | .expect_err("a reserved organisation must stop the boot"); |
| 427 | assert!( |
| 428 | error.to_string().contains("reserved"), |
| 429 | "the {boot} boot failed for another reason: {error}" |
| 430 | ); |
| 431 | |
| 432 | assert!( |
| 433 | !is_claimed(&SqliteUserRepo::new(pool.clone())) |
| 434 | .await |
| 435 | .expect("the query runs"), |
| 436 | "the {boot} boot left an owner behind" |
| 437 | ); |
| 438 | assert_eq!( |
| 439 | SqliteOrgRepo::new(pool.clone()) |
| 440 | .count() |
| 441 | .await |
| 442 | .expect("the query runs"), |
| 443 | 0, |
| 444 | "the {boot} boot left an organisation behind" |
| 445 | ); |
| 446 | |
| 447 | pool.close().await; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | #[tokio::test] |
| 452 | async fn the_seeded_owner_cannot_sign_in_with_any_password() { |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | let instance = boot_with_owner("ada", "ada@example.com").await; |
| 458 | |
| 459 | for guess in ["", "password", "a-long-enough-password"] { |
| 460 | let answer = post_form_from_page( |
| 461 | &instance, |
| 462 | "/auth/login", |
| 463 | &format!("email=ada@example.com&password={guess}"), |
| 464 | ) |
| 465 | .await; |
| 466 | |
| 467 | assert_eq!(answer.status, 303, "{guess:?} was not refused"); |
| 468 | assert_eq!(answer.header("location"), Some("/auth/login")); |
| 469 | assert!( |
| 470 | !sets_a_session(&answer), |
| 471 | "{guess:?} produced a session cookie: {:?}", |
| 472 | answer.header("set-cookie") |
| 473 | ); |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | #[tokio::test] |
| 478 | async fn the_seeded_owner_gets_in_through_a_reset_link() { |
| 479 | |
| 480 | |
| 481 | let instance = boot_with_owner("ada", "ada@example.com").await; |
| 482 | |
| 483 | let issued = mint_reset_for_handle( |
| 484 | "ada", |
| 485 | std::time::SystemTime::now(), |
| 486 | &SqliteUserRepo::new(instance.pool.clone()), |
| 487 | &SqliteOrgRepo::new(instance.pool.clone()), |
| 488 | &SqlitePasswordResetRepo::new(instance.pool.clone()), |
| 489 | ) |
| 490 | .await |
| 491 | .expect("the query runs") |
| 492 | .expect("the seeded owner holds the handle"); |
| 493 | |
| 494 | |
| 495 | |
| 496 | assert!(instance.config.public_url.is_none()); |
| 497 | let link = issued.link(&instance.base); |
| 498 | let path = link |
| 499 | .strip_prefix(&instance.base) |
| 500 | .expect("the link is on this instance") |
| 501 | .to_owned(); |
| 502 | assert!(path.starts_with("/auth/reset/"), "{link}"); |
| 503 | |
| 504 | let spent = post_form( |
| 505 | &instance, |
| 506 | &path, |
| 507 | "password=a-long-enough-password&confirmation=a-long-enough-password", |
| 508 | ) |
| 509 | .await; |
| 510 | assert_eq!(spent.status, 303, "the reset was refused"); |
| 511 | assert_eq!(spent.header("location"), Some("/auth/login?reset")); |
| 512 | |
| 513 | let signed_in = post_form_from_page( |
| 514 | &instance, |
| 515 | "/auth/login", |
| 516 | "email=ada@example.com&password=a-long-enough-password", |
| 517 | ) |
| 518 | .await; |
| 519 | assert_eq!(signed_in.status, 303); |
| 520 | assert_eq!( |
| 521 | signed_in.header("location"), |
| 522 | Some("/"), |
| 523 | "the owner could not sign in with the password they just set" |
| 524 | ); |
| 525 | } |
| 526 | |
| 527 | #[tokio::test] |
| 528 | async fn every_response_carries_the_security_headers_including_a_404() { |
| 529 | let instance = boot().await; |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 | for path in ["/api/instance", "/nothing-is-here"] { |
| 535 | let answer = get(&instance, path).await; |
| 536 | |
| 537 | assert!( |
| 538 | answer.status == 200 || answer.status == 404, |
| 539 | "{path} answered {}", |
| 540 | answer.status |
| 541 | ); |
| 542 | |
| 543 | let policy = answer |
| 544 | .header("content-security-policy") |
| 545 | .unwrap_or_else(|| panic!("{path} carries no CSP")); |
| 546 | assert!( |
| 547 | policy.contains("default-src 'none'"), |
| 548 | "{path}'s CSP is {policy}" |
| 549 | ); |
| 550 | assert!( |
| 551 | policy.contains("frame-ancestors 'none'"), |
| 552 | "{path}'s CSP is {policy}" |
| 553 | ); |
| 554 | |
| 555 | assert_eq!( |
| 556 | answer.header("x-content-type-options"), |
| 557 | Some("nosniff"), |
| 558 | "{path}" |
| 559 | ); |
| 560 | assert_eq!(answer.header("x-frame-options"), Some("DENY"), "{path}"); |
| 561 | |
| 562 | |
| 563 | assert_eq!( |
| 564 | answer.header("referrer-policy"), |
| 565 | Some("no-referrer"), |
| 566 | "{path}" |
| 567 | ); |
| 568 | assert_eq!( |
| 569 | answer.header("cache-control"), |
| 570 | Some("private, no-cache"), |
| 571 | "{path}" |
| 572 | ); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | #[tokio::test] |
| 577 | async fn a_post_without_a_csrf_token_is_refused_with_a_403() { |
| 578 | let instance = boot().await; |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | let empty = post_form(&instance, "/auth/logout", "").await; |
| 585 | assert_eq!(empty.status, 403, "{}", empty.body); |
| 586 | assert!( |
| 587 | empty.body.contains("submitted from somewhere else"), |
| 588 | "{}", |
| 589 | empty.body |
| 590 | ); |
| 591 | |
| 592 | let wrong = post_form(&instance, "/auth/logout", "csrf_token=not-a-token").await; |
| 593 | assert_eq!(wrong.status, 403, "{}", wrong.body); |
| 594 | |
| 595 | |
| 596 | |
| 597 | assert_eq!(empty.header("x-frame-options"), Some("DENY")); |
| 598 | } |
| 599 | |
| 600 | #[tokio::test] |
| 601 | async fn sign_in_refuses_a_post_that_does_not_say_where_it_came_from() { |
| 602 | |
| 603 | |
| 604 | |
| 605 | let instance = boot().await; |
| 606 | claim(&instance).await; |
| 607 | let credentials = "email=ada@example.com&password=a-long-enough-password"; |
| 608 | |
| 609 | |
| 610 | |
| 611 | let bare = post_form(&instance, "/auth/login", credentials).await; |
| 612 | assert_eq!(bare.status, 403, "{}", bare.body); |
| 613 | assert!( |
| 614 | bare.body.contains("submitted from somewhere else"), |
| 615 | "{}", |
| 616 | bare.body |
| 617 | ); |
| 618 | assert!( |
| 619 | !sets_a_session(&bare), |
| 620 | "a refused sign-in started a session: {:?}", |
| 621 | bare.header("set-cookie") |
| 622 | ); |
| 623 | |
| 624 | |
| 625 | |
| 626 | for site in ["same-site", "cross-site"] { |
| 627 | let forged = post_form_with( |
| 628 | &instance, |
| 629 | "/auth/login", |
| 630 | credentials, |
| 631 | &[("sec-fetch-site", site)], |
| 632 | ) |
| 633 | .await; |
| 634 | assert_eq!(forged.status, 403, "{site}: {}", forged.body); |
| 635 | assert!(!sets_a_session(&forged), "{site} started a session"); |
| 636 | } |
| 637 | |
| 638 | |
| 639 | let foreign = post_form_with( |
| 640 | &instance, |
| 641 | "/auth/login", |
| 642 | credentials, |
| 643 | &[("origin", "https://attacker.example")], |
| 644 | ) |
| 645 | .await; |
| 646 | assert_eq!(foreign.status, 403, "{}", foreign.body); |
| 647 | assert!( |
| 648 | !sets_a_session(&foreign), |
| 649 | "a foreign Origin started a session" |
| 650 | ); |
| 651 | |
| 652 | let own_origin = instance.base.clone(); |
| 653 | let from_origin = post_form_with( |
| 654 | &instance, |
| 655 | "/auth/login", |
| 656 | credentials, |
| 657 | &[("origin", own_origin.as_str())], |
| 658 | ) |
| 659 | .await; |
| 660 | assert_eq!(from_origin.status, 303, "{}", from_origin.body); |
| 661 | assert_eq!(from_origin.header("location"), Some("/")); |
| 662 | |
| 663 | |
| 664 | let from_page = post_form_from_page(&instance, "/auth/login", credentials).await; |
| 665 | assert_eq!(from_page.status, 303, "{}", from_page.body); |
| 666 | assert_eq!(from_page.header("location"), Some("/")); |
| 667 | assert!( |
| 668 | sets_a_session(&from_page), |
| 669 | "a same-origin sign-in set no session: {:?}", |
| 670 | from_page.headers |
| 671 | ); |
| 672 | } |
| 673 | |
| 674 | #[tokio::test] |
| 675 | async fn metrics_without_the_bearer_does_not_exist() { |
| 676 | let instance = boot().await; |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | let metrics = get(&instance, "/metrics").await; |
| 682 | let unrouted = get(&instance, "/definitely-not-a-route").await; |
| 683 | |
| 684 | assert_eq!(metrics.status, 404); |
| 685 | assert_eq!(metrics.status, unrouted.status); |
| 686 | assert_eq!(metrics.body, unrouted.body); |
| 687 | |
| 688 | assert!( |
| 689 | !metrics.body.contains("steid_http_requests_total"), |
| 690 | "the counters leaked into the refusal: {}", |
| 691 | metrics.body |
| 692 | ); |
| 693 | } |