-
Notifications
You must be signed in to change notification settings - Fork 516
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
feat: did-rotate #2816
Merged
dbluhm
merged 29 commits into
openwallet-foundation:main
from
petridishdev:feature/did-rotate
Mar 15, 2024
Merged
feat: did-rotate #2816
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
84903a8
feat: add protocol skeleton for did-rotate
dbluhm 85470cd
fix: keys for problem report out of alignment with spec
dbluhm 533222d
feat: add did rotate messages
dbluhm 5fe679d
feat: stub handlers for did rotate
dbluhm 3aaf38d
refactor: rename to record_keys_for_resolvable_did
dbluhm 9bd7a70
feat: add manager (stubs) and models
dbluhm 360189e
feat: finish off rotate manager implementation
dbluhm 087b7b9
fix: noticed_time vs time_noticed in schema
dbluhm e25d082
fix: mock references to renamed method
dbluhm 729f0a4
Merge branch 'main' into feature/did-rotate
amanji 11d2245
feat: add routes with tests
amanji 74f1744
feat: add message handlers with test
amanji 4a2c5f2
Merge remote-tracking branch 'upstream/main' into feature/did-rotate
amanji 3ef1d56
fix: test failures
amanji 2a3de73
fix: test failures
amanji 726ff1c
Merge branch 'main' into feature/did-rotate
swcurran d7bef00
GHA update for doc publishing, fix doc file that was blanked
swcurran 1cc41fd
Merge branch 'main' into feature/did-rotate
amanji 00fa718
Merge branch 'main' into feature/did-rotate
swcurran db05f1e
Merge branch 'main' into feature/did-rotate
amanji 9c323da
feat: add tests for did-rotate messages
amanji 1d13b7b
chore: update package dependencies
amanji 2d32f05
feat: add addional reportable errors
amanji d432281
feat: delete rotate record once ack is received
amanji d5a5907
Merge branch 'main' into feature/did-rotate
dbluhm 03b8e49
feat: create did:peer:2/4 in wallet did endpoint
amanji 9062a9f
chore: fix linter errors
amanji fa1290b
fix: test errors
amanji bdb2600
feat: tests for did rotate manager
amanji File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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,10 @@ | ||
"""Version definitions for this protocol.""" | ||
|
||
versions = [ | ||
{ | ||
"major_version": 1, | ||
"minimum_minor_version": 0, | ||
"current_minor_version": 0, | ||
"path": "v1_0", | ||
} | ||
] |
Empty file.
Empty file.
29 changes: 29 additions & 0 deletions
29
aries_cloudagent/protocols/did_rotate/v1_0/handlers/ack_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,29 @@ | ||
"""Rotate ack handler.""" | ||
|
||
from .....messaging.base_handler import BaseHandler | ||
from .....messaging.request_context import RequestContext | ||
from .....messaging.responder import BaseResponder | ||
from ..manager import DIDRotateManager | ||
from ..messages.ack import RotateAck | ||
|
||
|
||
class RotateAckHandler(BaseHandler): | ||
"""Message handler class for rotate ack message.""" | ||
|
||
async def handle(self, context: RequestContext, responder: BaseResponder): | ||
"""Handle rotate ack message. | ||
|
||
Args: | ||
context: request context | ||
responder: responder callback | ||
""" | ||
self._logger.debug("RotateAckHandler called with context %s", context) | ||
assert isinstance(context.message, RotateAck) | ||
|
||
connection_record = context.connection_record | ||
ack = context.message | ||
|
||
profile = context.profile | ||
did_rotate_mgr = DIDRotateManager(profile) | ||
|
||
await did_rotate_mgr.receive_ack(connection_record, ack) |
29 changes: 29 additions & 0 deletions
29
aries_cloudagent/protocols/did_rotate/v1_0/handlers/hangup_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,29 @@ | ||
"""Rotate hangup handler.""" | ||
|
||
from .....messaging.base_handler import BaseHandler | ||
from .....messaging.request_context import RequestContext | ||
from .....messaging.responder import BaseResponder | ||
from ..manager import DIDRotateManager | ||
from ..messages.hangup import Hangup | ||
|
||
|
||
class HangupHandler(BaseHandler): | ||
"""Message handler class for rotate message.""" | ||
|
||
async def handle(self, context: RequestContext, responder: BaseResponder): | ||
"""Handle rotate hangup message. | ||
|
||
Args: | ||
context: request context | ||
responder: responder callback | ||
""" | ||
self._logger.debug("HangupHandler called with context %s", context) | ||
assert isinstance(context.message, Hangup) | ||
|
||
connection_record = context.connection_record | ||
hangup = context.message | ||
|
||
profile = context.profile | ||
did_rotate_mgr = DIDRotateManager(profile) | ||
|
||
await did_rotate_mgr.receive_hangup(connection_record, hangup) |
29 changes: 29 additions & 0 deletions
29
aries_cloudagent/protocols/did_rotate/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,29 @@ | ||
"""Rotate problem report handler.""" | ||
|
||
from .....messaging.base_handler import BaseHandler | ||
from .....messaging.request_context import RequestContext | ||
from .....messaging.responder import BaseResponder | ||
from ..manager import DIDRotateManager | ||
from ..messages.problem_report import RotateProblemReport | ||
|
||
|
||
class ProblemReportHandler(BaseHandler): | ||
"""Message handler class for rotate message.""" | ||
|
||
async def handle(self, context: RequestContext, responder: BaseResponder): | ||
"""Handle rotate problem report message. | ||
|
||
Args: | ||
context: request context | ||
responder: responder callback | ||
""" | ||
self._logger.debug("ProblemReportHandler called with context %s", context) | ||
assert isinstance(context.message, RotateProblemReport) | ||
|
||
connection_record = context.connection_record | ||
problem_report = context.message | ||
|
||
profile = context.profile | ||
did_rotate_mgr = DIDRotateManager(profile) | ||
|
||
await did_rotate_mgr.receive_problem_report(connection_record, problem_report) |
30 changes: 30 additions & 0 deletions
30
aries_cloudagent/protocols/did_rotate/v1_0/handlers/rotate_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,30 @@ | ||
"""Rotate handler.""" | ||
|
||
from .....messaging.base_handler import BaseHandler | ||
from .....messaging.request_context import RequestContext | ||
from .....messaging.responder import BaseResponder | ||
from ..manager import DIDRotateManager | ||
from ..messages.rotate import Rotate | ||
|
||
|
||
class RotateHandler(BaseHandler): | ||
"""Message handler class for rotate message.""" | ||
|
||
async def handle(self, context: RequestContext, responder: BaseResponder): | ||
"""Handle rotate message. | ||
|
||
Args: | ||
context: request context | ||
responder: responder callback | ||
""" | ||
self._logger.debug("RotateHandler called with context %s", context) | ||
assert isinstance(context.message, Rotate) | ||
|
||
connection_record = context.connection_record | ||
rotate = context.message | ||
|
||
profile = context.profile | ||
did_rotate_mgr = DIDRotateManager(profile) | ||
|
||
if record := await did_rotate_mgr.receive_rotate(connection_record, rotate): | ||
await did_rotate_mgr.commit_rotate(connection_record, record) |
Empty file.
33 changes: 33 additions & 0 deletions
33
aries_cloudagent/protocols/did_rotate/v1_0/handlers/tests/test_ack_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 @@ | ||
import pytest | ||
|
||
from ......messaging.request_context import RequestContext | ||
from ......messaging.responder import MockResponder | ||
from ......tests import mock | ||
from ...messages.ack import RotateAck | ||
from .. import ack_handler as test_module | ||
|
||
|
||
@pytest.fixture() | ||
def request_context(): | ||
ctx = RequestContext.test_context() | ||
yield ctx | ||
|
||
|
||
class TestAckHandler: | ||
"""Unit tests for AckHandler.""" | ||
|
||
@pytest.mark.asyncio | ||
@mock.patch.object(test_module, "DIDRotateManager") | ||
async def test_handle(self, MockDIDRotateManager, request_context): | ||
MockDIDRotateManager.return_value.receive_ack = mock.CoroutineMock() | ||
|
||
request_context.message = RotateAck() | ||
request_context.connection_record = mock.MagicMock() | ||
|
||
handler = test_module.RotateAckHandler() | ||
responder = MockResponder() | ||
await handler.handle(request_context, responder) | ||
|
||
MockDIDRotateManager.return_value.receive_ack.assert_called_once_with( | ||
request_context.connection_record, request_context.message | ||
) |
33 changes: 33 additions & 0 deletions
33
aries_cloudagent/protocols/did_rotate/v1_0/handlers/tests/test_hangup_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 @@ | ||
import pytest | ||
|
||
from ......messaging.request_context import RequestContext | ||
from ......messaging.responder import MockResponder | ||
from ......tests import mock | ||
from ...messages.hangup import Hangup | ||
from .. import hangup_handler as test_module | ||
|
||
|
||
@pytest.fixture() | ||
def request_context(): | ||
ctx = RequestContext.test_context() | ||
yield ctx | ||
|
||
|
||
class TestHangupHandler: | ||
"""Unit tests for HangupHandler.""" | ||
|
||
@pytest.mark.asyncio | ||
@mock.patch.object(test_module, "DIDRotateManager") | ||
async def test_handle(self, MockDIDRotateManager, request_context): | ||
MockDIDRotateManager.return_value.receive_hangup = mock.CoroutineMock() | ||
|
||
request_context.message = Hangup() | ||
request_context.connection_record = mock.MagicMock() | ||
|
||
handler = test_module.HangupHandler() | ||
responder = MockResponder() | ||
await handler.handle(request_context, responder) | ||
|
||
MockDIDRotateManager.return_value.receive_hangup.assert_called_once_with( | ||
request_context.connection_record, request_context.message | ||
) |
37 changes: 37 additions & 0 deletions
37
aries_cloudagent/protocols/did_rotate/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,37 @@ | ||
import pytest | ||
|
||
from ......messaging.request_context import RequestContext | ||
from ......messaging.responder import MockResponder | ||
from ......tests import mock | ||
from ...messages.problem_report import RotateProblemReport | ||
from .. import problem_report_handler as test_module | ||
|
||
test_valid_rotate_request = { | ||
"to_did": "did:example:newdid", | ||
} | ||
|
||
|
||
@pytest.fixture() | ||
def request_context(): | ||
ctx = RequestContext.test_context() | ||
yield ctx | ||
|
||
|
||
class TestProblemReportHandler: | ||
"""Unit tests for ProblemReportHandler.""" | ||
|
||
@pytest.mark.asyncio | ||
@mock.patch.object(test_module, "DIDRotateManager") | ||
async def test_handle(self, MockDIDRotateManager, request_context): | ||
MockDIDRotateManager.return_value.receive_problem_report = mock.CoroutineMock() | ||
|
||
request_context.message = RotateProblemReport() | ||
request_context.connection_record = mock.MagicMock() | ||
|
||
handler = test_module.ProblemReportHandler() | ||
responder = MockResponder() | ||
await handler.handle(request_context, responder) | ||
|
||
MockDIDRotateManager.return_value.receive_problem_report.assert_called_once_with( | ||
request_context.connection_record, request_context.message | ||
) |
42 changes: 42 additions & 0 deletions
42
aries_cloudagent/protocols/did_rotate/v1_0/handlers/tests/test_rotate_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,42 @@ | ||
import pytest | ||
|
||
from ......messaging.request_context import RequestContext | ||
from ......messaging.responder import MockResponder | ||
from ......tests import mock | ||
from ...messages.rotate import Rotate | ||
from .. import rotate_handler as test_module | ||
|
||
test_valid_rotate_request = { | ||
"to_did": "did:example:newdid", | ||
} | ||
|
||
|
||
@pytest.fixture() | ||
def request_context(): | ||
ctx = RequestContext.test_context() | ||
yield ctx | ||
|
||
|
||
class TestRotateHandler: | ||
"""Unit tests for RotateHandler.""" | ||
|
||
@pytest.mark.asyncio | ||
@mock.patch.object(test_module, "DIDRotateManager") | ||
async def test_handle(self, MockDIDRotateManager, request_context): | ||
MockDIDRotateManager.return_value.receive_rotate = mock.CoroutineMock() | ||
MockDIDRotateManager.return_value.commit_rotate = mock.CoroutineMock() | ||
|
||
request_context.message = Rotate(**test_valid_rotate_request) | ||
request_context.connection_record = mock.MagicMock() | ||
|
||
handler = test_module.RotateHandler() | ||
responder = MockResponder() | ||
await handler.handle(request_context, responder) | ||
|
||
MockDIDRotateManager.return_value.receive_rotate.assert_called_once_with( | ||
request_context.connection_record, request_context.message | ||
) | ||
MockDIDRotateManager.return_value.commit_rotate.assert_called_once_with( | ||
request_context.connection_record, | ||
MockDIDRotateManager.return_value.receive_rotate.return_value, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should discuss this point; if we don't make this change now, there can be unexpected behavior in clusters. Additionally, once the rotation is completed, there is no way to handle any potentially out of order messages. If we did make this change, the cached value for the previous DIDs would be around until the cache expires them. There would still be issues in clustered environments without whole cluster caching, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can live with this for now, I think this PR is in a good state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I'm not entirely familiar with how the different caching mechanisms work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm feeling like the right option right now is probably to log an issue to address handling potentially out of order messages received after a rotation. It's an unlikely edge case and I think it will be more valuable to keep this PR moving for now.