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

preview from offer now contains attribute values - take them out of i… #596

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 @@ -38,7 +38,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):

credential_manager = CredentialManager(context)

credential_exchange_record = await credential_manager.receive_credential()
cred_ex_record = await credential_manager.receive_credential()

r_time = trace_event(
context.settings,
Expand All @@ -50,9 +50,9 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
# Automatically move to next state if flag is set
if context.settings.get("debug.auto_store_credential"):
(
credential_exchange_record,
cred_ex_record,
credential_ack_message,
) = await credential_manager.store_credential(credential_exchange_record)
) = await credential_manager.store_credential(cred_ex_record)

# Ack issuer that holder stored credential
await responder.send_reply(credential_ack_message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):

credential_manager = CredentialManager(context)

credential_exchange_record = await credential_manager.receive_offer()
cred_ex_record = await credential_manager.receive_offer()

r_time = trace_event(
context.settings,
Expand All @@ -51,7 +51,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
# If auto respond is turned on, automatically reply with credential request
if context.settings.get("debug.auto_respond_credential_offer"):
(_, credential_request_message) = await credential_manager.create_request(
cred_ex_record=credential_exchange_record,
cred_ex_record=cred_ex_record,
holder_did=context.connection_record.my_did,
)
await responder.send_reply(credential_request_message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
raise HandlerException("No connection established for credential proposal")

credential_manager = CredentialManager(context)
credential_exchange_record = await credential_manager.receive_proposal()
cred_ex_record = await credential_manager.receive_proposal()

r_time = trace_event(
context.settings,
Expand All @@ -48,12 +48,12 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
)

# If auto_offer is enabled, respond immediately with offer
if credential_exchange_record.auto_offer:
if cred_ex_record.auto_offer:
(
credential_exchange_record,
cred_ex_record,
credential_offer_message,
) = await credential_manager.create_offer(
credential_exchange_record, comment=context.message.comment
cred_ex_record, comment=context.message.comment
)

await responder.send_reply(credential_offer_message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from ..manager import CredentialManager
from ..messages.credential_request import CredentialRequest
from ..messages.credential_proposal import CredentialProposal

from .....utils.tracing import trace_event, get_timer

Expand Down Expand Up @@ -39,7 +38,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
raise HandlerException("No connection established for credential request")

credential_manager = CredentialManager(context)
cred_exchange_rec = await credential_manager.receive_request()
cred_ex_record = await credential_manager.receive_request()

r_time = trace_event(
context.settings,
Expand All @@ -49,20 +48,16 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
)

# If auto_issue is enabled, respond immediately
if cred_exchange_rec.auto_issue:
if cred_ex_record.auto_issue:
if (
cred_exchange_rec.credential_proposal_dict
and "credential_proposal" in cred_exchange_rec.credential_proposal_dict
cred_ex_record.credential_proposal_dict
and "credential_proposal" in cred_ex_record.credential_proposal_dict
):
(
cred_exchange_rec,
cred_ex_record,
credential_issue_message,
) = await credential_manager.issue_credential(
cred_ex_record=cred_exchange_rec,
comment=context.message.comment,
credential_values=CredentialProposal.deserialize(
cred_exchange_rec.credential_proposal_dict
).credential_proposal.attr_dict(),
cred_ex_record=cred_ex_record, comment=context.message.comment
)

await responder.send_reply(credential_issue_message)
Expand All @@ -76,6 +71,6 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
else:
self._logger.warning(
"Operation set for auto-issue but credential exchange record "
f"{cred_exchange_rec.credential_exchange_id} "
f"{cred_ex_record.credential_exchange_id} "
"has no attribute values"
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,26 @@ async def test_called_auto_issue(self):
attributes=(CredAttrSpec.list_plain(ATTR_DICT))
).serialize(),
"cred_def_id": CD_ID,
}
},
)

with async_mock.patch.object(
handler, "CredentialManager", autospec=True
) as mock_cred_mgr, async_mock.patch.object(
handler, "CredentialProposal", autospec=True
) as mock_cred_proposal:
) as mock_cred_mgr:
mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock(
return_value=cred_ex_rec
)
mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True
mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock(
return_value=(None, "credential_issue_message")
)
mock_cred_proposal.deserialize = async_mock.MagicMock(
return_value=mock_cred_proposal
)
mock_cred_proposal.credential_proposal = async_mock.MagicMock()
mock_cred_proposal.credential_proposal.attr_dict = async_mock.MagicMock(
return_value=ATTR_DICT
)
request_context.message = CredentialRequest()
request_context.connection_ready = True
handler_inst = handler.CredentialRequestHandler()
responder = MockResponder()
await handler_inst.handle(request_context, responder)
mock_cred_mgr.return_value.issue_credential.assert_called_once_with(
cred_ex_record=cred_ex_rec, comment=None, credential_values=ATTR_DICT,
cred_ex_record=cred_ex_rec, comment=None
)

