setting, session and profile fix

This commit is contained in:
debu-2 2026-10-07 06:16:26 +05:30
parent 068142ed61
commit a434af224c
34 changed files with 497 additions and 119 deletions

View file

@ -1,8 +1,16 @@
import base64
from datetime import datetime, timezone
from bson import ObjectId
from app.routers.emails import decode_cursor, encode_cursor, summarize
from app.routers.emails import (
decode_cursor,
decode_outbound_attachments,
encode_cursor,
sanitize_attachment_filename,
summarize,
)
from app.schemas import EmailAttachmentCreate
def test_cursor_round_trip_preserves_sort_key():
@ -56,3 +64,30 @@ def test_summary_uses_account_mailbox_read_state():
assert result.is_read is False
assert result.mailbox == "inbox"
assert result.snippet == "A short preview"
def test_sanitize_attachment_filename_strips_paths():
assert sanitize_attachment_filename("../../secret.pdf") == "secret.pdf"
def test_decode_outbound_attachments_splits_inline_and_files():
pdf = EmailAttachmentCreate(
filename="invoice.pdf",
content_type="application/pdf",
content_base64=base64.b64encode(b"%PDF-1.4").decode(),
disposition="attachment",
)
image = EmailAttachmentCreate(
filename="logo.png",
content_type="image/png",
content_base64=base64.b64encode(b"PNG").decode(),
disposition="inline",
content_id="logo@agmail",
)
inline_parts, files, metadata = decode_outbound_attachments([pdf, image])
assert [part.filename for part in files] == ["invoice.pdf"]
assert [part.filename for part in inline_parts] == ["logo.png"]
assert metadata[0]["size"] == 8
assert metadata[1]["disposition"] == "inline"

View file

@ -4,6 +4,7 @@ from unittest.mock import AsyncMock, patch
import pytest
from app.services.mail_sender import build_message, deliver_email, send_via_smtp, sign_message
from app.services.mime_body_extractor import ExtractedMimePart
def test_build_message_formats_named_sender_header():
@ -46,6 +47,32 @@ def test_build_message_adds_safe_fallback_sender_name():
assert message["From"] == "aGentic Email <notifications@gentic.email>"
def test_build_message_includes_file_attachments():
message = build_message(
sender="suyash@gentic.email",
sender_name="Suyash Dixit",
recipients=["recipient@example.com"],
cc=[],
subject="Invoice",
body_text="See attached",
body_html="<p>See attached</p>",
file_attachments=[
ExtractedMimePart(
filename="invoice.pdf",
content_type="application/pdf",
payload=b"%PDF-1.4",
)
],
)
filenames = [
part.get_filename()
for part in message.walk()
if part.get_filename()
]
assert filenames == ["invoice.pdf"]
def test_dkim_sign_uses_selector_before_domain():
message = build_message(
sender="user@ritoesis.com",