From e5aad8f1dc5a1b3308756e298f1f81143396ab23 Mon Sep 17 00:00:00 2001 From: zhoukailian Date: Thu, 26 Mar 2026 11:47:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=AF=E6=8C=81=E6=AF=AB=E7=A7=92?= =?UTF-8?q?=E7=BA=A7=E9=82=AE=E4=BB=B6=E6=97=B6=E9=97=B4=E6=88=B3=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E6=97=A7=E9=AA=8C=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_mail_code_reuse_guard.py | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/test_mail_code_reuse_guard.py b/tests/test_mail_code_reuse_guard.py index 0a586b3..2bc2d43 100644 --- a/tests/test_mail_code_reuse_guard.py +++ b/tests/test_mail_code_reuse_guard.py @@ -1,5 +1,6 @@ from src.services.duck_mail import DuckMailService from src.services.freemail import FreemailService +from src.services.moe_mail import MeoMailEmailService from src.services.temp_mail import TempMailService from src.services.tempmail import TempmailService @@ -359,3 +360,53 @@ def test_duck_mail_service_skips_previously_used_code_even_with_small_timestamp_ assert first_code == "111111" assert second_code == "654321" + + +def test_moe_mail_service_filters_old_messages_with_millisecond_timestamps(): + service = MeoMailEmailService({ + "base_url": "https://mail.example.com", + "api_key": "api-key", + }) + + def fake_make_request(method, endpoint, **kwargs): + if endpoint == "/api/emails/email-1": + return { + "messages": [ + { + "id": "msg-old", + "from_address": "noreply@openai.com", + "subject": "Your verification code", + "received_at": 1742378400000, + }, + { + "id": "msg-new", + "from_address": "noreply@openai.com", + "subject": "Your verification code", + "received_at": 1742378403000, + }, + ] + } + if endpoint == "/api/emails/email-1/msg-old": + return { + "message": { + "content": "Your OpenAI verification code is 111111", + } + } + if endpoint == "/api/emails/email-1/msg-new": + return { + "message": { + "content": "Your OpenAI verification code is 654321", + } + } + raise AssertionError(f"未准备响应: {method} {endpoint}") + + service._make_request = fake_make_request + + code = service.get_verification_code( + email="tester@example.com", + email_id="email-1", + timeout=1, + otp_sent_at=1742378402, + ) + + assert code == "654321"