test(webhook): pin the dynamic-route secret guard
Gate r2 findings 3 and 4. Mutating _dynamic_route_allowed to `if not effective_secret:` stayed green, because no test reached the hot-reload guard with a blank or non-string secret. The existing parametrized connect case now asserts the dynamic-route guard rejects the same secrets, and it goes red under that mutation (4/4). Also rename the test and its param to match what they cover (unusable, not only whitespace-only), and refresh the stale docstring to name _is_usable_secret.
This commit is contained in:
@@ -386,8 +386,8 @@ class WebhookAdapter(BasePlatformAdapter):
|
||||
return web.json_response({"status": "ok", "platform": "webhook"})
|
||||
|
||||
def _dynamic_route_allowed(self, name: str, route: dict) -> bool:
|
||||
"""An empty effective secret would make _handle_webhook skip HMAC validation → reject such
|
||||
dynamic routes; INSECURE_NO_AUTH is loopback-only."""
|
||||
"""Reject dynamic routes whose effective secret is missing, blank, or not a string
|
||||
(_is_usable_secret); INSECURE_NO_AUTH is loopback-only."""
|
||||
effective_secret = route.get("secret", self._global_secret)
|
||||
if not _is_usable_secret(effective_secret):
|
||||
logger.warning("[webhook] Dynamic route '%s' skipped: 'secret' is missing, blank, or not a string. "
|
||||
|
||||
@@ -1252,11 +1252,13 @@ def test_route_profile_validation_fails_closed():
|
||||
|
||||
|
||||
class TestBlankRouteSecretFailsClosed:
|
||||
@pytest.mark.parametrize("blank", [" ", "\t", "\n", 123])
|
||||
def test_connect_rejects_a_whitespace_only_route_secret(self, blank):
|
||||
adapter = _make_adapter(routes={"hook": {"secret": blank}})
|
||||
@pytest.mark.parametrize("secret", [" ", "\t", "\n", 123])
|
||||
def test_connect_rejects_an_unusable_route_secret(self, secret):
|
||||
adapter = _make_adapter(routes={"hook": {"secret": secret}})
|
||||
with pytest.raises(ValueError, match="missing, blank, or not a string"):
|
||||
asyncio.run(adapter.connect())
|
||||
# The hot-reload path applies the same guard to agent-created dynamic routes.
|
||||
assert adapter._dynamic_route_allowed("hook", {"secret": secret}) is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Reference in New Issue
Block a user