过滤 AWS 资源访问验证成功通知

This commit is contained in:
2026-10-08 16:13:16 +08:00
parent 2174b61606
commit 5db6f351cd
4 changed files with 155 additions and 8 deletions
+32
View File
@@ -204,6 +204,38 @@ class ReplayTests(unittest.TestCase):
self.assertEqual(after["report_history"], before["report_history"])
self.assertEqual(self.run_main("--replay-last"), first)
def test_filtered_access_validated_notice_is_deduplicated_without_history(self):
mail = EmailMessage()
mail["Subject"] = "Fw: Your Request For Accessing AWS Resources Has Been Validated"
mail["Message-ID"] = "<validated-42@example.com>"
mail.set_content("Your AWS resource-access request has completed verification.")
fake = FakeIMAP(mail.as_bytes())
with patch.object(check_mail.imaplib, "IMAP4_SSL", return_value=fake):
self.assertEqual(self.run_main(), check_mail.NO_NEW + "\n")
self.assertEqual(self.run_main(), check_mail.NO_NEW + "\n")
self.assertEqual(fake.fetches, 1)
state = json.loads(self.state.read_text(encoding="utf-8"))
entry = next(iter(state["mailboxes"].values()))
self.assertEqual(entry["uids"], ["42"])
self.assertEqual(entry["message_ids"], ["<validated-42@example.com>"])
self.assertNotIn("report_history", state)
self.assertNotIn("last_report", state)
def test_filtered_access_validated_notice_preserves_previous_report(self):
with patch.object(check_mail.imaplib, "IMAP4_SSL", return_value=self.fake):
first = self.run_main()
before = json.loads(self.state.read_text(encoding="utf-8"))
mail = EmailMessage()
mail["Subject"] = "Fw: 您访问 AWS 资源的请求已得到验证"
mail["Message-ID"] = "<validated-43@example.com>"
mail.set_content("<p>现在可以访问 AWS 资源。</p>", subtype="html")
with patch.object(check_mail.imaplib, "IMAP4_SSL", return_value=FakeIMAP(mail.as_bytes(), uid=b"43")):
self.assertEqual(self.run_main(), check_mail.NO_NEW + "\n")
after = json.loads(self.state.read_text(encoding="utf-8"))
self.assertEqual(after["report_history"], before["report_history"])
self.assertEqual(after["last_report"], before["last_report"])
self.assertEqual(self.run_main("--replay-last"), first)
if __name__ == "__main__":
unittest.main()