-
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 pull request #1734 from Indicio-tech/feat/revocation-notificati…
…on-v2 Feat/revocation notification v2
- Loading branch information
Showing
22 changed files
with
714 additions
and
1 deletion.
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
Empty file.
Empty file.
44 changes: 44 additions & 0 deletions
44
aries_cloudagent/protocols/revocation_notification/v2_0/handlers/revoke_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,44 @@ | ||
"""Handler for revoke message.""" | ||
|
||
from .....messaging.base_handler import BaseHandler | ||
from .....messaging.request_context import RequestContext | ||
from .....messaging.responder import BaseResponder | ||
|
||
from ..messages.revoke import Revoke | ||
|
||
|
||
class RevokeHandler(BaseHandler): | ||
"""Handler for revoke message.""" | ||
|
||
RECIEVED_TOPIC = "acapy::revocation-notification-v2::received" | ||
WEBHOOK_TOPIC = "acapy::webhook::revocation-notification-v2" | ||
|
||
async def handle(self, context: RequestContext, responder: BaseResponder): | ||
"""Handle revoke message.""" | ||
assert isinstance(context.message, Revoke) | ||
self._logger.debug( | ||
"Received notification of revocation for %s cred %s with comment: %s", | ||
context.message.revocation_format, | ||
context.message.credential_id, | ||
context.message.comment, | ||
) | ||
# Emit a webhook | ||
if context.settings.get("revocation.monitor_notification"): | ||
await context.profile.notify( | ||
self.WEBHOOK_TOPIC, | ||
{ | ||
"revocation_format": context.message.revocation_format, | ||
"credential_id": context.message.credential_id, | ||
"comment": context.message.comment, | ||
}, | ||
) | ||
|
||
# Emit an event | ||
await context.profile.notify( | ||
self.RECIEVED_TOPIC, | ||
{ | ||
"revocation_format": context.message.revocation_format, | ||
"credential_id": context.message.credential_id, | ||
"comment": context.message.comment, | ||
}, | ||
) |
Empty file.
75 changes: 75 additions & 0 deletions
75
...s_cloudagent/protocols/revocation_notification/v2_0/handlers/tests/test_revoke_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,75 @@ | ||
"""Test RevokeHandler.""" | ||
|
||
import pytest | ||
|
||
from ......config.settings import Settings | ||
from ......core.event_bus import EventBus, MockEventBus | ||
from ......core.in_memory import InMemoryProfile | ||
from ......core.profile import Profile | ||
from ......messaging.request_context import RequestContext | ||
from ......messaging.responder import MockResponder, BaseResponder | ||
from ...messages.revoke import Revoke | ||
from ..revoke_handler import RevokeHandler | ||
|
||
|
||
@pytest.fixture | ||
def event_bus(): | ||
yield MockEventBus() | ||
|
||
|
||
@pytest.fixture | ||
def responder(): | ||
yield MockResponder() | ||
|
||
|
||
@pytest.fixture | ||
def profile(event_bus): | ||
yield InMemoryProfile.test_profile(bind={EventBus: event_bus}) | ||
|
||
|
||
@pytest.fixture | ||
def message(): | ||
yield Revoke( | ||
revocation_format="indy-anoncreds", | ||
credential_id="mock_cred_revocation_id", | ||
comment="mock_comment", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def context(profile: Profile, message: Revoke): | ||
request_context = RequestContext(profile) | ||
request_context.message = message | ||
yield request_context | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_handle( | ||
context: RequestContext, responder: BaseResponder, event_bus: MockEventBus | ||
): | ||
await RevokeHandler().handle(context, responder) | ||
assert event_bus.events | ||
[(_, received)] = event_bus.events | ||
assert received.topic == RevokeHandler.RECIEVED_TOPIC | ||
assert "revocation_format" in received.payload | ||
assert "credential_id" in received.payload | ||
assert "comment" in received.payload | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_handle_monitor( | ||
context: RequestContext, responder: BaseResponder, event_bus: MockEventBus | ||
): | ||
context.settings["revocation.monitor_notification"] = True | ||
await RevokeHandler().handle(context, responder) | ||
[(_, webhook), (_, received)] = event_bus.events | ||
|
||
assert webhook.topic == RevokeHandler.WEBHOOK_TOPIC | ||
assert "revocation_format" in received.payload | ||
assert "credential_id" in received.payload | ||
assert "comment" in webhook.payload | ||
|
||
assert received.topic == RevokeHandler.RECIEVED_TOPIC | ||
assert "revocation_format" in received.payload | ||
assert "credential_id" in received.payload | ||
assert "comment" in received.payload |
20 changes: 20 additions & 0 deletions
20
aries_cloudagent/protocols/revocation_notification/v2_0/message_types.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,20 @@ | ||
"""Message type identifiers for Revocation Notification protocol.""" | ||
|
||
from ...didcomm_prefix import DIDCommPrefix | ||
|
||
|
||
SPEC_URI = ( | ||
"https://github.com/hyperledger/aries-rfcs/blob/main/features/" | ||
"0721-revocation-notification-v2/README.md" | ||
) | ||
PROTOCOL = "revocation_notification" | ||
VERSION = "2.0" | ||
BASE = f"{PROTOCOL}/{VERSION}" | ||
|
||
# Message types | ||
REVOKE = f"{BASE}/revoke" | ||
|
||
PROTOCOL_PACKAGE = "aries_cloudagent.protocols.revocation_notification.v2_0" | ||
MESSAGE_TYPES = DIDCommPrefix.qualify_all( | ||
{REVOKE: f"{PROTOCOL_PACKAGE}.messages.revoke.Revoke"} | ||
) |
Empty file.
69 changes: 69 additions & 0 deletions
69
aries_cloudagent/protocols/revocation_notification/v2_0/messages/revoke.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,69 @@ | ||
"""Revoke message.""" | ||
|
||
from marshmallow import fields, validate | ||
from .....messaging.agent_message import AgentMessage, AgentMessageSchema | ||
from .....messaging.decorators.please_ack_decorator import ( | ||
PleaseAckDecorator, | ||
PleaseAckDecoratorSchema, | ||
) | ||
from .....messaging.valid import UUIDFour | ||
from ..message_types import PROTOCOL_PACKAGE, REVOKE | ||
|
||
HANDLER_CLASS = f"{PROTOCOL_PACKAGE}.handlers.revoke_handler.RevokeHandler" | ||
|
||
|
||
class Revoke(AgentMessage): | ||
"""Class representing revoke message.""" | ||
|
||
class Meta: | ||
"""Revoke Meta.""" | ||
|
||
handler_class = HANDLER_CLASS | ||
message_type = REVOKE | ||
schema_class = "RevokeSchema" | ||
|
||
def __init__( | ||
self, | ||
*, | ||
revocation_format: str, | ||
credential_id: str, | ||
please_ack: PleaseAckDecorator = None, | ||
comment: str = None, | ||
**kwargs, | ||
): | ||
"""Initialize revoke message.""" | ||
super().__init__(**kwargs) | ||
self.revocation_format = revocation_format | ||
self.credential_id = credential_id | ||
self.comment = comment | ||
|
||
|
||
class RevokeSchema(AgentMessageSchema): | ||
"""Schema of Revoke message.""" | ||
|
||
class Meta: | ||
"""RevokeSchema Meta.""" | ||
|
||
model_class = Revoke | ||
|
||
revocation_format = fields.Str( | ||
required=True, | ||
description=("The format of the credential revocation ID"), | ||
example="indy-anoncreds", | ||
validate=validate.OneOf(["indy-anoncreds"]), | ||
) | ||
credential_id = fields.Str( | ||
required=True, | ||
description=("Credential ID of the issued credential to be revoked"), | ||
example=UUIDFour.EXAMPLE, | ||
) | ||
please_ack = fields.Nested( | ||
PleaseAckDecoratorSchema, | ||
required=False, | ||
description="Whether or not the holder should acknowledge receipt", | ||
data_key="~please_ack", | ||
) | ||
comment = fields.Str( | ||
required=False, | ||
description="Human readable information about revocation notification", | ||
) |
Empty file.
14 changes: 14 additions & 0 deletions
14
aries_cloudagent/protocols/revocation_notification/v2_0/messages/tests/test_revoke.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,14 @@ | ||
"""Test Revoke Message.""" | ||
|
||
from ..revoke import Revoke | ||
|
||
|
||
def test_instantiate(): | ||
msg = Revoke( | ||
revocation_format="indy-anoncreds", | ||
credential_id="test-id", | ||
comment="test", | ||
) | ||
assert msg.revocation_format == "indy-anoncreds" | ||
assert msg.credential_id == "test-id" | ||
assert msg.comment == "test" |
Empty file.
Oops, something went wrong.