# HG changeset patch # User Goffi # Date 1658497379 -7200 # Node ID bd84d289fc944637dbfbf0706bad5790fa5d2d94 # Parent c0bcbcf5b4b7bf01392330bd1b3b197cd645cc74 component AP gateway: fix item ID for XMPP items on Announce: if an Announced item is from XMPP, the AP id must be parsed to retrieve the XMPP original ID. rel 370 diff -r c0bcbcf5b4b7 -r bd84d289fc94 sat/plugins/plugin_comp_ap_gateway/http_server.py --- a/sat/plugins/plugin_comp_ap_gateway/http_server.py Thu Jul 21 18:07:35 2022 +0200 +++ b/sat/plugins/plugin_comp_ap_gateway/http_server.py Fri Jul 22 15:42:59 2022 +0200 @@ -288,6 +288,33 @@ # from post author in this case sender_jid = await self.apg.getJIDFromId(sender) repeater_jid = await self.apg.getJIDFromId(signing_actor) + repeated_item_id = obj["id"] + if self.apg.isLocalURL(repeated_item_id): + # the repeated object is from XMPP, we need to parse the URL to find + # the right ID + url_type, url_args = self.apg.parseAPURL(repeated_item_id) + if url_type != "item": + raise exceptions.DataError( + "local URI is not an item: {repeated_id}" + ) + try: + url_account, url_item_id = url_args + if not url_account or not url_item_id: + raise ValueError + except (RuntimeError, ValueError): + raise exceptions.DataError( + "local URI is invalid: {repeated_id}" + ) + else: + url_jid, url_node = await self.apg.getJIDAndNode(url_account) + if ((url_jid != sender_jid + or url_node and url_node != self.apg._m.namespace)): + raise exceptions.DataError( + "announced ID doesn't match sender ({sender}): " + f"[repeated_item_id]" + ) + + repeated_item_id = url_item_id obj["_repeated"] = { "by": repeater_jid.full(), @@ -296,7 +323,7 @@ "pubsub", path=sender_jid.full(), node=self.apg._m.namespace, - item=obj["id"] + item=repeated_item_id ) } # we must use activity's id and targets, not the original item ones