""" An invitation link, opened in the real application (harness/invite_link_probe.py). The functions behind a link are tested one by one in `test_invite_link_client.py`; this is where they meet the router, the sign-in state and the hub. Two readers: one with no account, who must be sent to register with the invitation kept, and one signed in, who must be shown it, join with one click and land on the group. For both, the code never appears in a request to the hub — it is the node's, and the hub is only handed the ticket. """ import json import shutil import subprocess import sys from pathlib import Path import pytest HARNESS = Path(__file__).parent / "harness" / "invite_link_probe.py" @pytest.fixture(scope="module") def cases(): if shutil.which("google-chrome") is None: pytest.skip("Chrome is not available") proc = subprocess.run([sys.executable, str(HARNESS)], capture_output=True, text=True, timeout=180) assert proc.returncode == 0, f"probe failed: {proc.stdout}{proc.stderr}" out = {c["case"]: c for c in json.loads(proc.stdout)} for c in out.values(): assert "error" not in c, c["error"] return out @pytest.mark.parametrize("case", ["signed_out", "signed_in", "signed_in_listed"]) def test_the_code_is_out_of_the_address_and_kept_in_the_tab(cases, case): c = cases[case] assert c["hash_after_load"] == "#/invite" assert c["pending"] and c["pending"]["c"] == "K7P2-9WQX" @pytest.mark.parametrize("case", ["signed_out", "signed_in", "signed_in_listed"]) def test_the_code_never_reaches_the_hub(cases, case): assert cases[case]["code_in_a_hub_request"] is False def test_a_reader_with_no_account_is_sent_to_register_with_the_invitation_kept(cases): c = cases["signed_out"] assert c["register_link"] and c["hash_after_click"] == "#/register" assert c["pending_after_click"] is True assert not any("/invite-links/" in u for u in c["hub_calls"]), ( "nothing about the invitation is asked of the hub before sign-in") def test_a_signed_in_reader_joins_with_one_click_and_lands_on_the_group(cases): c = cases["signed_in"] assert "the-owner" in c["text_after_load"] and "Some Group" in c["text_after_load"] assert c["join_button"] assert c["redeem_bodies"] == ['{"ticket":"AbCdEfGhIjKlMnOpQr-_12"}'] assert c["hash_after_click"] == "#/group/0f8fad5b-d9cb-469f-a165-70867728950e" def test_once_listed_the_joined_group_opens_under_its_handle(cases): """The group links (group-link.js) rewrite `#/group/` to the handle as soon as the hub lists the group. Joining from an invitation must land on the group page all the same, under that handle, with the rewrite adding no history entry of its own — and still without the code reaching the hub.""" c = cases["signed_in_listed"] assert c["join_button"] assert c["hash_settled"] == "#/Some Group@the-owner" assert c["group_page"] is True # The page load, then the Join button's navigation; the rewrite replaces. assert c["history_length"] == 2