Skip to content

The agent that grows with you

test(sms): pin the stripped Twilio token in the requirements check

kshitijk4poor62df46fdc44b
diff --git a/plugins/platforms/sms/adapter.py b/plugins/platforms/sms/adapter.py
index 3c9f7afa513..82f86307257 100644
--- a/plugins/platforms/sms/adapter.py
+++ b/plugins/platforms/sms/adapter.py
@@ -79,7 +79,7 @@ def _new_session(**kwargs):
def check_sms_requirements() -> bool:
"""Check if SMS adapter dependencies are available."""
return AIOHTTP_AVAILABLE and bool(
- _get_scoped_secret("TWILIO_ACCOUNT_SID") and (_get_scoped_secret("TWILIO_AUTH_TOKEN") or "").strip())
+ _get_scoped_secret("TWILIO_ACCOUNT_SID") and _get_scoped_secret("TWILIO_AUTH_TOKEN", "").strip())
class SmsAdapter(BasePlatformAdapter):
@@ -95,7 +95,7 @@ class SmsAdapter(BasePlatformAdapter):
super().__init__(config, Platform.SMS)
self._account_sid: str = _get_scoped_secret("TWILIO_ACCOUNT_SID", "")
# Stripped: a whitespace-only token must read as unset, not key the signature HMAC with blanks.
- self._auth_token: str = (_get_scoped_secret("TWILIO_AUTH_TOKEN", "") or "").strip()
+ self._auth_token: str = _get_scoped_secret("TWILIO_AUTH_TOKEN", "").strip()
# Scoped like the sibling reads above: a secondary profile must not send from the default
# profile's TWILIO_PHONE_NUMBER (#98738 class).
self._from_number: str = _get_scoped_secret("TWILIO_PHONE_NUMBER", "")
@@ -302,7 +302,7 @@ def _strip_markdown_for_sms(message: str) -> str:
async def _standalone_send(pconfig, chat_id, message, *, thread_id=None, media_files=None, force_document=False):
"""Out-of-process SMS delivery via the Twilio REST API (standalone_sender_fn contract)."""
- auth_token = (getattr(pconfig, "api_key", None) or _get_scoped_secret("TWILIO_AUTH_TOKEN", "") or "").strip()
+ auth_token = (getattr(pconfig, "api_key", None) or _get_scoped_secret("TWILIO_AUTH_TOKEN", "")).strip()
if not AIOHTTP_AVAILABLE:
return send_error("aiohttp not installed. Run: pip install aiohttp")
account_sid = _get_scoped_secret("TWILIO_ACCOUNT_SID", "")
diff --git a/tests/gateway/test_sms.py b/tests/gateway/test_sms.py
index ca24afeccea..7312224a58e 100644
--- a/tests/gateway/test_sms.py
+++ b/tests/gateway/test_sms.py
@@ -200,6 +200,9 @@ class TestTwilioSignatureValidation:
blank = self._make_adapter(auth_token=" ")
assert not any(blank._validate_twilio_signature(url, params, _compute_twilio_signature(k, url, params))
for k in (" ", ""))
+ from plugins.platforms.sms.adapter import check_sms_requirements
+ with patch.dict(os.environ, {"TWILIO_ACCOUNT_SID": "ACtest", "TWILIO_AUTH_TOKEN": " "}):
+ assert check_sms_requirements() is False
def test_port_variant_443_matches_without_port(self):