Mercurial > libervia-backend
annotate tests/unit/test_plugin_xep_0215.py @ 4220:5a0bddfa34ac
plugin XEP-0234: fix action type when pre-flight file confirmation is confirmed:
the `C.META_TYPE_FILE` can't be used in this case as it is a preflight and we don't have
yet data such as progress ID. `C.META_TYPE_FILE` is used as a sub-type to help with dialog
management in frontend.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 05 Mar 2024 17:31:49 +0100 |
parents | 4b842c1fb686 |
children | 2246eeeccc74 |
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 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from unittest.mock import 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) |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 services_elt = xml_tools.parse( |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 """ |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 <services xmlns="urn:xmpp:extdisco:2"> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 <service host="test.example" type="stun" port="1234" /> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 <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
|
37 <x xmlns="jabber:x:data" type="result"> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 <field type="hidden" var="FORM_TYPE"> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 <value>https://test.example/some_extension</value> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 </field> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 <field type="text-single" var="some_key"> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 <value>some_value</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="boolean" var="some_bool"> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 <value>0</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="list-multi" var="multiple_values"> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 <value>value_1</value> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 <value>value_2</value> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 </field> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 </x> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 </service> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 </services>" |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 """ |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 ) |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 services = xep_0215.parse_services(services_elt) |
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 expected_services = [ |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 { |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 "host": "test.example", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 "type": "stun", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 "port": 1234, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 }, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 { |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 "host": "example.org", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 "type": "turn", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 "port": 5678, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 "restricted": True, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 "extended": [ |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 { |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 "fields": [ |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 { |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 "name": "some_key", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 "type": "text-single", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 "value": "some_value", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 "values": ["some_value"], |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 }, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 { |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 "name": "some_bool", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 "type": "boolean", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 "value": "0", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 "values": ["0"], |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 }, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 { |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 "name": "multiple_values", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 "type": "list-multi", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 "value": "value_1", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 "values": ["value_1", "value_2"], |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 }, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 ], |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 "namespace": "https://test.example/some_extension", |
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 }, |
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 assert services == expected_services |
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 @ed |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 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
|
102 xep_0215 = XEP_0215(host) |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 client._xep_0215_services = {} |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 iq_result = MagicMock() |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 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
|
107 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 client.IQ.return_value = iq_result |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 iq_result_elt = xml_tools.parse( |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 """ |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 <iq type="result"> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 <services xmlns="urn:xmpp:extdisco:2"> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 <service host="test.example" type="stun" port="1234" /> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 <service host="example.org" type="turn" port="5678" |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 restricted="true" /> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 </services> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 </iq> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 """ |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 ) |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 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
|
122 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 services = await xep_0215.get_external_services(client) |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 expected_services = [ |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 { |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 "host": "test.example", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 "type": "stun", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 "port": 1234, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 }, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 { |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 "host": "example.org", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 "type": "turn", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 "port": 5678, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 "restricted": True, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 }, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 ] |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 assert services == expected_services |
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 @ed |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 async def test_request_credentials(self, host, client): |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 xep_0215 = XEP_0215(host) |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 iq_result = MagicMock() |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 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
|
147 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 client.IQ.return_value = iq_result |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 iq_result_elt = xml_tools.parse( |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 """ |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 <iq type="result"> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 <credentials xmlns="urn:xmpp:extdisco:2"> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 <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
|
155 password="pass1" restricted="true"/> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 </credentials> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 </iq> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 """ |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 ) |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 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
|
161 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 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
|
163 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 expected_credentials = [ |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 { |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 "host": "test.example", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 "type": "stun", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 "port": 1234, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 "username": "user1", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 "password": "pass1", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 "restricted": True, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 } |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 ] |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 assert credentials == expected_credentials |
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 def test_services_push(self, host, client): |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 xep_0215 = XEP_0215(host) |
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 client._xep_0215_services = { |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 jid.JID("test.example"): [ |
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 "host": "test.example", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 "type": "stun", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 "port": 1234, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 }, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 { |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 "host": "example.org", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 "type": "turn", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 "port": 5678, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 }, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 ], |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 } |
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 iq_elt = xml_tools.parse( |
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 <iq type="set" from="test.example"> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 <services xmlns="urn:xmpp:extdisco:2"> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 <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
|
200 <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
|
201 expires="2023-04-10T12:34:56Z" /> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 <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
|
203 </services> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 </iq> |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 """ |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 ) |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 xep_0215.on_services_push(iq_elt, client) |
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 expected_services = [ |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 { |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 "host": "test.example", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 "type": "stun", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 "port": 1234, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 "expires": 1681130096.0, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 }, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 { |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 "host": "example.net", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 "type": "stun", |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 "port": 2345, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 }, |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 ] |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 |
9496f28dadff
tests (unit): Add test for plugin XEP-0215:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 assert client._xep_0215_services[jid.JID("test.example")] == expected_services |