Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
eta
gajim
Commits
7dacd51c
Commit
7dacd51c
authored
7 years ago
by
Philipp Hörist
Browse files
Options
Downloads
Patches
Plain Diff
Add complex caps test
parent
737b5ae0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gajim/common/connection_handlers_events.py
+25
-18
25 additions, 18 deletions
gajim/common/connection_handlers_events.py
test/unit/test_caps_cache.py
+39
-3
39 additions, 3 deletions
test/unit/test_caps_cache.py
with
64 additions
and
21 deletions
gajim/common/connection_handlers_events.py
+
25
−
18
View file @
7dacd51c
...
@@ -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
'
...
...
This diff is collapsed.
Click to expand it.
test/unit/test_caps_cache.py
+
39
−
3
View file @
7dacd51c
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment