Fix a type stable-id -> stanza-id, and add a test case to be exhaustive

This commit is contained in:
louiz’
2020-03-11 00:32:18 +01:00
parent 40d2168ae5
commit fc22e06317
2 changed files with 13 additions and 7 deletions
+3 -3
View File
@@ -294,15 +294,15 @@ void BiboumiComponent::handle_message(const Stanza& stanza)
if (origin_id) if (origin_id)
nodes_to_reflect.push_back(*origin_id); nodes_to_reflect.push_back(*origin_id);
const auto own_address = std::to_string(iid) + '@' + this->served_hostname; const auto own_address = std::to_string(iid) + '@' + this->served_hostname;
for (const XmlNode* stable_id: stanza.get_children("stable-id", STABLE_ID_NS)) for (const XmlNode* stanza_id: stanza.get_children("stanza-id", STABLE_ID_NS))
{ {
// Stanza ID generating entities, which encounter a // Stanza ID generating entities, which encounter a
// <stanza-id/> element where the 'by' attribute matches // <stanza-id/> element where the 'by' attribute matches
// the 'by' attribute they would otherwise set, MUST // the 'by' attribute they would otherwise set, MUST
// delete that element even if they are not adding their // delete that element even if they are not adding their
// own stanza ID. // own stanza ID.
if (stable_id->get_tag("by") != own_address) if (stanza_id->get_tag("by") != own_address)
nodes_to_reflect.push_back(*stable_id); nodes_to_reflect.push_back(*stanza_id);
} }
bridge->send_channel_message(iid, body->get_inner(), id, std::move(nodes_to_reflect)); bridge->send_channel_message(iid, body->get_inner(), id, std::move(nodes_to_reflect));
} }
+10 -4
View File
@@ -8,19 +8,25 @@ scenario = (
scenarios.simple_channel_join.scenario, scenarios.simple_channel_join.scenario,
send_stanza("""<message id='first_id' from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}' type='groupchat'> send_stanza("""<message id='first_id' from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}' type='groupchat'>
<origin-id xmlns='urn:xmpp:sid:0' id='client-origin-id'/> <origin-id xmlns='urn:xmpp:sid:0' id='client-origin-id-should-be-kept'/>
<stanza-id xmlns='urn:xmpp:sid:0' id='client-stanza-id'/> <stanza-id xmlns='urn:xmpp:sid:0' id='client-stanza-id-should-be-removed' by='#foo%{irc_server_one}'/>
<stanza-id xmlns='urn:xmpp:sid:0' id='client-stanza-id-should-be-kept' by='someother@jid'/>
<body>coucou</body></message>"""), <body>coucou</body></message>"""),
# Entities, which are routing stanzas, SHOULD NOT strip any elements # Entities, which are routing stanzas, SHOULD NOT strip any elements
# qualified by the 'urn:xmpp:sid:0' namespace from message stanzas # qualified by the 'urn:xmpp:sid:0' namespace from message stanzas
# unless the preceding rule applied to those elements. # unless the preceding rule applied to those elements.
expect_stanza("/message/stable_id:origin-id[@id='client-origin-id']", expect_stanza("/message/stable_id:origin-id[@id='client-origin-id-should-be-kept']",
# Stanza ID generating entities, which encounter a <stanza-id/> # Stanza ID generating entities, which encounter a <stanza-id/>
# element where the 'by' attribute matches the 'by' attribute they # element where the 'by' attribute matches the 'by' attribute they
# would otherwise set, MUST delete that element even if they are not # would otherwise set, MUST delete that element even if they are not
# adding their own stanza ID. # adding their own stanza ID.
"/message/stable_id:stanza-id[@id][@by='#foo%{irc_server_one}']", "/message/stable_id:stanza-id[@id][@by='#foo%{irc_server_one}']",
"!/message/stable_id:stanza-id[@id='client-stanza-id']", "!/message/stable_id:stanza-id[@id='client-stanza-id-should-be-removed']",
# Entities, which are routing stanzas, SHOULD NOT strip
# any elements qualified by the 'urn:xmpp:sid:0'
# namespace from message stanzas unless the preceding
# rule applied to those elements.
"/message/stable_id:stanza-id[@id='client-stanza-id-should-be-kept'][@by='someother@jid']",
), ),
) )