-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/dispatch-active
- Loading branch information
Showing
11 changed files
with
570 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
aries_cloudagent/protocols/introduction/handlers/invitation_request_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
90 changes: 90 additions & 0 deletions
90
aries_cloudagent/protocols/introduction/handlers/tests/test_forward_invitation_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from asynctest import TestCase as AsyncTestCase | ||
from asynctest import mock as async_mock | ||
|
||
from .....config.injection_context import InjectionContext | ||
from .....connections.models.connection_record import ConnectionRecord | ||
from .....messaging.base_handler import HandlerException | ||
from .....messaging.request_context import RequestContext | ||
from .....messaging.responder import MockResponder | ||
|
||
from ....connections.messages.connection_invitation import ConnectionInvitation | ||
|
||
from ...messages.forward_invitation import ForwardInvitation | ||
|
||
from .. import forward_invitation_handler as test_module | ||
|
||
TEST_DID = "55GkHamhTU1ZbTbV2ab9DE" | ||
TEST_VERKEY = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" | ||
TEST_ROUTE_VERKEY = "9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC" | ||
TEST_LABEL = "Label" | ||
TEST_ENDPOINT = "http://localhost" | ||
TEST_IMAGE_URL = "http://aries.ca/images/sample.png" | ||
|
||
|
||
class TestForwardInvitationHandler(AsyncTestCase): | ||
async def setUp(self): | ||
self.context = RequestContext( | ||
base_context=InjectionContext(enforce_typing=False) | ||
) | ||
|
||
self.context.connection_ready = True | ||
self.context.message = ForwardInvitation( | ||
invitation=ConnectionInvitation( | ||
label=TEST_LABEL, | ||
did=TEST_DID, | ||
recipient_keys=[TEST_VERKEY], | ||
endpoint=TEST_ENDPOINT, | ||
routing_keys=[TEST_ROUTE_VERKEY], | ||
image_url=TEST_IMAGE_URL, | ||
), | ||
message="Hello World" | ||
) | ||
self.context.update_settings({"accept_invites": False}) | ||
|
||
async def test_handle(self): | ||
handler = test_module.ForwardInvitationHandler() | ||
|
||
responder = MockResponder() | ||
with async_mock.patch.object( | ||
test_module, "ConnectionManager", autospec=True | ||
) as mock_mgr: | ||
mock_mgr.return_value.receive_invitation = async_mock.CoroutineMock( | ||
return_value=ConnectionRecord(connection_id="dummy") | ||
) | ||
|
||
await handler.handle(self.context, responder) | ||
assert not(responder.messages) | ||
|
||
async def test_handle_auto_accept(self): | ||
handler = test_module.ForwardInvitationHandler() | ||
self.context.update_settings({"accept_invites": True}) | ||
|
||
mock_conn_rec = async_mock.MagicMock(connection_id="dummy") | ||
mock_conn_req = async_mock.MagicMock(label="test") | ||
|
||
responder = MockResponder() | ||
with async_mock.patch.object( | ||
test_module, "ConnectionManager", autospec=True | ||
) as mock_mgr: | ||
mock_mgr.return_value.receive_invitation = async_mock.CoroutineMock( | ||
return_value=mock_conn_rec | ||
) | ||
mock_mgr.return_value.create_request = async_mock.CoroutineMock( | ||
return_value=mock_conn_req | ||
) | ||
|
||
await handler.handle(self.context, responder) | ||
assert mock_mgr.return_value.create_request.called_once_with(mock_conn_rec) | ||
|
||
messages = responder.messages | ||
assert len(messages) == 1 | ||
(result, target) = messages[0] | ||
assert result == mock_conn_req | ||
assert target["connection_id"] == "dummy" | ||
|
||
async def test_handle_not_ready(self): | ||
handler = test_module.ForwardInvitationHandler() | ||
self.context.connection_ready = False | ||
|
||
with self.assertRaises(HandlerException): | ||
await handler.handle(self.context, None) |
82 changes: 82 additions & 0 deletions
82
aries_cloudagent/protocols/introduction/handlers/tests/test_invitation_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from asynctest import TestCase as AsyncTestCase | ||
from asynctest import mock as async_mock | ||
|
||
from .....config.injection_context import InjectionContext | ||
from .....connections.models.connection_record import ConnectionRecord | ||
from .....messaging.base_handler import HandlerException | ||
from .....messaging.request_context import RequestContext | ||
from .....messaging.responder import MockResponder | ||
from .....storage.base import BaseStorage | ||
from .....storage.basic import BasicStorage | ||
|
||
from ....connections.messages.connection_invitation import ConnectionInvitation | ||
|
||
from ...messages.invitation import Invitation | ||
from ...messages.invitation_request import InvitationRequest | ||
|
||
from .. import invitation_handler as test_module | ||
|
||
TEST_DID = "55GkHamhTU1ZbTbV2ab9DE" | ||
TEST_VERKEY = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" | ||
TEST_ROUTE_VERKEY = "9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC" | ||
TEST_LABEL = "Label" | ||
TEST_ENDPOINT = "http://localhost" | ||
TEST_IMAGE_URL = "http://aries.ca/images/sample.png" | ||
|
||
|
||
class TestInvitationHandler(AsyncTestCase): | ||
async def setUp(self): | ||
self.storage = BasicStorage() | ||
|
||
self.context = RequestContext( | ||
base_context=InjectionContext(enforce_typing=False) | ||
) | ||
self.context.injector.bind_instance(BaseStorage, self.storage) | ||
|
||
self.context.connection_ready = True | ||
self.context.message = Invitation( | ||
invitation=ConnectionInvitation( | ||
label=TEST_LABEL, | ||
did=TEST_DID, | ||
recipient_keys=[TEST_VERKEY], | ||
endpoint=TEST_ENDPOINT, | ||
routing_keys=[TEST_ROUTE_VERKEY], | ||
image_url=TEST_IMAGE_URL, | ||
), | ||
message="Hello World", | ||
) | ||
self.context.connection_record = async_mock.MagicMock(connection_id="dummy") | ||
|
||
async def test_handle(self): | ||
handler = test_module.InvitationHandler() | ||
|
||
mock_conn_rec = async_mock.MagicMock(connection_id="dummy") | ||
|
||
responder = MockResponder() | ||
with async_mock.patch.object( | ||
self.context, "inject", async_mock.CoroutineMock() | ||
) as mock_ctx_inject: | ||
mock_ctx_inject.return_value = async_mock.MagicMock( | ||
return_invitation=async_mock.CoroutineMock() | ||
) | ||
|
||
await handler.handle(self.context, responder) | ||
|
||
assert mock_ctx_inject.return_value.return_invitation.called_once_with( | ||
self.context.connection_record.connection_id, | ||
self.context.message, | ||
responder.send | ||
) | ||
|
||
async def test_handle_no_service(self): | ||
handler = test_module.InvitationHandler() | ||
|
||
with self.assertRaises(HandlerException): | ||
await handler.handle(self.context, None) | ||
|
||
async def test_handle_not_ready(self): | ||
handler = test_module.InvitationHandler() | ||
self.context.connection_ready = False | ||
|
||
with self.assertRaises(HandlerException): | ||
await handler.handle(self.context, None) |
85 changes: 85 additions & 0 deletions
85
aries_cloudagent/protocols/introduction/handlers/tests/test_invitation_request_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from asynctest import TestCase as AsyncTestCase | ||
from asynctest import mock as async_mock | ||
|
||
from .....config.injection_context import InjectionContext | ||
from .....connections.models.connection_record import ConnectionRecord | ||
from .....messaging.base_handler import HandlerException | ||
from .....messaging.request_context import RequestContext | ||
from .....messaging.responder import MockResponder | ||
|
||
from ....connections.messages.connection_invitation import ConnectionInvitation | ||
|
||
from ...messages.invitation import Invitation | ||
from ...messages.invitation_request import InvitationRequest | ||
|
||
from .. import invitation_request_handler as test_module | ||
|
||
TEST_DID = "55GkHamhTU1ZbTbV2ab9DE" | ||
TEST_VERKEY = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" | ||
TEST_ROUTE_VERKEY = "9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC" | ||
TEST_LABEL = "Label" | ||
TEST_ENDPOINT = "http://localhost" | ||
TEST_IMAGE_URL = "http://aries.ca/images/sample.png" | ||
|
||
|
||
class TestInvitationRequestHandler(AsyncTestCase): | ||
async def setUp(self): | ||
self.context = RequestContext( | ||
base_context=InjectionContext(enforce_typing=False) | ||
) | ||
|
||
self.context.connection_ready = True | ||
self.context.message = InvitationRequest( | ||
responder="test-agent", | ||
message="Hello World", | ||
) | ||
self.context.update_settings({"accept_requests": False}) | ||
|
||
async def test_handle(self): | ||
handler = test_module.InvitationRequestHandler() | ||
|
||
responder = MockResponder() | ||
inv_req = InvitationRequest(responder=responder, message="Hello") | ||
|
||
with async_mock.patch.object( | ||
test_module, "ConnectionManager", autospec=True | ||
) as mock_mgr: | ||
await handler.handle(self.context, responder) | ||
|
||
async def test_handle_auto_accept(self): | ||
handler = test_module.InvitationRequestHandler() | ||
self.context.update_settings({"accept_requests": True}) | ||
|
||
conn_invitation=ConnectionInvitation( | ||
label=TEST_LABEL, | ||
did=TEST_DID, | ||
recipient_keys=[TEST_VERKEY], | ||
endpoint=TEST_ENDPOINT, | ||
routing_keys=[TEST_ROUTE_VERKEY], | ||
image_url=TEST_IMAGE_URL, | ||
) | ||
mock_conn_rec = async_mock.MagicMock(connection_id="dummy") | ||
|
||
responder = MockResponder() | ||
with async_mock.patch.object( | ||
test_module, "ConnectionManager", autospec=True | ||
) as mock_mgr: | ||
mock_mgr.return_value.create_invitation = async_mock.CoroutineMock( | ||
return_value=(mock_conn_rec, conn_invitation) | ||
) | ||
|
||
await handler.handle(self.context, responder) | ||
assert mock_mgr.return_value.create_invitation.called_once_with() | ||
|
||
messages = responder.messages | ||
assert len(messages) == 1 | ||
(result, _) = messages[0] | ||
assert type(result) == Invitation | ||
assert result._thread._thid == self.context.message._message_id | ||
|
||
async def test_handle_not_ready(self): | ||
handler = test_module.InvitationRequestHandler() | ||
self.context.connection_ready = False | ||
|
||
with self.assertRaises(HandlerException): | ||
await handler.handle(self.context, None) |
99 changes: 99 additions & 0 deletions
99
aries_cloudagent/protocols/introduction/tests/test_routes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from asynctest import TestCase as AsyncTestCase | ||
from asynctest import mock as async_mock | ||
|
||
from aiohttp import web as aio_web | ||
|
||
from ....config.injection_context import InjectionContext | ||
from ....connections.models.connection_record import ConnectionRecord | ||
from ....messaging.request_context import RequestContext | ||
|
||
from .. import routes as test_module | ||
|
||
|
||
class TestIntroductionRoutes(AsyncTestCase): | ||
async def test_introduction_start_no_service(self): | ||
context = RequestContext( | ||
base_context=InjectionContext(enforce_typing=False) | ||
) | ||
|
||
mock_req = async_mock.MagicMock() | ||
mock_req.app = { | ||
"request_context": context, | ||
"outbound_message_router": None | ||
} | ||
mock_req.json = async_mock.CoroutineMock( | ||
return_value={ | ||
"my_seed": "my_seed", | ||
"my_did": "my_did", | ||
"their_seed": "their_seed", | ||
"their_did": "their_did", | ||
"their_verkey": "their_verkey", | ||
"their_endpoint": "their_endpoint", | ||
"their_role": "their_role", | ||
"alias": "alias", | ||
} | ||
) | ||
mock_req.match_info = {"id": "dummy"} | ||
mock_req.query = { | ||
"target_connection_id": "dummy", | ||
"message": "Hello", | ||
} | ||
|
||
with self.assertRaises(test_module.web.HTTPForbidden): | ||
await test_module.introduction_start(mock_req) | ||
|
||
async def test_introduction_start(self): | ||
context = RequestContext( | ||
base_context=InjectionContext(enforce_typing=False) | ||
) | ||
|
||
mock_req = async_mock.MagicMock() | ||
mock_req.app = { | ||
"request_context": context, | ||
"outbound_message_router": None | ||
} | ||
mock_req.json = async_mock.CoroutineMock( | ||
return_value={ | ||
"my_seed": "my_seed", | ||
"my_did": "my_did", | ||
"their_seed": "their_seed", | ||
"their_did": "their_did", | ||
"their_verkey": "their_verkey", | ||
"their_endpoint": "their_endpoint", | ||
"their_role": "their_role", | ||
"alias": "alias", | ||
} | ||
) | ||
mock_req.match_info = {"id": "dummy"} | ||
mock_req.query = { | ||
"target_connection_id": "dummy", | ||
"message": "Hello", | ||
} | ||
|
||
mock_conn_rec = async_mock.MagicMock() | ||
mock_conn_rec.serialize = async_mock.MagicMock() | ||
|
||
test_module.web.json_response = async_mock.CoroutineMock() | ||
|
||
with async_mock.patch.object( | ||
context, "inject", async_mock.CoroutineMock() | ||
) as mock_ctx_inject: | ||
mock_ctx_inject.return_value = async_mock.MagicMock( | ||
start_introduction=async_mock.CoroutineMock() | ||
) | ||
|
||
await test_module.introduction_start(mock_req) | ||
mock_ctx_inject.return_value.start_introduction.assert_called_once_with( | ||
mock_req.match_info["id"], | ||
mock_req.query["target_connection_id"], | ||
mock_req.query["message"], | ||
mock_req.app["outbound_message_router"], | ||
) | ||
test_module.web.json_response.assert_called_once_with({}) | ||
|
||
async def test_register(self): | ||
mock_app = async_mock.MagicMock() | ||
mock_app.add_routes = async_mock.MagicMock() | ||
|
||
await test_module.register(mock_app) | ||
mock_app.add_routes.assert_called_once() |
Oops, something went wrong.