Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply security patch 0.11.x #3120

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from .....messaging.base_handler import (
BaseHandler,
BaseResponder,
HandlerException,
RequestContext,
)

from ..messages.menu import Menu
from ..util import save_connection_menu

Expand All @@ -23,6 +23,9 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
self._logger.debug("MenuHandler called with context %s", context)
assert isinstance(context.message, Menu)

if not context.connection_ready:
raise HandlerException("No connection established")

self._logger.info("Received action menu: %s", context.message)

await save_connection_menu(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from .....messaging.base_handler import (
BaseHandler,
BaseResponder,
HandlerException,
RequestContext,
)

from ..base_service import BaseMenuService
from ..messages.menu_request import MenuRequest

Expand All @@ -23,6 +23,9 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
self._logger.debug("MenuRequestHandler called with context %s", context)
assert isinstance(context.message, MenuRequest)

if not context.connection_ready:
raise HandlerException("No connection established")

self._logger.info("Received action menu request")

service: BaseMenuService = context.inject_or(BaseMenuService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from .....messaging.base_handler import (
BaseHandler,
BaseResponder,
HandlerException,
RequestContext,
)

from ..base_service import BaseMenuService
from ..messages.perform import Perform

Expand All @@ -23,6 +23,9 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
self._logger.debug("PerformHandler called with context %s", context)
assert isinstance(context.message, Perform)

if not context.connection_ready:
raise HandlerException("No connection established")

self._logger.info("Received action menu perform request")

service: BaseMenuService = context.inject_or(BaseMenuService)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from unittest import IsolatedAsyncioTestCase

from aries_cloudagent.tests import mock

from ......messaging.request_context import RequestContext
from ......messaging.responder import MockResponder

from .. import menu_handler as handler


Expand All @@ -12,6 +12,7 @@ async def test_called(self):
request_context = RequestContext.test_context()
request_context.connection_record = mock.MagicMock()
request_context.connection_record.connection_id = "dummy"
request_context.connection_ready = True

handler.save_connection_menu = mock.CoroutineMock()
responder = MockResponder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from unittest import IsolatedAsyncioTestCase

from aries_cloudagent.tests import mock

from ......messaging.request_context import RequestContext
from ......messaging.responder import MockResponder

from .. import menu_request_handler as handler


Expand All @@ -18,6 +18,7 @@ async def test_called(self):

self.context.connection_record = mock.MagicMock()
self.context.connection_record.connection_id = "dummy"
self.context.connection_ready = True

responder = MockResponder()
self.context.message = handler.MenuRequest()
Expand All @@ -39,6 +40,7 @@ async def test_called_no_active_menu(self):

self.context.connection_record = mock.MagicMock()
self.context.connection_record.connection_id = "dummy"
self.context.connection_ready = True

responder = MockResponder()
self.context.message = handler.MenuRequest()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from unittest import IsolatedAsyncioTestCase

from aries_cloudagent.tests import mock

from ......messaging.request_context import RequestContext
from ......messaging.responder import MockResponder

from .. import perform_handler as handler


Expand All @@ -18,12 +18,11 @@ async def test_called(self):

self.context.connection_record = mock.MagicMock()
self.context.connection_record.connection_id = "dummy"
self.context.connection_ready = True

responder = MockResponder()
self.context.message = handler.Perform()
self.menu_service.perform_menu_action = mock.CoroutineMock(
return_value="perform"
)
self.menu_service.perform_menu_action = mock.CoroutineMock(return_value="perform")

handler_inst = handler.PerformHandler()
await handler_inst.handle(self.context, responder)
Expand All @@ -41,6 +40,7 @@ async def test_called_no_active_menu(self):

self.context.connection_record = mock.MagicMock()
self.context.connection_record.connection_id = "dummy"
self.context.connection_ready = True

responder = MockResponder()
self.context.message = handler.Perform()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from .....messaging.base_handler import (
BaseHandler,
BaseResponder,
HandlerException,
RequestContext,
)

from ..messages.basicmessage import BasicMessage


Expand All @@ -22,6 +22,9 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
self._logger.debug("BasicMessageHandler called with context %s", context)
assert isinstance(context.message, BasicMessage)

if not context.connection_ready:
raise HandlerException("No connection established")

self._logger.info("Received basic message: %s", context.message.content)

body = context.message.content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
from .....messaging.base_handler import (
BaseHandler,
BaseResponder,
RequestContext,
HandlerException,
RequestContext,
)

from ..manager import V10DiscoveryMgr
from ..messages.disclose import Disclose

Expand All @@ -18,10 +17,12 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
"""Message handler implementation."""
self._logger.debug("DiscloseHandler called with context %s", context)
assert isinstance(context.message, Disclose)

if not context.connection_ready:
raise HandlerException(
"Received disclosures message from inactive connection"
)

profile = context.profile
mgr = V10DiscoveryMgr(profile)
await mgr.receive_disclose(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from .....messaging.base_handler import (
BaseHandler,
BaseResponder,
HandlerException,
RequestContext,
)

from ..manager import V10DiscoveryMgr
from ..messages.query import Query

Expand All @@ -17,6 +17,10 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
"""Message handler implementation."""
self._logger.debug("QueryHandler called with context %s", context)
assert isinstance(context.message, Query)

if not context.connection_ready:
raise HandlerException("No connection established")

profile = context.profile
mgr = V10DiscoveryMgr(profile)
reply = await mgr.receive_query(context.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from ......core.protocol_registry import ProtocolRegistry
from ......messaging.request_context import RequestContext
from ......messaging.responder import MockResponder

from ...handlers.query_handler import QueryHandler
from ...messages.disclose import Disclose
from ...messages.query import Query
Expand All @@ -30,6 +29,7 @@ async def test_query_all(self, request_context):
query_msg = Query(query="*")
query_msg.assign_thread_id("test123")
request_context.message = query_msg
request_context.connection_ready = True
handler = QueryHandler()
responder = MockResponder()
await handler.handle(request_context, responder)
Expand All @@ -50,6 +50,7 @@ async def test_query_all_disclose_list_settings(self, request_context):
query_msg = Query(query="*")
query_msg.assign_thread_id("test123")
request_context.message = query_msg
request_context.connection_ready = True
handler = QueryHandler()
responder = MockResponder()
await handler.handle(request_context, responder)
Expand All @@ -65,6 +66,7 @@ async def test_receive_query_process_disclosed(self, request_context):
query_msg = Query(query="*")
query_msg.assign_thread_id("test123")
request_context.message = query_msg
request_context.connection_ready = True
handler = QueryHandler()
responder = MockResponder()
with mock.patch.object(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
from .....messaging.base_handler import (
BaseHandler,
BaseResponder,
RequestContext,
HandlerException,
RequestContext,
)

from ..manager import V20DiscoveryMgr
from ..messages.disclosures import Disclosures

Expand All @@ -18,10 +17,12 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
"""Message handler implementation."""
self._logger.debug("DiscloseHandler called with context %s", context)
assert isinstance(context.message, Disclosures)

if not context.connection_ready:
raise HandlerException(
"Received disclosures message from inactive connection"
)

profile = context.profile
mgr = V20DiscoveryMgr(profile)
await mgr.receive_disclose(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from .....messaging.base_handler import (
BaseHandler,
BaseResponder,
HandlerException,
RequestContext,
)

from ..manager import V20DiscoveryMgr
from ..messages.queries import Queries

Expand All @@ -17,6 +17,10 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
"""Message handler implementation."""
self._logger.debug("QueryHandler called with context %s", context)
assert isinstance(context.message, Queries)

if not context.connection_ready:
raise HandlerException("No connection established")

profile = context.profile
mgr = V20DiscoveryMgr(profile)
reply = await mgr.receive_query(context.message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from typing import Generator

import pytest

from aries_cloudagent.tests import mock

from ......core.protocol_registry import ProtocolRegistry
from ......core.goal_code_registry import GoalCodeRegistry
from ......core.protocol_registry import ProtocolRegistry
from ......messaging.request_context import RequestContext
from ......messaging.responder import MockResponder
from ......protocols.issue_credential.v1_0.controller import (
Expand All @@ -16,7 +18,6 @@
from ......protocols.present_proof.v1_0.message_types import (
CONTROLLERS as pres_proof_v1_controller,
)

from ...handlers.queries_handler import QueriesHandler
from ...manager import V20DiscoveryMgr
from ...messages.disclosures import Disclosures
Expand All @@ -27,7 +28,7 @@


@pytest.fixture()
def request_context() -> RequestContext:
def request_context() -> Generator[RequestContext, None, None]:
ctx = RequestContext.test_context()
protocol_registry = ProtocolRegistry()
goal_code_registry = GoalCodeRegistry()
Expand All @@ -48,6 +49,7 @@ async def test_queries_all(self, request_context):
queries = Queries(queries=test_queries)
queries.assign_thread_id("test123")
request_context.message = queries
request_context.connection_ready = True
handler = QueriesHandler()
responder = MockResponder()
await handler.handle(request_context, responder)
Expand All @@ -67,6 +69,7 @@ async def test_queries_protocol_goal_code_all(self, request_context):
queries = Queries(queries=test_queries)
queries.assign_thread_id("test123")
request_context.message = queries
request_context.connection_ready = True
handler = QueriesHandler()
responder = MockResponder()
await handler.handle(request_context, responder)
Expand Down Expand Up @@ -105,6 +108,7 @@ async def test_queries_protocol_goal_code_all_disclose_list_settings(
queries = Queries(queries=test_queries)
queries.assign_thread_id("test123")
request_context.message = queries
request_context.connection_ready = True
handler = QueriesHandler()
responder = MockResponder()
await handler.handle(request_context, responder)
Expand All @@ -129,6 +133,7 @@ async def test_receive_query_process_disclosed(self, request_context):
queries_msg = Queries(queries=test_queries)
queries_msg.assign_thread_id("test123")
request_context.message = queries_msg
request_context.connection_ready = True
handler = QueriesHandler()
responder = MockResponder()
with mock.patch.object(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from .....messaging.base_handler import (
BaseHandler,
BaseResponder,
HandlerException,
RequestContext,
)

from ..manager import TransactionManager, TransactionManagerError
from ..messages.transaction_job_to_send import TransactionJobToSend

Expand All @@ -24,10 +24,11 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
self._logger.debug(f"TransactionJobToSendHandler called with context {context}")
assert isinstance(context.message, TransactionJobToSend)

if not context.connection_ready:
raise HandlerException("No connection established")

mgr = TransactionManager(context.profile)
try:
await mgr.set_transaction_their_job(
context.message, context.message_receipt
)
await mgr.set_transaction_their_job(context.message, context.message_receipt)
except TransactionManagerError:
self._logger.exception("Error receiving transaction jobs")
Loading
Loading