"""The read-only guard is the only thing preventing this client from spending the user's money or taking someone's class spot. Test it hard.""" from __future__ import annotations import pytest from wodify import actions def test_every_registered_action_is_read_only(): for key, action in actions.ACTIONS.items(): actions.assert_read_only(action.path) # must not raise assert action.key == key, "registry key must match Action.key" assert action.path, f"{key} has no path" assert not action.path.startswith("/"), f"{key} path should be relative" def test_get_returns_action(): assert actions.get("bookings").key == "bookings" def test_unknown_action_rejected(): with pytest.raises(actions.UnknownActionError): actions.get("definitely-not-a-real-action") # Real mutating endpoint names observed in Wodify's client, plus plausible # variants. None may ever pass the guard. @pytest.mark.parametrize("path", [ "WodifyClient_Class/Classes/Class/ServiceAPICreateClassReservation", "WodifyClient_Class/Classes/Class/ActionCancelReservation", "WodifyClient_DataFetch_WB/WOD_Flow/SaveWorkoutResult", "WodifyClient/Common/ActionAcceptTermsAndConditions", "WodifyClient_Class/Classes/Class/ClientActionSignInToClass", "WodifyClient/MainScreens/ActionSubmitAppReview", "WodifyClient_Class/Classes/ActionLeaveWaitlist", "WodifyClient/Account/ActionLogout", "WodifyClient/POS/ActionPurchaseItem", "WodifyClient/WOD/ActionAddResult", ]) def test_write_endpoints_are_refused(path): with pytest.raises(actions.WriteAttemptError): actions.assert_read_only(path) def test_guard_is_case_insensitive(): with pytest.raises(actions.WriteAttemptError): actions.assert_read_only("Module/Screen/ACTIONCREATERESERVATION") def test_guard_does_not_block_legitimate_read_paths(): """Guard markers must not false-positive on the reads we actually need. 'GetClassWaitList' in particular has to stay callable -- reading a waitlist is fine, joining or leaving it is not. """ safe = [ "WodifyClient_DataFetch_WB/Schedule_OS/GetClassWaitList_WB/DataActionGetClassWaitList", "WodifyClient_DataFetch_WB/Schedule_OS/GetClassAttendees_WB/DataActionGetClassAttendees", "WodifyClient_DataFetch_WB/WOD_Flow/GetWorkoutData_HasWodLeaderboardComponents" "/DataActionGetWorkoutDataHasWodLeaderboardComponents", "WodifyClient_Class/Classes/Attendance/DataActionGetClasses", ] for path in safe: actions.assert_read_only(path) def test_all_expected_actions_registered(): expected = {"bookings", "workout", "wodflags", "attendees", "classdetail", "coach", "schedule", "waitlist"} assert expected <= set(actions.keys()) def test_dead_home_getclasses_is_not_registered(): """The Home-variant GetClasses returns placeholders even when the real client calls it (confirmed live). It must stay out of the allowlist so nothing reports its empty response as a real answer.""" assert "classes" not in actions.ACTIONS for action in actions.ACTIONS.values(): assert "Classes/Attendance/DataActionGetClasses" not in action.path def test_get_returns_action_for_workout_probe(): """wodflags is deliberately not called 'workout': it returns a boolean, and naming it 'workout' invited reporting 'no workout' from a probe response.""" action = actions.get("wodflags") assert "NOT the workout text" in action.summary