open Hito_app open Support let suite = [ ( "web.isolation", [ ( "two trainees never share workout or logbook state", `Quick, fun () -> (* Two trainees on the same store, each with their own cookie jar. One begins and finishes a workout; the other must see none of it: not the in-progress workout, not the saved record. This proves the per-trainee scoping the service promises, over HTTP. *) let alice, repo = client_with_repo () in let _ = register alice ~username:"alice" ~password:"heavyduty1" in let bob = { alice with jar = [] } in let _ = register bob ~username:"bobby" ~password:"heavyduty1" in let alice_t = the_trainee repo ~username:"alice" in let bob_t = the_trainee repo ~username:"bobby" in (* Alice selects and begins a workout, records a slot. *) let token = Option.get (csrf_token (body (get alice "/"))) in let _ = post alice "/routines/ideal/select" [ ("dream.csrf", token) ] in let token = Option.get (csrf_token (body (get alice "/"))) in let _ = post alice "/workout" [ ("dream.csrf", token); ("override", "false") ] in let token = Option.get (csrf_token (body (get alice "/workout?slot=1"))) in let _ = post alice "/workout/slots/1" [ ("dream.csrf", token); ("load", "12"); ("reps", "8"); ("extension", ""); ] in (* Alice has a workout in progress; Bob does not. *) Alcotest.(check bool) "Alice has a workout in progress" true (Option.is_some (Lwt_main.run (Test_repo.in_progress repo alice_t.Trainee.id))); Alcotest.(check bool) "Bob has no workout in progress" true (Option.is_none (Lwt_main.run (Test_repo.in_progress repo bob_t.Trainee.id))); Alcotest.(check int) "Bob's workout view redirects" 303 (status (get bob "/workout")); (* Alice finishes; her record becomes t1:w1 for her. *) let token = Option.get (csrf_token (body (get alice "/workout"))) in let _ = post alice "/workout/finish" [ ("dream.csrf", token) ] in Alcotest.(check int) "Alice has one saved workout" 1 (List.length (Lwt_main.run (Test_repo.history repo alice_t.Trainee.id))); Alcotest.(check int) "Alice sees her saved workout" 200 (status (get alice "/logbook/t1:w1")); (* Bob's history is empty, and Alice's record is unreachable from Bob's session. The stored identity names Alice, so it does not exist. *) Alcotest.(check int) "Bob's history is empty" 0 (List.length (Lwt_main.run (Test_repo.history repo bob_t.Trainee.id))); Alcotest.(check int) "Bob cannot open a record he does not own" 404 (status (get bob "/logbook/t1:w1")) ); ] ); ]