Conversations: pump LibreDesk through aimsight-libredesk, list and show the transcripts safely
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ca2f66ce3d
commit
3544f29d85
6 files changed
+449
-2
No files matched your search
+37
-1
@@ -377,7 +377,43 @@ def check_support():
|
||||
support.supports.clear()
|
||||
|
||||
|
||||
CHECKS = [check_server, check_station, check_optimization, check_analysis, check_validation, check_support]
|
||||
def check_conversations():
|
||||
# the Conversations page (conversations.py): the list, the transcript rendered safely, the files, the pumping refused
|
||||
# on a bad range; without LibreDesk (the pumping is libredesk/conversations/, tested there)
|
||||
import conversations
|
||||
root, before = temp_folder(), conversations.FOLDER
|
||||
conversations.FOLDER = root
|
||||
try:
|
||||
c = root / "42"
|
||||
(c / "attachments").mkdir(parents=True)
|
||||
(c / "conversation.json").write_text(json.dumps({"reference_number": "42", "subject": "A jump", "status": "Open",
|
||||
"updated_at": "2026-11-18T09:00:00Z", "contact": {"first_name": "Jean", "last_name": "", "email": "j@x.ch"}}))
|
||||
(c / "messages.json").write_text(json.dumps([
|
||||
{"type": "incoming", "created_at": "2026-11-18T08:00:00Z", "attachments": [{"url": "attachments/p.png"}]},
|
||||
{"type": "activity", "created_at": "2026-11-18T08:05:00Z", "attachments": []},
|
||||
{"type": "outgoing", "created_at": "2026-11-18T08:10:00Z", "attachments": [{"url": "attachments/x.svg"}]}]))
|
||||
(c / "transcript.md").write_text("# A jump\n\n<script>alert(1)</script>\n\n\n")
|
||||
(c / "attachments" / "p.png").write_bytes(b"png")
|
||||
(c / "attachments" / "x.svg").write_text("<svg onload='alert(1)'/>")
|
||||
(root / "pumped.json").write_text("{}") # not a conversation
|
||||
assert conversations.list_conversations() == [{"reference": "42", "subject": "A jump", "contact": "Jean",
|
||||
"status": "Open", "last": "2026-11-18T08:10:00Z", "messages": 2, "attachments": 2}], conversations.list_conversations()
|
||||
page = conversations.transcript("42", False)
|
||||
assert "<script>" not in page and "<script>" in page and '<img alt="p" src="attachments/p.png"' in page, page
|
||||
assert server.conversation_file("42", "attachments/x.svg").headers["content-disposition"].startswith("attachment")
|
||||
png = server.conversation_file("42", "attachments/p.png").headers
|
||||
assert "content-disposition" not in png and png["x-content-type-options"] == "nosniff"
|
||||
assert "img-src 'self'" in server.conversation_transcript("42").headers["content-security-policy"]
|
||||
refuses(conversations.transcript, "../analyses", False)
|
||||
refuses(server.conversation_file, "42", "../../etc/passwd")
|
||||
assert "From and To" in refuses(conversations.pump, {"start": "2026-11-01"})
|
||||
assert set(conversations.pump_state()) == {"running", "log"}
|
||||
finally:
|
||||
conversations.FOLDER = before
|
||||
shutil.rmtree(root)
|
||||
|
||||
|
||||
CHECKS = [check_server, check_station, check_optimization, check_analysis, check_validation, check_support, check_conversations]
|
||||
|
||||
if __name__ == "__main__":
|
||||
name = sys.argv[1] if len(sys.argv) > 1 else None
|
||||
|
||||
Reference in new issue
Block a user