Skip to content

Commit

Permalink
Merge branch 'main' into fix/endorse-did
Browse files Browse the repository at this point in the history
  • Loading branch information
ianco authored Apr 12, 2022
2 parents 9296ff3 + 9712d0d commit 6e76073
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
7 changes: 5 additions & 2 deletions aries_cloudagent/messaging/models/base_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from ..util import datetime_to_str, time_now
from ..valid import INDY_ISO8601_DATETIME

from .base import BaseModel, BaseModelSchema
from .base import BaseModel, BaseModelSchema, BaseModelError

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -329,7 +329,10 @@ async def query(
positive=False,
alt=alt,
):
result.append(cls.from_storage(record.id, vals))
try:
result.append(cls.from_storage(record.id, vals))
except BaseModelError as err:
raise BaseModelError(f"{err}, for record id {record.id}")
return result

async def save(
Expand Down
21 changes: 21 additions & 0 deletions aries_cloudagent/messaging/models/tests/test_base_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
StorageError,
StorageRecord,
)
from ....messaging.models.base import BaseModelError

from ...util import time_now

Expand Down Expand Up @@ -181,6 +182,26 @@ async def test_query(self):
assert result[0]._id == record_id
assert result[0].value == record_value

async def test_query_x(self):
session = InMemoryProfile.test_session()
mock_storage = async_mock.MagicMock(BaseStorage, autospec=True)
session.context.injector.bind_instance(BaseStorage, mock_storage)
record_id = "record_id"
record_value = {"created_at": time_now(), "updated_at": time_now()}
tag_filter = {"tag": "filter"}
stored = StorageRecord(
BaseRecordImpl.RECORD_TYPE, json.dumps(record_value), {}, record_id
)

mock_storage.find_all_records.return_value = [stored]
with async_mock.patch.object(
BaseRecordImpl,
"from_storage",
async_mock.MagicMock(side_effect=BaseModelError),
):
with self.assertRaises(BaseModelError):
await BaseRecordImpl.query(session, tag_filter)

async def test_query_post_filter(self):
session = InMemoryProfile.test_session()
mock_storage = async_mock.MagicMock(BaseStorage, autospec=True)
Expand Down
14 changes: 12 additions & 2 deletions aries_cloudagent/protocols/present_proof/v2_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
UUID4,
)
from ....storage.error import StorageError, StorageNotFoundError
from ....storage.base import BaseStorage
from ....storage.vc_holder.base import VCHolder
from ....storage.vc_holder.vc_record import VCRecord
from ....utils.tracing import trace_event, get_timer, AdminAPIMessageTracingSchema
Expand Down Expand Up @@ -1265,8 +1266,17 @@ async def present_proof_remove(request: web.BaseRequest):
pres_ex_record = None
try:
async with context.profile.session() as session:
pres_ex_record = await V20PresExRecord.retrieve_by_id(session, pres_ex_id)
await pres_ex_record.delete_record(session)
try:
pres_ex_record = await V20PresExRecord.retrieve_by_id(
session, pres_ex_id
)
await pres_ex_record.delete_record(session)
except (BaseModelError, ValidationError):
storage = session.inject(BaseStorage)
storage_record = await storage.get_record(
record_type=V20PresExRecord.RECORD_TYPE, record_id=pres_ex_id
)
await storage.delete_record(storage_record)
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except StorageError as err:
Expand Down
14 changes: 8 additions & 6 deletions demo/runners/faber.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,15 @@ async def main(args):
)
pres_req_id = proof_request["presentation_exchange_id"]
url = (
"http://"
+ os.getenv("DOCKERHOST").replace(
"{PORT}", str(faber_agent.agent.admin_port + 1)
os.getenv("WEBHOOK_TARGET")
or (
"http://"
+ os.getenv("DOCKERHOST").replace(
"{PORT}", str(faber_agent.agent.admin_port + 1)
)
+ "/webhooks"
)
+ "/webhooks/pres_req/"
+ pres_req_id
+ "/"
+ f"/pres_req/{pres_req_id}/"
)
log_msg(f"Proof request url: {url}")
qr = QRCode(border=1)
Expand Down
4 changes: 3 additions & 1 deletion demo/runners/support/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ async def listen_webhooks(self, webhook_port):
if RUN_MODE == "pwd":
self.webhook_url = f"http://localhost:{str(webhook_port)}/webhooks"
else:
self.webhook_url = (
self.webhook_url = self.external_webhook_target or (
f"http://{self.external_host}:{str(webhook_port)}/webhooks"
)
app = web.Application()
Expand Down Expand Up @@ -769,6 +769,8 @@ async def _send_connectionless_proof_req(self, request: ClientRequest):
return web.Response(status=404)
proof_reg_txn = proof_exch["presentation_request_dict"]
proof_reg_txn["~service"] = await self.service_decorator()
if request.headers["Accept"] == "application/json":
return web.json_response(proof_reg_txn)
objJsonStr = json.dumps(proof_reg_txn)
objJsonB64 = base64.b64encode(objJsonStr.encode("ascii"))
service_url = self.webhook_url
Expand Down

0 comments on commit 6e76073

Please sign in to comment.