Mercurial > libervia-backend
annotate tests/unit/test_plugin_xep_0373.py @ 4197:9cda0347e0ac
plugin XEP-0359: if no origin ID is found, use <message> ID instead:
This way, we always have the right ID to check for non groupchat message in
`History.origin_id`.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 13 Dec 2023 22:00:25 +0100 |
parents | 4b842c1fb686 |
children | f1d0cde61af7 |
rev | line source |
---|---|
3933
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
1 from datetime import datetime, timedelta, timezone |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
2 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
3 import pytest |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4069
diff
changeset
|
4 from libervia.backend.core import exceptions |
4069
3d91d0aa68db
tests (unit): Skip XEP-0373 test if gpg can't be imported
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
5 try: |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4069
diff
changeset
|
6 from libervia.backend.plugins.plugin_xep_0373 import XEP_0373, NS_OX |
4069
3d91d0aa68db
tests (unit): Skip XEP-0373 test if gpg can't be imported
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
7 except exceptions.MissingModule as e: |
3d91d0aa68db
tests (unit): Skip XEP-0373 test if gpg can't be imported
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
8 pytest.skip(f"Can't test XEP-0373: {e}", allow_module_level=True) |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4069
diff
changeset
|
9 from libervia.backend.tools.xmpp_datetime import parse_datetime |
3933
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
10 from twisted.words.protocols.jabber import jid |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
11 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
12 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
13 a = jid.JID("foo@example.com") |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
14 b = jid.JID("bar@example.com") |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
15 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
16 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
17 def test_signcrypt_element_args() -> None: |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
18 with pytest.raises(ValueError): |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
19 XEP_0373.build_signcrypt_element([]) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
20 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
21 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
22 def test_signcrypt_element() -> None: |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
23 signcrypt_elt, payload_elt = XEP_0373.build_signcrypt_element([ a, b ]) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
24 payload_elt.addElement("signcrypt-test-content", content="signcrypt test content") |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
25 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
26 rpad_elt = next(signcrypt_elt.elements(NS_OX, "rpad")) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
27 time_elt = next(signcrypt_elt.elements(NS_OX, "time")) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
28 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
29 rpad = str(rpad_elt) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
30 timestamp = parse_datetime(time_elt["stamp"]) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
31 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
32 signcrypt_elt.children.remove(rpad_elt) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
33 signcrypt_elt.children.remove(time_elt) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
34 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
35 assert rpad |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
36 assert (datetime.now(timezone.utc) - timestamp) < timedelta(seconds=10) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
37 assert signcrypt_elt.toXml() == ( |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
38 "<signcrypt xmlns='urn:xmpp:openpgp:0'>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
39 "<to jid='foo@example.com'/>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
40 "<to jid='bar@example.com'/>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
41 "<payload>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
42 "<signcrypt-test-content>signcrypt test content</signcrypt-test-content>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
43 "</payload>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
44 "</signcrypt>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
45 ) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
46 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
47 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
48 def test_sign_element_args() -> None: |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
49 with pytest.raises(ValueError): |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
50 XEP_0373.build_sign_element([], True) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
51 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
52 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
53 def test_sign_element_with_rpad() -> None: |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
54 sign_elt, payload_elt = XEP_0373.build_sign_element([ a, b ], True) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
55 payload_elt.addElement("sign-test-content", content="sign test content") |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
56 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
57 rpad_elt = next(sign_elt.elements(NS_OX, "rpad")) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
58 time_elt = next(sign_elt.elements(NS_OX, "time")) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
59 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
60 rpad = str(rpad_elt) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
61 timestamp = parse_datetime(time_elt["stamp"]) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
62 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
63 sign_elt.children.remove(rpad_elt) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
64 sign_elt.children.remove(time_elt) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
65 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
66 assert rpad |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
67 assert (datetime.now(timezone.utc) - timestamp) < timedelta(seconds=10) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
68 assert sign_elt.toXml() == ( |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
69 "<sign xmlns='urn:xmpp:openpgp:0'>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
70 "<to jid='foo@example.com'/>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
71 "<to jid='bar@example.com'/>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
72 "<payload>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
73 "<sign-test-content>sign test content</sign-test-content>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
74 "</payload>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
75 "</sign>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
76 ) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
77 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
78 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
79 def test_sign_element_without_rpad() -> None: |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
80 sign_elt, payload_elt = XEP_0373.build_sign_element([ a, b ], False) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
81 payload_elt.addElement("sign-test-content", content="sign test content") |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
82 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
83 rpad_elt = next(sign_elt.elements(NS_OX, "rpad"), None) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
84 time_elt = next(sign_elt.elements(NS_OX, "time")) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
85 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
86 timestamp = parse_datetime(time_elt["stamp"]) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
87 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
88 sign_elt.children.remove(time_elt) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
89 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
90 assert rpad_elt is None |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
91 assert (datetime.now(timezone.utc) - timestamp) < timedelta(seconds=10) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
92 assert sign_elt.toXml() == ( |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
93 "<sign xmlns='urn:xmpp:openpgp:0'>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
94 "<to jid='foo@example.com'/>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
95 "<to jid='bar@example.com'/>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
96 "<payload>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
97 "<sign-test-content>sign test content</sign-test-content>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
98 "</payload>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
99 "</sign>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
100 ) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
101 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
102 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
103 def test_crypt_element_with_recipients() -> None: |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
104 crypt_elt, payload_elt = XEP_0373.build_crypt_element([ a, b ]) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
105 payload_elt.addElement("crypt-test-content", content="crypt test content") |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
106 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
107 rpad_elt = next(crypt_elt.elements(NS_OX, "rpad")) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
108 time_elt = next(crypt_elt.elements(NS_OX, "time")) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
109 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
110 rpad = str(rpad_elt) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
111 timestamp = parse_datetime(time_elt["stamp"]) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
112 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
113 crypt_elt.children.remove(rpad_elt) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
114 crypt_elt.children.remove(time_elt) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
115 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
116 assert rpad |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
117 assert (datetime.now(timezone.utc) - timestamp) < timedelta(seconds=10) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
118 assert crypt_elt.toXml() == ( |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
119 "<crypt xmlns='urn:xmpp:openpgp:0'>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
120 "<to jid='foo@example.com'/>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
121 "<to jid='bar@example.com'/>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
122 "<payload>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
123 "<crypt-test-content>crypt test content</crypt-test-content>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
124 "</payload>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
125 "</crypt>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
126 ) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
127 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
128 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
129 def test_crypt_element_without_recipients() -> None: |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
130 crypt_elt, payload_elt = XEP_0373.build_crypt_element([]) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
131 payload_elt.addElement("crypt-test-content", content="crypt test content") |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
132 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
133 rpad_elt = next(crypt_elt.elements(NS_OX, "rpad")) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
134 time_elt = next(crypt_elt.elements(NS_OX, "time")) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
135 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
136 rpad = str(rpad_elt) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
137 timestamp = parse_datetime(time_elt["stamp"]) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
138 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
139 crypt_elt.children.remove(rpad_elt) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
140 crypt_elt.children.remove(time_elt) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
141 |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
142 assert rpad |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
143 assert (datetime.now(timezone.utc) - timestamp) < timedelta(seconds=10) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
144 assert crypt_elt.toXml() == ( |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
145 "<crypt xmlns='urn:xmpp:openpgp:0'>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
146 "<payload>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
147 "<crypt-test-content>crypt test content</crypt-test-content>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
148 "</payload>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
149 "</crypt>" |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff
changeset
|
150 ) |