Mercurial > libervia-backend
annotate tests/unit/test_plugin_xep_0320.py @ 4141:ba8ddfdd334f
cli (loops): run GLib loop in same thread as asyncio:
use the new `install_glib_asyncio_iteration` to run GLib in the same thread as asyncio.
rel 426
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 01 Nov 2023 14:05:53 +0100 |
parents | 4b842c1fb686 |
children | f1d0cde61af7 |
rev | line source |
---|---|
4049 | 1 #!/usr/bin/env python3 |
2 | |
3 # Libervia: an XMPP client | |
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org) | |
5 | |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 from twisted.words.xish import domish | |
20 | |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4049
diff
changeset
|
21 from libervia.backend.plugins.plugin_xep_0320 import NS_JINGLE_DTLS, XEP_0320 |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4049
diff
changeset
|
22 from libervia.backend.tools import xml_tools |
4049 | 23 |
24 | |
25 class TestXEP0320: | |
26 def test_parse_transport_trigger(self, host): | |
27 """<transport> element is parsed correctly in trigger""" | |
28 xep_0320 = XEP_0320(host) | |
29 | |
30 transport_elt = xml_tools.parse( | |
31 f"<transport><fingerprint xmlns='{NS_JINGLE_DTLS}' hash='sha-256' " | |
32 "setup='active'>6D:8F:6A:53:A3:7E:10:B2:58:16:AB:A3:92:6F:8A:5B:2D:55:1C:FB:" | |
33 "2F:E3:6E:94:FE:4F:4E:FE:D4:77:49:B6</fingerprint></transport>" | |
34 ) | |
35 | |
36 ice_data = {} | |
37 result = xep_0320._parse_transport_trigger(transport_elt, ice_data) | |
38 | |
39 expected_ice_data = { | |
40 "fingerprint": { | |
41 "hash": "sha-256", | |
42 "setup": "active", | |
43 "fingerprint": | |
44 "6D:8F:6A:53:A3:7E:10:B2:58:16:AB:A3:92:6F:8A:5B:2D:55:1C:" | |
45 "FB:2F:E3:6E:94:FE:4F:4E:FE:D4:77:49:B6", | |
46 }, | |
47 } | |
48 | |
49 assert ice_data == expected_ice_data | |
50 assert result | |
51 | |
52 def test_build_transport(self, host): | |
53 """<transport> element is buid correctly in trigger""" | |
54 xep_0320 = XEP_0320(host) | |
55 | |
56 transport_elt = domish.Element((None, "transport")) | |
57 | |
58 ice_data = { | |
59 "fingerprint": { | |
60 "hash": "sha-256", | |
61 "setup": "active", | |
62 "fingerprint": | |
63 "6D:8F:6A:53:A3:7E:10:B2:58:16:AB:A3:92:6F:8A:5B:2D:55:1C:" | |
64 "FB:2F:E3:6E:94:FE:4F:4E:FE:D4:77:49:B6", | |
65 }, | |
66 } | |
67 | |
68 result = xep_0320._build_transport_trigger(transport_elt, ice_data) | |
69 | |
70 expected_transport_elt = xml_tools.parse( | |
71 f"<transport><fingerprint xmlns='{NS_JINGLE_DTLS}' hash='sha-256' " | |
72 "setup='active'>6D:8F:6A:53:A3:7E:10:B2:58:16:AB:A3:92:6F:8A:5B:2D:55:1C:FB:" | |
73 "2F:E3:6E:94:FE:4F:4E:FE:D4:77:49:B6</fingerprint></transport>""" | |
74 ) | |
75 | |
76 assert transport_elt.toXml() == expected_transport_elt.toXml() | |
77 assert result |