Skip to content

Commit 9ef48ad

Browse files
committed
fix(utils): drop the dead error boundary in validate_push_notification_url
PushNotificationUrlValidator already catches InvalidUrlError and logs, so the wrapper's own try/except was unreachable dead code and showed up as a -25% coverage regression on the per-file report (spotted by the coverage bot on this PR). The wrapper is now a single-line delegation to the domain wrapper, which owns the logging; a dedicated test module locks the boolean, fail-closed contract directly. Signed-off-by: andy <linux2011@qq.com>
1 parent 6de3710 commit 9ef48ad

2 files changed

Lines changed: 59 additions & 13 deletions

File tree

‎src/a2a/utils/push_url_validator.py‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,8 @@
66
entry point.
77
"""
88

9-
import logging
9+
from a2a.utils.url_validation import PushNotificationUrlValidator
1010

11-
from a2a.utils.url_validation import (
12-
InvalidUrlError,
13-
PushNotificationUrlValidator,
14-
)
15-
16-
17-
logger = logging.getLogger(__name__)
1811

1912
_validator = PushNotificationUrlValidator()
2013

@@ -39,8 +32,4 @@ async def validate_push_notification_url(url: str) -> bool:
3932
The default on those constructors is ``None`` (no library
4033
screening).
4134
"""
42-
try:
43-
return await _validator.validate(url)
44-
except InvalidUrlError:
45-
logger.warning('Push-notification URL rejected: %s', url)
46-
return False
35+
return await _validator.validate(url)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""Tests for the validate_push_notification_url compatibility wrapper.
2+
3+
The wrapper delegates to PushNotificationUrlValidator and keeps the
4+
historical boolean, fail-closed contract (issue #1023 refactor).
5+
"""
6+
7+
import a2a.utils.push_url_validator as push_url_validator_module
8+
import pytest
9+
10+
from a2a.utils.push_url_validator import validate_push_notification_url
11+
12+
13+
PUBLIC_IP = '93.184.216.34'
14+
15+
16+
def _pin_resolver(monkeypatch, *ips: str) -> None:
17+
"""Pin the module singleton's resolver to deterministic addresses."""
18+
19+
async def resolve(host: str, port: int):
20+
return [(2, 1, 6, '', (ip, port)) for ip in ips]
21+
22+
monkeypatch.setattr(
23+
push_url_validator_module._validator._validator,
24+
'_resolver',
25+
resolve,
26+
)
27+
28+
29+
def _pin_failing_resolver(monkeypatch) -> None:
30+
"""Pin the module singleton's resolver to a failing lookup."""
31+
32+
async def resolve(host: str, port: int):
33+
raise OSError('no DNS')
34+
35+
monkeypatch.setattr(
36+
push_url_validator_module._validator._validator,
37+
'_resolver',
38+
resolve,
39+
)
40+
41+
42+
@pytest.mark.asyncio
43+
async def test_returns_true_for_public_http_url(monkeypatch):
44+
_pin_resolver(monkeypatch, PUBLIC_IP)
45+
assert await validate_push_notification_url('http://example.com/hook')
46+
47+
48+
@pytest.mark.asyncio
49+
async def test_returns_false_for_non_http_scheme(monkeypatch):
50+
_pin_resolver(monkeypatch, PUBLIC_IP)
51+
assert not await validate_push_notification_url('ftp://example.com/file')
52+
53+
54+
@pytest.mark.asyncio
55+
async def test_returns_false_when_resolution_fails(monkeypatch):
56+
_pin_failing_resolver(monkeypatch)
57+
assert not await validate_push_notification_url('http://example.com/hook')

0 commit comments

Comments
 (0)