File: test_entity_caps.py

package info (click to toggle)
python-nbxmpp 2.0.2-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,120 kB
  • sloc: python: 14,949; makefile: 8
file content (197 lines) | stat: -rw-r--r-- 8,758 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import unittest

from nbxmpp.util import compute_caps_hash
from nbxmpp.modules.discovery import parse_disco_info
from nbxmpp.protocol import Iq
from nbxmpp.protocol import DiscoInfoMalformed

class EntityCaps(unittest.TestCase):

    def test_multiple_field_values(self):
        node = """
        <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>"""

        info = parse_disco_info(Iq(node=node))
        hash_ = compute_caps_hash(info)
        self.assertEqual(hash_, 'q07IKJEyjvHSyhy//CH0CxmKi8w=')

    def test_ignore_invalid_forms(self):
        node = """
        <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>
            <x xmlns='jabber:x:data' type='result'>
              <field var='FORM_TYPE'>
                <value>urn:xmpp:dataforms:softwareinfo</value>
              </field>
              <field var='ip_version'>
                <value>ipv4</value>
                <value>ipv6</value>
              </field>
            </x>
            <x xmlns='jabber:x:data' type='result'>
              <field var='ip_version'>
                <value>ipv4</value>
                <value>ipv6</value>
              </field>
            </x>
          </query>
        </iq>"""

        info = parse_disco_info(Iq(node=node))
        hash_ = compute_caps_hash(info)
        self.assertEqual(hash_, 'q07IKJEyjvHSyhy//CH0CxmKi8w=')

    def test_multiple_form_type_values(self):
        node = """
        <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>
                <value>urn:xmpp:dataforms:softwareinfo_test</value>
              </field>
              <field var='ip_version'>
                <value>ipv4</value>
                <value>ipv6</value>
              </field>
            </x>
          </query>
        </iq>"""

        info = parse_disco_info(Iq(node=node))
        with self.assertRaises(DiscoInfoMalformed):
            hash_ = compute_caps_hash(info)

    def test_non_unique_form_type_value(self):
        node = """
        <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>
            </x>
            <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>
            </x>
          </query>
        </iq>"""

        info = parse_disco_info(Iq(node=node))
        with self.assertRaises(DiscoInfoMalformed):
            hash_ = compute_caps_hash(info)

    def test_non_unique_feature(self):
        node = """
        <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/muc'/>
            <feature var='http://jabber.org/protocol/disco#info'/>
            <feature var='http://jabber.org/protocol/disco#items'/>
            <feature var='http://jabber.org/protocol/muc'/>
          </query>
        </iq>"""

        info = parse_disco_info(Iq(node=node))
        with self.assertRaises(DiscoInfoMalformed):
            hash_ = compute_caps_hash(info)

    def test_non_unique_identity(self):
        node = """
        <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='en' category='client' name='Psi 0.11' type='pc'/>
            <feature var='http://jabber.org/protocol/caps'/>
            <feature var='http://jabber.org/protocol/muc'/>
            <feature var='http://jabber.org/protocol/disco#info'/>
            <feature var='http://jabber.org/protocol/disco#items'/>
            <feature var='http://jabber.org/protocol/muc'/>
          </query>
        </iq>"""

        info = parse_disco_info(Iq(node=node))
        with self.assertRaises(DiscoInfoMalformed):
            hash_ = compute_caps_hash(info)