Skip to content

Commit 55e52d6

Browse files
committed
test: implicit invites
Signed-off-by: Micah Peltier <micah6_8@yahoo.com>
1 parent 91ba45b commit 55e52d6

1 file changed

Lines changed: 143 additions & 0 deletions

File tree

aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,149 @@ async def test_receive_request_public_did_no_auto_accept(self):
971971
messages = self.responder.messages
972972
assert not messages
973973

974+
async def test_receive_request_implicit_public_did_not_enabled(self):
975+
async with self.profile.session() as session:
976+
mock_request = async_mock.MagicMock(
977+
did=TestConfig.test_did,
978+
did_doc_attach=async_mock.MagicMock(
979+
data=async_mock.MagicMock(
980+
verify=async_mock.CoroutineMock(return_value=True),
981+
signed=async_mock.MagicMock(
982+
decode=async_mock.MagicMock(return_value="dummy-did-doc")
983+
),
984+
)
985+
),
986+
_thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"),
987+
)
988+
mediation_record = MediationRecord(
989+
role=MediationRecord.ROLE_CLIENT,
990+
state=MediationRecord.STATE_GRANTED,
991+
connection_id=self.test_mediator_conn_id,
992+
routing_keys=self.test_mediator_routing_keys,
993+
endpoint=self.test_mediator_endpoint,
994+
)
995+
await mediation_record.save(session)
996+
997+
await session.wallet.create_local_did(
998+
method=DIDMethod.SOV,
999+
key_type=KeyType.ED25519,
1000+
seed=None,
1001+
did=TestConfig.test_did,
1002+
)
1003+
1004+
self.profile.context.update_settings({"public_invites": True})
1005+
1006+
with async_mock.patch.object(
1007+
test_module, "ConnRecord", async_mock.MagicMock()
1008+
) as mock_conn_rec_cls, async_mock.patch.object(
1009+
test_module, "DIDDoc", autospec=True
1010+
) as mock_did_doc, async_mock.patch.object(
1011+
test_module, "DIDPosture", autospec=True
1012+
) as mock_did_posture, async_mock.patch.object(
1013+
self.manager,
1014+
"verify_diddoc",
1015+
async_mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did))):
1016+
mock_did_posture.get = async_mock.MagicMock(
1017+
return_value=test_module.DIDPosture.PUBLIC
1018+
)
1019+
mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.CoroutineMock(
1020+
side_effect=StorageNotFoundError()
1021+
)
1022+
mock_conn_rec_cls.retrieve_by_invitation_msg_id = (
1023+
async_mock.CoroutineMock(return_value=None)
1024+
)
1025+
1026+
with self.assertRaises(DIDXManagerError) as context:
1027+
await self.manager.receive_request(
1028+
request=mock_request,
1029+
recipient_did=TestConfig.test_did,
1030+
my_endpoint=None,
1031+
alias=None,
1032+
auto_accept_implicit=None,
1033+
)
1034+
assert "Unsolicited connection requests" in str(context.exception)
1035+
1036+
async def test_receive_request_implicit_public_did(self):
1037+
async with self.profile.session() as session:
1038+
mock_request = async_mock.MagicMock(
1039+
did=TestConfig.test_did,
1040+
did_doc_attach=async_mock.MagicMock(
1041+
data=async_mock.MagicMock(
1042+
verify=async_mock.CoroutineMock(return_value=True),
1043+
signed=async_mock.MagicMock(
1044+
decode=async_mock.MagicMock(return_value="dummy-did-doc")
1045+
),
1046+
)
1047+
),
1048+
_thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"),
1049+
)
1050+
mediation_record = MediationRecord(
1051+
role=MediationRecord.ROLE_CLIENT,
1052+
state=MediationRecord.STATE_GRANTED,
1053+
connection_id=self.test_mediator_conn_id,
1054+
routing_keys=self.test_mediator_routing_keys,
1055+
endpoint=self.test_mediator_endpoint,
1056+
)
1057+
await mediation_record.save(session)
1058+
1059+
await session.wallet.create_local_did(
1060+
method=DIDMethod.SOV,
1061+
key_type=KeyType.ED25519,
1062+
seed=None,
1063+
did=TestConfig.test_did,
1064+
)
1065+
1066+
self.profile.context.update_settings({"public_invites": True})
1067+
self.profile.context.update_settings({"requests_through_public_did": True})
1068+
ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO
1069+
STATE_REQUEST = ConnRecord.State.REQUEST
1070+
1071+
with async_mock.patch.object(
1072+
test_module, "ConnRecord", async_mock.MagicMock()
1073+
) as mock_conn_rec_cls, async_mock.patch.object(
1074+
test_module, "DIDDoc", autospec=True
1075+
) as mock_did_doc, async_mock.patch.object(
1076+
test_module, "DIDPosture", autospec=True
1077+
) as mock_did_posture, async_mock.patch.object(
1078+
self.manager,
1079+
"verify_diddoc",
1080+
async_mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did))):
1081+
mock_did_posture.get = async_mock.MagicMock(
1082+
return_value=test_module.DIDPosture.PUBLIC
1083+
)
1084+
mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.CoroutineMock(
1085+
side_effect=StorageNotFoundError()
1086+
)
1087+
mock_conn_rec_cls.retrieve_by_invitation_msg_id = (
1088+
async_mock.CoroutineMock(return_value=None)
1089+
)
1090+
1091+
mock_conn_record = async_mock.MagicMock(
1092+
accept=ACCEPT_AUTO,
1093+
my_did=None,
1094+
state=STATE_REQUEST.rfc23,
1095+
attach_request=async_mock.CoroutineMock(),
1096+
retrieve_request=async_mock.CoroutineMock(),
1097+
metadata_get_all=async_mock.CoroutineMock(return_value={}),
1098+
metadata_get=async_mock.CoroutineMock(return_value=True),
1099+
save=async_mock.CoroutineMock(),
1100+
)
1101+
1102+
mock_conn_rec_cls.return_value = mock_conn_record
1103+
1104+
conn_rec = await self.manager.receive_request(
1105+
request=mock_request,
1106+
recipient_did=TestConfig.test_did,
1107+
recipient_verkey=None,
1108+
my_endpoint=None,
1109+
alias=None,
1110+
auto_accept_implicit=None,
1111+
)
1112+
assert conn_rec
1113+
self.oob_mock.clean_finished_oob_record.assert_called_once_with(
1114+
self.profile, mock_request
1115+
)
1116+
9741117
async def test_receive_request_peer_did(self):
9751118
async with self.profile.session() as session:
9761119
mock_request = async_mock.MagicMock(

0 commit comments

Comments
 (0)