Mercurial > libervia-backend
annotate tests/e2e/libervia-cli/test_libervia-cli.py @ 4322:00837fa13e5a default tip @
tools (common/template), cli (call/gui): use font-awesome instead of fontello:
following change in Libervia Media, code has been updated to use font-awesome now instead
of fontello.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 26 Oct 2024 22:42:17 +0200 |
parents | 4cd4922de876 |
children |
rev | line source |
---|---|
3415 | 1 #!/usr/bin/env python3 |
2 | |
3480
7550ae9cfbac
Renamed the project from "Salut à Toi" to "Libervia":
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
3 # Libervia: an XMPP client |
3479 | 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
3415 | 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 | |
3962
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
19 import json |
3415 | 20 import os |
21 import shutil | |
3946
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
22 from time import sleep |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
23 |
3415 | 24 import sh |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
25 from sh import li |
3415 | 26 |
3962
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
27 import pytest |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
28 from libervia.backend.plugins.plugin_sec_oxps import NS_OXPS |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
29 from libervia.backend.plugins.plugin_sec_pte import NS_PTE |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
30 from libervia.backend.plugins.plugin_xep_0277 import NS_ATOM |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
31 from libervia.backend.tools.common import uri |
3962
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
32 |
3415 | 33 |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
34 if os.getenv("LIBERVIA_TEST_ENV_E2E") is None: |
3415 | 35 pytest.skip( |
36 "skipping end-to-end tests, we are not in a test environment", | |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
37 allow_module_level=True, |
3415 | 38 ) |
39 | |
40 | |
41 pytestmark = pytest.mark.usefixtures("test_profiles") | |
42 | |
43 | |
44 class TestInstall: | |
45 | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
46 def test_li_can_run(self): |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
47 li("--version") |
3415 | 48 |
49 | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
50 class TestLiberviaCliAccount: |
3415 | 51 |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
52 def test_create_and_delete(self, li_json): |
3415 | 53 """Create an account in-band, connect it, then delete it and its profile""" |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
54 li.account.create( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
55 "test_create@server1.test", "test", profile="test_create", host="server1.test" |
3415 | 56 ) |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
57 profiles = li_json.profile.list() |
3415 | 58 assert "test_create" in profiles |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
59 li.profile.connect(connect=True, profile="test_create") |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
60 li.account.delete(profile="test_create", force=True) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
61 li.profile.delete("test_create", force=True) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
62 profiles = li_json.profile.list() |
3415 | 63 assert "test_create" not in profiles |
64 | |
65 | |
66 @pytest.mark.usefixtures("pubsub_nodes") | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
67 class TestLiberviaCliPubsub: |
3415 | 68 |
69 def test_node_create_info_delete(self): | |
70 node_name = "tmp_node" | |
71 with pytest.raises(sh.ErrorReturnCode_16): | |
72 # the node should not exist | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
73 li.pubsub.node.info(node=node_name) |
3415 | 74 try: |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
75 li.pubsub.node.create(node=node_name) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
76 # if node exist as expected, following command won't raise an exception |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
77 metadata = li.pubsub.node.info(node=node_name) |
3415 | 78 assert len(metadata.strip()) |
79 finally: | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
80 li.pubsub.node.delete(node=node_name, force=True) |
3415 | 81 |
82 with pytest.raises(sh.ErrorReturnCode_16): | |
83 # the node should not exist anymore | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
84 li.pubsub.node.info(node=node_name) |
3415 | 85 |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
86 def test_set_get_delete_purge(self, li_elt): |
3415 | 87 content = "test item" |
88 payload = f"<test>{content}</test>" | |
89 | |
90 # we create 3 items and check them | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
91 item1_id = li.pubsub.set(node="test", quiet=True, _in=payload) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
92 item2_id = li.pubsub.set(node="test", quiet=True, _in=payload) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
93 item3_id = li.pubsub.set(node="test", quiet=True, _in=payload) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
94 parsed_elt = li_elt.pubsub.get(node="test", item=item1_id) |
3415 | 95 payload = parsed_elt.firstChildElement() |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
96 assert payload.name == "test" |
3415 | 97 assert str(payload) == content |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
98 parsed_elt = li_elt.pubsub.get(node="test", item=item2_id) |
3415 | 99 payload = parsed_elt.firstChildElement() |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
100 assert payload.name == "test" |
3415 | 101 assert str(payload) == content |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
102 parsed_elt = li_elt.pubsub.get(node="test", item=item3_id) |
3415 | 103 payload = parsed_elt.firstChildElement() |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
104 assert payload.name == "test" |
3415 | 105 assert str(payload) == content |
106 | |
107 # deleting first item should work | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
108 li.pubsub.delete(node="test", item=item1_id, force=True) |
3415 | 109 with pytest.raises(sh.ErrorReturnCode_16): |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
110 li.pubsub.get(node="test", item=item1_id) |
3415 | 111 |
112 # there must be a least item2 and item3 in the node | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
113 node_items = li_elt.pubsub.get(node="test") |
3415 | 114 assert len(list(node_items.elements())) >= 2 |
115 | |
116 # after purge, node must be empty | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
117 li.pubsub.node.purge(node="test", force=True) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
118 node_items = li_elt.pubsub.get(node="test") |
3415 | 119 assert len(list(node_items.elements())) == 0 |
120 | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
121 def test_edit(self, editor, li_elt): |
3415 | 122 content = "original item" |
123 payload = f"<test>{content}</test>" | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
124 item_id = li.pubsub.set(node="test", quiet=True, _in=payload) |
3415 | 125 editor.set_filter('content.replace("original", "edited")') |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
126 li.pubsub.edit(node="test", item=item_id, _env=editor.env) |
3415 | 127 assert "original item" in editor.original_content |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
128 parsed_elt = li_elt.pubsub.get(node="test", item=item_id) |
3415 | 129 edited_payload = parsed_elt.firstChildElement() |
130 expected_edited_content = content.replace("original", "edited") | |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
131 assert edited_payload.name == "test" |
3415 | 132 assert str(edited_payload) == expected_edited_content |
133 | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
134 def test_affiliations(self, li_json): |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
135 affiliations = li_json.pubsub.affiliations() |
3415 | 136 assert affiliations["test"] == "owner" |
137 | |
138 def test_uri(self): | |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
139 built_uri = li.pubsub.uri(service="pubsub.example.net", node="some_node").strip() |
3415 | 140 assert built_uri == "xmpp:pubsub.example.net?;node=some_node" |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
141 built_uri = li.pubsub.uri( |
3415 | 142 service="pubsub.example.net", node="some_node", item="some_item" |
143 ).strip() | |
144 assert built_uri == "xmpp:pubsub.example.net?;node=some_node;item=some_item" | |
145 | |
3674
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
146 def test_cache_search(self, li_json): |
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
147 """A Full-Text Search query can be done""" |
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
148 sk_txt = "this is a blog post about Slovakia" |
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
149 fr_txt = "this is a blog post about France" |
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
150 nc_txt = "this is a blog post about New Caledonia" |
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
151 au_txt = "this is a blog post about Australia" |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
152 li.blog.set("-t", "travel", "-t", "europe", _in=sk_txt, syntax="markdown") |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
153 li.blog.set("-t", "travel", "-t", "europe", _in=fr_txt, syntax="markdown") |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
154 li.blog.set("-t", "travel", "-t", "south pacific", _in=nc_txt, syntax="markdown") |
3674
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
155 li.blog.set( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
156 "-t", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
157 "travel", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
158 "-t", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
159 "south pacific", |
3674
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
160 _in="this is a blog post about Australia", |
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
161 title=au_txt, |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
162 syntax="markdown", |
3674
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
163 ) |
3769
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
164 # we get the blog to activate the cache for it |
3674
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
165 li.blog.get(max_items=1) |
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
166 # FTS |
3769
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
167 found = [] |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
168 for __ in range(5): |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
169 found = li_json.pubsub.cache.search( |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
170 type="blog", fts='Slovakia OR "New Caledonia"' |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
171 ) |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
172 if found: |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
173 break |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
174 else: |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
175 # retrieving blog triggers the caching, but it's done in parallel |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
176 # thus we may have nothing in cache yet |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
177 sleep(0.5) |
3674
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
178 assert len(found) == 2 |
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
179 assert all(i["content"] in (sk_txt, nc_txt) for i in found) |
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
180 # search by field |
3769
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
181 found = li_json.pubsub.cache.search( |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
182 "-F", "tags", "overlap", "travel", type="blog" |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
183 ) |
3674
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
184 assert len(found) == 4 |
3769
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
185 found = li_json.pubsub.cache.search( |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
186 "-F", "tags", "overlap", "europe", type="blog" |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
187 ) |
3674
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
188 assert len(found) == 2 |
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
189 assert all(i["content"] in (sk_txt, fr_txt) for i in found) |
3769
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
190 found = li_json.pubsub.cache.search( |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
191 "-F", "tags", "ioverlap", "SOUTH PACIFIC", type="blog" |
a75874df92b8
tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents:
3731
diff
changeset
|
192 ) |
3674
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
193 assert all(i["content"] in (nc_txt, au_txt) for i in found) |
eeb8be32d644
tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents:
3658
diff
changeset
|
194 |
3415 | 195 |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
196 class TestLiberviaCliBlog: |
3415 | 197 MICROBLOG_NS = "urn:xmpp:microblog:0" |
198 | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
199 def test_set_get(self, li_json): |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
200 li.blog.set(_in="markdown **bold** [link](https://example.net)") |
3731
7e51cfc36d4e
tests (e2e/CLI/set_get): fix RSM request:
Goffi <goffi@goffi.org>
parents:
3674
diff
changeset
|
201 item_data = li_json.blog.get(max=1, before="") |
3415 | 202 item = item_data[0][0] |
203 metadata = item_data[1] | |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
204 assert metadata["service"] == "account1@server1.test" |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
205 assert metadata["node"] == self.MICROBLOG_NS |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
206 assert metadata["rsm"].keys() <= {"first", "last", "index", "count"} |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
207 item_id = item["id"] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3974
diff
changeset
|
208 expected_uri = uri.build_xmpp_uri( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
209 "pubsub", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
210 subtype="microblog", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
211 path="account1@server1.test", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
212 node=self.MICROBLOG_NS, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
213 item=item_id, |
3415 | 214 ) |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
215 assert item["uri"] == expected_uri |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
216 assert item["content_xhtml"] == ( |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
217 "<div><p>markdown <strong>bold</strong> " |
3415 | 218 '<a href="https://example.net">link</a></p></div>' |
219 ) | |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
220 assert isinstance(item["published"], int) |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
221 assert isinstance(item["updated"], int) |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
222 assert isinstance(item["comments"], list) |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
223 assert isinstance(item["tags"], list) |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
224 assert item["author"] == "account1" |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
225 assert item["author_jid"] == "account1@server1.test" |
3415 | 226 |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
227 def test_edit(self, editor, li_json): |
3415 | 228 payload_md = "content in **markdown**" |
229 editor.set_filter(repr(payload_md)) | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
230 li.blog.edit(_env=editor.env) |
3415 | 231 assert len(editor.original_content) == 0 |
232 assert editor.new_content == payload_md | |
3658
9e491b2bab88
test (e2e/cli): use `max_items` instead of `max` when retrieving blog items:
Goffi <goffi@goffi.org>
parents:
3498
diff
changeset
|
233 items_data = li_json.blog.get(max_items=1) |
3415 | 234 last_item = items_data[0][0] |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
235 last_item_id = last_item["id"] |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
236 assert last_item["content"] == "content in markdown" |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
237 assert last_item["content_xhtml"] == ( |
3415 | 238 "<div><p>content in <strong>markdown</strong></p></div>" |
239 ) | |
240 editor.set_filter('f"{content} extended"') | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
241 li.blog.edit("--last-item", _env=editor.env) |
3415 | 242 assert editor.original_content == payload_md |
243 assert editor.new_content == f"{payload_md} extended" | |
3658
9e491b2bab88
test (e2e/cli): use `max_items` instead of `max` when retrieving blog items:
Goffi <goffi@goffi.org>
parents:
3498
diff
changeset
|
244 items_data = li_json.blog.get(max_items=1) |
3415 | 245 last_item = items_data[0][0] |
246 # we check that the id hasn't been modified | |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
247 assert last_item["id"] == last_item_id |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
248 assert last_item["content"] == "content in markdown extended" |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
249 assert last_item["content_xhtml"] == ( |
3415 | 250 "<div><p>content in <strong>markdown</strong> extended</p></div>" |
251 ) | |
252 | |
253 | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
254 class TestLiberviaCliFile: |
3415 | 255 |
256 def test_upload_get(self, fake_file): | |
257 source_file = fake_file.size(10240) | |
258 source_file_hash = fake_file.get_source_hash(source_file) | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
259 upload_url = li.file.upload(source_file).strip() |
3415 | 260 |
261 dest_file = fake_file.new_dest_file() | |
262 try: | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
263 li.file.get(upload_url, dest_file=dest_file) |
3415 | 264 dest_file_hash = fake_file.get_dest_hash(dest_file) |
265 finally: | |
266 dest_file.unlink() | |
267 | |
268 assert source_file_hash == dest_file_hash | |
269 | |
270 def test_send_receive(self, fake_file): | |
271 source_file = fake_file.size(10240) | |
272 source_file_hash = fake_file.get_source_hash(source_file) | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
273 send_cmd = li.file.send(source_file, "account1@server2.test", _bg=True) |
3415 | 274 dest_path = fake_file.dest_files / "test_send_receive" |
275 dest_path.mkdir() | |
276 try: | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
277 li.file.receive( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
278 "account1@server1.test", profile="account1_s2", path=dest_path |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
279 ) |
3415 | 280 dest_file = dest_path / source_file.name |
281 dest_file_hash = fake_file.get_dest_hash(dest_file) | |
282 finally: | |
283 shutil.rmtree(dest_path) | |
284 send_cmd.wait() | |
285 | |
286 assert source_file_hash == dest_file_hash | |
3946
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
287 |
4236
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
288 def test_send_receive_webrtc(self, fake_file): |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
289 source_file = fake_file.size(10240) |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
290 source_file_hash = fake_file.get_source_hash(source_file) |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
291 send_cmd = li.file.send( |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
292 source_file, "account1@server2.test", webrtc=True, _bg=True |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
293 ) |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
294 dest_path = fake_file.dest_files / "test_send_receive" |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
295 dest_path.mkdir() |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
296 try: |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
297 li.file.receive( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
298 "account1@server1.test", profile="account1_s2", path=dest_path |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
299 ) |
4236
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
300 dest_file = dest_path / source_file.name |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
301 dest_file_hash = fake_file.get_dest_hash(dest_file) |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
302 finally: |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
303 shutil.rmtree(dest_path) |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
304 send_cmd.wait() |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
305 |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
306 assert source_file_hash == dest_file_hash |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
307 |
f59e9421a650
test (unit/cli): Add a file send/receive test for WebRTC:
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
308 |
3946
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
309 class TestE2EEncryption: |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
310 |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
311 def test_pubsub_encryption_oxps(self, li_elt): |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
312 secret_blog = "this is a secret blog post" |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
313 node = "e2ee_blog" |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
314 li.blog.set(_in=secret_blog, node="e2ee_blog", item="test_e2ee", encrypt=True) |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
315 |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
316 # the item should be transparently decrypted |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
317 parsed_decrypted = li_elt.pubsub.get(node=node, item="test_e2ee", no_cache=True) |
3946
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
318 entry_elt = parsed_decrypted.firstChildElement() |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
319 assert entry_elt.name == "entry" |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
320 assert entry_elt.uri == NS_ATOM |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
321 assert secret_blog in parsed_decrypted.toXml() |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
322 |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
323 # with --no-decrypt, we should have the encrypted item |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
324 parsed_ori_item = li_elt.pubsub.get( |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
325 node=node, item="test_e2ee", no_decrypt=True, no_cache=True |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
326 ) |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
327 encrypted_elt = parsed_ori_item.firstChildElement() |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
328 assert encrypted_elt.name == "encrypted" |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
329 assert encrypted_elt.uri == NS_OXPS |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
330 # the body must not be readable in plain text |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
331 assert secret_blog not in parsed_ori_item.toXml() |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
332 |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
333 def test_pubsub_secrets_sharing_oxps(self, li_elt): |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
334 secret_blog = "this is a secret blog post" |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
335 node = "secret_sharing" |
3946
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
336 |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
337 li.blog.set(_in=secret_blog, node=node, item="test_e2ee", encrypt=True) |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
338 |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
339 # the item must not be decrypted for account1_s2 (secret is not known) |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
340 parsed_item = li_elt.pubsub.get( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
341 service="account1@server1.test", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
342 node=node, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
343 item="test_e2ee", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
344 no_cache=True, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
345 profile="account1_s2", |
3946
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
346 ) |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
347 encrypted_elt = parsed_item.firstChildElement() |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
348 assert encrypted_elt.name == "encrypted" |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
349 assert encrypted_elt.uri == NS_OXPS |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
350 # the body must not be readable in plain text |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
351 assert secret_blog not in parsed_item.toXml() |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
352 |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
353 # we share the secrets |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
354 li.pubsub.secret.share( |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
355 "account1@server2.test", service="account1@server1.test", node=node |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
356 ) |
3946
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
357 |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
358 # and get the item again |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
359 parsed_item = li_elt.pubsub.get( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
360 service="account1@server1.test", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
361 node=node, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
362 item="test_e2ee", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
363 no_cache=True, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
364 profile="account1_s2", |
3946
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
365 ) |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
366 # now it should be decrypted |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
367 entry_elt = parsed_item.firstChildElement() |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
368 assert entry_elt.name == "entry" |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
369 assert entry_elt.uri == NS_ATOM |
f2a5936f2496
tests (e2e/cli): add test for pubsub encryption:
Goffi <goffi@goffi.org>
parents:
3769
diff
changeset
|
370 assert secret_blog in parsed_item.toXml() |
3962
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
371 |
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
372 def test_pubsub_signature(self, li_json): |
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
373 """A pubsub item can be signed, and the signature can be verified""" |
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
374 body = "this message is signed" |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
375 service = "account1@server1.test" |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
376 node = "blog_signing" |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
377 item = "signed_item" |
3962
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
378 li.blog.set(_in=body, service=service, node=node, item=item, sign=True) |
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
379 attachments = li_json.pubsub.attachments.get( |
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
380 service=service, node=node, item=item |
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
381 ) |
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
382 assert len(attachments) == 1 |
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
383 attachment = attachments[0] |
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
384 assert attachment["from"] == "account1@server1.test" |
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
385 signature_json = attachment["signature"] |
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
386 sign_data = li_json.pubsub.signature.check( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
387 json.dumps(signature_json), |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
388 service=service, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
389 node=node, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
390 item=item, |
3962
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
391 ) |
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
392 assert sign_data["signer"] == "account1@server1.test" |
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
393 assert sign_data["validated"] == True |
2d9d0b77e82b
tests (e2e/cli): add a test for Pubsub Signing:
Goffi <goffi@goffi.org>
parents:
3946
diff
changeset
|
394 assert all(t == "undecided" for t in sign_data["trusts"].values()) |
3971
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
395 |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
396 def test_jingle_encrypted_transport_jet(self, fake_file): |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
397 """A file is sent and received properly with JET OMEMO""" |
4227 | 398 # FIXME: transport should be checked to see if content is actually encrypted. |
399 # Maybe we can use tcpdump? | |
400 li.encryption.start("account1@server2.test", name="omemo_legacy") | |
3971
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
401 source_file = fake_file.size(10240) |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
402 source_file_hash = fake_file.get_source_hash(source_file) |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
403 send_cmd = li.file.send( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
404 source_file, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
405 "account1@server2.test", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
406 encrypt=True, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
407 _bg=True, |
3971
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
408 ) |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
409 dest_path = fake_file.dest_files / "test_send_receive" |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
410 dest_path.mkdir() |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
411 try: |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
412 li.file.receive( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
413 "account1@server1.test", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
414 profile="account1_s2", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
415 path=dest_path, |
4227 | 416 ) |
3971
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
417 dest_file = dest_path / source_file.name |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
418 dest_file_hash = fake_file.get_dest_hash(dest_file) |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
419 finally: |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
420 shutil.rmtree(dest_path) |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
421 send_cmd.wait() |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
422 |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
423 assert source_file_hash == dest_file_hash |
9b1d74a6b48c
tests (e2e/cli): add tests for JET:
Goffi <goffi@goffi.org>
parents:
3962
diff
changeset
|
424 li.encryption.stop("account1@server2.test") |
3974
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
425 |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
426 def test_pubsub_targeted_encryption_pte(self, li_elt): |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
427 """An item is encrypted for specific recipients""" |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
428 secret_blog = "this is a secret blog post" |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
429 node = "e2ee_blog" |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
430 item = "test_pte" |
4227 | 431 li.encryption.start("account1@server2.test", name="omemo") |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
432 li.encryption.start("account1@server1.test", name="omemo", profile="account1_s2") |
3974
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
433 li.blog.set( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
434 _in=secret_blog, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
435 node="e2ee_blog", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
436 item=item, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
437 encrypt_for="account1@server2.test", |
3974
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
438 ) |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
439 |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
440 # the item should be transparently decrypted |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
441 parsed_decrypted = li_elt.pubsub.get( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
442 service="account1@server1.test", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
443 node=node, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
444 item=item, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
445 no_cache=True, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4236
diff
changeset
|
446 profile="account1_s2", |
3974
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
447 ) |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
448 entry_elt = parsed_decrypted.firstChildElement() |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
449 assert entry_elt.name == "entry" |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
450 assert entry_elt.uri == NS_ATOM |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
451 assert secret_blog in parsed_decrypted.toXml() |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
452 |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
453 # with --no-decrypt, we should have the encrypted item |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
454 parsed_ori_item = li_elt.pubsub.get( |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
455 node=node, item=item, no_decrypt=True, no_cache=True |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
456 ) |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
457 encrypted_elt = parsed_ori_item.firstChildElement() |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
458 assert encrypted_elt.name == "encrypted" |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
459 assert encrypted_elt.uri == NS_PTE |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
460 # the body must not be readable in plain text |
5e3b983ab2c6
tests (e2e/cli): test for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3971
diff
changeset
|
461 assert secret_blog not in parsed_ori_item.toXml() |