test_title.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import os
  2. import sqlite3
  3. from .fixtures import *
  4. def test_title_is_htmlencoded_in_index_html(tmp_path, process, disable_extractors_dict):
  5. """
  6. https://github.com/ArchiveBox/ArchiveBox/issues/330
  7. Unencoded content should not be rendered as it facilitates xss injections
  8. and breaks the layout.
  9. """
  10. subprocess.run(['archivebox', 'add', 'http://127.0.0.1:8080/static/title_with_html.com.html'],
  11. capture_output=True, env=disable_extractors_dict)
  12. list_process = subprocess.run(["archivebox", "list", "--html"], capture_output=True)
  13. assert "<textarea>" not in list_process.stdout.decode("utf-8")
  14. def test_title_in_meta_title(tmp_path, process, disable_extractors_dict):
  15. add_process = subprocess.run(["archivebox", "add", "http://127.0.0.1:8080/static/title_with_html.com.html"],
  16. capture_output=True, env=disable_extractors_dict)
  17. os.chdir(tmp_path)
  18. conn = sqlite3.connect("index.sqlite3")
  19. conn.row_factory = sqlite3.Row
  20. c = conn.cursor()
  21. c.execute("SELECT title from core_snapshot")
  22. snapshot = c.fetchone()
  23. conn.close()
  24. assert snapshot[0] == "It All Starts with a Humble <textarea> ◆ 24 ways"
  25. def test_title_in_meta_og(tmp_path, process, disable_extractors_dict):
  26. add_process = subprocess.run(["archivebox", "add", "http://127.0.0.1:8080/static/title_og_with_html.com.html"],
  27. capture_output=True, env=disable_extractors_dict)
  28. os.chdir(tmp_path)
  29. conn = sqlite3.connect("index.sqlite3")
  30. conn.row_factory = sqlite3.Row
  31. c = conn.cursor()
  32. c.execute("SELECT title from core_snapshot")
  33. snapshot = c.fetchone()
  34. conn.close()
  35. assert snapshot[0] == "It All Starts with a Humble <textarea>"
  36. def test_title_malformed(tmp_path, process, disable_extractors_dict):
  37. add_process = subprocess.run(["archivebox", "add", "http://127.0.0.1:8080/static/malformed.html"],
  38. capture_output=True, env=disable_extractors_dict)
  39. os.chdir(tmp_path)
  40. conn = sqlite3.connect("index.sqlite3")
  41. conn.row_factory = sqlite3.Row
  42. c = conn.cursor()
  43. c.execute("SELECT title from core_snapshot")
  44. snapshot = c.fetchone()
  45. conn.close()
  46. assert snapshot[0] == "malformed document"