From f31296a954d3f207026e33d125b7703a1bd2adbd Mon Sep 17 00:00:00 2001 From: Philip Feairheller Date: Wed, 6 Dec 2023 08:22:53 -0800 Subject: [PATCH] Fix ipex/grant endpoint (#143) * Update the AID state returned from Boot. Signed-off-by: pfeairheller * Fix ipex/grant endpoint to work correctly with attachments Signed-off-by: pfeairheller --------- Signed-off-by: pfeairheller --- src/keria/app/agenting.py | 5 +++-- src/keria/app/ipexing.py | 20 ++++++++++---------- tests/app/test_ipexing.py | 18 ++---------------- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/keria/app/agenting.py b/src/keria/app/agenting.py index bc03a99..e42c7c9 100644 --- a/src/keria/app/agenting.py +++ b/src/keria/app/agenting.py @@ -528,7 +528,7 @@ def recur(self, tyme, deeds=None): postman = forwarding.StreamPoster(hby=self.hby, hab=self.agentHab, recp=recp, topic="credential") try: credSaid = serder.ked['e']['acdc']['d'] - creder = self.rgy.creds.get(keys=(credSaid,)) + creder = self.rgy.reger.creds.get(keys=(credSaid,)) sendArtifacts(self.hby, self.rgy.reger, postman, creder, recp) sources = self.rgy.reger.sources(self.hby.db, creder) for source, atc in sources: @@ -585,6 +585,7 @@ def recur(self, tyme): for label in ("anc", "iss", "acdc"): ked = embeds[label] if label not in pathed or not pathed[label]: + print(f"missing path label {label}") continue sadder = coring.Sadder(ked=ked) @@ -865,7 +866,7 @@ def on_post(self, req, rep): raise falcon.HTTPBadRequest(description="multisig groups not supported as agent controller") rep.status = falcon.HTTP_202 - rep.data = json.dumps(asdict(ctrlHab.kever.state())).encode("utf-8") + rep.data = json.dumps(asdict(agent.agentHab.kever.state())).encode("utf-8") class KeyStateCollectionEnd: diff --git a/src/keria/app/ipexing.py b/src/keria/app/ipexing.py index 7d01645..0aca983 100644 --- a/src/keria/app/ipexing.py +++ b/src/keria/app/ipexing.py @@ -151,7 +151,6 @@ def on_post(req, rep, name): """ agent = req.context.agent - # Get the hab hab = agent.hby.habByName(name) if hab is None: raise falcon.HTTPNotFound(description=f"alias={name} is not a valid reference to an identifier") @@ -167,7 +166,7 @@ def on_post(req, rep, name): match route: case "/ipex/grant": - IpexGrantCollectionEnd.sendGrant(agent, hab, ked, sigs, rec) + IpexGrantCollectionEnd.sendGrant(agent, hab, ked, sigs, atc, rec) case "/multisig/exn": IpexGrantCollectionEnd.sendMultisigExn(agent, hab, ked, sigs, atc, rec) @@ -175,7 +174,7 @@ def on_post(req, rep, name): rep.data = json.dumps(ked).encode("utf-8") @staticmethod - def sendGrant(agent, hab, ked, sigs, rec): + def sendGrant(agent, hab, ked, sigs, atc, rec): for recp in rec: # Have to verify we already know all the recipients. if recp not in agent.hby.kevers: raise falcon.HTTPBadRequest(description=f"attempt to send to unknown AID={recp}") @@ -189,6 +188,7 @@ def sendGrant(agent, hab, ked, sigs, rec): seal = eventing.SealEvent(i=hab.pre, s=hex(kever.lastEst.s), d=kever.lastEst.d) ims = eventing.messagize(serder=serder, sigers=sigers, seal=seal) + ims = ims + atc.encode("utf-8") # make a copy and parse agent.hby.psr.parseOne(ims=bytearray(ims)) @@ -197,7 +197,7 @@ def sendGrant(agent, hab, ked, sigs, rec): del ims[:serder.size] agent.exchanges.append(dict(said=serder.said, pre=hab.pre, rec=rec, topic='credential')) - agent.grants.append(dict(said=ked['d'], pre=hab.pre)) + agent.grants.append(dict(said=ked['d'], pre=hab.pre, rec=rec)) @staticmethod def sendMultisigExn(agent, hab, ked, sigs, atc, rec): @@ -210,13 +210,13 @@ def sendMultisigExn(agent, hab, ked, sigs, atc, rec): if grant['r'] != "/ipex/grant": raise falcon.HTTPBadRequest(description=f"invalid route for embedded ipex grant {ked['r']}") - # Have to add the atc to the end... this will be Pathed signatures for embeds - if 'exn' not in atc or not atc['exn']: - raise falcon.HTTPBadRequest(description=f"attachment missing for ACDC, unable to process request.") - holder = grant['a']['i'] serder = serdering.SerderKERI(sad=grant) - ims = bytearray(serder.raw) + atc['exn'].encode("utf-8") + sigers = [coring.Siger(qb64=sig) for sig in sigs] + seal = eventing.SealEvent(i=hab.pre, s=hex(hab.kever.lastEst.s), d=hab.kever.lastEst.d) + + ims = eventing.messagize(serder=serder, sigers=sigers, seal=seal) + ims = ims + atc.encode("utf-8") agent.hby.psr.parseOne(ims=ims) agent.exchanges.append(dict(said=serder.said, pre=hab.pre, rec=holder, topic="credential")) agent.grants.append(dict(said=grant['d'], pre=hab.pre)) @@ -231,7 +231,7 @@ def sendMultisigExn(agent, hab, ked, sigs, atc, rec): ims = eventing.messagize(serder=serder, sigers=sigers, seal=seal) - ims.extend(atc['exn'].encode("utf-8")) # add the pathed attachments + ims.extend(atc.encode("utf-8")) # add the pathed attachments # make a copy and parse agent.hby.psr.parseOne(ims=bytearray(ims)) diff --git a/tests/app/test_ipexing.py b/tests/app/test_ipexing.py index 9d98fbb..2ab87b4 100644 --- a/tests/app/test_ipexing.py +++ b/tests/app/test_ipexing.py @@ -307,7 +307,7 @@ def test_ipex_grant(helpers, mockHelpingNowIso8601, seeder): body = dict( exn=exn.ked, sigs=sigs, - atc=dict(exn=end.decode("utf-8")), + atc=end.decode("utf-8"), rec=["EZ-i0d8JZAoTNZH3ULaU6JR2nmwyvYAfSVPzhzS6b5CM"] ) @@ -318,24 +318,10 @@ def test_ipex_grant(helpers, mockHelpingNowIso8601, seeder): 'AID=EZ-i0d8JZAoTNZH3ULaU6JR2nmwyvYAfSVPzhzS6b5CM', 'title': '400 Bad Request'} - # Bad attachments - body = dict( - exn=exn.ked, - sigs=sigs, - atc=dict(bad=end.decode("utf-8")), - rec=[pre1] - ) - - data = json.dumps(body).encode("utf-8") - res = client.simulate_post(path="/identifiers/legal-entity/ipex/grant", body=data) - assert res.status_code == 400 - assert res.json == {'description': 'attachment missing for ACDC, unable to process request.', - 'title': '400 Bad Request'} - body = dict( exn=exn.ked, sigs=sigs, - atc=dict(exn=end.decode("utf-8")), + atc=end.decode("utf-8"), rec=[pre1] )