annotate tests/unit/test_plugin_xep_0373.py @ 4285:f1d0cde61af7

tests (unit): fix tests + black reformatting.
author Goffi <goffi@goffi.org>
date Sun, 14 Jul 2024 17:42:53 +0200
parents 4b842c1fb686
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
5
4069
3d91d0aa68db tests (unit): Skip XEP-0373 test if gpg can't be imported
Goffi <goffi@goffi.org>
parents: 3933
diff changeset
6 try:
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4069
diff changeset
7 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
8 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
9 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
10 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
11 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
12
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
13
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
14 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
15 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
16
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
17
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
18 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
19 with pytest.raises(ValueError):
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
20 XEP_0373.build_signcrypt_element([])
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
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
23 def test_signcrypt_element() -> None:
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
24 signcrypt_elt, payload_elt = XEP_0373.build_signcrypt_element([a, b])
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
25 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
26
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
27 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
28 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
29
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
30 rpad = str(rpad_elt)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
31 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
32
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
33 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
34 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
35
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
36 assert rpad
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
37 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
38 assert signcrypt_elt.toXml() == (
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
39 "<signcrypt xmlns='urn:xmpp:openpgp:0'>"
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
40 "<to jid='foo@example.com'/>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
41 "<to jid='bar@example.com'/>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
42 "<payload>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
43 "<signcrypt-test-content>signcrypt test content</signcrypt-test-content>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
44 "</payload>"
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
45 "</signcrypt>"
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
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
49 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
50 with pytest.raises(ValueError):
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
51 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
52
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
53
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
54 def test_sign_element_with_rpad() -> None:
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
55 sign_elt, payload_elt = XEP_0373.build_sign_element([a, b], True)
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
56 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
57
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
58 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
59 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
60
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
61 rpad = str(rpad_elt)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
62 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
63
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
64 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
65 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
66
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
67 assert rpad
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
68 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
69 assert sign_elt.toXml() == (
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
70 "<sign xmlns='urn:xmpp:openpgp:0'>"
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
71 "<to jid='foo@example.com'/>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
72 "<to jid='bar@example.com'/>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
73 "<payload>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
74 "<sign-test-content>sign test content</sign-test-content>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
75 "</payload>"
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
76 "</sign>"
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
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
80 def test_sign_element_without_rpad() -> None:
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
81 sign_elt, payload_elt = XEP_0373.build_sign_element([a, b], False)
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
82 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
83
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
84 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
85 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
86
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
87 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
88
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
89 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
90
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
91 assert rpad_elt is None
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
92 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
93 assert sign_elt.toXml() == (
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
94 "<sign xmlns='urn:xmpp:openpgp:0'>"
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
95 "<to jid='foo@example.com'/>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
96 "<to jid='bar@example.com'/>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
97 "<payload>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
98 "<sign-test-content>sign test content</sign-test-content>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
99 "</payload>"
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
100 "</sign>"
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
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
104 def test_crypt_element_with_recipients() -> None:
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
105 crypt_elt, payload_elt = XEP_0373.build_crypt_element([a, b])
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
106 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
107
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
108 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
109 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
110
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
111 rpad = str(rpad_elt)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
112 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
113
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
114 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
115 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
116
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
117 assert rpad
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
118 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
119 assert crypt_elt.toXml() == (
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
120 "<crypt xmlns='urn:xmpp:openpgp:0'>"
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
121 "<to jid='foo@example.com'/>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
122 "<to jid='bar@example.com'/>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
123 "<payload>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
124 "<crypt-test-content>crypt test content</crypt-test-content>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
125 "</payload>"
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
126 "</crypt>"
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
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
130 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
131 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
132 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
133
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
134 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
135 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
136
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
137 rpad = str(rpad_elt)
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
138 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
139
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
140 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
141 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
142
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
143 assert rpad
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
144 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
145 assert crypt_elt.toXml() == (
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
146 "<crypt xmlns='urn:xmpp:openpgp:0'>"
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
147 "<payload>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
148 "<crypt-test-content>crypt test content</crypt-test-content>"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
149 "</payload>"
3933
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
150 "</crypt>"
cecf45416403 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
diff changeset
151 )