forked from openwallet-foundation/acapy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openwallet-foundation#2394 from dbluhm/feature/did…
…x-reject feat: add DID Exchange specific problem reports and reject endpoint
- Loading branch information
Showing
19 changed files
with
517 additions
and
66 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
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
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
33 changes: 33 additions & 0 deletions
33
aries_cloudagent/protocols/didexchange/v1_0/handlers/problem_report_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,33 @@ | ||
"""Problem report handler for DID Exchange.""" | ||
|
||
from .....messaging.base_handler import ( | ||
BaseHandler, | ||
BaseResponder, | ||
HandlerException, | ||
RequestContext, | ||
) | ||
from ..manager import DIDXManager, DIDXManagerError | ||
from ..messages.problem_report import DIDXProblemReport | ||
|
||
|
||
class DIDXProblemReportHandler(BaseHandler): | ||
"""Handler class for DID Exchange problem report messages.""" | ||
|
||
async def handle(self, context: RequestContext, responder: BaseResponder): | ||
"""Handle problem report message.""" | ||
self._logger.debug(f"DIDXProblemReportHandler called with context {context}") | ||
assert isinstance(context.message, DIDXProblemReport) | ||
|
||
self._logger.info("Received problem report: %s", context.message.description) | ||
profile = context.profile | ||
mgr = DIDXManager(profile) | ||
try: | ||
if context.connection_record: | ||
await mgr.receive_problem_report( | ||
context.connection_record, context.message | ||
) | ||
else: | ||
raise HandlerException("No connection established for problem report") | ||
except DIDXManagerError: | ||
# Unrecognized problem report code | ||
self._logger.exception("Error receiving DID Exchange problem report") |
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
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
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
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
56 changes: 56 additions & 0 deletions
56
aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_problem_report_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,56 @@ | ||
from asynctest import mock as async_mock | ||
import pytest | ||
|
||
from .. import problem_report_handler as test_module | ||
from ......messaging.base_handler import HandlerException | ||
from ......messaging.request_context import RequestContext | ||
from ......messaging.responder import MockResponder | ||
from ...manager import DIDXManagerError | ||
from ...messages.problem_report import DIDXProblemReport | ||
|
||
|
||
@pytest.fixture() | ||
def request_context(): | ||
ctx = RequestContext.test_context() | ||
yield ctx | ||
|
||
|
||
class TestDIDXProblemReportHandler: | ||
"""Unit test problem report handler.""" | ||
|
||
@pytest.mark.asyncio | ||
@async_mock.patch.object(test_module, "DIDXManager") | ||
async def test_called(self, manager, request_context): | ||
manager.return_value.receive_problem_report = async_mock.CoroutineMock() | ||
request_context.message = DIDXProblemReport() | ||
request_context.connection_record = async_mock.MagicMock() | ||
handler_inst = test_module.DIDXProblemReportHandler() | ||
responder = MockResponder() | ||
await handler_inst.handle(request_context, responder) | ||
assert not responder.messages | ||
assert manager.return_value.receive_problem_report.called_once() | ||
|
||
@pytest.mark.asyncio | ||
@async_mock.patch.object(test_module, "DIDXManager") | ||
async def test_called_no_conn(self, manager, request_context): | ||
manager.return_value.receive_problem_report = async_mock.CoroutineMock() | ||
request_context.message = DIDXProblemReport() | ||
handler_inst = test_module.DIDXProblemReportHandler() | ||
responder = MockResponder() | ||
with pytest.raises(HandlerException): | ||
await handler_inst.handle(request_context, responder) | ||
|
||
@pytest.mark.asyncio | ||
@async_mock.patch.object(test_module, "DIDXManager") | ||
async def test_called_unrecognized_report_exception( | ||
self, manager, request_context, caplog | ||
): | ||
manager.return_value.receive_problem_report = async_mock.CoroutineMock( | ||
side_effect=DIDXManagerError() | ||
) | ||
request_context.message = DIDXProblemReport() | ||
request_context.connection_record = async_mock.MagicMock() | ||
handler_inst = test_module.DIDXProblemReportHandler() | ||
responder = MockResponder() | ||
await handler_inst.handle(request_context, responder) | ||
assert "Error receiving DID Exchange problem report" in caplog.text |
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
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
Oops, something went wrong.