Skip to content

Commit 91e872c

Browse files
committed
WIP Disallow initiating webhook server without host url and port
* Cover with tests
1 parent f15f330 commit 91e872c

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

aries_cloudcontroller/aries_controller.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,22 @@ def __post_init__(self):
3737
)
3838

3939
def init_webhook_server(
40-
self, webhook_host: str = None, webhook_port: int = None, webhook_base: str = ""
40+
self, webhook_host: str, webhook_port: int, webhook_base: str = ""
4141
):
4242
"""Create a webhooklisteners
4343
4444
Args:
4545
----
4646
webhook_host : str
47-
The url of the webhook host (default is None)
47+
The url of the webhook host
4848
webhook_port : int
49-
The exposed port for webhooks on the host (default is None)
49+
The exposed port for webhooks on the host
5050
webhook_base : str
5151
The base url for webhooks (default is "")
5252
"""
53+
assert type(webhook_host) is str
54+
assert webhook_host != ""
55+
assert type(webhook_port) is int
5356
self.webhook_server: AriesWebhookServer = AriesWebhookServer(
5457
webhook_host=webhook_host,
5558
webhook_port=webhook_port,

tests/test_aries_controller.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class TestAriesAgentController:
1212

1313
admin_url = "0.0.0.0"
14-
webhook_host = ""
14+
webhook_host = "0.0.0.0"
1515
webhook_port = 8000
1616
webhook_base = ""
1717

@@ -50,6 +50,24 @@ async def test_init_webhook_server(self):
5050
assert ac.webhook_server.is_multitenant
5151
await ac.terminate()
5252

53+
@pytest.mark.asyncio
54+
async def test_init_webhook_server_args_host_type(self):
55+
with pytest.raises(AssertionError):
56+
ac = AriesAgentController(admin_url=self.admin_url, is_multitenant=True)
57+
ac.init_webhook_server(webhook_host=1234, webhook_port=1234, webhook_base=self.webhook_base)
58+
59+
@pytest.mark.asyncio
60+
async def test_init_webhook_server_args_host_non_empty(self):
61+
with pytest.raises(AssertionError):
62+
ac = AriesAgentController(admin_url=self.admin_url, is_multitenant=True)
63+
ac.init_webhook_server(webhook_host="", webhook_port=1234, webhook_base=self.webhook_base)
64+
65+
@pytest.mark.asyncio
66+
async def test_init_webhook_server_args_port(self):
67+
with pytest.raises(AssertionError):
68+
ac = AriesAgentController(admin_url=self.admin_url, is_multitenant=True)
69+
ac.init_webhook_server(webhook_host="", webhook_port="1234", webhook_base=self.webhook_base)
70+
5371
@pytest.mark.asyncio
5472
async def test_listen_webhooks_error(self, caplog):
5573
caplog.set_level(logging.WARNING)

0 commit comments

Comments
 (0)