Skip to content

Commit 4aa4366

Browse files
committed
WIP proposal new webhook server logic
* Assert passed IP address is a valid IP address * unit test
1 parent b7f8d96 commit 4aa4366

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

aries_cloudcontroller/aries_controller.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .controllers.multitenant import MultitenancyController
66

77
import logging
8+
import ipaddress
89

910
logger = logging.getLogger("aries_controller")
1011

@@ -51,7 +52,7 @@ async def init_webhook_server(
5152
The base url for webhooks (default is "")
5253
"""
5354
assert type(webhook_host) is str
54-
assert webhook_host != ""
55+
assert ipaddress.ip_address(webhook_host)
5556
assert type(webhook_port) is int
5657
try:
5758
self.webhook_server: AriesWebhookServer = AriesWebhookServer(

tests/test_aries_controller.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,22 @@ async def test_init_webhook_server_args_host_type(self):
6161
)
6262

6363
@pytest.mark.asyncio
64-
async def test_init_webhook_server_args_host_non_empty(self):
65-
with pytest.raises(AssertionError):
64+
async def test_init_webhook_server_invalid_ip(self):
65+
with pytest.raises(
66+
ValueError, match="does not appear to be an IPv4 or IPv6 address"
67+
):
68+
ac = AriesAgentController(admin_url=self.admin_url, is_multitenant=True)
69+
await ac.init_webhook_server(
70+
webhook_host="12345.123456.1234.0",
71+
webhook_port=1234,
72+
webhook_base=self.webhook_base,
73+
)
74+
75+
@pytest.mark.asyncio
76+
async def test_init_webhook_server_empty_invalid_ip(self):
77+
with pytest.raises(
78+
ValueError, match="does not appear to be an IPv4 or IPv6 address"
79+
):
6680
ac = AriesAgentController(admin_url=self.admin_url, is_multitenant=True)
6781
await ac.init_webhook_server(
6882
webhook_host="", webhook_port=1234, webhook_base=self.webhook_base
@@ -73,7 +87,9 @@ async def test_init_webhook_server_args_port(self):
7387
with pytest.raises(AssertionError):
7488
ac = AriesAgentController(admin_url=self.admin_url, is_multitenant=True)
7589
await ac.init_webhook_server(
76-
webhook_host="", webhook_port="1234", webhook_base=self.webhook_base
90+
webhook_host=self.webhook_host,
91+
webhook_port="1234",
92+
webhook_base=self.webhook_base,
7793
)
7894

7995
@pytest.mark.asyncio

0 commit comments

Comments
 (0)