XEP-0030: API changes
- ``supports``, ``has_identity``, ``get_info``, ``get_items`` are now coroutines
- ``set_info````set_items``, ``del_items``, ``add_item``, ``add_identity``,
``del_identity``, ``set_identities``, ``del_identities``, ``add_feature``,
``del_feature``, ``set_feature``, ``set_features``, ``del_features``
now return a Future
also fix has_identity and supports which have been broken in forever
2021-02-14 11:06:05 +00:00
|
|
|
import asyncio
|
2010-11-18 20:50:45 +00:00
|
|
|
import time
|
2010-12-09 23:57:27 +00:00
|
|
|
|
2013-07-26 11:02:26 +00:00
|
|
|
import unittest
|
2014-07-17 12:19:04 +00:00
|
|
|
from slixmpp.test import SlixTest
|
2010-11-18 20:50:45 +00:00
|
|
|
|
|
|
|
|
2014-07-17 12:19:04 +00:00
|
|
|
class TestStreamDisco(SlixTest):
|
2010-12-09 23:57:27 +00:00
|
|
|
|
2010-11-18 20:50:45 +00:00
|
|
|
"""
|
|
|
|
Test using the XEP-0030 plugin.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.stream_close()
|
|
|
|
|
2010-12-09 23:57:27 +00:00
|
|
|
def testInfoEmptyDefaultNode(self):
|
2010-11-18 20:50:45 +00:00
|
|
|
"""
|
2010-12-09 23:57:27 +00:00
|
|
|
Info query result from an entity MUST have at least one identity
|
2010-11-18 20:50:45 +00:00
|
|
|
and feature, namely http://jabber.org/protocol/disco#info.
|
|
|
|
|
|
|
|
Since the XEP-0030 plugin is loaded, a disco response should
|
|
|
|
be generated and not an error result.
|
|
|
|
"""
|
2010-12-09 23:57:27 +00:00
|
|
|
self.stream_start(mode='client',
|
|
|
|
plugins=['xep_0030'])
|
2010-11-18 20:50:45 +00:00
|
|
|
|
|
|
|
self.recv("""
|
|
|
|
<iq type="get" id="test">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="result" id="test">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info">
|
|
|
|
<identity category="client" type="bot" />
|
|
|
|
<feature var="http://jabber.org/protocol/disco#info" />
|
|
|
|
</query>
|
2010-12-09 23:57:27 +00:00
|
|
|
</iq>
|
|
|
|
""")
|
2010-11-18 20:50:45 +00:00
|
|
|
|
2010-12-09 23:57:27 +00:00
|
|
|
def testInfoEmptyDefaultNodeComponent(self):
|
2010-11-18 20:50:45 +00:00
|
|
|
"""
|
2010-12-09 23:57:27 +00:00
|
|
|
Test requesting an empty, default node using a Component.
|
2010-11-18 20:50:45 +00:00
|
|
|
"""
|
|
|
|
self.stream_start(mode='component',
|
2010-12-09 23:57:27 +00:00
|
|
|
jid='tester.localhost',
|
2010-11-18 20:50:45 +00:00
|
|
|
plugins=['xep_0030'])
|
|
|
|
|
|
|
|
self.recv("""
|
|
|
|
<iq type="get" id="test">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="result" id="test">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info">
|
|
|
|
<identity category="component" type="generic" />
|
|
|
|
<feature var="http://jabber.org/protocol/disco#info" />
|
|
|
|
</query>
|
2010-12-09 23:57:27 +00:00
|
|
|
</iq>
|
|
|
|
""")
|
2010-11-18 20:50:45 +00:00
|
|
|
|
|
|
|
def testInfoIncludeNode(self):
|
|
|
|
"""
|
|
|
|
Results for info queries directed to a particular node MUST
|
|
|
|
include the node in the query response.
|
|
|
|
"""
|
2010-12-09 23:57:27 +00:00
|
|
|
self.stream_start(mode='client',
|
|
|
|
plugins=['xep_0030'])
|
2010-11-18 20:50:45 +00:00
|
|
|
|
2010-12-09 23:57:27 +00:00
|
|
|
|
|
|
|
self.xmpp['xep_0030'].static.add_node(node='testing')
|
2010-11-18 20:50:45 +00:00
|
|
|
|
|
|
|
self.recv("""
|
2015-04-21 18:10:47 +00:00
|
|
|
<iq to="tester@localhost/resource" type="get" id="test">
|
2010-11-18 20:50:45 +00:00
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info"
|
|
|
|
node="testing" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="result" id="test">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info"
|
|
|
|
node="testing">
|
|
|
|
</query>
|
2010-12-09 23:57:27 +00:00
|
|
|
</iq>""",
|
2010-11-18 20:50:45 +00:00
|
|
|
method='mask')
|
|
|
|
|
2010-12-09 23:57:27 +00:00
|
|
|
def testItemsIncludeNode(self):
|
|
|
|
"""
|
|
|
|
Results for items queries directed to a particular node MUST
|
|
|
|
include the node in the query response.
|
|
|
|
"""
|
|
|
|
self.stream_start(mode='client',
|
|
|
|
plugins=['xep_0030'])
|
|
|
|
|
|
|
|
|
|
|
|
self.xmpp['xep_0030'].static.add_node(node='testing')
|
|
|
|
|
|
|
|
self.recv("""
|
2015-04-21 18:10:47 +00:00
|
|
|
<iq to="tester@localhost/resource" type="get" id="test">
|
2010-12-09 23:57:27 +00:00
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items"
|
|
|
|
node="testing" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="result" id="test">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items"
|
|
|
|
node="testing">
|
|
|
|
</query>
|
|
|
|
</iq>""",
|
|
|
|
method='mask')
|
|
|
|
|
|
|
|
def testDynamicInfoJID(self):
|
|
|
|
"""
|
|
|
|
Test using a dynamic info handler for a particular JID.
|
|
|
|
"""
|
|
|
|
self.stream_start(mode='client',
|
|
|
|
plugins=['xep_0030'])
|
|
|
|
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
def dynamic_jid(jid, node, ifrom, iq):
|
2010-12-09 23:57:27 +00:00
|
|
|
result = self.xmpp['xep_0030'].stanza.DiscoInfo()
|
|
|
|
result['node'] = node
|
|
|
|
result.add_identity('client', 'console', name='Dynamic Info')
|
|
|
|
return result
|
|
|
|
|
|
|
|
self.xmpp['xep_0030'].set_node_handler('get_info',
|
|
|
|
jid='tester@localhost',
|
|
|
|
handler=dynamic_jid)
|
|
|
|
|
|
|
|
self.recv("""
|
|
|
|
<iq type="get" id="test" to="tester@localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info"
|
|
|
|
node="testing" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="result" id="test">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info"
|
|
|
|
node="testing">
|
|
|
|
<identity category="client"
|
|
|
|
type="console"
|
|
|
|
name="Dynamic Info" />
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testDynamicInfoGlobal(self):
|
|
|
|
"""
|
|
|
|
Test using a dynamic info handler for all requests.
|
|
|
|
"""
|
|
|
|
self.stream_start(mode='component',
|
|
|
|
jid='tester.localhost',
|
|
|
|
plugins=['xep_0030'])
|
|
|
|
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
def dynamic_global(jid, node, ifrom, iq):
|
2010-12-09 23:57:27 +00:00
|
|
|
result = self.xmpp['xep_0030'].stanza.DiscoInfo()
|
|
|
|
result['node'] = node
|
|
|
|
result.add_identity('component', 'generic', name='Dynamic Info')
|
|
|
|
return result
|
|
|
|
|
|
|
|
self.xmpp['xep_0030'].set_node_handler('get_info',
|
|
|
|
handler=dynamic_global)
|
|
|
|
|
|
|
|
self.recv("""
|
|
|
|
<iq type="get" id="test"
|
|
|
|
to="user@tester.localhost"
|
|
|
|
from="tester@localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info"
|
|
|
|
node="testing" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="result" id="test"
|
|
|
|
to="tester@localhost"
|
|
|
|
from="user@tester.localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info"
|
|
|
|
node="testing">
|
|
|
|
<identity category="component"
|
|
|
|
type="generic"
|
|
|
|
name="Dynamic Info" />
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testOverrideJIDInfoHandler(self):
|
|
|
|
"""Test overriding a JID info handler."""
|
|
|
|
self.stream_start(mode='client',
|
|
|
|
plugins=['xep_0030'])
|
|
|
|
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
def dynamic_jid(jid, node, ifrom, iq):
|
2010-12-09 23:57:27 +00:00
|
|
|
result = self.xmpp['xep_0030'].stanza.DiscoInfo()
|
|
|
|
result['node'] = node
|
|
|
|
result.add_identity('client', 'console', name='Dynamic Info')
|
|
|
|
return result
|
|
|
|
|
|
|
|
self.xmpp['xep_0030'].set_node_handler('get_info',
|
|
|
|
jid='tester@localhost',
|
|
|
|
handler=dynamic_jid)
|
|
|
|
|
|
|
|
|
2016-09-20 06:58:29 +00:00
|
|
|
self.xmpp['xep_0030'].restore_defaults(jid='tester@localhost',
|
|
|
|
node='testing')
|
2010-12-09 23:57:27 +00:00
|
|
|
|
|
|
|
self.xmpp['xep_0030'].add_identity(jid='tester@localhost',
|
|
|
|
node='testing',
|
|
|
|
category='automation',
|
|
|
|
itype='command-list')
|
|
|
|
|
|
|
|
self.recv("""
|
|
|
|
<iq type="get" id="test" to="tester@localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info"
|
|
|
|
node="testing" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="result" id="test">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info"
|
|
|
|
node="testing">
|
|
|
|
<identity category="automation"
|
|
|
|
type="command-list" />
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testOverrideGlobalInfoHandler(self):
|
|
|
|
"""Test overriding the global JID info handler."""
|
|
|
|
self.stream_start(mode='component',
|
|
|
|
jid='tester.localhost',
|
|
|
|
plugins=['xep_0030'])
|
|
|
|
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
def dynamic_global(jid, node, ifrom, iq):
|
2010-12-09 23:57:27 +00:00
|
|
|
result = self.xmpp['xep_0030'].stanza.DiscoInfo()
|
|
|
|
result['node'] = node
|
|
|
|
result.add_identity('component', 'generic', name='Dynamic Info')
|
|
|
|
return result
|
|
|
|
|
|
|
|
self.xmpp['xep_0030'].set_node_handler('get_info',
|
|
|
|
handler=dynamic_global)
|
|
|
|
|
2016-09-20 06:58:29 +00:00
|
|
|
self.xmpp['xep_0030'].restore_defaults(jid='user@tester.localhost',
|
|
|
|
node='testing')
|
2010-12-09 23:57:27 +00:00
|
|
|
|
|
|
|
self.xmpp['xep_0030'].add_feature(jid='user@tester.localhost',
|
|
|
|
node='testing',
|
|
|
|
feature='urn:xmpp:ping')
|
|
|
|
|
|
|
|
self.recv("""
|
|
|
|
<iq type="get" id="test"
|
|
|
|
to="user@tester.localhost"
|
|
|
|
from="tester@localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info"
|
|
|
|
node="testing" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="result" id="test"
|
|
|
|
to="tester@localhost"
|
|
|
|
from="user@tester.localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info"
|
|
|
|
node="testing">
|
|
|
|
<feature var="urn:xmpp:ping" />
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testGetInfoRemote(self):
|
|
|
|
"""
|
|
|
|
Test sending a disco#info query to another entity
|
|
|
|
and receiving the result.
|
|
|
|
"""
|
|
|
|
self.stream_start(mode='client',
|
|
|
|
plugins=['xep_0030'])
|
|
|
|
|
|
|
|
events = set()
|
|
|
|
|
|
|
|
def handle_disco_info(iq):
|
|
|
|
events.add('disco_info')
|
|
|
|
|
|
|
|
|
|
|
|
self.xmpp.add_event_handler('disco_info', handle_disco_info)
|
|
|
|
|
XEP-0030: API changes
- ``supports``, ``has_identity``, ``get_info``, ``get_items`` are now coroutines
- ``set_info````set_items``, ``del_items``, ``add_item``, ``add_identity``,
``del_identity``, ``set_identities``, ``del_identities``, ``add_feature``,
``del_feature``, ``set_feature``, ``set_features``, ``del_features``
now return a Future
also fix has_identity and supports which have been broken in forever
2021-02-14 11:06:05 +00:00
|
|
|
|
|
|
|
self.xmpp.wrap(self.xmpp['xep_0030'].get_info('user@localhost', 'foo'))
|
|
|
|
self.wait_()
|
2010-12-09 23:57:27 +00:00
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" to="user@localhost" id="1">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info"
|
|
|
|
node="foo" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.recv("""
|
|
|
|
<iq type="result" to="tester@localhost" id="1">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#info"
|
|
|
|
node="foo">
|
|
|
|
<identity category="client" type="bot" />
|
|
|
|
<feature var="urn:xmpp:ping" />
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2016-10-22 12:35:54 +00:00
|
|
|
self.assertEqual(events, {'disco_info'},
|
2010-12-09 23:57:27 +00:00
|
|
|
"Disco info event was not triggered: %s" % events)
|
|
|
|
|
|
|
|
def testDynamicItemsJID(self):
|
|
|
|
"""
|
|
|
|
Test using a dynamic items handler for a particular JID.
|
|
|
|
"""
|
|
|
|
self.stream_start(mode='client',
|
|
|
|
plugins=['xep_0030'])
|
|
|
|
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
def dynamic_jid(jid, node, ifrom, iq):
|
2010-12-09 23:57:27 +00:00
|
|
|
result = self.xmpp['xep_0030'].stanza.DiscoItems()
|
|
|
|
result['node'] = node
|
|
|
|
result.add_item('tester@localhost', node='foo', name='JID')
|
|
|
|
return result
|
|
|
|
|
|
|
|
self.xmpp['xep_0030'].set_node_handler('get_items',
|
|
|
|
jid='tester@localhost',
|
|
|
|
handler=dynamic_jid)
|
|
|
|
|
|
|
|
self.recv("""
|
|
|
|
<iq type="get" id="test" to="tester@localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items"
|
|
|
|
node="testing" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="result" id="test">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items"
|
|
|
|
node="testing">
|
|
|
|
<item jid="tester@localhost" node="foo" name="JID" />
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testDynamicItemsGlobal(self):
|
|
|
|
"""
|
|
|
|
Test using a dynamic items handler for all requests.
|
|
|
|
"""
|
|
|
|
self.stream_start(mode='component',
|
|
|
|
jid='tester.localhost',
|
|
|
|
plugins=['xep_0030'])
|
|
|
|
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
def dynamic_global(jid, node, ifrom, iq):
|
2010-12-09 23:57:27 +00:00
|
|
|
result = self.xmpp['xep_0030'].stanza.DiscoItems()
|
|
|
|
result['node'] = node
|
|
|
|
result.add_item('tester@localhost', node='foo', name='Global')
|
|
|
|
return result
|
|
|
|
|
|
|
|
self.xmpp['xep_0030'].set_node_handler('get_items',
|
|
|
|
handler=dynamic_global)
|
|
|
|
|
|
|
|
self.recv("""
|
|
|
|
<iq type="get" id="test"
|
|
|
|
to="user@tester.localhost"
|
|
|
|
from="tester@localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items"
|
|
|
|
node="testing" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="result" id="test"
|
|
|
|
to="tester@localhost"
|
|
|
|
from="user@tester.localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items"
|
|
|
|
node="testing">
|
|
|
|
<item jid="tester@localhost" node="foo" name="Global" />
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testOverrideJIDItemsHandler(self):
|
|
|
|
"""Test overriding a JID items handler."""
|
|
|
|
self.stream_start(mode='client',
|
|
|
|
plugins=['xep_0030'])
|
|
|
|
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
def dynamic_jid(jid, node, ifrom, iq):
|
2010-12-09 23:57:27 +00:00
|
|
|
result = self.xmpp['xep_0030'].stanza.DiscoItems()
|
|
|
|
result['node'] = node
|
|
|
|
result.add_item('tester@localhost', node='foo', name='Global')
|
|
|
|
return result
|
|
|
|
|
|
|
|
self.xmpp['xep_0030'].set_node_handler('get_items',
|
|
|
|
jid='tester@localhost',
|
|
|
|
handler=dynamic_jid)
|
|
|
|
|
|
|
|
|
2016-09-20 06:58:29 +00:00
|
|
|
self.xmpp['xep_0030'].restore_defaults(jid='tester@localhost',
|
|
|
|
node='testing')
|
2010-12-09 23:57:27 +00:00
|
|
|
|
2010-12-28 20:37:02 +00:00
|
|
|
self.xmpp['xep_0030'].add_item(ijid='tester@localhost',
|
2010-12-09 23:57:27 +00:00
|
|
|
node='testing',
|
2010-12-28 20:37:02 +00:00
|
|
|
jid='tester@localhost',
|
|
|
|
subnode='foo',
|
2010-12-09 23:57:27 +00:00
|
|
|
name='Test')
|
|
|
|
|
|
|
|
self.recv("""
|
|
|
|
<iq type="get" id="test" to="tester@localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items"
|
|
|
|
node="testing" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="result" id="test">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items"
|
|
|
|
node="testing">
|
|
|
|
<item jid="tester@localhost" node="foo" name="Test" />
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testOverrideGlobalItemsHandler(self):
|
|
|
|
"""Test overriding the global JID items handler."""
|
|
|
|
self.stream_start(mode='component',
|
|
|
|
jid='tester.localhost',
|
|
|
|
plugins=['xep_0030'])
|
|
|
|
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
def dynamic_global(jid, node, ifrom, iq):
|
2010-12-09 23:57:27 +00:00
|
|
|
result = self.xmpp['xep_0030'].stanza.DiscoItems()
|
|
|
|
result['node'] = node
|
|
|
|
result.add_item('tester.localhost', node='foo', name='Global')
|
|
|
|
return result
|
|
|
|
|
|
|
|
self.xmpp['xep_0030'].set_node_handler('get_items',
|
|
|
|
handler=dynamic_global)
|
|
|
|
|
2016-09-20 06:58:29 +00:00
|
|
|
self.xmpp['xep_0030'].restore_defaults(jid='user@tester.localhost',
|
|
|
|
node='testing')
|
2010-12-09 23:57:27 +00:00
|
|
|
|
2010-12-28 20:37:02 +00:00
|
|
|
self.xmpp['xep_0030'].add_item(ijid='user@tester.localhost',
|
2010-12-09 23:57:27 +00:00
|
|
|
node='testing',
|
2010-12-28 20:37:02 +00:00
|
|
|
jid='user@tester.localhost',
|
|
|
|
subnode='foo',
|
2010-12-09 23:57:27 +00:00
|
|
|
name='Test')
|
|
|
|
|
|
|
|
self.recv("""
|
|
|
|
<iq type="get" id="test"
|
|
|
|
to="user@tester.localhost"
|
|
|
|
from="tester@localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items"
|
|
|
|
node="testing" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="result" id="test"
|
|
|
|
to="tester@localhost"
|
|
|
|
from="user@tester.localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items"
|
|
|
|
node="testing">
|
|
|
|
<item jid="user@tester.localhost" node="foo" name="Test" />
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
def testGetItemsRemote(self):
|
|
|
|
"""
|
|
|
|
Test sending a disco#items query to another entity
|
|
|
|
and receiving the result.
|
|
|
|
"""
|
|
|
|
self.stream_start(mode='client',
|
|
|
|
plugins=['xep_0030'])
|
|
|
|
|
|
|
|
events = set()
|
|
|
|
results = set()
|
|
|
|
|
|
|
|
def handle_disco_items(iq):
|
|
|
|
events.add('disco_items')
|
|
|
|
results.update(iq['disco_items']['items'])
|
|
|
|
|
|
|
|
|
|
|
|
self.xmpp.add_event_handler('disco_items', handle_disco_items)
|
|
|
|
|
XEP-0030: API changes
- ``supports``, ``has_identity``, ``get_info``, ``get_items`` are now coroutines
- ``set_info````set_items``, ``del_items``, ``add_item``, ``add_identity``,
``del_identity``, ``set_identities``, ``del_identities``, ``add_feature``,
``del_feature``, ``set_feature``, ``set_features``, ``del_features``
now return a Future
also fix has_identity and supports which have been broken in forever
2021-02-14 11:06:05 +00:00
|
|
|
self.xmpp.wrap(self.xmpp['xep_0030'].get_items('user@localhost', 'foo'))
|
|
|
|
self.wait_()
|
2010-12-09 23:57:27 +00:00
|
|
|
|
|
|
|
self.send("""
|
|
|
|
<iq type="get" to="user@localhost" id="1">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items"
|
|
|
|
node="foo" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.recv("""
|
|
|
|
<iq type="result" to="tester@localhost" id="1">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items"
|
|
|
|
node="foo">
|
|
|
|
<item jid="user@localhost" node="bar" name="Test" />
|
|
|
|
<item jid="user@localhost" node="baz" name="Test 2" />
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2016-10-22 12:35:54 +00:00
|
|
|
items = {('user@localhost', 'bar', 'Test'),
|
|
|
|
('user@localhost', 'baz', 'Test 2')}
|
|
|
|
self.assertEqual(events, {'disco_items'},
|
2010-12-09 23:57:27 +00:00
|
|
|
"Disco items event was not triggered: %s" % events)
|
|
|
|
self.assertEqual(results, items,
|
|
|
|
"Unexpected items: %s" % results)
|
|
|
|
|
2021-03-07 18:48:07 +00:00
|
|
|
def testGetItemsIterators(self):
|
2011-01-08 16:19:31 +00:00
|
|
|
"""Test interaction between XEP-0030 and XEP-0059 plugins."""
|
2021-03-07 18:48:07 +00:00
|
|
|
iteration_finished = []
|
|
|
|
jids_found = set()
|
2011-01-08 16:19:31 +00:00
|
|
|
|
|
|
|
self.stream_start(mode='client',
|
|
|
|
plugins=['xep_0030', 'xep_0059'])
|
|
|
|
|
2021-03-07 18:48:07 +00:00
|
|
|
async def run_test():
|
|
|
|
iterator = await self.xmpp['xep_0030'].get_items(
|
|
|
|
jid='foo@localhost',
|
|
|
|
node='bar',
|
|
|
|
iterator=True
|
|
|
|
)
|
|
|
|
iterator.amount = 10
|
|
|
|
async for page in iterator:
|
|
|
|
for item in page['disco_items']['items']:
|
|
|
|
jids_found.add(item[0])
|
|
|
|
iteration_finished.append(True)
|
|
|
|
|
|
|
|
test_run = self.xmpp.wrap(run_test())
|
|
|
|
self.wait_()
|
2011-01-08 16:19:31 +00:00
|
|
|
self.send("""
|
|
|
|
<iq id="2" type="get" to="foo@localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items"
|
|
|
|
node="bar">
|
|
|
|
<set xmlns="http://jabber.org/protocol/rsm">
|
|
|
|
<max>10</max>
|
|
|
|
</set>
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
self.recv("""
|
|
|
|
<iq id="2" type="result" to="tester@localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items">
|
2021-03-07 18:48:07 +00:00
|
|
|
<item jid="a@b" node="1"/>
|
|
|
|
<item jid="b@b" node="2"/>
|
|
|
|
<item jid="c@b" node="3"/>
|
|
|
|
<item jid="d@b" node="4"/>
|
|
|
|
<item jid="e@b" node="5"/>
|
2011-01-08 16:19:31 +00:00
|
|
|
<set xmlns="http://jabber.org/protocol/rsm">
|
2021-03-07 18:48:07 +00:00
|
|
|
<first index='0'>a@b</first>
|
|
|
|
<last>e@b</last>
|
|
|
|
<count>10</count>
|
2011-01-08 16:19:31 +00:00
|
|
|
</set>
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
2021-03-07 18:48:07 +00:00
|
|
|
self.wait_()
|
|
|
|
self.send("""
|
|
|
|
<iq id="3" type="get" to="foo@localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items"
|
|
|
|
node="bar">
|
|
|
|
<set xmlns="http://jabber.org/protocol/rsm">
|
|
|
|
<max>10</max>
|
|
|
|
<after>e@b</after>
|
|
|
|
</set>
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
self.recv("""
|
|
|
|
<iq id="3" type="result" to="tester@localhost">
|
|
|
|
<query xmlns="http://jabber.org/protocol/disco#items">
|
|
|
|
<item jid="f@b" node="6"/>
|
|
|
|
<item jid="g@b" node="7"/>
|
|
|
|
<item jid="h@b" node="8"/>
|
|
|
|
<item jid="i@b" node="9"/>
|
|
|
|
<item jid="j@b" node="10"/>
|
|
|
|
<set xmlns="http://jabber.org/protocol/rsm">
|
|
|
|
<first index='5'>f@b</first>
|
|
|
|
<last>j@b</last>
|
|
|
|
<count>10</count>
|
|
|
|
</set>
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
expected_jids = {'%s@b' % i for i in 'abcdefghij'}
|
|
|
|
self.run_coro(test_run)
|
|
|
|
self.assertEqual(expected_jids, jids_found)
|
|
|
|
self.assertEqual(iteration_finished, [True])
|
2011-01-08 16:19:31 +00:00
|
|
|
|
2010-11-18 20:50:45 +00:00
|
|
|
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamDisco)
|