mock_cred_mgr.assert_called_once_with(request_context)
Expand All @@ -101,20 +92,14 @@ async def test_called_auto_issue_no_preview(self):

with async_mock.patch.object(
handler, "CredentialManager", autospec=True
) as mock_cred_mgr, async_mock.patch.object(
handler, "CredentialProposal", autospec=True
) as mock_cred_proposal:
) as mock_cred_mgr:
mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock(
return_value=cred_ex_rec
)
mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True
mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock(
return_value=(None, "credential_issue_message")
)
mock_cred_proposal.deserialize = async_mock.MagicMock(
return_value=mock_cred_proposal
)
mock_cred_proposal.credential_proposal = async_mock.MagicMock()

request_context.message = CredentialRequest()
request_context.connection_ready = True
Expand Down
10 changes: 4 additions & 6 deletions aries_cloudagent/protocols/issue_credential/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,7 @@ async def receive_request(self):
return cred_ex_record

async def issue_credential(
self,
cred_ex_record: V10CredentialExchange,
*,
comment: str = None,
credential_values: dict,
self, cred_ex_record: V10CredentialExchange, *, comment: str = None,
) -> Tuple[V10CredentialExchange, CredentialIssue]:
"""
Issue a credential.
Expand All @@ -466,7 +462,6 @@ async def issue_credential(
cred_ex_record: The credential exchange record
for which to issue a credential
comment: optional human-readable comment pertaining to credential issue
credential_values: dict of credential attribute {name: value} pairs

Returns:
Tuple: (Updated credential exchange record, credential message)
Expand Down Expand Up @@ -518,6 +513,9 @@ async def issue_credential(
else:
tails_path = None

credential_values = CredentialProposal.deserialize(
cred_ex_record.credential_proposal_dict
).credential_proposal.attr_dict(decode=False)
issuer: BaseIssuer = await self.context.inject(BaseIssuer)
try:
(
Expand Down
12 changes: 1 addition & 11 deletions aries_cloudagent/protocols/issue_credential/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ class V10CredentialIssueRequestSchema(Schema):
"""Request schema for sending credential issue admin message."""

comment = fields.Str(description="Human-readable comment", required=False)
credential_preview = fields.Nested(CredentialPreviewSchema, required=True)


class V10CredentialProblemReportRequestSchema(Schema):
Expand Down Expand Up @@ -1042,9 +1041,6 @@ async def credential_exchange_issue(request: web.BaseRequest):

body = await request.json()
comment = body.get("comment")
preview_spec = body.get("credential_preview")
if not preview_spec:
raise web.HTTPBadRequest(reason="credential_preview must be provided")

credential_exchange_id = request.match_info["cred_ex_id"]
try:
Expand All @@ -1063,17 +1059,11 @@ async def credential_exchange_issue(request: web.BaseRequest):
if not connection_record.is_ready:
raise web.HTTPForbidden(reason=f"Connection {connection_id} not ready")

credential_preview = CredentialPreview.deserialize(preview_spec)

credential_manager = CredentialManager(context)
(
cred_ex_record,
credential_issue_message,
) = await credential_manager.issue_credential(
cred_ex_record,
comment=comment,
credential_values=credential_preview.attr_dict(decode=False),
)
) = await credential_manager.issue_credential(cred_ex_record, comment=comment)

result = cred_ex_record.serialize()
except (StorageError, IssuerError, BaseModelError, CredentialManagerError) as err:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,13 @@ async def test_issue_credential(self):
credential_definition_id=CRED_DEF_ID,
credential_offer=indy_offer,
credential_request=indy_cred_req,
credential_proposal_dict=CredentialProposal(
credential_proposal=CredentialPreview.deserialize(
{"attributes": [{"name": "attr", "value": "value"}]}
),
cred_def_id=CRED_DEF_ID,
schema_id=SCHEMA_ID,
).serialize(),
initiator=V10CredentialExchange.INITIATOR_SELF,
role=V10CredentialExchange.ROLE_ISSUER,
state=V10CredentialExchange.STATE_REQUEST_RECEIVED,
Expand Down Expand Up @@ -894,7 +901,7 @@ async def test_issue_credential(self):
]
)
(ret_exchange, ret_cred_issue) = await self.manager.issue_credential(
stored_exchange, comment=comment, credential_values=cred_values
stored_exchange, comment=comment
)

save_ex.assert_called_once()
Expand All @@ -914,9 +921,7 @@ async def test_issue_credential(self):
(
ret_existing_exchange,
ret_existing_cred,
) = await self.manager.issue_credential(
stored_exchange, comment=comment, credential_values=cred_values
)
) = await self.manager.issue_credential(stored_exchange, comment=comment)
assert ret_existing_exchange == ret_exchange
assert ret_existing_cred._thread_id == thread_id

Expand All @@ -936,6 +941,13 @@ async def test_issue_credential_non_revocable(self):
credential_definition_id=CRED_DEF_ID,
credential_offer=indy_offer,
credential_request=indy_cred_req,
credential_proposal_dict=CredentialProposal(
credential_proposal=CredentialPreview.deserialize(
{"attributes": [{"name": "attr", "value": "value"}]}
),
cred_def_id=CRED_DEF_ID,
schema_id=SCHEMA_ID,
).serialize(),
initiator=V10CredentialExchange.INITIATOR_SELF,
role=V10CredentialExchange.ROLE_ISSUER,
state=V10CredentialExchange.STATE_REQUEST_RECEIVED,
Expand Down Expand Up @@ -963,7 +975,7 @@ async def test_issue_credential_non_revocable(self):
V10CredentialExchange, "save", autospec=True
) as save_ex:
(ret_exchange, ret_cred_issue) = await self.manager.issue_credential(
stored_exchange, comment=comment, credential_values=cred_values
stored_exchange, comment=comment
)

save_ex.assert_called_once()
Expand All @@ -981,7 +993,6 @@ async def test_issue_credential_request_bad_state(self):
connection_id = "test_conn_id"
indy_offer = {"schema_id": SCHEMA_ID, "cred_def_id": CRED_DEF_ID}
thread_id = "thread-id"
cred_values = {"attr": "value"}

stored_exchange = V10CredentialExchange(
credential_exchange_id="dummy-cxid",
Expand All @@ -996,9 +1007,7 @@ async def test_issue_credential_request_bad_state(self):
)

with self.assertRaises(CredentialManagerError):
await self.manager.issue_credential(
stored_exchange, credential_values=cred_values
)
await self.manager.issue_credential(stored_exchange)

async def test_issue_credential_no_active_rr(self):
connection_id = "test_conn_id"
Expand All @@ -1014,6 +1023,13 @@ async def test_issue_credential_no_active_rr(self):
credential_definition_id=CRED_DEF_ID,
credential_offer=indy_offer,
credential_request=indy_cred_req,
credential_proposal_dict=CredentialProposal(
credential_proposal=CredentialPreview.deserialize(
{"attributes": [{"name": "attr", "value": "value"}]}
),
cred_def_id=CRED_DEF_ID,
schema_id=SCHEMA_ID,
).serialize(),
initiator=V10CredentialExchange.INITIATOR_SELF,
role=V10CredentialExchange.ROLE_ISSUER,
state=V10CredentialExchange.STATE_REQUEST_RECEIVED,
Expand All @@ -1037,9 +1053,7 @@ async def test_issue_credential_no_active_rr(self):
return_value=[]
)
with self.assertRaises(CredentialManagerError) as x_cred_mgr:
await self.manager.issue_credential(
stored_exchange, comment=comment, credential_values=cred_values
)
await self.manager.issue_credential(stored_exchange, comment=comment)
assert "has no active revocation registry" in x_cred_mgr.message

async def test_issue_credential_rr_full(self):
Expand All @@ -1056,6 +1070,13 @@ async def test_issue_credential_rr_full(self):
credential_definition_id=CRED_DEF_ID,
credential_offer=indy_offer,
credential_request=indy_cred_req,
credential_proposal_dict=CredentialProposal(
credential_proposal=CredentialPreview.deserialize(
{"attributes": [{"name": "attr", "value": "value"}]}
),
cred_def_id=CRED_DEF_ID,
schema_id=SCHEMA_ID,
).serialize(),
initiator=V10CredentialExchange.INITIATOR_SELF,
role=V10CredentialExchange.ROLE_ISSUER,
state=V10CredentialExchange.STATE_REQUEST_RECEIVED,
Expand Down Expand Up @@ -1087,9 +1108,7 @@ async def test_issue_credential_rr_full(self):
)

with self.assertRaises(test_module.IssuerRevocationRegistryFullError):
await self.manager.issue_credential(
stored_exchange, comment=comment, credential_values=cred_values
)
await self.manager.issue_credential(stored_exchange, comment=comment)

async def test_receive_credential(self):
connection_id = "test_conn_id"
Expand Down
Loading