forge
Explore
Log in

Don't you dare go Hollow

Page tests share their fixtures and merge into tables

Browse files at this commit

8a535cbf626970b4700191acd83fccdcc0512567Ahmet Kaan GümüşParent: b00f3f4
  • test
    • page tests share their fixtures and merge into tables
Show full message
✅ test: page tests share their fixtures and merge into tables

admin_backups 6 -> 3, admin_replication 5 -> 3, account_tools_tests 8 -> 4,
audit_log 6 -> 2, assets 8 -> 6, archive 4 (unchanged), admin_health 1
(unchanged), avatars 3 (unchanged). 41 -> 26 tests in scope.

Scenarios that share one fixture run in order, each asserting its own
result and naming it in assert messages. Tests that need a pristine
instance or different config keep their own fixture.
crates/forge-web/src/pages/account_tools_tests.rsmodified+7 -21
@@ -72,9 +72,11 @@ fn csrf(extra: &str) -> Option<String> {
72 }72 }
73 73
74 #[tokio::test]74 #[tokio::test]
75-async fn admin_pages_are_404_for_non_admins() {75+async fn admin_account_tools() {
76 let dir = tempfile::tempdir().unwrap();76 let dir = tempfile::tempdir().unwrap();
77 let fx = fixture(dir.path(), None).await;77 let fx = fixture(dir.path(), None).await;
78+
79+ // Admin pages and actions are 404 for anonymous visitors and plain users.
78 let detail = format!("/admin/users/{}", fx.user_id);80 let detail = format!("/admin/users/{}", fx.user_id);
79 for uri in ["/admin/health", detail.as_str()] {81 for uri in ["/admin/health", detail.as_str()] {
80 assert_eq!(82 assert_eq!(
@@ -96,12 +98,8 @@ async fn admin_pages_are_404_for_non_admins() {
96 .0,98 .0,
97 40499 404
98 );100 );
99-}
100 101
101-#[tokio::test]102+ // Suspending needs the CSRF token, is audited, signs the user out and shows on their page.
102-async fn suspending_needs_csrf_and_is_audited() {
103- let dir = tempfile::tempdir().unwrap();
104- let fx = fixture(dir.path(), None).await;
105 let uri = format!("/admin/users/{}/suspend", fx.user_id);103 let uri = format!("/admin/users/{}/suspend", fx.user_id);
106 let (status, _) = send(104 let (status, _) = send(
107 &fx.router,105 &fx.router,
@@ -156,12 +154,8 @@ async fn suspending_needs_csrf_and_is_audited() {
156 .await;154 .await;
157 assert_eq!(status, 303);155 assert_eq!(status, 303);
158 assert!(fx.store.suspension(&fx.user_id).await.unwrap().is_none());156 assert!(fx.store.suspension(&fx.user_id).await.unwrap().is_none());
159-}
160 157
161-#[tokio::test]158+ // The last administrator cannot be demoted from the page.
162-async fn the_last_admin_cannot_be_demoted_or_suspended_from_the_page() {
163- let dir = tempfile::tempdir().unwrap();
164- let fx = fixture(dir.path(), None).await;
165 let base = format!("/admin/users/{}", fx.admin_id);159 let base = format!("/admin/users/{}", fx.admin_id);
166 let (status, body) = send(160 let (status, body) = send(
167 &fx.router,161 &fx.router,
@@ -175,12 +169,8 @@ async fn the_last_admin_cannot_be_demoted_or_suspended_from_the_page() {
175 assert!(body.contains("last administrator"), "{body}");169 assert!(body.contains("last administrator"), "{body}");
176 let me = fx.store.user_by_id(&fx.admin_id).await.unwrap().unwrap();170 let me = fx.store.user_by_id(&fx.admin_id).await.unwrap().unwrap();
177 assert!(me.is_admin);171 assert!(me.is_admin);
178-}
179 172
180-#[tokio::test]173+ // The reset link is shown once and signs the user out.
181-async fn reset_link_is_shown_once_and_signs_the_user_out() {
182- let dir = tempfile::tempdir().unwrap();
183- let fx = fixture(dir.path(), None).await;
184 let (status, body) = send(174 let (status, body) = send(
185 &fx.router,175 &fx.router,
186 "POST",176 "POST",
@@ -203,12 +193,8 @@ async fn reset_link_is_shown_once_and_signs_the_user_out() {
203 .unwrap()193 .unwrap()
204 .is_empty()194 .is_empty()
205 );195 );
206-}
207 196
208-#[tokio::test]197+ // Disabling two-factor clears it.
209-async fn disabling_two_factor_clears_it() {
210- let dir = tempfile::tempdir().unwrap();
211- let fx = fixture(dir.path(), None).await;
212 fx.store198 fx.store
213 .set_totp_secret(&fx.user_id, "sealed")199 .set_totp_secret(&fx.user_id, "sealed")
214 .await200 .await
crates/forge-web/src/pages/admin_backups.rsmodified+74 -75
@@ -415,13 +415,17 @@ mod tests {
415 (status, String::from_utf8_lossy(&bytes).into_owned())415 (status, String::from_utf8_lossy(&bytes).into_owned())
416 }416 }
417 417
418+ /// One configured instance serves every scenario below, since building it is the slow part.
419+ /// The scenarios run in order: the run-count checks need the runs recorded so far.
418 #[tokio::test]420 #[tokio::test]
419- async fn page_is_404_for_anonymous_and_non_admins() {421+ async fn backups_page_and_manual_runs() {
420 let fx = fixture(true).await;422 let fx = fixture(true).await;
423+
424+ // Anonymous visitors and plain users get a 404 for the page and for the run endpoint.
421 let (anon, _) = send(&fx.router, "GET", "/admin/backups", None, None).await;425 let (anon, _) = send(&fx.router, "GET", "/admin/backups", None, None).await;
422- assert_eq!(anon, 404);426+ assert_eq!(anon, 404, "anonymous page");
423 let (user, _) = send(&fx.router, "GET", "/admin/backups", Some(USER_TOKEN), None).await;427 let (user, _) = send(&fx.router, "GET", "/admin/backups", Some(USER_TOKEN), None).await;
424- assert_eq!(user, 404);428+ assert_eq!(user, 404, "plain user page");
425 let (posted, _) = send(429 let (posted, _) = send(
426 &fx.router,430 &fx.router,
427 "POST",431 "POST",
@@ -430,46 +434,40 @@ mod tests {
430 Some(format!("csrf={CSRF}")),434 Some(format!("csrf={CSRF}")),
431 )435 )
432 .await;436 .await;
433- assert_eq!(posted, 404);437+ assert_eq!(posted, 404, "plain user run");
434- }
435-
436- #[tokio::test]
437- async fn page_lists_runs_and_hides_the_healthcheck_token() {
438- let fx = fixture(true).await;
439- let mut config = (*fx.state.config).clone();
440- config.backup.healthcheck_url = "https://hc.example.test/ping/SECRET-TOKEN".into();
441- let mut state = fx.state.clone();
442- state.config = std::sync::Arc::new(config);
443- let router = app_router(state.clone());
444-
445- let id = state
446- .store
447- .start_run(RunKind::Backup, RunTrigger::Schedule)
448- .await
449- .expect("start");
450- state
451- .store
452- .finish_run(&id, false, None, None, Some("disk full"))
453- .await
454- .expect("finish");
455 438
456- let (status, body) = send(&router, "GET", "/admin/backups", Some(ADMIN_TOKEN), None).await;439+ // A backup already running refuses a second one, and the refusal records no run.
457- assert_eq!(status, 200);440+ let held = fx.state.jobs.claim(RunKind::Backup).expect("claim");
458- assert!(body.contains("schedule"));441+ let (status, _) = send(
459- assert!(body.contains("disk full"));442+ &fx.router,
460- assert!(body.contains("hc.example.test"));443+ "POST",
444+ "/admin/backups/run",
445+ Some(ADMIN_TOKEN),
446+ Some(format!("csrf={CSRF}")),
447+ )
448+ .await;
449+ assert_eq!(status, 303, "busy run");
450+ let (_, page) = send(
451+ &fx.router,
452+ "GET",
453+ "/admin/backups?notice=already%20running%3A%20x",
454+ Some(ADMIN_TOKEN),
455+ None,
456+ )
457+ .await;
458+ assert!(page.contains("already running"), "busy notice");
461 assert!(459 assert!(
462- !body.contains("SECRET-TOKEN"),460+ fx.state
463- "the healthcheck token must not be shown"461+ .store
462+ .recent_runs(5)
463+ .await
464+ .expect("runs")
465+ .is_empty(),
466+ "busy run records nothing"
464 );467 );
465- assert!(body.contains("Run backup now"));468+ drop(held);
466- assert!(body.contains("Run fsck now"));
467- }
468 469
469- #[tokio::test]470+ // A POST without the CSRF token is refused. With it, fsck starts, is audited and recorded.
470- async fn post_starts_a_run_audits_it_and_records_it() {
471- let fx = fixture(true).await;
472- // Refused without the CSRF token.
473 let (bad, _) = send(471 let (bad, _) = send(
474 &fx.router,472 &fx.router,
475 "POST",473 "POST",
@@ -478,7 +476,7 @@ mod tests {
478 Some("csrf=wrong".into()),476 Some("csrf=wrong".into()),
479 )477 )
480 .await;478 .await;
481- assert_eq!(bad, 403);479+ assert_eq!(bad, 403, "fsck without csrf");
482 480
483 let (status, _) = send(481 let (status, _) = send(
484 &fx.router,482 &fx.router,
@@ -488,7 +486,7 @@ mod tests {
488 Some(format!("csrf={CSRF}")),486 Some(format!("csrf={CSRF}")),
489 )487 )
490 .await;488 .await;
491- assert_eq!(status, 303);489+ assert_eq!(status, 303, "fsck with csrf");
492 490
493 // Wait for the background fsck to finish and record itself.491 // Wait for the background fsck to finish and record itself.
494 let mut runs = Vec::new();492 let mut runs = Vec::new();
@@ -500,9 +498,9 @@ mod tests {
500 tokio::time::sleep(std::time::Duration::from_millis(20)).await;498 tokio::time::sleep(std::time::Duration::from_millis(20)).await;
501 }499 }
502 assert_eq!(runs.len(), 1, "{runs:?}");500 assert_eq!(runs.len(), 1, "{runs:?}");
503- assert_eq!(runs[0].kind, RunKind::Fsck);501+ assert_eq!(runs[0].kind, RunKind::Fsck, "fsck run kind");
504- assert_eq!(runs[0].trigger, RunTrigger::Manual);502+ assert_eq!(runs[0].trigger, RunTrigger::Manual, "fsck run trigger");
505- assert_eq!(runs[0].ok, Some(true));503+ assert_eq!(runs[0].ok, Some(true), "fsck run result");
506 504
507 let audit = fx505 let audit = fx
508 .state506 .state
@@ -510,42 +508,43 @@ mod tests {
510 .list_audit(&Default::default(), None, 10)508 .list_audit(&Default::default(), None, 10)
511 .await509 .await
512 .expect("audit");510 .expect("audit");
513- assert!(audit.iter().any(|e| e.action == AuditAction::FsckStarted));511+ assert!(
512+ audit.iter().any(|e| e.action == AuditAction::FsckStarted),
513+ "fsck is audited"
514+ );
514 515
515 let (_, page) = send(&fx.router, "GET", "/admin/backups", Some(ADMIN_TOKEN), None).await;516 let (_, page) = send(&fx.router, "GET", "/admin/backups", Some(ADMIN_TOKEN), None).await;
516- assert!(page.contains("fsck"));517+ assert!(page.contains("fsck"), "fsck run is listed");
517- }
518 518
519- #[tokio::test]519+ // The page lists runs, and the healthcheck URL is shown without its secret token.
520- async fn a_backup_run_while_one_is_active_says_already_running() {520+ let mut config = (*fx.state.config).clone();
521- let fx = fixture(true).await;521+ config.backup.healthcheck_url = "https://hc.example.test/ping/SECRET-TOKEN".into();
522- let _held = fx.state.jobs.claim(RunKind::Backup).expect("claim");522+ let mut state = fx.state.clone();
523- let (status, _) = send(523+ state.config = std::sync::Arc::new(config);
524- &fx.router,524+ let router = app_router(state.clone());
525- "POST",525+
526- "/admin/backups/run",526+ let id = state
527- Some(ADMIN_TOKEN),527+ .store
528- Some(format!("csrf={CSRF}")),528+ .start_run(RunKind::Backup, RunTrigger::Schedule)
529- )529+ .await
530- .await;530+ .expect("start");
531- assert_eq!(status, 303);531+ state
532- let (_, page) = send(532+ .store
533- &fx.router,533+ .finish_run(&id, false, None, None, Some("disk full"))
534- "GET",534+ .await
535- "/admin/backups?notice=already%20running%3A%20x",535+ .expect("finish");
536- Some(ADMIN_TOKEN),536+
537- None,537+ let (status, body) = send(&router, "GET", "/admin/backups", Some(ADMIN_TOKEN), None).await;
538- )538+ assert_eq!(status, 200);
539- .await;539+ assert!(body.contains("schedule"));
540- assert!(page.contains("already running"));540+ assert!(body.contains("disk full"));
541+ assert!(body.contains("hc.example.test"));
541 assert!(542 assert!(
542- fx.state543+ !body.contains("SECRET-TOKEN"),
543- .store544+ "the healthcheck token must not be shown"
544- .recent_runs(5)
545- .await
546- .expect("runs")
547- .is_empty()
548 );545 );
546+ assert!(body.contains("Run backup now"));
547+ assert!(body.contains("Run fsck now"));
549 }548 }
550 549
551 #[tokio::test]550 #[tokio::test]
crates/forge-web/src/pages/admin_replication.rsmodified+32 -34
@@ -421,11 +421,15 @@ mod tests {
421 (status, String::from_utf8_lossy(&bytes).into_owned())421 (status, String::from_utf8_lossy(&bytes).into_owned())
422 }422 }
423 423
424+ /// One configured instance serves the page and reconcile scenarios below, since building it is
425+ /// the slow part. The scenarios run in order, each asserting only its own result.
424 #[tokio::test]426 #[tokio::test]
425- async fn page_and_reconcile_are_404_for_anonymous_and_non_admins() {427+ async fn replication_page_and_reconcile() {
426 let fx = fixture(true).await;428 let fx = fixture(true).await;
429+
430+ // Anonymous visitors and plain users get a 404 for the page and the reconcile endpoint.
427 let (anon, _) = send(&fx.router, "GET", "/admin/replication", None, None).await;431 let (anon, _) = send(&fx.router, "GET", "/admin/replication", None, None).await;
428- assert_eq!(anon, 404);432+ assert_eq!(anon, 404, "anonymous page");
429 let (user, _) = send(433 let (user, _) = send(
430 &fx.router,434 &fx.router,
431 "GET",435 "GET",
@@ -434,7 +438,7 @@ mod tests {
434 None,438 None,
435 )439 )
436 .await;440 .await;
437- assert_eq!(user, 404);441+ assert_eq!(user, 404, "plain user page");
438 let (posted, _) = send(442 let (posted, _) = send(
439 &fx.router,443 &fx.router,
440 "POST",444 "POST",
@@ -443,13 +447,10 @@ mod tests {
443 Some(format!("csrf={CSRF}")),447 Some(format!("csrf={CSRF}")),
444 )448 )
445 .await;449 .await;
446- assert_eq!(posted, 404);450+ assert_eq!(posted, 404, "plain user reconcile");
447 assert!(!fx.state.replication.take_reconcile_request());451 assert!(!fx.state.replication.take_reconcile_request());
448- }
449 452
450- #[tokio::test]453+ // The page shows the target and repo health, without secrets, and keeps stale rows visible.
451- async fn page_shows_target_db_and_repo_health_without_secrets() {
452- let fx = fixture(true).await;
453 let store = &fx.state.store;454 let store = &fx.state.store;
454 store455 store
455 .record_replication_ok(DB_SUBJECT, None)456 .record_replication_ok(DB_SUBJECT, None)
@@ -482,21 +483,18 @@ mod tests {
482 );483 );
483 assert!(body.contains("pending cleanup"));484 assert!(body.contains("pending cleanup"));
484 assert!(body.contains("Reconcile now"));485 assert!(body.contains("Reconcile now"));
485- }
486 486
487- #[tokio::test]487+ // A reconcile without the CSRF token is refused. With it, the request is queued and audited.
488- async fn unconfigured_page_says_so_and_reconcile_is_refused() {488+ let (bad, _) = send(
489- let fx = fixture(false).await;
490- let (status, body) = send(
491 &fx.router,489 &fx.router,
492- "GET",490+ "POST",
493- "/admin/replication",491+ "/admin/replication/reconcile",
494 Some(ADMIN_TOKEN),492 Some(ADMIN_TOKEN),
495- None,493+ Some("csrf=wrong".into()),
496 )494 )
497 .await;495 .await;
498- assert_eq!(status, 200);496+ assert_eq!(bad, 403, "reconcile without csrf");
499- assert!(body.contains("Replication is off"));497+ assert!(!fx.state.replication.take_reconcile_request());
500 498
501 let (status, _) = send(499 let (status, _) = send(
502 &fx.router,500 &fx.router,
@@ -506,8 +504,8 @@ mod tests {
506 Some(format!("csrf={CSRF}")),504 Some(format!("csrf={CSRF}")),
507 )505 )
508 .await;506 .await;
509- assert_eq!(status, 303);507+ assert_eq!(status, 303, "reconcile with csrf");
510- assert!(!fx.state.replication.take_reconcile_request());508+ assert!(fx.state.replication.take_reconcile_request());
511 let audit = fx509 let audit = fx
512 .state510 .state
513 .store511 .store
@@ -515,25 +513,26 @@ mod tests {
515 .await513 .await
516 .expect("audit");514 .expect("audit");
517 assert!(515 assert!(
518- !audit516+ audit
519 .iter()517 .iter()
520- .any(|e| e.action == AuditAction::ReplicationReconcileStarted)518+ .any(|e| e.action == AuditAction::ReplicationReconcileStarted),
519+ "the request is audited"
521 );520 );
522 }521 }
523 522
524 #[tokio::test]523 #[tokio::test]
525- async fn reconcile_needs_csrf_and_is_audited() {524+ async fn unconfigured_page_says_so_and_reconcile_is_refused() {
526- let fx = fixture(true).await;525+ let fx = fixture(false).await;
527- let (bad, _) = send(526+ let (status, body) = send(
528 &fx.router,527 &fx.router,
529- "POST",528+ "GET",
530- "/admin/replication/reconcile",529+ "/admin/replication",
531 Some(ADMIN_TOKEN),530 Some(ADMIN_TOKEN),
532- Some("csrf=wrong".into()),531+ None,
533 )532 )
534 .await;533 .await;
535- assert_eq!(bad, 403);534+ assert_eq!(status, 200);
536- assert!(!fx.state.replication.take_reconcile_request());535+ assert!(body.contains("Replication is off"));
537 536
538 let (status, _) = send(537 let (status, _) = send(
539 &fx.router,538 &fx.router,
@@ -544,7 +543,7 @@ mod tests {
544 )543 )
545 .await;544 .await;
546 assert_eq!(status, 303);545 assert_eq!(status, 303);
547- assert!(fx.state.replication.take_reconcile_request());546+ assert!(!fx.state.replication.take_reconcile_request());
548 let audit = fx547 let audit = fx
549 .state548 .state
550 .store549 .store
@@ -552,10 +551,9 @@ mod tests {
552 .await551 .await
553 .expect("audit");552 .expect("audit");
554 assert!(553 assert!(
555- audit554+ !audit
556 .iter()555 .iter()
557- .any(|e| e.action == AuditAction::ReplicationReconcileStarted),556+ .any(|e| e.action == AuditAction::ReplicationReconcileStarted)
558- "the request is audited"
559 );557 );
560 }558 }
561 559
crates/forge-web/src/pages/assets.rsmodified+29 -46
@@ -261,8 +261,9 @@ mod tests {
261 use topcoat::router::{Body, Router, RouterBuilderDiscoverExt, to_bytes};261 use topcoat::router::{Body, Router, RouterBuilderDiscoverExt, to_bytes};
262 262
263 #[tokio::test]263 #[tokio::test]
264- async fn bundled_fonts_are_served_as_immutable_woff2() {264+ async fn fonts_and_licenses_are_served() {
265 let router: Router = Router::builder().discover().cookies().build();265 let router: Router = Router::builder().discover().cookies().build();
266+ // Bundled fonts are immutable woff2 files.
266 for uri in [267 for uri in [
267 "/assets/fonts/figtree-5.3.0-latin-wght.woff2",268 "/assets/fonts/figtree-5.3.0-latin-wght.woff2",
268 "/assets/fonts/figtree-5.3.0-latin-ext-wght.woff2",269 "/assets/fonts/figtree-5.3.0-latin-ext-wght.woff2",
@@ -287,11 +288,8 @@ mod tests {
287 let body = to_bytes(res.into_body(), usize::MAX).await.unwrap();288 let body = to_bytes(res.into_body(), usize::MAX).await.unwrap();
288 assert!(body.starts_with(b"wOF2"), "{uri}");289 assert!(body.starts_with(b"wOF2"), "{uri}");
289 }290 }
290- }
291 291
292- #[tokio::test]292+ // Font licences are plain text.
293- async fn font_licenses_are_served_as_text() {
294- let router: Router = Router::builder().discover().cookies().build();
295 for uri in [293 for uri in [
296 "/assets/fonts/Figtree-OFL.txt",294 "/assets/fonts/Figtree-OFL.txt",
297 "/assets/fonts/IBMPlexMono-OFL.txt",295 "/assets/fonts/IBMPlexMono-OFL.txt",
@@ -339,27 +337,33 @@ mod tests {
339 }337 }
340 338
341 #[tokio::test]339 #[tokio::test]
342- async fn nav_script_is_served_as_immutable_javascript() {340+ async fn immutable_assets_are_served_with_long_cache() {
343 let router: Router = Router::builder().discover().cookies().build();341 let router: Router = Router::builder().discover().cookies().build();
344- let req = Request::builder()342+ // Each bundle is immutable under its own type. Its body holds the marker, when one is given.
345- .method("GET")343+ for (uri, kind, marker) in [
346- .uri(crate::views::NAV_SCRIPT_HREF)344+ ("/assets/main.css", "text/css; charset=utf-8", ""),
347- .body(Body::empty())345+ (crate::views::NAV_SCRIPT_HREF, "text/javascript; charset=utf-8", "__forgeSoft"),
348- .unwrap();346+ (crate::views::highlight_href(), "text/css; charset=utf-8", ""),
349- let res = router.handle(req).await;347+ ] {
350- assert_eq!(res.status(), 200);348+ let req = Request::builder()
351- assert_eq!(349+ .method("GET")
352- res.headers()["content-type"],350+ .uri(uri)
353- "text/javascript; charset=utf-8"351+ .body(Body::empty())
354- );352+ .unwrap();
355- assert!(353+ let res = router.handle(req).await;
356- res.headers()["cache-control"]354+ assert_eq!(res.status(), 200, "{uri}");
357- .to_str()355+ assert_eq!(res.headers()["content-type"], kind, "{uri}");
358- .unwrap()356+ assert!(
359- .contains("immutable")357+ res.headers()["cache-control"]
360- );358+ .to_str()
361- let body = to_bytes(res.into_body(), usize::MAX).await.unwrap();359+ .unwrap()
362- assert!(String::from_utf8_lossy(&body).contains("__forgeSoft"));360+ .contains("immutable"),
361+ "{uri}"
362+ );
363+ let body = to_bytes(res.into_body(), usize::MAX).await.unwrap();
364+ assert!(!body.is_empty(), "{uri}");
365+ assert!(String::from_utf8_lossy(&body).contains(marker), "{uri}");
366+ }
363 }367 }
364 368
365 #[tokio::test]369 #[tokio::test]
@@ -412,27 +416,6 @@ mod tests {
412 }416 }
413 }417 }
414 418
415- #[tokio::test]
416- async fn highlight_css_is_served_with_long_cache() {
417- let router: Router = Router::builder().discover().cookies().build();
418- let req = Request::builder()
419- .method("GET")
420- .uri(crate::views::highlight_href())
421- .body(Body::empty())
422- .unwrap();
423- let res = router.handle(req).await;
424- assert_eq!(res.status(), 200);
425- assert_eq!(res.headers()["content-type"], "text/css; charset=utf-8");
426- assert!(
427- res.headers()["cache-control"]
428- .to_str()
429- .unwrap()
430- .contains("immutable")
431- );
432- let body = to_bytes(res.into_body(), usize::MAX).await.unwrap();
433- assert!(!body.is_empty());
434- }
435-
436 #[tokio::test]419 #[tokio::test]
437 async fn custom_css_keys_the_hue_choices_and_is_empty_without_one() {420 async fn custom_css_keys_the_hue_choices_and_is_empty_without_one() {
438 let router: Router = Router::builder().discover().cookies().build();421 let router: Router = Router::builder().discover().cookies().build();
crates/forge-web/src/pages/audit_log.rsmodified+7 -18
@@ -365,17 +365,16 @@ mod tests {
365 }365 }
366 366
367 #[tokio::test]367 #[tokio::test]
368- async fn admin_page_is_404_for_anonymous_and_non_admins() {368+ async fn audit_log_pages_and_recording() {
369 let fx = fixture().await;369 let fx = fixture().await;
370+
371+ // The admin page is 404 for anonymous visitors and plain users.
370 let (anon, _) = send(&fx.router, "GET", "/admin/audit", None, None).await;372 let (anon, _) = send(&fx.router, "GET", "/admin/audit", None, None).await;
371 assert_eq!(anon, 404);373 assert_eq!(anon, 404);
372 let (user, _) = send(&fx.router, "GET", "/admin/audit", Some(TOKEN), None).await;374 let (user, _) = send(&fx.router, "GET", "/admin/audit", Some(TOKEN), None).await;
373 assert_eq!(user, 404);375 assert_eq!(user, 404);
374- }
375 376
376- #[tokio::test]377+ // The admin page lists entries and filters them by action.
377- async fn admin_page_lists_entries_and_filters_by_action() {
378- let fx = fixture().await;
379 let admin = fx.store.create_user("root", None, "h", true).await.unwrap();378 let admin = fx.store.create_user("root", None, "h", true).await.unwrap();
380 crate::test_support::create_session(&fx.store, &admin.id, ADMIN_TOKEN, ADMIN_CSRF).await;379 crate::test_support::create_session(&fx.store, &admin.id, ADMIN_TOKEN, ADMIN_CSRF).await;
381 let mut entry = AuditEntry::new(AuditAction::LoginFailed);380 let mut entry = AuditEntry::new(AuditAction::LoginFailed);
@@ -416,11 +415,8 @@ mod tests {
416 )415 )
417 .await;416 .await;
418 assert!(body.contains("There is no action named nonsense."));417 assert!(body.contains("There is no action named nonsense."));
419- }
420 418
421- #[tokio::test]419+ // Adding an SSH key is recorded in the audit log.
422- async fn adding_an_ssh_key_is_recorded() {
423- let fx = fixture().await;
424 let form = form_urlencoded::Serializer::new(String::new())420 let form = form_urlencoded::Serializer::new(String::new())
425 .append_pair("csrf", CSRF)421 .append_pair("csrf", CSRF)
426 .append_pair("title", "laptop")422 .append_pair("title", "laptop")
@@ -445,11 +441,8 @@ mod tests {
445 assert_eq!(rows[0].actor_id.as_deref(), Some(fx.user.id.as_str()));441 assert_eq!(rows[0].actor_id.as_deref(), Some(fx.user.id.as_str()));
446 assert_eq!(rows[0].target_name, "laptop");442 assert_eq!(rows[0].target_name, "laptop");
447 assert_eq!(rows[0].target_kind, "ssh_key");443 assert_eq!(rows[0].target_kind, "ssh_key");
448- }
449 444
450- #[tokio::test]445+ // The own log shows only entries about the viewer.
451- async fn own_log_shows_only_entries_about_the_viewer() {
452- let fx = fixture().await;
453 let bob = fx.store.create_user("bob", None, "h", false).await.unwrap();446 let bob = fx.store.create_user("bob", None, "h", false).await.unwrap();
454 let mut mine = AuditEntry::new(AuditAction::LoginSuccess);447 let mut mine = AuditEntry::new(AuditAction::LoginSuccess);
455 mine.actor_id = Some(fx.user.id.clone());448 mine.actor_id = Some(fx.user.id.clone());
@@ -477,15 +470,11 @@ mod tests {
477 assert_eq!(status, 200);470 assert_eq!(status, 200);
478 assert_eq!(body.matches("login_success").count(), 1);471 assert_eq!(body.matches("login_success").count(), 1);
479 assert!(body.contains("password_reset_by_admin"));472 assert!(body.contains("password_reset_by_admin"));
480- }
481 473
482- #[tokio::test]474+ // The own log needs a session.
483- async fn own_log_requires_a_session() {
484- let fx = fixture().await;
485 let (status, _) = send(&fx.router, "GET", "/settings/security/log", None, None).await;475 let (status, _) = send(&fx.router, "GET", "/settings/security/log", None, None).await;
486 assert_eq!(status, 303);476 assert_eq!(status, 303);
487 }477 }
488-
489 #[test]478 #[test]
490 fn anonymous_actor_and_target_fallbacks() {479 fn anonymous_actor_and_target_fallbacks() {
491 let mut entry = AuditEntry::new(AuditAction::LoginFailed);480 let mut entry = AuditEntry::new(AuditAction::LoginFailed);