|
@@ -4,9 +4,11 @@ from unittest import TestCase
|
|
|
from unittest.mock import Mock
|
|
from unittest.mock import Mock
|
|
|
|
|
|
|
|
from plugins import ita_plugin as otp
|
|
from plugins import ita_plugin as otp
|
|
|
-from plugins.ita_plugin import CalendarGateError
|
|
|
|
|
from plugins.ita_plugin import OtpMailConfig, ItaProtocolError, parse_otp_body, resolve_route_config
|
|
from plugins.ita_plugin import OtpMailConfig, ItaProtocolError, parse_otp_body, resolve_route_config
|
|
|
-from vs_types import BizLogicError, PermissionDeniedError, SessionExpiredOrInvalidError
|
|
|
|
|
|
|
+from vs_types import (
|
|
|
|
|
+ BizLogicError, PermissionDeniedError, RateLimiteddError,
|
|
|
|
|
+ SessionExpiredOrInvalidError,
|
|
|
|
|
+)
|
|
|
|
|
|
|
|
|
|
|
|
|
class OtpParserTests(TestCase):
|
|
class OtpParserTests(TestCase):
|
|
@@ -95,7 +97,7 @@ class CloudOtpTests(TestCase):
|
|
|
def test_account_mailbox_failure_does_not_read_another_inbox(self):
|
|
def test_account_mailbox_failure_does_not_read_another_inbox(self):
|
|
|
config = OtpMailConfig(authorization_source="account")
|
|
config = OtpMailConfig(authorization_source="account")
|
|
|
self.client.fetch_mail_content.side_effect = PermissionDeniedError("private-provider-details")
|
|
self.client.fetch_mail_content.side_effect = PermissionDeniedError("private-provider-details")
|
|
|
- with self.assertRaisesRegex(CalendarGateError, "not permitted"):
|
|
|
|
|
|
|
+ with self.assertRaisesRegex(PermissionDeniedError, "not permitted"):
|
|
|
otp.fetch_otp_from_cloud(config, recipient="second@example.test",
|
|
otp.fetch_otp_from_cloud(config, recipient="second@example.test",
|
|
|
sent_at="2026-08-31 01:02:03", api=self.client)
|
|
sent_at="2026-08-31 01:02:03", api=self.client)
|
|
|
self.client.fetch_mail_content.assert_called_once()
|
|
self.client.fetch_mail_content.assert_called_once()
|
|
@@ -111,12 +113,18 @@ class CloudOtpTests(TestCase):
|
|
|
|
|
|
|
|
def test_provider_failures_are_redacted_and_not_site_session_errors(self):
|
|
def test_provider_failures_are_redacted_and_not_site_session_errors(self):
|
|
|
marker = 'PRIVATE_MAIL_CONTENT_001234'
|
|
marker = 'PRIVATE_MAIL_CONTENT_001234'
|
|
|
- for error in (BizLogicError(marker), PermissionDeniedError(marker),
|
|
|
|
|
- SessionExpiredOrInvalidError(marker), ValueError(marker), TimeoutError(marker)):
|
|
|
|
|
|
|
+ cases = (
|
|
|
|
|
+ (BizLogicError(marker), BizLogicError),
|
|
|
|
|
+ (PermissionDeniedError(marker), PermissionDeniedError),
|
|
|
|
|
+ (SessionExpiredOrInvalidError(marker), SessionExpiredOrInvalidError),
|
|
|
|
|
+ (ValueError(marker), BizLogicError),
|
|
|
|
|
+ (TimeoutError(marker), BizLogicError),
|
|
|
|
|
+ )
|
|
|
|
|
+ for error, expected in cases:
|
|
|
self.client.reset_mock()
|
|
self.client.reset_mock()
|
|
|
self.client.fetch_mail_content.side_effect = error
|
|
self.client.fetch_mail_content.side_effect = error
|
|
|
with self.subTest(error=type(error).__name__):
|
|
with self.subTest(error=type(error).__name__):
|
|
|
- with self.assertRaises(CalendarGateError) as caught:
|
|
|
|
|
|
|
+ with self.assertRaises(expected) as caught:
|
|
|
self.fetch()
|
|
self.fetch()
|
|
|
rendered = ''.join(traceback.format_exception(caught.exception))
|
|
rendered = ''.join(traceback.format_exception(caught.exception))
|
|
|
self.assertNotIn(marker, rendered)
|
|
self.assertNotIn(marker, rendered)
|
|
@@ -124,7 +132,7 @@ class CloudOtpTests(TestCase):
|
|
|
self.client.fetch_mail_content_from_top.assert_not_called()
|
|
self.client.fetch_mail_content_from_top.assert_not_called()
|
|
|
|
|
|
|
|
def test_invalid_input_never_reads_mail(self):
|
|
def test_invalid_input_never_reads_mail(self):
|
|
|
- with self.assertRaises(CalendarGateError):
|
|
|
|
|
|
|
+ with self.assertRaises(BizLogicError):
|
|
|
otp.fetch_otp_from_cloud(self.config, recipient='not-an-address', sent_at='invalid', api=self.client)
|
|
otp.fetch_otp_from_cloud(self.config, recipient='not-an-address', sent_at='invalid', api=self.client)
|
|
|
self.client.fetch_mail_content.assert_not_called()
|
|
self.client.fetch_mail_content.assert_not_called()
|
|
|
|
|
|
|
@@ -145,7 +153,13 @@ class CloudOtpTests(TestCase):
|
|
|
self.assertEqual(otp.fetch_otp_from_cloud(self.config,
|
|
self.assertEqual(otp.fetch_otp_from_cloud(self.config,
|
|
|
recipient="applicant@example.test", sent_at="2026-08-31 01:02:03", api=client), "001234")
|
|
recipient="applicant@example.test", sent_at="2026-08-31 01:02:03", api=client), "001234")
|
|
|
else:
|
|
else:
|
|
|
- with self.assertRaises(CalendarGateError) as raised:
|
|
|
|
|
|
|
+ expected = {
|
|
|
|
|
+ 401: SessionExpiredOrInvalidError,
|
|
|
|
|
+ 403: PermissionDeniedError,
|
|
|
|
|
+ 429: RateLimiteddError,
|
|
|
|
|
+ 504: BizLogicError,
|
|
|
|
|
+ }[status]
|
|
|
|
|
+ with self.assertRaises(expected) as raised:
|
|
|
otp.fetch_otp_from_cloud(self.config, recipient="applicant@example.test",
|
|
otp.fetch_otp_from_cloud(self.config, recipient="applicant@example.test",
|
|
|
sent_at="2026-08-31 01:02:03", api=client)
|
|
sent_at="2026-08-31 01:02:03", api=client)
|
|
|
rendered = ''.join(traceback.format_exception(raised.exception))
|
|
rendered = ''.join(traceback.format_exception(raised.exception))
|
|
@@ -160,6 +174,6 @@ class CloudOtpTests(TestCase):
|
|
|
for body in (None, "unknown template", "OTP Code:123456 OTP Code:654321"):
|
|
for body in (None, "unknown template", "OTP Code:123456 OTP Code:654321"):
|
|
|
with self.subTest(body=body):
|
|
with self.subTest(body=body):
|
|
|
self.client.fetch_mail_content.return_value = body
|
|
self.client.fetch_mail_content.return_value = body
|
|
|
- with self.assertRaises(CalendarGateError):
|
|
|
|
|
|
|
+ with self.assertRaises(BizLogicError):
|
|
|
self.fetch()
|
|
self.fetch()
|
|
|
self.client.fetch_mail_content_from_top.assert_not_called()
|
|
self.client.fetch_mail_content_from_top.assert_not_called()
|