test_the_comment_endpoint_refuses_what_it_must

Tests › tests/test_wiki_hub.py

passed Passed in the packaged run.

What this test is for

Why it exists

SAME DOOR AS EVERY PAGE: the session cookie, JSON only (a cross-site form cannot send it without a preflight), the hub's own origin when one is sent, a size cap, and the store's own refusals (empty, over the limit) passed back with their reason.

Verifies REQ-DDB-WIKI-032 REQ-DDB-WIKI-033

Given

  1. server, builder, live, _gone = hub
  2. builder.release.set()
5 more
  1. url = f"http://127.0.0.1:{server.port}/api/{live.slug}/comment"
  2. cookie = f"clew_wiki={server.token}"
  3. good = json.dumps({"page": "a.html", "anchor": "", "quote": "", "body": "hi"}).encode()
  4. empty = json.dumps({"page": "a.html", "anchor": "", "quote": "", "body": " "}).encode()
  5. status, reply = _post(url, empty, cookie)
→

When

  1. —
→

Then

  1. ✓ _post(url, good)[0] equals 403
  2. ✓ _post(url, good, cookie, kind="text/plain")[0] equals 415
  3. ✓ _post(url, good, cookie, origin="http://evil.example")[0] equals 403
  4. ✓ _post(url, b"x" * 70_000, cookie)[0] equals 413
  5. ✓ status equals 400
  6. ✓ reply contains "empty"
  7. ✓ _post(f"http://127.0.0.1:{server.port}/api/nosuch/comment", good, cookie)[0] equals 404
  8. ✓ CommentStore.for_repo(server.home, live.repo_path).unread() equals []

What it exercises

The parts of the system's flows this test ran, measured by per-test coverage: lit steps ran in this test, dimmed ones did not, and ▶ marks where the test called in. Each title opens the whole flow with these steps lit.

Build this wiki from the index · 37 of 400 steps

callercallercallercallerclew/wiki/build.pyclew/wiki/build.pyclew/wiki/build.pyclew/wiki/build.pyclew/wiki/config.pyclew/wiki/config.pyclew/wiki/config.pyclew/wiki/config.pyother filesother filesother filesother filestry (line 708)trybuild_wiki1. build_wiki → load_wiki_config1load_wiki_config2. load_wiki_config → _read_section2_read_section▶ test enters3–6. load_wiki_config → _overlaid3_overlaid +3 more7. _requirements_section → read_requirements_section7read_requirements_section8. read_requirements_section → _validate_node8_validate_node

… 7 steps between

callercallercallercallercallerclew/wiki/build.pyclew/wiki/build.pyclew/wiki/build.pyclew/wiki/build.pyclew/wiki/build.pyclew/wiki/config.pyclew/wiki/config.pyclew/wiki/config.pyclew/wiki/config.pyclew/wiki/config.pyother filesother filesother filesother filesother filesloop (line 417)loopalt (line 421)altloop (line 135)loopopt (line 137)optloop (line 632)looptry (line 752)tryloop (line 1312)loopopt (line 1314)optbuild_wiki16. list → link16link17. _validate_dict_node → _validate_node17_validate_node18. load_wiki_config → _top_level18_top_level▶ test enters19–21. load_wiki_config → _unknown19_unknown +2 more22. _strings → all22all23. all → _events23_events▶ test enters24. all → _public24_public25. all → list25list26–28. load_wiki_config → _strings26_strings +2 more29. _audiences → _unknown29_unknown30–37. load_wiki_config → _pinned_catalogs30_pinned_catalogs +7 more38. _declared_report → read_guard_section38read_guard_section39–41. load_wiki_config → _issues39_issues +2 more42. _sbom → all42all43–47. load_wiki_config → _one_of43_one_of +4 more48. _comments → all48all49–55. load_wiki_config → _doc_tags49_doc_tags +6 more56. build_wiki → report_limit56report_limit57. build_wiki → _build_site57_build_site

… 343 later steps

4 more

tests/test_wiki_hub.py:410 · its file's page

What it checks (7)

  1. assert _post(url, good)[0] == 403 observes _post
  2. assert _post(url, good, cookie, kind="text/plain")[0] == 415 observes _post
  3. assert _post(url, good, cookie, origin="http://evil.example")[0] == 403 observes _post
  4. assert _post(url, b"x" * 70_000, cookie)[0] == 413 observes _post
  5. assert status == 400 and "empty" in reply not attributed
  6. assert _post(f"http://127.0.0.1:{server.port}/api/nosuch/comment", good, cookie)[0] == 404 observes _post
  7. assert CommentStore.for_repo(server.home, live.repo_path).unread() == [] not attributed

Where the product reaches it

No product flow reaches this code: no product entry point's flow calls any of the functions this test calls.

Call flow

test_the_comment_endpoint_refuses_what_it_must→_post

What it reaches

Each row runs from this test, through the calls it makes, to the code a requirement names. If that code breaks, the test's checks are what should catch it. Reaching is not proving: a check only proves what it observes. No mutation records were given, so these rows say what the test REACHES.

Requirements it verifies (2)

requirementlinked byimplementers exercised
REQ-DDB-WIKI-032catalogunknown
REQ-DDB-WIKI-033catalogunknown
Also reaches 2 requirements

Its run touches their code; that is reach, not proof.