Skip to content
Snippets Groups Projects
Commit 7dacd51c authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Add complex caps test

parent 737b5ae0
No related branches found
No related tags found
No related merge requests found
...@@ -2318,18 +2318,31 @@ class AgentInfoReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): ...@@ -2318,18 +2318,31 @@ class AgentInfoReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
if self.id_ in self.conn.disco_info_ids: if self.id_ in self.conn.disco_info_ids:
self.conn.disco_info_ids.remove(self.id_) self.conn.disco_info_ids.remove(self.id_)
if self.id_ is None: if self.id_ is None:
log.warning('Invalid IQ received without an ID. Ignoring it: %s' % \ log.warning('Invalid IQ received without an ID. '
self.stanza) 'Ignoring it: %s', self.stanza)
return return
# According to XEP-0030: # According to XEP-0030:
# For identity: category, type is mandatory, name is optional. # For identity: category, type is mandatory, name is optional.
# For feature: var is mandatory # For feature: var is mandatory
self.identities, self.features, self.data = [], [], [] self.identities, self.features, self.data, self.node = self.parse_stanza(self.stanza)
q = self.stanza.getTag('query')
self.node = q.getAttr('node') if not self.identities:
if not self.node: # ejabberd doesn't send identities when we browse online users
self.node = '' # see http://www.jabber.ru/bugzilla/show_bug.cgi?id=225
qc = self.stanza.getQueryChildren() self.identities = [{'category': 'server', 'type': 'im',
'name': self.node}]
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: if not qc:
qc = [] qc = []
...@@ -2338,21 +2351,15 @@ class AgentInfoReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): ...@@ -2338,21 +2351,15 @@ class AgentInfoReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
attr = {} attr = {}
for key in i.getAttrs().keys(): for key in i.getAttrs().keys():
attr[key] = i.getAttr(key) attr[key] = i.getAttr(key)
self.identities.append(attr) identities.append(attr)
elif i.getName() == 'feature': elif i.getName() == 'feature':
var = i.getAttr('var') var = i.getAttr('var')
if var: if var:
self.features.append(var) features.append(var)
elif i.getName() == 'x' and i.getNamespace() == nbxmpp.NS_DATA: elif i.getName() == 'x' and i.getNamespace() == nbxmpp.NS_DATA:
self.data.append(nbxmpp.DataForm(node=i)) data.append(nbxmpp.DataForm(node=i))
if not self.identities: return identities, features, data, node
# ejabberd doesn't send identities when we browse online users
# see http://www.jabber.ru/bugzilla/show_bug.cgi?id=225
self.identities = [{'category': 'server', 'type': 'im',
'name': self.node}]
self.get_jid_resource()
return True
class AgentInfoErrorReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): class AgentInfoErrorReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
name = 'agent-info-error-received' name = 'agent-info-error-received'
......
...@@ -6,12 +6,46 @@ import unittest ...@@ -6,12 +6,46 @@ import unittest
import lib import lib
lib.setup_env() 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 import caps_cache as caps
from gajim.common.contacts import Contact from gajim.common.contacts import Contact
from gajim.common.connection_handlers_events import AgentInfoReceivedEvent
from mock import Mock 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): class CommonCapsTest(unittest.TestCase):
...@@ -93,8 +127,10 @@ class TestCapsCache(CommonCapsTest): ...@@ -93,8 +127,10 @@ class TestCapsCache(CommonCapsTest):
def test_hash(self): def test_hash(self):
'''tests the hash computation''' '''tests the hash computation'''
computed_hash = caps.compute_caps_hash(self.identities, self.features) stanza = Iq(node=COMPLEX_EXAMPLE)
self.assertEqual(self.caps_hash, computed_hash) 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): class TestClientCaps(CommonCapsTest):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment