summaryrefslogtreecommitdiff
path: root/tests/test_stream_xep_0405.py
blob: 9bc01601b42b2c94fe5768c1975b351daedaad13 (plain)
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
import unittest
from slixmpp.test import SlixTest
from slixmpp import JID


class TestMIXPAM(SlixTest):

    def setUp(self):
        self.stream_start(plugins=['xep_0405'])

    def tearDown(self):
        self.stream_close()

    def testGetRosterEmpty(self):
        """Test requesting an empty annotated roster"""

        fut = self.xmpp.wrap(self.xmpp['xep_0405'].get_mix_roster())

        self.wait_()
        self.send("""
          <iq type="get" id="1">
            <query xmlns="jabber:iq:roster">
                <annotate xmlns='urn:xmpp:mix:roster:0' />
            </query>
          </iq>
        """)

        self.recv("""
          <iq type="result" id="1"
              to="tester@localhost" />
        """)

        result = self.run_coro(fut)

    def testGetRoster(self):
        """Test requesting an annotated roster"""

        fut = self.xmpp.wrap(self.xmpp['xep_0405'].get_mix_roster())

        self.wait_()
        self.send("""
          <iq type="get" id="1">
            <query xmlns="jabber:iq:roster">
                <annotate xmlns='urn:xmpp:mix:roster:0' />
            </query>
          </iq>
        """)

        self.recv("""
          <iq type="result" id="1" to="tester@localhost">
            <query xmlns="jabber:iq:roster">
              <item jid='romeo@example.net'/>
              <item jid='juliet@example.net'/>
              <item jid='balcony@example.net'>
                <channel xmlns='urn:xmpp:mix:roster:0'
                         participant-id='123456'/>
              </item>
            </query>
          </iq>
        """)

        self.wait_()
        contacts, channels = fut.result()
        self.assertEqual(len(contacts), 2)
        self.assertEqual(contacts[0]['jid'], 'romeo@example.net')
        self.assertEqual(contacts[1]['jid'], 'juliet@example.net')
        self.assertEqual(len(channels), 1)
        self.assertEqual(channels[0]['jid'], 'balcony@example.net')
        self.assertEqual(
            channels[0]['channel']['participant-id'],
            '123456'
        )

    def testClientJoin(self):
        """Test a client join"""

        fut = self.xmpp.wrap(self.xmpp['xep_0405'].join_channel(
            JID('coven@mix.shakespeare.example'),
            'toto',
        ))
        self.send("""
            <iq type='set' to='tester@localhost' id='1'>
              <client-join xmlns='urn:xmpp:mix:pam:2'
                           channel='coven@mix.shakespeare.example'>
                <join xmlns='urn:xmpp:mix:core:1'>
                  <nick>toto</nick>
                  <subscribe node='urn:xmpp:mix:nodes:messages'/>
                  <subscribe node='urn:xmpp:mix:nodes:participants'/>
                  <subscribe node='urn:xmpp:mix:nodes:info'/>
                </join>
              </client-join>
            </iq>
        """)
        self.recv("""
            <iq type='result'
                from='tester@localhost'
                to='tester@localhost/resource'
                id='1'>
                  <client-join xmlns='urn:xmpp:mix:pam:2'>
                    <join xmlns='urn:xmpp:mix:core:1'
                          jid='123456#coven@mix.shakespeare.example'>
                      <subscribe node='urn:xmpp:mix:nodes:messages'/>
                      <subscribe node='urn:xmpp:mix:nodes:participants'/>
                      <subscribe node='urn:xmpp:mix:nodes:info'/>
                   </join>
                 </client-join>
            </iq>
        """)
        self.wait_()
        self.assertEqual(fut.result(), set())

    def testClientJoinNotAllNodes(self):
        """Test a client join where one of the nodes is rejected"""

        fut = self.xmpp.wrap(self.xmpp['xep_0405'].join_channel(
            JID('coven@mix.shakespeare.example'),
            'toto',
        ))
        self.send("""
            <iq type='set' to='tester@localhost' id='1'>
              <client-join xmlns='urn:xmpp:mix:pam:2'
                           channel='coven@mix.shakespeare.example'>
                <join xmlns='urn:xmpp:mix:core:1'>
                  <nick>toto</nick>
                  <subscribe node='urn:xmpp:mix:nodes:messages'/>
                  <subscribe node='urn:xmpp:mix:nodes:participants'/>
                  <subscribe node='urn:xmpp:mix:nodes:info'/>
                </join>
              </client-join>
            </iq>
        """)
        self.recv("""
            <iq type='result'
                from='tester@localhost'
                to='tester@localhost/resource'
                id='1'>
                  <client-join xmlns='urn:xmpp:mix:pam:2'>
                    <join xmlns='urn:xmpp:mix:core:1'
                          jid='123456#coven@mix.shakespeare.example'>
                      <subscribe node='urn:xmpp:mix:nodes:messages'/>
                      <subscribe node='urn:xmpp:mix:nodes:participants'/>
                   </join>
                 </client-join>
            </iq>
        """)
        self.wait_()
        self.assertEqual(fut.result(), {'urn:xmpp:mix:nodes:info'})

    def testClientLeave(self):
        """Test a client leave"""

        fut = self.xmpp.wrap(self.xmpp['xep_0405'].leave_channel(
            JID('coven@mix.shakespeare.example'),
        ))
        self.send("""
            <iq type='set'
                to='tester@localhost'
                id='1'>
              <client-leave xmlns='urn:xmpp:mix:pam:2'
                            channel='coven@mix.shakespeare.example'>
                <leave xmlns='urn:xmpp:mix:core:1'/>
              </client-leave>
            </iq>
        """)
        self.recv("""
            <iq type='result'
                from='tester@localhost'
                to='tester@localhost/resource'
                id='1'>
              <client-leave xmlns='urn:xmpp:mix:pam:2'
                            channel='coven@mix.shakespeare.example'>
                <leave xmlns='urn:xmpp:mix:core:1'/>
              </client-leave>
            </iq>
        """)

        self.assertEqual(fut.done(), True)
        self.assertEqual(fut.exception(), None)


suite = unittest.TestLoader().loadTestsFromTestCase(TestMIXPAM)