From e8bc173437ac91a88abebc3bc8c6b7f07885da68 Mon Sep 17 00:00:00 2001 From: Fergal Date: Tue, 15 Oct 2024 23:32:38 +0100 Subject: [PATCH] feat: allow prefix when sending exn message (#307) --- src/keria/peer/exchanging.py | 6 +++--- tests/peer/test_exchanging.py | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/keria/peer/exchanging.py b/src/keria/peer/exchanging.py index d6409faf..7ea889ca 100644 --- a/src/keria/peer/exchanging.py +++ b/src/keria/peer/exchanging.py @@ -34,7 +34,7 @@ def on_post(req, rep, name): Args: req (Request): falcon HTTP request object rep (Response): falcon HTTP response object - name (str): human readable alias for AID context + name (str): human readable name or prefix for AID context --- summary: Post an exchange message for an identifier. description: This endpoint posts an exchange message to a specific named identifier. @@ -85,9 +85,9 @@ def on_post(req, rep, name): body = req.get_media() # Get the hab - hab = agent.hby.habByName(name) + hab = agent.hby.habs[name] if name in agent.hby.habs else agent.hby.habByName(name) if hab is None: - raise falcon.HTTPNotFound(description=f"alias={name} is not a valid reference to an identifier") + raise falcon.HTTPNotFound(description=f"{name} is not a valid reference to an identifier") # Get the exn, sigs, additional attachments and recipients from the request ked = httping.getRequiredParam(body, "exn") diff --git a/tests/peer/test_exchanging.py b/tests/peer/test_exchanging.py index 47badb68..4780c8da 100644 --- a/tests/peer/test_exchanging.py +++ b/tests/peer/test_exchanging.py @@ -79,7 +79,15 @@ def test_exchange_end(helpers): assert len(agent.exchanges) == 1 doist.recur(deeds=deeds) + assert len(agent.exchanges) == 0 + + # Use prefix instead of alias to send again + res = client.simulate_post(path="/identifiers/EHgwVwQT15OJvilVvW57HE4w0-GPs_Stj2OFoAHZSysY/exchanges", json=body) + assert res.status_code == 202 + assert res.json == cexn.ked + assert len(agent.exchanges) == 1 + doist.recur(deeds=deeds) assert len(agent.exchanges) == 0 agent.exnseeker.index(cexn.said)