|
| 1 | +import logging |
| 2 | +import re |
| 3 | +import pytest |
| 4 | +import pytest_asyncio |
| 5 | +from aiohttp import ( |
| 6 | + web, |
| 7 | + ClientSession, |
| 8 | +) |
| 9 | + |
| 10 | +from ..aries_webhook_server import AriesWebhookServer |
| 11 | +from ..controllers.multitenant import MultitenancyController |
| 12 | + |
| 13 | +from ..aries_tenant_controller import AriesTenantController |
| 14 | + |
| 15 | +LOGGER = logging.getLogger(__name__) |
| 16 | + |
| 17 | + |
| 18 | +class TestAriesAgentControllerBase(): |
| 19 | + |
| 20 | + admin_url = "0.0.0.0" |
| 21 | + webhook_host = "" |
| 22 | + webhook_port = 8000 |
| 23 | + webhook_base = "" |
| 24 | + wallet_id = "123456789" |
| 25 | + tenant_jwt = "987654321" |
| 26 | + |
| 27 | + @pytest.mark.asyncio |
| 28 | + async def test_init_args_missing_wallet_id(self): |
| 29 | + with pytest.raises( |
| 30 | + TypeError, |
| 31 | + match=re.escape("__init__ missing required wallet_id (str)")): |
| 32 | + AriesTenantController(admin_url=self.admin_url) |
| 33 | + |
| 34 | + @pytest.mark.asyncio |
| 35 | + async def test_init_args_missing_tenant_jwt(self): |
| 36 | + with pytest.raises( |
| 37 | + TypeError, |
| 38 | + match=re.escape("__init__ missing required tenant_jwt (str)")): |
| 39 | + AriesTenantController(admin_url=self.admin_url, wallet_id=self.wallet_id) |
| 40 | + |
| 41 | + @pytest.mark.asyncio |
| 42 | + async def test_init_webhook_server(self): |
| 43 | + ac = AriesTenantController( |
| 44 | + admin_url=self.admin_url, |
| 45 | + wallet_id=self.wallet_id, |
| 46 | + tenant_jwt=self.tenant_jwt) |
| 47 | + with pytest.raises( |
| 48 | + NotImplementedError, |
| 49 | + match=("Please, use an AriesAgentController to start a webhook server\n" |
| 50 | + "Webhook server fct is disallowed for tenant controllers.")): |
| 51 | + ac.init_webhook_server() |
| 52 | + await ac.terminate() |
| 53 | + |
| 54 | + @pytest.mark.asyncio |
| 55 | + async def test_listen_webhooks(self): |
| 56 | + ac = AriesTenantController( |
| 57 | + admin_url=self.admin_url, |
| 58 | + wallet_id=self.wallet_id, |
| 59 | + tenant_jwt=self.tenant_jwt) |
| 60 | + with pytest.raises( |
| 61 | + NotImplementedError, |
| 62 | + match=("Please, use an AriesAgentController to start a webhook server\n" |
| 63 | + "Webhook server fct is disallowed for tenant controllers.")): |
| 64 | + ac.listen_webhooks() |
| 65 | + await ac.terminate() |
| 66 | + |
| 67 | + @pytest.mark.asyncio |
| 68 | + async def test_update_wallet_id(self): |
| 69 | + new_wallet_id = "567438291" |
| 70 | + ac = AriesTenantController( |
| 71 | + admin_url=self.admin_url, |
| 72 | + wallet_id=self.wallet_id, |
| 73 | + tenant_jwt=self.tenant_jwt) |
| 74 | + assert ac.wallet_id != new_wallet_id |
| 75 | + ac.update_wallet_id(wallet_id=new_wallet_id) |
| 76 | + assert ac.wallet_id == new_wallet_id |
| 77 | + with pytest.raises( |
| 78 | + AssertionError, |
| 79 | + match="wallet_id must not be empty"): |
| 80 | + ac.update_wallet_id(wallet_id="") |
| 81 | + with pytest.raises( |
| 82 | + AssertionError, |
| 83 | + match="wallet_id must be a string"): |
| 84 | + ac.update_wallet_id(wallet_id=23456) |
| 85 | + await ac.terminate() |
| 86 | + |
| 87 | + @pytest.mark.asyncio |
| 88 | + async def test_update_tenant_jwt(self): |
| 89 | + new_tenant_jwt = "567438291" |
| 90 | + ac = AriesTenantController( |
| 91 | + admin_url=self.admin_url, |
| 92 | + wallet_id=self.wallet_id, |
| 93 | + tenant_jwt=self.tenant_jwt) |
| 94 | + assert ac.tenant_jwt != new_tenant_jwt |
| 95 | + ac.update_tenant_jwt(wallet_id=self.wallet_id, tenant_jwt=new_tenant_jwt) |
| 96 | + assert ac.tenant_jwt == new_tenant_jwt |
| 97 | + with pytest.raises( |
| 98 | + AssertionError, |
| 99 | + match="tenant_jwt must not be empty"): |
| 100 | + ac.update_tenant_jwt(wallet_id=self.wallet_id, tenant_jwt="") |
| 101 | + with pytest.raises( |
| 102 | + AssertionError, |
| 103 | + match="tenant_jwt must be a string"): |
| 104 | + ac.update_tenant_jwt(wallet_id=self.wallet_id, tenant_jwt=23456) |
| 105 | + await ac.terminate() |
| 106 | + |
| 107 | + @pytest.mark.asyncio |
| 108 | + async def test_remove_tenant_jwt(self): |
| 109 | + ac = AriesTenantController( |
| 110 | + admin_url=self.admin_url, |
| 111 | + wallet_id=self.wallet_id, |
| 112 | + tenant_jwt=self.tenant_jwt) |
| 113 | + ac.remove_tenant_jwt() |
| 114 | + assert not ac.tenant_jwt |
| 115 | + assert 'Authorization' not in ac.headers |
| 116 | + assert 'Authorization' not in ac.client_session.headers |
| 117 | + assert 'content-type' not in ac.client_session.headers |
| 118 | + assert 'content-type' not in ac.headers |
| 119 | + await ac.terminate() |
0 commit comments