Don't hardcode ver, update node name, and add tests
This commit is contained in:
@@ -46,6 +46,7 @@ def match(stanza, xpath):
|
||||
'disco_info': 'http://jabber.org/protocol/disco#info',
|
||||
'muc_traffic': 'http://jabber.org/protocol/muc#traffic',
|
||||
'disco_items': 'http://jabber.org/protocol/disco#items',
|
||||
'caps': 'http://jabber.org/protocol/caps',
|
||||
'commands': 'http://jabber.org/protocol/commands',
|
||||
'dataform': 'jabber:x:data',
|
||||
'version': 'jabber:iq:version',
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
from scenarios import *
|
||||
|
||||
scenario = (
|
||||
send_stanza("<presence id='get1' from='{jid_one}/{resource_one}' to='{biboumi_host}' xmlns='jabber:component:accept'></presence>"),
|
||||
expect_stanza("/presence/caps:c[@hash='sha-1'][@node][@ver]",
|
||||
after = (
|
||||
save_value("ver", extract_attribute("/presence/caps:c[@hash='sha-1'][@node][@ver]", "ver")),
|
||||
save_value("node", extract_attribute("/presence/caps:c[@hash='sha-1'][@node][@ver]", "node")),
|
||||
)
|
||||
),
|
||||
# Assert node and ver are consistent
|
||||
send_stanza("<presence id='get2' from='{jid_one}/{resource_one}' to='{biboumi_host}' xmlns='jabber:component:accept'></presence>"),
|
||||
expect_stanza("/presence/caps:c[@hash='sha-1'][@node='{node}'][@ver='{ver}']"),
|
||||
# If we ask for this node then we should get it back
|
||||
send_stanza("<iq type='get' id='get3' from='{jid_one}/{resource_one}' to='{biboumi_host}'><query xmlns='http://jabber.org/protocol/disco#info' node='{node}#{ver}' /></iq>"),
|
||||
expect_stanza("/iq/disco_info:query[@node='{node}#{ver}']"),
|
||||
# But if we ask for invalid values then we don't
|
||||
send_stanza("<iq type='get' id='get4' from='{jid_one}/{resource_one}' to='{biboumi_host}' xmlns='jabber:component:accept'><query xmlns='http://jabber.org/protocol/disco#info' node='{node}#asdf' /></iq>"),
|
||||
expect_stanza("!/iq/disco_info:query[@node='{node}#{ver}']"),
|
||||
send_stanza("<iq type='get' id='get5' from='{jid_one}/{resource_one}' to='{biboumi_host}' xmlns='jabber:component:accept'><query xmlns='http://jabber.org/protocol/disco#info' node='asdf' /></iq>"),
|
||||
expect_stanza("!/iq/disco_info:query[@node='{node}#{ver}']"),
|
||||
)
|
||||
|
||||
@@ -7,5 +7,8 @@ scenario = (
|
||||
"/iq/disco_info:query/disco_info:feature[@var='http://jabber.org/protocol/commands']",
|
||||
"/iq/disco_info:query/disco_info:feature[@var='urn:xmpp:ping']",
|
||||
"/iq/disco_info:query/disco_info:feature[@var='urn:xmpp:mam:2']",
|
||||
"/iq/disco_info:query/disco_info:feature[@var='jabber:iq:version']"),
|
||||
"/iq/disco_info:query/disco_info:feature[@var='jabber:iq:version']",
|
||||
"/iq/disco_info:query/disco_info:identity[@category='conference'][@type='irc']",
|
||||
"/iq/disco_info:query/disco_info:identity[@category='gateway'][@type='irc']",
|
||||
),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
#include "catch2/catch_test_macros.hpp"
|
||||
#include <xmpp/hash_disco.hpp>
|
||||
#include <xmpp/xmpp_parser.hpp>
|
||||
#include <xmpp/xmpp_stanza.hpp>
|
||||
|
||||
// WARN: This generation might be wrong!!! These test might be wrong!!!
|
||||
|
||||
TEST_CASE("Hash disco 1") {
|
||||
XmppParser xml;
|
||||
|
||||
const std::string doc =
|
||||
R"(<stream><iq type='result'><query xmlns="http://jabber.org/protocol/disco#info">
|
||||
<identity xmlns='' category="client" name="BombusMod" type="mobile"/>
|
||||
<feature xmlns='' var="http://jabber.org/protocol/si"/>
|
||||
<feature xmlns='' var="http://jabber.org/protocol/bytestreams"/>
|
||||
<feature xmlns='' var="http://jabber.org/protocol/chatstates"/>
|
||||
<feature xmlns='' var="http://jabber.org/protocol/disco#info"/>
|
||||
<feature xmlns='' var="http://jabber.org/protocol/disco#items"/>
|
||||
<feature xmlns='' var="urn:xmpp:ping"/>
|
||||
<feature xmlns='' var="jabber:iq:time"/>
|
||||
<feature xmlns='' var="jabber:iq:privacy"/>
|
||||
<feature xmlns='' var="jabber:iq:version"/>
|
||||
<feature xmlns='' var="http://jabber.org/protocol/rosterx"/>
|
||||
<feature xmlns='' var="urn:xmpp:time"/>
|
||||
<feature xmlns='' var="jabber:x:oob"/>
|
||||
<feature xmlns='' var="http://jabber.org/protocol/ibb"/>
|
||||
<feature xmlns='' var="http://jabber.org/protocol/si/profile/file-transfer"/>
|
||||
<feature xmlns='' var="urn:xmpp:receipts"/>
|
||||
<feature xmlns='' var="jabber:iq:roster"/>
|
||||
<feature xmlns='' var="jabber:iq:last"/>
|
||||
</query></iq></stream>)";
|
||||
|
||||
auto check_stanza = [](const Stanza &stanza) {
|
||||
const std::string hash = Xmpp::hash_disco_sha1(stanza);
|
||||
CHECK(hash == "YjVkN2NhODU2ZWQyZjhhNjJjOTE1MWMxYjQ0YmUwM2Q0ODhhZDI2MA==");
|
||||
};
|
||||
xml.add_stanza_callback([check_stanza](const Stanza &stanza) {
|
||||
check_stanza(stanza);
|
||||
// Do the same checks on a copy of that stanza.
|
||||
Stanza copy(stanza);
|
||||
check_stanza(copy);
|
||||
// And do the same checks on moved-constructed stanza
|
||||
Stanza moved(std::move(copy));
|
||||
});
|
||||
CHECK(doc.size() <= std::numeric_limits<int>::max());
|
||||
xml.feed(doc.data(), static_cast<int>(doc.size()), true);
|
||||
}
|
||||
|
||||
// Just one more test case to make sure we aren't always generating the same string
|
||||
TEST_CASE("Hash disco 2") {
|
||||
XmppParser xml;
|
||||
|
||||
const std::string doc =
|
||||
R"(<stream><iq type='result'><query xmlns='http://jabber.org/protocol/disco#info'>
|
||||
<identity xmlns='' xml:lang='el' category='client' name='Ψ 0.11' type='pc'/>
|
||||
<identity xmlns='' xml:lang='en' category='client' name='Psi 0.11' type='mobile'/>
|
||||
<feature xmlns='' var='http://jabber.org/protocol/caps'/>
|
||||
<feature xmlns='' var='http://jabber.org/protocol/disco#info'/>
|
||||
<feature xmlns='' var='http://jabber.org/protocol/disco#items'/>
|
||||
<feature xmlns='' var='http://jabber.org/protocol/muc'/>
|
||||
</query></iq></stream>)";
|
||||
|
||||
auto check_stanza = [](const Stanza &stanza) {
|
||||
const std::string hash = Xmpp::hash_disco_sha1(stanza);
|
||||
CHECK(hash == "ZmY1ZTJjZjUyZjkwMjA2OTliZGFhYzYxMmVmMTI5YjdmYzNhZTIwYw==");
|
||||
};
|
||||
xml.add_stanza_callback([check_stanza](const Stanza &stanza) {
|
||||
check_stanza(stanza);
|
||||
// Do the same checks on a copy of that stanza.
|
||||
Stanza copy(stanza);
|
||||
check_stanza(copy);
|
||||
// And do the same checks on moved-constructed stanza
|
||||
Stanza moved(std::move(copy));
|
||||
});
|
||||
CHECK(doc.size() <= std::numeric_limits<int>::max());
|
||||
xml.feed(doc.data(), static_cast<int>(doc.size()), true);
|
||||
}
|
||||
|
||||
TEST_CASE("Hash disco 2 different order") {
|
||||
XmppParser xml;
|
||||
|
||||
const std::string doc =
|
||||
R"(<stream><iq type='result'><query xmlns='http://jabber.org/protocol/disco#info'>
|
||||
<identity xmlns='' xml:lang='en' category='client' name='Psi 0.11' type='mobile'/>
|
||||
<identity xmlns='' xml:lang='el' category='client' name='Ψ 0.11' type='pc'/>
|
||||
<feature xmlns='' var='http://jabber.org/protocol/disco#info'/>
|
||||
<feature xmlns='' var='http://jabber.org/protocol/caps'/>
|
||||
<feature xmlns='' var='http://jabber.org/protocol/disco#items'/>
|
||||
<feature xmlns='' var='http://jabber.org/protocol/muc'/>
|
||||
</query></iq></stream>)";
|
||||
|
||||
auto check_stanza = [](const Stanza &stanza) {
|
||||
const std::string hash = Xmpp::hash_disco_sha1(stanza);
|
||||
CHECK(hash == "ZmY1ZTJjZjUyZjkwMjA2OTliZGFhYzYxMmVmMTI5YjdmYzNhZTIwYw==");
|
||||
};
|
||||
xml.add_stanza_callback([check_stanza](const Stanza &stanza) {
|
||||
check_stanza(stanza);
|
||||
// Do the same checks on a copy of that stanza.
|
||||
Stanza copy(stanza);
|
||||
check_stanza(copy);
|
||||
// And do the same checks on moved-constructed stanza
|
||||
Stanza moved(std::move(copy));
|
||||
});
|
||||
CHECK(doc.size() <= std::numeric_limits<int>::max());
|
||||
xml.feed(doc.data(), static_cast<int>(doc.size()), true);
|
||||
}
|
||||
Reference in New Issue
Block a user