diff --git a/gajim/common/connection_handlers_events.py b/gajim/common/connection_handlers_events.py index 2c8596a57f9637c2e71262481d4ded3c58da977a..29ebf1be2e14e3822a8cba6a3c9fb0668bbdae94 100644 --- a/gajim/common/connection_handlers_events.py +++ b/gajim/common/connection_handlers_events.py @@ -2318,18 +2318,31 @@ 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() + 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 + # 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 + + @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 = [] @@ -2338,21 +2351,15 @@ class AgentInfoReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): attr = {} for key in i.getAttrs().keys(): attr[key] = i.getAttr(key) - self.identities.append(attr) + identities.append(attr) elif i.getName() == 'feature': var = i.getAttr('var') if var: - self.features.append(var) + features.append(var) 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: - # 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 + return identities, features, data, node class AgentInfoErrorReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): name = 'agent-info-error-received' diff --git a/test/unit/test_caps_cache.py b/test/unit/test_caps_cache.py index a0bbdd545fedc3a67b2d17c604daaed99f5b85a3..66fcc02c7fa23e01645b3f74a9b1dcfe82f2e2bd 100644 --- a/test/unit/test_caps_cache.py +++ b/test/unit/test_caps_cache.py @@ -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):