annotate tests/unit/test_plugin_xep_0215.py @ 4321:2246eeeccc74 default tip @

tests (unit): fix tests: - test_ap-gateway: fix missing implementation of `client.is_local` - test_plugin_xep_0215: fix missing return value of `has_feature`
author Goffi <goffi@goffi.org>
date Mon, 30 Sep 2024 14:15:47 +0200
parents 4b842c1fb686
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4034
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia: an XMPP client
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org)
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 from twisted.internet import defer
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from pytest_twisted import ensureDeferred as ed
4321
2246eeeccc74 tests (unit): fix tests:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
21 from unittest.mock import AsyncMock, MagicMock
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4034
diff changeset
22 from libervia.backend.plugins.plugin_xep_0215 import XEP_0215
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4034
diff changeset
23 from libervia.backend.tools import xml_tools
4034
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from twisted.words.protocols.jabber import jid
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
25
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
26
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 class TestXEP0215:
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 def test_parse_services(self, host):
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 """Services are parsed correctly"""
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 xep_0215 = XEP_0215(host)
4321
2246eeeccc74 tests (unit): fix tests:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
31 host.memory.disco.has_feature = AsyncMock()
2246eeeccc74 tests (unit): fix tests:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
32 host.memory.disco.has_feature.return_value = True
2246eeeccc74 tests (unit): fix tests:
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
33
4034
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 services_elt = xml_tools.parse(
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 """
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 <services xmlns="urn:xmpp:extdisco:2">
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 <service host="test.example" type="stun" port="1234" />
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 <service host="example.org" type="turn" port="5678" restricted="true">
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 <x xmlns="jabber:x:data" type="result">
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 <field type="hidden" var="FORM_TYPE">
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 <value>https://test.example/some_extension</value>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 </field>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 <field type="text-single" var="some_key">
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 <value>some_value</value>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 </field>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 <field type="boolean" var="some_bool">
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 <value>0</value>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 </field>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 <field type="list-multi" var="multiple_values">
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 <value>value_1</value>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 <value>value_2</value>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 </field>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 </x>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 </service>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 </services>"
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 """
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 )
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
59
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 services = xep_0215.parse_services(services_elt)
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
61
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 expected_services = [
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 {
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 "host": "test.example",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 "type": "stun",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 "port": 1234,
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 },
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 {
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 "host": "example.org",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 "type": "turn",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 "port": 5678,
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 "restricted": True,
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 "extended": [
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 {
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 "fields": [
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 {
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 "name": "some_key",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 "type": "text-single",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 "value": "some_value",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 "values": ["some_value"],
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 },
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 {
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 "name": "some_bool",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 "type": "boolean",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 "value": "0",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 "values": ["0"],
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 },
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 {
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 "name": "multiple_values",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 "type": "list-multi",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 "value": "value_1",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 "values": ["value_1", "value_2"],
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 },
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 ],
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 "namespace": "https://test.example/some_extension",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 }
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 ],
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 },
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 ]
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
100
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 assert services == expected_services
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
102
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 @ed
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 async def test_get_external_services(self, host, client):
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 xep_0215 = XEP_0215(host)
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 client._xep_0215_services = {}
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
107
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 iq_result = MagicMock()
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 iq_result.send.return_value = defer.succeed(iq_result)
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
110
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 client.IQ.return_value = iq_result
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
112
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 iq_result_elt = xml_tools.parse(
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 """
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 <iq type="result">
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 <services xmlns="urn:xmpp:extdisco:2">
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 <service host="test.example" type="stun" port="1234" />
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 <service host="example.org" type="turn" port="5678"
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 restricted="true" />
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 </services>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 </iq>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 """
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 )
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 iq_result.send.return_value = defer.succeed(iq_result_elt)
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
125
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 services = await xep_0215.get_external_services(client)
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
127
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 expected_services = [
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 {
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 "host": "test.example",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 "type": "stun",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 "port": 1234,
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 },
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 {
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 "host": "example.org",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 "type": "turn",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 "port": 5678,
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 "restricted": True,
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 },
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 ]
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
141
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 assert services == expected_services
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
143
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 @ed
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 async def test_request_credentials(self, host, client):
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 xep_0215 = XEP_0215(host)
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
147
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 iq_result = MagicMock()
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 iq_result.send.return_value = defer.succeed(iq_result)
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
150
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 client.IQ.return_value = iq_result
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
152
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 iq_result_elt = xml_tools.parse(
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 """
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 <iq type="result">
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 <credentials xmlns="urn:xmpp:extdisco:2">
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 <service host="test.example" type="stun" port="1234" username="user1"
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 password="pass1" restricted="true"/>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 </credentials>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 </iq>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 """
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 )
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 iq_result.send.return_value = defer.succeed(iq_result_elt)
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
164
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 credentials = await xep_0215.request_credentials(client, "test.example", "stun")
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
166
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 expected_credentials = [
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 {
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 "host": "test.example",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 "type": "stun",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 "port": 1234,
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 "username": "user1",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 "password": "pass1",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 "restricted": True,
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 }
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 ]
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
177
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 assert credentials == expected_credentials
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
179
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 def test_services_push(self, host, client):
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 xep_0215 = XEP_0215(host)
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
182
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 client._xep_0215_services = {
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 jid.JID("test.example"): [
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 {
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 "host": "test.example",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 "type": "stun",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 "port": 1234,
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 },
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 {
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 "host": "example.org",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 "type": "turn",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 "port": 5678,
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 },
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 ],
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 }
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
197
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 iq_elt = xml_tools.parse(
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 """
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 <iq type="set" from="test.example">
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 <services xmlns="urn:xmpp:extdisco:2">
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 <service action="add" host="example.net" type="stun" port="2345" />
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 <service action="modify" host="test.example" type="stun" port="1234"
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 expires="2023-04-10T12:34:56Z" />
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 <service action="delete" host="example.org" type="turn" port="5678" />
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 </services>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 </iq>
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 """
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 )
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
210
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 xep_0215.on_services_push(iq_elt, client)
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
212
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 expected_services = [
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 {
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 "host": "test.example",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 "type": "stun",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 "port": 1234,
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 "expires": 1681130096.0,
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 },
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 {
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 "host": "example.net",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 "type": "stun",
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 "port": 2345,
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 },
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 ]
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
226
9496f28dadff tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 assert client._xep_0215_services[jid.JID("test.example")] == expected_services