test_opsec_tor_i2p_lesson.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. # SPDX-License-Identifier: Apache-2.0
  2. """The OPSEC lesson for Tor and I2P: registered, honest about what was read, diagrammed, and safe to read.
  3. docs/wiki/OPSEC-for-Tor-and-I2P-That-Holds-Up-Identities-Layers-Metadata-and-Habits.md is page 6 of the seven-page
  4. series on VPNs, Tor and I2P. It sets the Tor Project's own browsing advice beside the four layers of an identity
  5. (device, network, account, behavior), tells documented cases of mistakes by date and source with no person named,
  6. gives one honest checklist for a beginner and a separate one for a journalist or a person at risk, and points at
  7. organizations that help. A banner that claims more than was done, a dead link, a missing registration, an address
  8. outside the documentation ranges, a claim with no status or date, a diagram with no alt text, no source or no picture,
  9. a layer that lost its leaks, a case that names a person, a checklist that merged into the other, a link to a page
  10. that is not written yet, a link to a page that has a link cap, an extension of the darknet page that repeats it, or
  11. a line that states a security detail about this repository would each teach or reveal the wrong thing.
  12. """
  13. import json
  14. import re
  15. from pathlib import Path
  16. from wikitext import page_text
  17. ROOT = Path(__file__).resolve().parent.parent
  18. WIKI = ROOT / "docs" / "wiki"
  19. NAME = "OPSEC-for-Tor-and-I2P-That-Holds-Up-Identities-Layers-Metadata-and-Habits"
  20. PAGE = WIKI / f"{NAME}.md"
  21. DARKNET = WIKI / "The-Darknet-Landscape-Markets-OPSEC-Clearnet-and-Layering-Tor-I2P-and-VPN.md"
  22. BROWSING = "The-Browsing-Setups-Compared-Tor-Browser-Brave-Whonix-Tails-and-Qubes-with-Whonix"
  23. OVERVIEW = "Tor-I2P-and-the-Darknet-Without-the-Myths"
  24. LINK = re.compile(r"\]\(([A-Za-z0-9_-]+)\.md(?:#[^)]*)?\)")
  25. ADDR = re.compile(r"\b(?:\d{1,3}\.){3}\d{1,3}\b")
  26. ALLOWED_ADDR = re.compile(r"^(?:192\.0\.2\.\d{1,3}|198\.51\.100\.\d{1,3}|203\.0\.113\.\d{1,3})$")
  27. ONION = re.compile(r"\b[a-z2-7]{16,56}\.(?:onion|b32\.i2p)\b")
  28. STATUS_WORDS = ("Read", "General knowledge", "**est.**", "Observed", "Not read")
  29. URL = re.compile(r"\]\(https://[^)\s]+\)")
  30. DIAGRAM = re.compile(
  31. r"!\[(?P<alt>[^\]\n]*)\]\((?P<path>images/[^)\n]+\.png)\)\n\n<details>\n<summary>Diagram source \(Mermaid\)</summary>"
  32. r"\n\n```mermaid\n(?P<src>.*?)\n```\n\n</details>",
  33. re.DOTALL,
  34. )
  35. IMAGE_ANY = re.compile(r"!\[[^\]\n]*\]\([^)\n]+\)")
  36. MAX_ALT = 150
  37. EXPECTED_DIAGRAMS = 4
  38. DATE_READ = "2026-11-01"
  39. LONG_RANDOM = re.compile(r"[A-Za-z0-9+/=_-]{32,}")
  40. LAYERS = ("Device", "Network", "Account", "Behavior")
  41. RULES = ("Use Tor Browser and software set up for Tor", "Do not sign in as yourself", "Do not torrent over Tor",
  42. "Do not add extensions or plugins", "Use HTTPS", "Do not open downloaded documents while online",
  43. "Keep the window at its default size", "Keep the software updated", "Do not reuse an identity across contexts",
  44. "Do not pick your exit country")
  45. BEGINNER = "## A checklist for a beginner who wants to browse privately"
  46. AT_RISK = "## A checklist for a journalist or a person at risk"
  47. HELPERS = ("accessnow.org", "ssd.eff.org", "freedom.press", "digitalfirstaid.org", "cpj.org", "securityinabox.org")
  48. PEOPLE = ("Ulbricht", "Eldo", "McAfee", "Cazes", "Dread Pirate", "Roberts")
  49. def text() -> str:
  50. return page_text(PAGE)
  51. def register_rows(body: str) -> list[list[str]]:
  52. reg = body.split("## Claims register")[1]
  53. rows = [line for line in reg.splitlines() if line.startswith("|") and not line.startswith("|---")]
  54. return [[c.strip() for c in r.strip("|").split("|")] for r in rows[1:]]
  55. def rows_missing_status(body: str) -> list[str]:
  56. return [r[0] for r in register_rows(body) if not any(w in r[-1] for w in STATUS_WORDS)]
  57. def stray_addresses(body: str) -> list[str]:
  58. return [a for a in ADDR.findall(body) if not ALLOWED_ADDR.match(a)]
  59. def tables(body: str) -> list[list[str]]:
  60. """Every markdown table as its list of lines, found by a header line followed by a separator line."""
  61. lines = body.splitlines()
  62. found = []
  63. for i, line in enumerate(lines[:-1]):
  64. if line.startswith("|") and re.match(r"^\|(?:\s*:?-{3,}:?\s*\|)+\s*$", lines[i + 1]):
  65. block = [line]
  66. for later in lines[i + 2:]:
  67. if not later.startswith("|"):
  68. break
  69. block.append(later)
  70. found.append(block)
  71. return found
  72. def unnamed_first_cells(body: str) -> list[str]:
  73. return [t[0] for t in tables(body) if not t[0].strip("|").split("|")[0].strip()]
  74. def section(body: str, heading: str) -> str:
  75. start = body.index(heading)
  76. return body[start:].split("\n## ", 1)[0]
  77. def table_in(body: str, heading: str) -> list[list[str]]:
  78. block = next(iter(tables(section(body, heading))), None)
  79. assert block is not None, f"no table under {heading}"
  80. return [[c.strip() for c in r.strip("|").split("|")] for r in block[1:]]
  81. def layer_problems(body: str) -> list[str]:
  82. """The layers table has the four layers in order and every row says what leaks and what Tor or I2P changes."""
  83. rows = table_in(body, "## The four layers of an identity")
  84. problems = []
  85. if [r[0].split(":")[-1].strip() for r in rows] != list(LAYERS):
  86. problems.append(f"layers are {[r[0] for r in rows]}")
  87. for r in rows:
  88. if len(r) != 4 or any(len(c) < 30 for c in r[1:]):
  89. problems.append(f"thin row: {r[0]}")
  90. return problems
  91. def rule_problems(body: str) -> list[str]:
  92. rows = table_in(body, "## The Tor Project's own advice, one rule at a time")
  93. problems = []
  94. if [r[0] for r in rows] != list(RULES):
  95. problems.append(f"rules are {[r[0] for r in rows]}")
  96. for r in rows:
  97. if len(r) != 4 or not URL.search(r[3]) or DATE_READ not in r[3]:
  98. problems.append(f"rule without a dated source: {r[0]}")
  99. return problems
  100. def diagram_problems(body: str, root: Path = ROOT, wiki: Path = WIKI) -> list[str]:
  101. """Every picture on the page is a wrapped diagram with alt text, a Mermaid source and a picture on disk."""
  102. problems = []
  103. wrapped = list(DIAGRAM.finditer(body))
  104. if len(wrapped) != len(IMAGE_ANY.findall(body)):
  105. problems.append("a picture on the page is not a wrapped diagram")
  106. for m in wrapped:
  107. alt = m["alt"].strip()
  108. if len(alt) < 20 or len(alt) > MAX_ALT:
  109. problems.append(f"alt text length {len(alt)}: {alt[:40]!r}")
  110. if not m["src"].strip():
  111. problems.append(f"empty source for {m['path']}")
  112. if not (wiki / m["path"]).is_file():
  113. problems.append(f"picture missing: {m['path']}")
  114. return problems
  115. def names_a_person(body: str) -> list[str]:
  116. return [p for p in PEOPLE if re.search(rf"\b{re.escape(p)}\b", body)]
  117. def checklist_items(body: str, heading: str) -> list[str]:
  118. return [ln for ln in section(body, heading).splitlines() if re.match(r"^\d+\. ", ln)]
  119. def test_the_banner_says_it_was_written_from_reading_and_nothing_was_run():
  120. body = text()
  121. assert body.startswith("# OPSEC for Tor and I2P that holds up")
  122. assert "Page 6 of a seven-page series" in body
  123. assert "Status: unverified draft, written from reading" in body
  124. assert "Nothing on this page was run" in body
  125. assert "**Not run:**" in body and DATE_READ in body
  126. assert "## Not verified, plainly" in body
  127. def test_every_linked_wiki_page_exists_and_the_finished_siblings_are_linked():
  128. body = text()
  129. links = set(LINK.findall(body))
  130. assert len(links) >= 10, "the guard collected too few links"
  131. missing = sorted(t for t in links if not (WIKI / f"{t}.md").exists())
  132. assert not missing, missing
  133. for needed in (
  134. OVERVIEW, BROWSING,
  135. "How-Tor-Works-in-Depth-Circuits-Relays-Directory-Authorities-and-Onion-Services",
  136. "How-I2P-Works-Tunnels-Garlic-Routing-and-the-Network-Database",
  137. "How-a-VPN-Works-Tunnels-What-It-Hides-What-It-Does-Not-and-What-an-Audit-Proves",
  138. "Privacy-Security-and-Anonymity-Three-Different-Things-and-Why-There-Is-No-Silver-Bullet",
  139. "The-Darknet-Landscape-Markets-OPSEC-Clearnet-and-Layering-Tor-I2P-and-VPN",
  140. "Privacy-vs-Security-Blinds-and-Locks-Physical-Security-and-Monero",
  141. "Cryptography-Fundamentals-Symmetric-Asymmetric-Hashing-Certificates-and-Keys",
  142. "Threat-Model",
  143. ):
  144. assert needed in links, needed
  145. def test_the_detecting_page_is_linked_now_that_it_exists():
  146. body = text()
  147. assert "detecting and managing Tor, I2P and VPN traffic on a network" in body
  148. found = {t for t in LINK.findall(body) if t.startswith("Detecting-and-Managing-Tor-I2P-and-VPN-")}
  149. assert found, "the series page 7 exists and must be linked"
  150. assert all((WIKI / f"{t}.md").exists() for t in found), found
  151. # The stale statement that the last page is not written yet is gone.
  152. assert "The last page is not written yet" not in body
  153. EXERCISES = "Hands-On-Whonix-and-Qubes-OS-Gateway-Split-Compartments-Disposables-and-Policy-Prompts"
  154. def exercise_links(body: str) -> set[str]:
  155. return {t for t in LINK.findall(body) if t == EXERCISES}
  156. def test_the_whonix_and_qubes_exercises_are_linked_now_that_they_exist():
  157. body = text()
  158. assert "hands-on Whonix and Qubes exercises" in body
  159. assert exercise_links(body) == {EXERCISES}, "the exercises page (issue 372) exists and must be linked"
  160. assert (WIKI / f"{EXERCISES}.md").is_file()
  161. # The stale statement that the exercises are not written yet is gone.
  162. assert "are not written yet, so they are named in plain text" not in body
  163. def test_the_exercise_link_guard_bites():
  164. assert not exercise_links("the hands-on Whonix and Qubes exercises (issue 372) are not written yet")
  165. assert exercise_links(f"the [hands-on Whonix and Qubes exercises]({EXERCISES}.md)")
  166. def test_a_page_with_a_link_cap_is_not_linked():
  167. # tests/test_blast_radius_lesson.py caps how many pages may link that lesson, and the cap is full.
  168. assert "Plan-for-Failure-Blast-Radius" not in text()
  169. def test_the_lesson_is_registered_in_contents_reading_order_and_nav_after_the_browsing_page():
  170. nav = (WIKI / "_nav.yaml").read_text(encoding="utf-8")
  171. assert f"page: {NAME}," in nav
  172. for special in ("Contents.md", "Reading-Order.md"):
  173. assert f"{NAME}.md" in (WIKI / special).read_text(encoding="utf-8"), special
  174. lines = nav.splitlines()
  175. idx = next(i for i, row in enumerate(lines) if f"page: {NAME}," in row)
  176. assert f"page: {BROWSING}," in lines[idx - 1], "the page follows the browsing setups page in the track"
  177. assert 'status: "draft"' in lines[idx] and 'subgroup: "Tor, I2P, VPN and browsing"' in lines[idx]
  178. related = re.search(r"related: \[([^\]]*)\]", lines[idx]).group(1).split(", ")
  179. assert 3 <= len(related) <= 6, related
  180. assert all((WIKI / f"{r}.md").exists() for r in related), related
  181. def test_glossary_rows_point_at_real_headings():
  182. heads = {re.sub(r"[^a-z0-9-]", "", re.sub(r"[^a-z0-9 -]", "", h.lower()).strip().replace(" ", "-"))
  183. for h in re.findall(r"^#+ (.+)$", text(), re.MULTILINE)}
  184. anchors = set()
  185. terms = []
  186. glossary = (WIKI / "Glossary.md").read_text(encoding="utf-8").splitlines()
  187. for line in glossary:
  188. if f"{NAME}.md" in line:
  189. terms.append(line.split("|")[1].strip().strip("*").lower())
  190. anchors.update(re.findall(rf"{NAME}\.md#([a-z0-9-]+)", line))
  191. assert len(terms) >= 4, "expected glossary rows for the new terms"
  192. assert len(set(terms)) == len(terms), "a glossary term is defined twice"
  193. every = [ln.split("|")[1].strip().strip("*").lower() for ln in glossary if ln.startswith("| **")]
  194. assert all(every.count(t) == 1 for t in terms), [t for t in terms if every.count(t) != 1]
  195. assert anchors and anchors <= heads, sorted(anchors - heads)
  196. def test_only_documentation_addresses_no_onion_names_long_random_values_or_em_dashes():
  197. body = text()
  198. assert not stray_addresses(body), set(stray_addresses(body))
  199. assert not ONION.findall(body)
  200. assert "—" not in body
  201. visible = re.sub(r"\]\([^)\s]+\)", "]()", body)
  202. runs = [r for r in LONG_RANDOM.findall(visible) if re.search(r"[0-9]", r) and re.search(r"[A-Za-z]", r)]
  203. assert not runs, runs
  204. def test_the_address_guard_bites():
  205. assert stray_addresses("host 8.8.8.8") == ["8.8.8.8"]
  206. assert stray_addresses("host 10.0.0.1 and 192.0.3.1") == ["10.0.0.1", "192.0.3.1"]
  207. assert not stray_addresses("Alice 192.0.2.10 and 203.0.113.50")
  208. assert ONION.findall("go to " + "a" * 56 + ".onion")
  209. assert LONG_RANDOM.findall("x" + "a1" * 20)
  210. def test_every_diagram_has_alt_text_a_source_block_and_a_picture_that_exists():
  211. body = text()
  212. wrapped = list(DIAGRAM.finditer(body))
  213. assert len(wrapped) == EXPECTED_DIAGRAMS, f"expected {EXPECTED_DIAGRAMS} diagrams, found {len(wrapped)}"
  214. assert not diagram_problems(body)
  215. manifest = json.loads((ROOT / "docs" / "diagrams.json").read_text())
  216. for m in wrapped:
  217. assert f"docs/wiki/{m['path']}" in manifest, m["path"]
  218. names = [m["path"] for m in wrapped]
  219. assert len(set(names)) == len(names)
  220. def test_the_diagram_guard_bites(tmp_path):
  221. wiki = tmp_path
  222. (wiki / "images").mkdir()
  223. alt = "Diagram, the four layers of an identity and where each one leaks when you use Tor or I2P"
  224. good = (f"![{alt}](images/a.png)\n\n<details>\n<summary>Diagram source (Mermaid)</summary>\n\n```mermaid\n"
  225. "flowchart LR\n a --> b\n```\n\n</details>")
  226. assert diagram_problems(good, tmp_path, wiki) == ["picture missing: images/a.png"]
  227. (wiki / "images" / "a.png").write_bytes(b"x")
  228. assert not diagram_problems(good, tmp_path, wiki)
  229. assert diagram_problems(good.replace(alt, "x"), tmp_path, wiki)
  230. assert diagram_problems(good.replace(alt, "x" * (MAX_ALT + 1)), tmp_path, wiki)
  231. assert diagram_problems("![alt text long enough to pass](images/a.png)\n\n```mermaid\nflowchart LR\n```", tmp_path, wiki)
  232. def test_the_diagrams_cover_the_required_topics():
  233. sources = " ".join(m["src"] for m in DIAGRAM.finditer(text())).lower()
  234. for term in ("device", "network", "account", "behavior", "fingerprint", "metadata", "ip address", "login",
  235. "writing style", "timing", "new identity", "separate", "restart", "threat model", "helpline"):
  236. assert term in sources, term
  237. def test_every_table_has_a_named_first_header_cell_and_the_guard_bites():
  238. assert len(tables(text())) >= 6, "the guard collected too few tables"
  239. assert not unnamed_first_cells(text()), unnamed_first_cells(text())
  240. assert unnamed_first_cells("| | B |\n|---|---|\n| x | y |\n") == ["| | B |"]
  241. assert not unnamed_first_cells("| A | B |\n|---|---|\n| x | y |\n")
  242. def test_the_layers_table_has_four_layers_each_with_leaks_and_what_tor_or_i2p_changes():
  243. body = text()
  244. assert not layer_problems(body), layer_problems(body)
  245. assert layer_problems(body.replace("| Layer 3: Account |", "| Layer 3: Login |", 1))
  246. sec = section(body, "## The four layers of an identity")
  247. for word in ("Tor and I2P act here", "You act here", "ISP"):
  248. assert word in sec, word
  249. def test_the_tor_projects_rules_are_all_present_each_with_a_dated_source():
  250. body = text()
  251. assert not rule_problems(body), rule_problems(body)
  252. assert rule_problems(body.replace("| Do not torrent over Tor |", "| Torrent as you like |", 1))
  253. sec = section(body, "## The Tor Project's own advice, one rule at a time")
  254. for word in ("support.torproject.org", "tb-manual.torproject.org", "letterboxing", "strongly discouraged",
  255. "must be kept updated", "practically impossible"):
  256. assert word in sec, word
  257. # The series plan's wording and the Tor Project's wording are told apart.
  258. assert "the series plan's wording" in sec.lower() or "wording of the series plan" in sec.lower()
  259. def test_the_login_exception_is_stated_with_its_example():
  260. sec = section(text(), "## Logins: the exception and what it costs")
  261. assert "censored" in sec and "unless" in sec.lower()
  262. assert "they know who you are" in sec
  263. def test_the_cases_have_a_date_a_layer_and_a_source_and_name_no_person():
  264. body = text()
  265. rows = table_in(body, "## Documented mistakes, by date and source")
  266. assert len(rows) >= 3, "the guard collected too few cases"
  267. for r in rows:
  268. assert len(r) == 5, r
  269. assert re.search(r"\b20\d\d\b", r[0]), r[0]
  270. assert any(layer in r[2] for layer in LAYERS), r[2]
  271. assert URL.search(r[4]) and DATE_READ in r[4], r[0]
  272. assert not names_a_person(body), names_a_person(body)
  273. assert names_a_person("a man named Eldo") == ["Eldo"]
  274. assert not names_a_person("the Second Circuit opinion")
  275. sec = section(body, "## Documented mistakes, by date and source")
  276. for word in ("allegation", "secondary", "Not read"):
  277. assert word in sec, word
  278. def test_the_darknet_page_is_extended_not_duplicated():
  279. darknet = page_text(DARKNET)
  280. assert f"({NAME}.md" in darknet, "the darknet page points at this page from its OPSEC section"
  281. trap = section(darknet, "## The OPSEC trap: perfect technique without a threat model")
  282. assert f"({NAME}.md" in trap
  283. mine = text()
  284. assert "## The OPSEC trap: perfect technique without a threat model" not in mine
  285. assert "The-Darknet-Landscape-Markets-OPSEC-Clearnet-and-Layering-Tor-I2P-and-VPN.md#the-opsec-trap" in mine
  286. # None of the darknet page's four-principle table rows is copied here.
  287. assert "### Four general principles, seen in public cases" not in mine
  288. def test_the_two_checklists_are_separate_and_each_item_is_a_numbered_action():
  289. body = text()
  290. assert body.index(BEGINNER) < body.index(AT_RISK)
  291. beginner, risk = checklist_items(body, BEGINNER), checklist_items(body, AT_RISK)
  292. assert len(beginner) >= 8 and len(risk) >= 8, (len(beginner), len(risk))
  293. low = section(body, BEGINNER).lower()
  294. for word in ("qubes", "whonix", "tails"):
  295. assert word not in low, f"the beginner list stays simple: {word}"
  296. risk_low = section(body, AT_RISK).lower()
  297. for word in ("threat model", "trainer", "helpline", "one purpose"):
  298. assert word in risk_low, word
  299. assert "does not replace" in risk_low
  300. assert checklist_items("## X\n\n1. a\n2. b\n", "## X") == ["1. a", "2. b"]
  301. def test_the_helpers_are_named_with_what_each_one_says_about_itself_and_the_date_read():
  302. sec = section(text(), "## Organizations that help people at risk")
  303. for host in HELPERS:
  304. assert host in sec, host
  305. assert sec.count(DATE_READ) >= 6
  306. for word in ("free-of-charge", "24/7", "two hours", "Digital First Aid Kit", "Safety Kit"):
  307. assert word in sec or word.lower() in sec.lower(), word
  308. def test_every_claims_register_row_has_a_status_a_source_and_the_read_date():
  309. rows = register_rows(text())
  310. assert len(rows) >= 28, "the guard collected too few rows"
  311. assert not rows_missing_status(text())
  312. sourced = [r for r in rows if URL.search(r[1])]
  313. assert len(sourced) >= 20, "the page reads twenty outside sources"
  314. for r in sourced:
  315. assert DATE_READ in r[2], r[0]
  316. sources = " ".join(r[1] for r in rows)
  317. for host in ("support.torproject.org", "tb-manual.torproject.org", "tails.net", "geti2p.net", "ssd.eff.org",
  318. "accessnow.org", "freedom.press", "digitalfirstaid.org", "cpj.org", "securityinabox.org",
  319. "nbcnews.com", "arxiv.org", "law.justia.com"):
  320. assert host in sources, host
  321. def test_the_register_guard_bites():
  322. bad = "## Claims register\n\n| Claim | Source | Status |\n|---|---|---|\n| X | y | maybe |\n"
  323. assert rows_missing_status(bad) == ["X"]
  324. def test_the_sources_are_cited_with_their_own_words_and_dates():
  325. body = text()
  326. for item in ("Generally it is impossible to have perfect anonymity", "Torrent file-sharing applications have been observed",
  327. "DO NOT IGNORE THIS WARNING", "Last Reviewed: January 28, 2025", "Tails is safe but not magic",
  328. "2012-12-04", "2013-12-18", "2017-05-31", "round-trip translation", "free route mixnet",
  329. "separate Firefox profile", "mat2", "It is impossible to reliably find and remove all metadata",
  330. "Seven Steps To Digital Security", "Simpler is Safer"):
  331. assert item in body, item
  332. def test_the_sections_run_in_order():
  333. body = text()
  334. order = ["## The idea in one paragraph", "## Threat model first, then tools",
  335. "## The four layers of an identity", "## The Tor Project's own advice, one rule at a time",
  336. "## One identity per compartment", "## Logins: the exception and what it costs",
  337. "## Files, photos and metadata", "## Writing style and timing", "## I2P: the same habits, a different pipe",
  338. "## Documented mistakes, by date and source", "## OPSEC theater: effort with no threat model",
  339. BEGINNER, AT_RISK, "## Organizations that help people at risk", "## Exercises", "## Checkpoint",
  340. "## Common mistakes", "## Not verified, plainly", "## Claims register"]
  341. positions = [body.index(h) for h in order]
  342. assert positions == sorted(positions)
  343. def test_the_page_carries_no_maintainer_opinion_or_badge_commentary():
  344. low = text().lower()
  345. for banned in ("larp", "skid", "poser", "badge", "the maintainer's view", "starter pack"):
  346. assert banned not in low, banned
  347. def test_the_page_states_nothing_about_this_repositorys_own_security_and_names_no_machine():
  348. lower = text().lower()
  349. for banned in ("this repository", "our droplet", "this project's lab", "twingate", "doppler", "spacelift", "hostname",
  350. "serial number of"):
  351. assert banned not in lower, banned
  352. def test_american_spelling_only():
  353. lower = text().lower()
  354. for british in ("behaviour", "colour", "defence", "anonymise", "organisation", "favour", "centre ", "licence",
  355. "recognise", "minimise", "analyse", "pseudonymise", "catalogue", "sceptic", "grey ", "whilst"):
  356. assert british not in lower, british
  357. def test_the_page_makes_no_evasion_how_to_or_illegal_content():
  358. body = text().lower()
  359. assert "no way around a block, a paywall or a rule" in body
  360. for banned in ("buy drugs", "vendor shop", "how to buy", "evade", "bypass the filter", "get around geo",
  361. "unblock netflix", "launder", "how to hide from", "step-by-step install", "sudo apt",
  362. "avoid law enforcement", "avoid detection"):
  363. assert banned not in body, banned
  364. assert "no address of any onion or i2p service" in body
  365. def test_the_law_note_tells_learners_to_check_their_jurisdiction():
  366. body = text()
  367. assert "Check the law where you live" in body
  368. assert "nothing here is legal advice" in body.lower()
  369. assert "No country's law was checked" in body
  370. def test_no_product_is_ranked_best_or_sold():
  371. lower = text().lower()
  372. for banned in ("best vpn", "the best browser", "we recommend", "i recommend", "top pick", "buy now", "affiliate link"):
  373. assert banned not in lower, banned