Add complex caps test
This commit is contained in:
parent
737b5ae04a
commit
7dacd51c1d
|
@ -2318,33 +2318,13 @@ class AgentInfoReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|||
if self.id_ in self.conn.disco_info_ids:
|
||||
self.conn.disco_info_ids.remove(self.id_)
|
||||
if self.id_ is None:
|
||||
log.warning('Invalid IQ received without an ID. Ignoring it: %s' % \
|
||||
self.stanza)
|
||||
log.warning('Invalid IQ received without an ID. '
|
||||
'Ignoring it: %s', self.stanza)
|
||||
return
|
||||
# According to XEP-0030:
|
||||
# For identity: category, type is mandatory, name is optional.
|
||||
# For feature: var is mandatory
|
||||
self.identities, self.features, self.data = [], [], []
|
||||
q = self.stanza.getTag('query')
|
||||
self.node = q.getAttr('node')
|
||||
if not self.node:
|
||||
self.node = ''
|
||||
qc = self.stanza.getQueryChildren()
|
||||
if not qc:
|
||||
qc = []
|
||||
|
||||
for i in qc:
|
||||
if i.getName() == 'identity':
|
||||
attr = {}
|
||||
for key in i.getAttrs().keys():
|
||||
attr[key] = i.getAttr(key)
|
||||
self.identities.append(attr)
|
||||
elif i.getName() == 'feature':
|
||||
var = i.getAttr('var')
|
||||
if var:
|
||||
self.features.append(var)
|
||||
elif i.getName() == 'x' and i.getNamespace() == nbxmpp.NS_DATA:
|
||||
self.data.append(nbxmpp.DataForm(node=i))
|
||||
self.identities, self.features, self.data, self.node = self.parse_stanza(self.stanza)
|
||||
|
||||
if not self.identities:
|
||||
# ejabberd doesn't send identities when we browse online users
|
||||
|
@ -2354,6 +2334,33 @@ class AgentInfoReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|||
self.get_jid_resource()
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def parse_stanza(cls, stanza):
|
||||
identities, features, data, node = [], [], [], None
|
||||
q = stanza.getTag('query')
|
||||
node = q.getAttr('node')
|
||||
if not node:
|
||||
node = ''
|
||||
|
||||
qc = stanza.getQueryChildren()
|
||||
if not qc:
|
||||
qc = []
|
||||
|
||||
for i in qc:
|
||||
if i.getName() == 'identity':
|
||||
attr = {}
|
||||
for key in i.getAttrs().keys():
|
||||
attr[key] = i.getAttr(key)
|
||||
identities.append(attr)
|
||||
elif i.getName() == 'feature':
|
||||
var = i.getAttr('var')
|
||||
if var:
|
||||
features.append(var)
|
||||
elif i.getName() == 'x' and i.getNamespace() == nbxmpp.NS_DATA:
|
||||
data.append(nbxmpp.DataForm(node=i))
|
||||
|
||||
return identities, features, data, node
|
||||
|
||||
class AgentInfoErrorReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||
name = 'agent-info-error-received'
|
||||
base_network_events = []
|
||||
|
|
|
@ -6,12 +6,46 @@ import unittest
|
|||
import lib
|
||||
lib.setup_env()
|
||||
|
||||
from nbxmpp import NS_MUC, NS_PING, NS_XHTML_IM
|
||||
from nbxmpp import NS_MUC, NS_PING, NS_XHTML_IM, Iq
|
||||
from gajim.common import caps_cache as caps
|
||||
from gajim.common.contacts import Contact
|
||||
from gajim.common.connection_handlers_events import AgentInfoReceivedEvent
|
||||
|
||||
from mock import Mock
|
||||
|
||||
COMPLEX_EXAMPLE = '''
|
||||
<iq from='benvolio@capulet.lit/230193' id='disco1' to='juliet@capulet.lit/chamber' type='result'>
|
||||
<query xmlns='http://jabber.org/protocol/disco#info' node='http://psi-im.org#q07IKJEyjvHSyhy//CH0CxmKi8w='>
|
||||
<identity xml:lang='en' category='client' name='Psi 0.11' type='pc'/>
|
||||
<identity xml:lang='el' category='client' name='Ψ 0.11' type='pc'/>
|
||||
<feature var='http://jabber.org/protocol/caps'/>
|
||||
<feature var='http://jabber.org/protocol/disco#info'/>
|
||||
<feature var='http://jabber.org/protocol/disco#items'/>
|
||||
<feature var='http://jabber.org/protocol/muc'/>
|
||||
<x xmlns='jabber:x:data' type='result'>
|
||||
<field var='FORM_TYPE' type='hidden'>
|
||||
<value>urn:xmpp:dataforms:softwareinfo</value>
|
||||
</field>
|
||||
<field var='ip_version'>
|
||||
<value>ipv4</value>
|
||||
<value>ipv6</value>
|
||||
</field>
|
||||
<field var='os'>
|
||||
<value>Mac</value>
|
||||
</field>
|
||||
<field var='os_version'>
|
||||
<value>10.5.1</value>
|
||||
</field>
|
||||
<field var='software'>
|
||||
<value>Psi</value>
|
||||
</field>
|
||||
<field var='software_version'>
|
||||
<value>0.11</value>
|
||||
</field>
|
||||
</x>
|
||||
</query>
|
||||
</iq>'''
|
||||
|
||||
|
||||
class CommonCapsTest(unittest.TestCase):
|
||||
|
||||
|
@ -93,8 +127,10 @@ class TestCapsCache(CommonCapsTest):
|
|||
|
||||
def test_hash(self):
|
||||
'''tests the hash computation'''
|
||||
computed_hash = caps.compute_caps_hash(self.identities, self.features)
|
||||
self.assertEqual(self.caps_hash, computed_hash)
|
||||
stanza = Iq(node=COMPLEX_EXAMPLE)
|
||||
identities, features, data, _ = AgentInfoReceivedEvent.parse_stanza(stanza)
|
||||
computed_hash = caps.compute_caps_hash(identities, features, data)
|
||||
self.assertEqual('q07IKJEyjvHSyhy//CH0CxmKi8w=', computed_hash)
|
||||
|
||||
|
||||
class TestClientCaps(CommonCapsTest):
|
||||
|
|
Loading…
Reference in New Issue