Mercurial > libervia-backend
annotate tests/unit/test_ap-gateway.py @ 3809:04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
this patch adds 4 tests to check pubsub <=> AP item retractation and message <=> AP item
retractation.
rel 367
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 17 Jun 2022 15:50:34 +0200 |
parents | 39fc2e1b3793 |
children | 81c79b7cafa7 |
rev | line source |
---|---|
3733 | 1 #!/usr/bin/env python3 |
2 | |
3 # Libervia: an XMPP client | |
4 # Copyright (C) 2009-2022 Jérôme Poisson (goffi@goffi.org) | |
5 | |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 from copy import deepcopy | |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
20 from unittest.mock import MagicMock, AsyncMock, patch, DEFAULT |
3733 | 21 from urllib import parse |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
22 from functools import partial |
3733 | 23 |
24 import pytest | |
25 from pytest_twisted import ensureDeferred as ed | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
26 from twisted.internet import defer |
3733 | 27 from twisted.words.protocols.jabber import jid |
28 from twisted.web.server import Request | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
29 from twisted.words.xish import domish |
3733 | 30 from wokkel import rsm, pubsub |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
31 from treq.response import _Response as TReqResponse |
3733 | 32 |
33 from sat.core import exceptions | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
34 from sat.core.constants import Const as C |
3733 | 35 from sat.plugins import plugin_comp_ap_gateway |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
36 from sat.plugins.plugin_comp_ap_gateway import constants as ap_const |
3733 | 37 from sat.plugins.plugin_comp_ap_gateway.http_server import HTTPServer |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
38 from sat.plugins.plugin_xep_0277 import NS_ATOM |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
39 from sat.plugins.plugin_xep_0422 import NS_FASTEN |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
40 from sat.plugins.plugin_xep_0424 import NS_MESSAGE_RETRACT |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
41 from sat.plugins.plugin_xep_0465 import NS_PPS |
3733 | 42 from sat.tools.utils import xmpp_date |
43 from sat.tools import xml_tools | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
44 from sat.plugins.plugin_comp_ap_gateway import TYPE_ACTOR |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
45 from sat.memory.sqla_mapping import SubscriptionState |
3733 | 46 |
47 | |
48 TEST_BASE_URL = "https://example.org" | |
49 TEST_USER = "test_user" | |
50 TEST_AP_ACCOUNT = f"{TEST_USER}@example.org" | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
51 TEST_AP_ACTOR_ID = f"{TEST_BASE_URL}/users/{TEST_USER}" |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
52 PUBLIC_URL = "test.example" |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
53 TEST_JID = jid.JID(f"some_user@{PUBLIC_URL}") |
3733 | 54 |
55 AP_REQUESTS = { | |
56 f"{TEST_BASE_URL}/.well-known/webfinger?" | |
57 f"resource=acct:{parse.quote(TEST_AP_ACCOUNT)}": { | |
58 "aliases": [ | |
59 f"{TEST_BASE_URL}/@{TEST_USER}", | |
60 f"{TEST_BASE_URL}/users/{TEST_USER}" | |
61 ], | |
62 "links": [ | |
63 { | |
64 "href": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
65 "rel": "self", | |
66 "type": "application/activity+json" | |
67 }, | |
68 ], | |
69 "subject": f"acct:{TEST_AP_ACCOUNT}" | |
70 }, | |
71 | |
72 f"{TEST_BASE_URL}/users/{TEST_USER}": { | |
73 "@context": [ | |
74 "https://www.w3.org/ns/activitystreams", | |
75 ], | |
76 "endpoints": { | |
77 "sharedInbox": f"{TEST_BASE_URL}/inbox" | |
78 }, | |
79 "followers": f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
80 "following": f"{TEST_BASE_URL}/users/{TEST_USER}/following", | |
81 "id": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
82 "inbox": f"{TEST_BASE_URL}/users/{TEST_USER}/inbox", | |
83 "name": "", | |
84 "outbox": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox", | |
85 "preferredUsername": f"{TEST_USER}", | |
86 "type": "Person", | |
87 "url": f"{TEST_BASE_URL}/@{TEST_USER}" | |
88 }, | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
89 f"{TEST_BASE_URL}/.well-known/webfinger?" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
90 f"resource=acct:{parse.quote('ext_user@example.org')}": { |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
91 "aliases": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
92 f"{TEST_BASE_URL}/@ext_user", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
93 f"{TEST_BASE_URL}/users/ext_user" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
94 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
95 "links": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
96 { |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
97 "href": f"{TEST_BASE_URL}/users/ext_user", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
98 "rel": "self", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
99 "type": "application/activity+json" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
100 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
101 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
102 "subject": f"acct:ext_user@example.org" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
103 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
104 f"{TEST_BASE_URL}/users/ext_user": { |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
105 "@context": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
106 "https://www.w3.org/ns/activitystreams", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
107 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
108 "endpoints": { |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
109 "sharedInbox": f"{TEST_BASE_URL}/inbox" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
110 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
111 "followers": f"{TEST_BASE_URL}/users/ext_user/followers", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
112 "following": f"{TEST_BASE_URL}/users/ext_user/following", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
113 "id": f"{TEST_BASE_URL}/users/ext_user", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
114 "inbox": f"{TEST_BASE_URL}/users/ext_user/inbox", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
115 "name": "", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
116 "outbox": f"{TEST_BASE_URL}/users/ext_user/outbox", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
117 "preferredUsername": f"ext_user", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
118 "type": "Person", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
119 "url": f"{TEST_BASE_URL}/@ext_user" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
120 }, |
3733 | 121 f"{TEST_BASE_URL}/users/{TEST_USER}/outbox": { |
122 "@context": "https://www.w3.org/ns/activitystreams", | |
123 "first": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true", | |
124 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox", | |
125 "last": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true", | |
126 "totalItems": 4, | |
127 "type": "OrderedCollection" | |
128 }, | |
129 f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true": { | |
130 "@context": [ | |
131 "https://www.w3.org/ns/activitystreams", | |
132 ], | |
133 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true", | |
134 "orderedItems": [ | |
135 { | |
136 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
137 "cc": [ | |
138 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
139 ], | |
140 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/1/activity", | |
141 "object": { | |
142 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
143 "cc": [ | |
144 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
145 ], | |
146 "content": "<p>test message 1</p>", | |
147 "contentMap": { | |
148 "en": "<p>test message 1</p>" | |
149 }, | |
150 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/1", | |
151 "inReplyTo": None, | |
152 "published": "2021-12-16T17:28:03Z", | |
153 "sensitive": False, | |
154 "summary": None, | |
155 "tag": [], | |
156 "to": [ | |
157 "https://www.w3.org/ns/activitystreams#Public" | |
158 ], | |
159 "type": "Note", | |
160 "url": f"{TEST_BASE_URL}/@{TEST_USER}/1" | |
161 }, | |
162 "published": "2021-12-16T17:28:03Z", | |
163 "to": [ | |
164 "https://www.w3.org/ns/activitystreams#Public" | |
165 ], | |
166 "type": "Create" | |
167 }, | |
168 { | |
169 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
170 "cc": [ | |
171 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
172 ], | |
173 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/2/activity", | |
174 "object": { | |
175 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
176 "cc": [ | |
177 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
178 ], | |
179 "content": "<p>test message 2</p>", | |
180 "contentMap": { | |
181 "en": "<p>test message 2</p>" | |
182 }, | |
183 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/2", | |
184 "inReplyTo": None, | |
185 "published": "2021-12-16T17:27:03Z", | |
186 "sensitive": False, | |
187 "summary": None, | |
188 "tag": [], | |
189 "to": [ | |
190 "https://www.w3.org/ns/activitystreams#Public" | |
191 ], | |
192 "type": "Note", | |
193 "url": f"{TEST_BASE_URL}/@{TEST_USER}/2" | |
194 }, | |
195 "published": "2021-12-16T17:27:03Z", | |
196 "to": [ | |
197 "https://www.w3.org/ns/activitystreams#Public" | |
198 ], | |
199 "type": "Create" | |
200 }, | |
201 { | |
202 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
203 "cc": [ | |
204 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
205 ], | |
206 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/3/activity", | |
207 "object": { | |
208 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
209 "cc": [ | |
210 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
211 ], | |
212 "content": "<p>test message 3</p>", | |
213 "contentMap": { | |
214 "en": "<p>test message 3</p>" | |
215 }, | |
216 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/3", | |
217 "inReplyTo": None, | |
218 "published": "2021-12-16T17:26:03Z", | |
219 "sensitive": False, | |
220 "summary": None, | |
221 "tag": [], | |
222 "to": [ | |
223 "https://www.w3.org/ns/activitystreams#Public" | |
224 ], | |
225 "type": "Note", | |
226 "url": f"{TEST_BASE_URL}/@{TEST_USER}/3" | |
227 }, | |
228 "published": "2021-12-16T17:26:03Z", | |
229 "to": [ | |
230 "https://www.w3.org/ns/activitystreams#Public" | |
231 ], | |
232 "type": "Create" | |
233 }, | |
234 { | |
235 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
236 "cc": [ | |
237 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
238 ], | |
239 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/4/activity", | |
240 "object": { | |
241 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
242 "cc": [ | |
243 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
244 ], | |
245 "content": "<p>test message 4</p>", | |
246 "contentMap": { | |
247 "en": "<p>test message 4</p>" | |
248 }, | |
249 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/4", | |
250 "inReplyTo": None, | |
251 "published": "2021-12-16T17:25:03Z", | |
252 "sensitive": False, | |
253 "summary": None, | |
254 "tag": [], | |
255 "to": [ | |
256 "https://www.w3.org/ns/activitystreams#Public" | |
257 ], | |
258 "type": "Note", | |
259 "url": f"{TEST_BASE_URL}/@{TEST_USER}/4" | |
260 }, | |
261 "published": "2021-12-16T17:25:03Z", | |
262 "to": [ | |
263 "https://www.w3.org/ns/activitystreams#Public" | |
264 ], | |
265 "type": "Create" | |
266 }, | |
267 ], | |
268 "partOf": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox", | |
269 "prev": None, | |
270 "type": "OrderedCollectionPage" | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
271 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
272 f"{TEST_BASE_URL}/users/{TEST_USER}/following": { |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
273 "@context": "https://www.w3.org/ns/activitystreams", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
274 "first": f"{TEST_BASE_URL}/users/{TEST_USER}/following?page=1", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
275 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/following", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
276 "totalItems": 2, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
277 "type": "OrderedCollection" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
278 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
279 f"{TEST_BASE_URL}/users/{TEST_USER}/following?page=1": { |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
280 "@context": "https://www.w3.org/ns/activitystreams", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
281 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/following?page=1", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
282 "orderedItems": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
283 f"{TEST_BASE_URL}/users/ext_user", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
284 f"https://{PUBLIC_URL}/_ap/{TYPE_ACTOR}/local_user%40{PUBLIC_URL}", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
285 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
286 "partOf": "{TEST_BASE_URL}/users/{TEST_USER}/following", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
287 "totalItems": 2, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
288 "type": "OrderedCollectionPage" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
289 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
290 f"{TEST_BASE_URL}/users/{TEST_USER}/followers": { |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
291 "@context": "https://www.w3.org/ns/activitystreams", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
292 "first": f"{TEST_BASE_URL}/users/{TEST_USER}/followers?page=1", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
293 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/followers", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
294 "totalItems": 2, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
295 "type": "OrderedCollection" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
296 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
297 f"{TEST_BASE_URL}/users/{TEST_USER}/followers?page=1": { |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
298 "@context": "https://www.w3.org/ns/activitystreams", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
299 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/followers?page=1", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
300 "orderedItems": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
301 f"{TEST_BASE_URL}/users/ext_user", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
302 f"https://{PUBLIC_URL}/_ap/{TYPE_ACTOR}/local_user%40{PUBLIC_URL}", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
303 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
304 "partOf": "{TEST_BASE_URL}/users/{TEST_USER}/followers", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
305 "totalItems": 2, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
306 "type": "OrderedCollectionPage" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
307 }, |
3733 | 308 |
309 } | |
310 | |
311 XMPP_ITEM_TPL = """ | |
312 <item id='{id}' publisher='{publisher_jid}'> | |
313 <entry xmlns='http://www.w3.org/2005/Atom' xml:lang='en'> | |
314 <title type='xhtml'> | |
315 <div xmlns='http://www.w3.org/1999/xhtml'> | |
316 <p> | |
317 XMPP item {id} | |
318 </p> | |
319 </div> | |
320 </title> | |
321 <title type='text'> | |
322 XMPP item {id} | |
323 </title> | |
324 <author> | |
325 <name> | |
326 test_user | |
327 </name> | |
328 <uri> | |
329 xmpp:{publisher_jid} | |
330 </uri> | |
331 </author> | |
332 <updated> | |
333 {updated} | |
334 </updated> | |
335 <published> | |
336 {published} | |
337 </published> | |
338 <id> | |
339 xmpp:{publisher_jid}?;node=urn%3Axmpp%3Amicroblog%3A0;item={id} | |
340 </id> | |
341 </entry> | |
342 </item> | |
343 """ | |
344 | |
345 ITEM_BASE_TS = 1643385499 | |
346 XMPP_ITEMS = [ | |
347 xml_tools.parse( | |
348 "".join( | |
349 l.strip() for l in XMPP_ITEM_TPL.format( | |
350 id=i, | |
351 publisher_jid="some_user@test.example", | |
352 updated=xmpp_date(ITEM_BASE_TS + i * 60), | |
353 published=xmpp_date(ITEM_BASE_TS + i * 60), | |
354 ).split("\n") | |
355 ), | |
356 namespace=pubsub.NS_PUBSUB | |
357 ) | |
358 for i in range(1, 5) | |
359 ] | |
360 | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
361 |
3733 | 362 async def mock_ap_get(url): |
363 return deepcopy(AP_REQUESTS[url]) | |
364 | |
365 | |
366 async def mock_treq_json(data): | |
367 return dict(data) | |
368 | |
369 | |
370 async def mock_getItems(*args, **kwargs): | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
371 ret_items = kwargs.pop("ret_items", XMPP_ITEMS) |
3733 | 372 rsm_resp = rsm.RSMResponse( |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
373 first=ret_items[0]["id"], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
374 last=ret_items[-1]["id"], |
3733 | 375 index=0, |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
376 count=len(ret_items) |
3733 | 377 ) |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
378 return ret_items, {"rsm": rsm_resp.toDict(), "complete": True} |
3733 | 379 |
380 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
381 def getVirtualClient(jid): |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
382 client = MagicMock() |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
383 client.jid = jid |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
384 return client |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
385 |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
386 |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
387 class FakeTReqPostResponse: |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
388 code = 202 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
389 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
390 |
3733 | 391 @pytest.fixture(scope="session") |
392 def ap_gateway(host): | |
393 gateway = plugin_comp_ap_gateway.APGateway(host) | |
394 gateway.initialised = True | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
395 gateway.isPubsub = AsyncMock() |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
396 gateway.isPubsub.return_value = False |
3733 | 397 client = MagicMock() |
398 client.jid = jid.JID("ap.test.example") | |
399 client.host = "test.example" | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
400 client.getVirtualClient = getVirtualClient |
3733 | 401 gateway.client = client |
402 gateway.local_only = True | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
403 gateway.public_url = PUBLIC_URL |
3733 | 404 gateway.ap_path = '_ap' |
405 gateway.base_ap_url = parse.urljoin( | |
406 f"https://{gateway.public_url}", | |
407 f"{gateway.ap_path}/" | |
408 ) | |
409 gateway.server = HTTPServer(gateway) | |
410 return gateway | |
411 | |
412 | |
413 class TestActivityPubGateway: | |
414 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
415 def getTitleXHTML(self, item_elt: domish.Element) -> domish.Element: |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
416 return next( |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
417 t for t in item_elt.entry.elements(NS_ATOM, "title") |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
418 if t.getAttribute("type") == "xhtml" |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
419 ) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
420 |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
421 |
3733 | 422 @ed |
423 async def test_jid_and_node_convert_to_ap_handle(self, ap_gateway): | |
424 """JID and pubsub node are converted correctly to an AP actor handle""" | |
425 get_account = ap_gateway.getAPAccountFromJidAndNode | |
426 | |
427 # local jid | |
428 assert await get_account( | |
429 jid_ = jid.JID("simple@test.example"), | |
430 node = None | |
431 ) == "simple@test.example" | |
432 | |
433 # non local jid | |
434 assert await get_account( | |
435 jid_ = jid.JID("simple@example.org"), | |
436 node = None | |
437 ) == "___simple.40example.2eorg@ap.test.example" | |
438 | |
439 # local jid with non microblog node | |
440 assert await get_account( | |
441 jid_ = jid.JID("simple@test.example"), | |
442 node = "some_other_node" | |
443 ) == "some_other_node---simple@test.example" | |
444 | |
445 # local pubsub node | |
446 with patch.object(ap_gateway, "isPubsub") as isPubsub: | |
447 isPubsub.return_value = True | |
448 assert await get_account( | |
449 jid_ = jid.JID("pubsub.test.example"), | |
450 node = "some_node" | |
451 ) == "some_node@pubsub.test.example" | |
452 | |
453 # non local pubsub node | |
454 with patch.object(ap_gateway, "isPubsub") as isPubsub: | |
455 isPubsub.return_value = True | |
456 assert await get_account( | |
457 jid_ = jid.JID("pubsub.example.org"), | |
458 node = "some_node" | |
459 ) == "___some_node.40pubsub.2eexample.2eorg@ap.test.example" | |
460 | |
461 @ed | |
462 async def test_ap_handle_convert_to_jid_and_node(self, ap_gateway, monkeypatch): | |
463 """AP actor handle convert correctly to JID and pubsub node""" | |
464 get_jid_node = ap_gateway.getJIDAndNode | |
465 | |
466 # for following assertion, host is not a pubsub service | |
467 with patch.object(ap_gateway, "isPubsub") as isPubsub: | |
468 isPubsub.return_value = False | |
469 | |
470 # simple local jid | |
471 assert await get_jid_node( | |
472 "toto@test.example" | |
473 ) == (jid.JID("toto@test.example"), None) | |
474 | |
475 # simple external jid | |
476 | |
477 ## with "local_only" set, it should raise an exception | |
478 with pytest.raises(exceptions.PermissionError): | |
479 await get_jid_node("toto@example.org") | |
480 | |
481 ## with "local_only" unset, it should work | |
482 with monkeypatch.context() as m: | |
483 m.setattr(ap_gateway, "local_only", False, raising=True) | |
484 assert await get_jid_node( | |
485 "toto@example.org" | |
486 ) == (jid.JID("toto@example.org"), None) | |
487 | |
488 # explicit node | |
489 assert await get_jid_node( | |
490 "tata---toto@test.example" | |
491 ) == (jid.JID("toto@test.example"), "tata") | |
492 | |
493 # for following assertion, host is a pubsub service | |
494 with patch.object(ap_gateway, "isPubsub") as isPubsub: | |
495 isPubsub.return_value = True | |
496 | |
497 # simple local node | |
498 assert await get_jid_node( | |
499 "toto@pubsub.test.example" | |
500 ) == (jid.JID("pubsub.test.example"), "toto") | |
501 | |
502 # encoded local node | |
503 assert await get_jid_node( | |
504 "___urn.3axmpp.3amicroblog.3a0@pubsub.test.example" | |
505 ) == (jid.JID("pubsub.test.example"), "urn:xmpp:microblog:0") | |
506 | |
507 @ed | |
508 async def test_ap_to_pubsub_conversion(self, ap_gateway, monkeypatch): | |
509 """AP requests are converted to pubsub""" | |
510 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get) | |
511 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) | |
512 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get) | |
513 | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
514 actor_data = await ap_gateway.getAPActorDataFromAccount(TEST_AP_ACCOUNT) |
3735
04ecc8eeb81a
tests (ap-gateway): fix use of outbox URL to get items
Goffi <goffi@goffi.org>
parents:
3733
diff
changeset
|
515 outbox = await ap_gateway.apGetObject(actor_data, "outbox") |
04ecc8eeb81a
tests (ap-gateway): fix use of outbox URL to get items
Goffi <goffi@goffi.org>
parents:
3733
diff
changeset
|
516 items, rsm_resp = await ap_gateway.getAPItems(outbox, 2) |
3733 | 517 |
518 assert rsm_resp.count == 4 | |
519 assert rsm_resp.index == 0 | |
520 assert rsm_resp.first == "https://example.org/users/test_user/statuses/4" | |
521 assert rsm_resp.last == "https://example.org/users/test_user/statuses/3" | |
522 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
523 title_xhtml = self.getTitleXHTML(items[0]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
524 assert title_xhtml.toXml() == ( |
3733 | 525 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
526 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 4</p></div>" | |
527 "</title>" | |
528 ) | |
529 author_uri = str( | |
530 [e for e in items[0].entry.author.elements() if e.name == "uri"][0] | |
531 ) | |
532 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
533 assert str(items[0].entry.published) == "2021-12-16T17:25:03Z" | |
534 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
535 title_xhtml = self.getTitleXHTML(items[1]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
536 assert title_xhtml.toXml() == ( |
3733 | 537 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
538 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 3</p></div>" | |
539 "</title>" | |
540 ) | |
541 author_uri = str( | |
542 [e for e in items[1].entry.author.elements() if e.name == "uri"][0] | |
543 ) | |
544 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
545 assert str(items[1].entry.published) == "2021-12-16T17:26:03Z" | |
546 | |
547 items, rsm_resp = await ap_gateway.getAPItems( | |
3735
04ecc8eeb81a
tests (ap-gateway): fix use of outbox URL to get items
Goffi <goffi@goffi.org>
parents:
3733
diff
changeset
|
548 outbox, |
3733 | 549 max_items=2, |
550 after_id="https://example.org/users/test_user/statuses/3", | |
551 ) | |
552 | |
553 assert rsm_resp.count == 4 | |
554 assert rsm_resp.index == 2 | |
555 assert rsm_resp.first == "https://example.org/users/test_user/statuses/2" | |
556 assert rsm_resp.last == "https://example.org/users/test_user/statuses/1" | |
557 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
558 title_xhtml = self.getTitleXHTML(items[0]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
559 assert title_xhtml.toXml() == ( |
3733 | 560 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
561 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 2</p></div>" | |
562 "</title>" | |
563 ) | |
564 author_uri = str( | |
565 [e for e in items[0].entry.author.elements() if e.name == "uri"][0] | |
566 ) | |
567 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
568 assert str(items[0].entry.published) == "2021-12-16T17:27:03Z" | |
569 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
570 title_xhtml = self.getTitleXHTML(items[1]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
571 assert title_xhtml.toXml() == ( |
3733 | 572 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
573 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 1</p></div>" | |
574 "</title>" | |
575 ) | |
576 author_uri = str( | |
577 [e for e in items[1].entry.author.elements() if e.name == "uri"][0] | |
578 ) | |
579 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
580 assert str(items[1].entry.published) == "2021-12-16T17:28:03Z" | |
581 | |
582 items, rsm_resp = await ap_gateway.getAPItems( | |
3735
04ecc8eeb81a
tests (ap-gateway): fix use of outbox URL to get items
Goffi <goffi@goffi.org>
parents:
3733
diff
changeset
|
583 outbox, |
3733 | 584 max_items=1, |
585 start_index=2 | |
586 ) | |
587 | |
588 assert rsm_resp.count == 4 | |
589 assert rsm_resp.index == 2 | |
590 assert rsm_resp.first == "https://example.org/users/test_user/statuses/2" | |
591 assert rsm_resp.last == "https://example.org/users/test_user/statuses/2" | |
592 assert len(items) == 1 | |
593 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
594 title_xhtml = self.getTitleXHTML(items[0]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
595 assert title_xhtml.toXml() == ( |
3733 | 596 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
597 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 2</p></div>" | |
598 "</title>" | |
599 ) | |
600 assert str(items[0].entry.published) == "2021-12-16T17:27:03Z" | |
601 | |
602 items, rsm_resp = await ap_gateway.getAPItems( | |
3735
04ecc8eeb81a
tests (ap-gateway): fix use of outbox URL to get items
Goffi <goffi@goffi.org>
parents:
3733
diff
changeset
|
603 outbox, |
3733 | 604 max_items=3, |
605 chronological_pagination=False | |
606 ) | |
607 assert rsm_resp.count == 4 | |
608 assert rsm_resp.index == 1 | |
609 assert rsm_resp.first == "https://example.org/users/test_user/statuses/3" | |
610 assert rsm_resp.last == "https://example.org/users/test_user/statuses/1" | |
611 assert len(items) == 3 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
612 title_xhtml = self.getTitleXHTML(items[0]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
613 assert title_xhtml.toXml() == ( |
3733 | 614 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
615 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 3</p></div>" | |
616 "</title>" | |
617 ) | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
618 title_xhtml = self.getTitleXHTML(items[2]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
619 assert title_xhtml.toXml() == ( |
3733 | 620 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
621 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 1</p></div>" | |
622 "</title>" | |
623 ) | |
624 | |
625 def ap_request_params(self, ap_gateway, type_=None, url=None, query_data=None): | |
626 """Generate parameters for HTTPAPGServer's AP*Request | |
627 | |
628 @param type_: one of the AP query type (e.g. "outbox") | |
629 @param url: URL to query (mutually exclusif with type_) | |
630 @param query_data: query data as returned by parse.parse_qs | |
631 @return dict with kw params to use | |
632 """ | |
633 assert type_ and url is None or url and type_ is None | |
634 if type_ is not None: | |
635 path = f"_ap/{type_}/some_user%40test.example" | |
636 else: | |
637 url_parsed = parse.urlparse(url) | |
638 path = url_parsed.path.lstrip("/") | |
639 type_ = path.split("/")[1] | |
640 if query_data is None: | |
641 query_data = parse.parse_qs(url_parsed.query) | |
642 | |
643 if query_data: | |
644 uri = f"{path}?{parse.urlencode(query_data, doseq=True)}" | |
645 else: | |
646 uri = path | |
647 | |
648 test_jid = jid.JID("some_user@test.example") | |
649 request = Request(MagicMock()) | |
650 request.path = path.encode() | |
651 request.uri = uri.encode() | |
652 ap_url = parse.urljoin( | |
653 f"https://{ap_gateway.public_url}", | |
654 path | |
655 ) | |
656 kwargs = { | |
657 "request": request, | |
658 "account_jid": test_jid, | |
659 "node": None, | |
660 "ap_account": test_jid.full(), | |
661 "ap_url": ap_url, | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
662 "signing_actor": None |
3733 | 663 } |
664 if type_ == "outbox" and query_data: | |
665 kwargs["query_data"] = query_data | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
666 # signing_actor is not used for page requests |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
667 del kwargs["signing_actor"] |
3733 | 668 return kwargs |
669 | |
670 @ed | |
671 async def test_pubsub_to_ap_conversion(self, ap_gateway, monkeypatch): | |
672 """Pubsub nodes are converted to AP collections""" | |
673 monkeypatch.setattr(ap_gateway._p, "getItems", mock_getItems) | |
674 outbox = await ap_gateway.server.resource.APOutboxRequest( | |
675 **self.ap_request_params(ap_gateway, "outbox") | |
676 ) | |
677 assert outbox["@context"] == "https://www.w3.org/ns/activitystreams" | |
678 assert outbox["id"] == "https://test.example/_ap/outbox/some_user%40test.example" | |
679 assert outbox["totalItems"] == len(XMPP_ITEMS) | |
680 assert outbox["type"] == "OrderedCollection" | |
681 assert outbox["first"] | |
682 assert outbox["last"] | |
683 | |
684 first_page = await ap_gateway.server.resource.APOutboxPageRequest( | |
685 **self.ap_request_params(ap_gateway, url=outbox["first"]) | |
686 ) | |
687 assert first_page["@context"] == "https://www.w3.org/ns/activitystreams" | |
688 assert first_page["id"] == "https://test.example/_ap/outbox/some_user%40test.example?page=first" | |
689 assert first_page["type"] == "OrderedCollectionPage" | |
690 assert first_page["partOf"] == outbox["id"] | |
691 assert len(first_page["orderedItems"]) == len(XMPP_ITEMS) | |
692 first_item = first_page["orderedItems"][0] | |
693 assert first_item["@context"] == "https://www.w3.org/ns/activitystreams" | |
694 assert first_item["id"] == "https://test.example/_ap/item/some_user%40test.example/4" | |
695 assert first_item["actor"] == "https://test.example/_ap/actor/some_user%40test.example" | |
696 assert first_item["type"] == "Create" | |
697 first_item_obj = first_item["object"] | |
698 assert first_item_obj["id"] == first_item["id"] | |
699 assert first_item_obj["type"] == "Note" | |
700 assert first_item_obj["published"] == "2022-01-28T16:02:19Z" | |
701 assert first_item_obj["attributedTo"] == first_item["actor"] | |
702 assert first_item_obj["content"] == "<div><p>XMPP item 4</p></div>" | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
703 assert first_item_obj["to"] == ["https://www.w3.org/ns/activitystreams#Public"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
704 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
705 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
706 async def test_following_to_pps(self, ap_gateway, monkeypatch): |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
707 """AP following items are converted to Public Pubsub Subscription subscriptions""" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
708 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
709 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
710 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
711 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
712 items, __ = await ap_gateway.pubsub_service.items( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
713 jid.JID("toto@example.org"), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
714 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
715 ap_gateway._pps.subscriptions_node, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
716 None, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
717 None, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
718 None |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
719 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
720 assert len(items) == 2 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
721 for idx, entity in enumerate(( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
722 "local_user@test.example", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
723 "ext_user\\40example.org@ap.test.example" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
724 )): |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
725 subscription_elt = next(items[idx].elements(NS_PPS, "subscription"), None) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
726 assert subscription_elt is not None |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
727 assert subscription_elt["node"] == ap_gateway._m.namespace |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
728 assert subscription_elt["service"] == entity |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
729 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
730 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
731 async def test_followers_to_pps(self, ap_gateway, monkeypatch): |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
732 """AP followers items are converted to Public Pubsub Subscription subscribers""" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
733 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
734 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
735 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
736 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
737 items, __ = await ap_gateway.pubsub_service.items( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
738 jid.JID("toto@example.org"), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
739 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
740 ap_gateway._pps.getPublicSubscribersNode(ap_gateway._m.namespace), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
741 None, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
742 None, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
743 None |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
744 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
745 assert len(items) == 2 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
746 for idx, entity in enumerate(( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
747 "local_user@test.example", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
748 "ext_user\\40example.org@ap.test.example" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
749 )): |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
750 subscriber_elt = next(items[idx].elements(NS_PPS, "subscriber"), None) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
751 assert subscriber_elt is not None |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
752 assert subscriber_elt["jid"] == entity |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
753 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
754 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
755 async def test_pps_to_following(self, ap_gateway, monkeypatch): |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
756 """Public Pubsub Subscription subscriptions are converted to AP following items""" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
757 subscriptions = [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
758 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
759 id="subscription_1", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
760 payload = ap_gateway._pps.buildSubscriptionElt( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
761 ap_gateway._m.namespace, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
762 jid.JID("local_user@test.example") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
763 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
764 ), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
765 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
766 id="subscription_2", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
767 payload = ap_gateway._pps.buildSubscriptionElt( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
768 ap_gateway._m.namespace, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
769 jid.JID("ext_user\\40example.org@ap.test.example") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
770 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
771 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
772 ] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
773 monkeypatch.setattr(ap_gateway._p, "getItems", partial( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
774 mock_getItems, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
775 ret_items=subscriptions |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
776 )) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
777 following = await ap_gateway.server.resource.APFollowingRequest( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
778 **self.ap_request_params(ap_gateway, "following") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
779 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
780 assert following["@context"] == "https://www.w3.org/ns/activitystreams" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
781 assert following["id"] == "https://test.example/_ap/following/some_user%40test.example" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
782 assert following["totalItems"] == len(subscriptions) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
783 assert following["type"] == "OrderedCollection" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
784 assert following.get("first") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
785 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
786 first_page = following["first"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
787 assert first_page["type"] == "OrderedCollectionPage" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
788 assert len(first_page["orderedItems"]) == len(subscriptions) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
789 items = first_page["orderedItems"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
790 assert items == ['local_user@test.example', 'ext_user@example.org'] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
791 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
792 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
793 async def test_pps_to_followers(self, ap_gateway, monkeypatch): |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
794 """Public Pubsub Subscription subscribers are converted to AP followers""" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
795 subscribers = [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
796 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
797 id="subscriber_1", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
798 payload = ap_gateway._pps.buildSubscriberElt( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
799 jid.JID("local_user@test.example") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
800 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
801 ), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
802 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
803 id="subscriber_2", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
804 payload = ap_gateway._pps.buildSubscriberElt( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
805 jid.JID("ext_user\\40example.org@ap.test.example") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
806 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
807 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
808 ] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
809 monkeypatch.setattr(ap_gateway._p, "getItems", partial( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
810 mock_getItems, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
811 ret_items=subscribers |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
812 )) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
813 followers = await ap_gateway.server.resource.APFollowersRequest( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
814 **self.ap_request_params(ap_gateway, "followers") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
815 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
816 assert followers["@context"] == "https://www.w3.org/ns/activitystreams" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
817 assert followers["id"] == "https://test.example/_ap/followers/some_user%40test.example" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
818 assert followers["totalItems"] == len(subscribers) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
819 assert followers["type"] == "OrderedCollection" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
820 assert followers.get("first") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
821 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
822 first_page = followers["first"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
823 assert first_page["type"] == "OrderedCollectionPage" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
824 assert len(first_page["orderedItems"]) == len(subscribers) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
825 items = first_page["orderedItems"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
826 assert items == ['local_user@test.example', 'ext_user@example.org'] |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
827 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
828 @ed |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
829 async def test_xmpp_message_to_ap_direct_message(self, ap_gateway, monkeypatch): |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
830 """XMPP message are sent as AP direct message""" |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
831 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
832 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
833 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get) |
3808
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
834 mess_data = { |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
835 "from": TEST_JID, |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
836 "to": ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT), |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
837 "type": "chat", |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
838 "message": {"": "This is a test message."}, |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
839 "extra": { |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
840 "origin-id": "123" |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
841 } |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
842 } |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
843 with patch.object(ap_gateway, "signAndPost") as signAndPost: |
3808
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
844 await ap_gateway.onMessage(ap_gateway.client, mess_data) |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
845 url, actor_id, doc = signAndPost.call_args[0] |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
846 assert url == "https://example.org/users/test_user/inbox" |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
847 assert actor_id == "https://test.example/_ap/actor/some_user%40test.example" |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
848 obj = doc["object"] |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
849 assert doc["@context"] == "https://www.w3.org/ns/activitystreams" |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
850 assert doc["actor"] == "https://test.example/_ap/actor/some_user%40test.example" |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
851 assert obj["type"] == "Note" |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
852 assert obj["content"] == "This is a test message." |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
853 assert obj["attributedTo"] == ( |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
854 "https://test.example/_ap/actor/some_user%40test.example" |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
855 ) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
856 # we must have a direct message, thus the item must be only addressed to destinee |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
857 # ("to" attribute of the message), and the "Public" namespace must not be set |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
858 assert doc["to"] == ["https://example.org/users/test_user"] |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
859 assert obj["to"] == ["https://example.org/users/test_user"] |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
860 for field in ("bto", "cc", "bcc", "audience"): |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
861 assert field not in doc |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
862 assert field not in obj |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
863 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
864 @ed |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
865 async def test_ap_direct_message_to_xmpp_message(self, ap_gateway, monkeypatch): |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
866 """AP direct message are sent as XMPP message (not Pubsub)""" |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
867 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
868 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
869 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
870 # we have to patch DeferredList to not wait forever |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
871 monkeypatch.setattr(defer, "DeferredList", AsyncMock()) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
872 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
873 xmpp_actor_id = ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, TEST_JID.userhost()) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
874 direct_ap_message = { |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
875 'attributedTo': TEST_AP_ACTOR_ID, |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
876 'cc': [], |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
877 'content': '<p>test direct message</p>', |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
878 'contentMap': {'en': '<p>test direct message</p>'}, |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
879 'id': f'{TEST_AP_ACTOR_ID}/statuses/123', |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
880 'published': '2022-05-20T08:14:39Z', |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
881 'to': [xmpp_actor_id], |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
882 'type': 'Note', |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
883 } |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
884 client = ap_gateway.client.getVirtualClient( |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
885 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
886 ) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
887 with patch.object(client, "sendMessage") as sendMessage: |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
888 await ap_gateway.newAPItem( |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
889 client, None, ap_gateway._m.namespace, direct_ap_message |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
890 ) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
891 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
892 # sendMessage must be called for <message> stanza, and the "message" argument must |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
893 # be set to the content of the original AP message |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
894 assert sendMessage.called |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
895 assert sendMessage.call_args.args[0] == TEST_JID |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
896 assert sendMessage.call_args.args[1] == {"": "test direct message"} |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
897 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
898 @ed |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
899 async def test_pubsub_retract_to_ap_delete(self, ap_gateway, monkeypatch): |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
900 """Pubsub retract requests are converted to AP delete activity""" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
901 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
902 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
903 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
904 retract_id = "retract_123" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
905 retract_elt = domish.Element((pubsub.NS_PUBSUB_EVENT, "retract")) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
906 retract_elt["id"] = retract_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
907 items_event = pubsub.ItemsEvent( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
908 sender=TEST_JID, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
909 recipient=ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT), |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
910 nodeIdentifier=ap_gateway._m.namespace, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
911 items=[retract_elt], |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
912 headers={} |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
913 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
914 with patch.object(ap_gateway, "signAndPost") as signAndPost: |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
915 signAndPost.return_value = FakeTReqPostResponse() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
916 # we simulate the reception of a retract event |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
917 await ap_gateway._itemsReceived(ap_gateway.client, items_event) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
918 url, actor_id, doc = signAndPost.call_args[0] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
919 jid_account = await ap_gateway.getAPAccountFromJidAndNode(TEST_JID, None) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
920 jid_actor_id = ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, jid_account) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
921 assert url == f"{TEST_BASE_URL}/users/{TEST_USER}/inbox" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
922 assert actor_id == jid_actor_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
923 assert doc["type"] == "Delete" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
924 assert doc["actor"] == jid_actor_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
925 obj = doc["object"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
926 assert obj["type"] == ap_const.TYPE_TOMBSTONE |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
927 url_item_id = ap_gateway.buildAPURL(ap_const.TYPE_ITEM, jid_account, retract_id) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
928 assert obj["id"] == url_item_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
929 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
930 @ed |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
931 async def test_ap_delete_to_pubsub_retract(self, ap_gateway): |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
932 """AP delete activity is converted to pubsub retract""" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
933 client = ap_gateway.client.getVirtualClient( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
934 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
935 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
936 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
937 ap_item = { |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
938 "@context": "https://www.w3.org/ns/activitystreams", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
939 "actor": TEST_AP_ACTOR_ID, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
940 "id": "https://test.example/retract_123", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
941 "type": "Delete", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
942 "object": {"id": f"{TEST_AP_ACTOR_ID}/item/123", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
943 "type": "Tombstone"}, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
944 "to": ["https://www.w3.org/ns/activitystreams#Public"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
945 } |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
946 with patch.multiple( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
947 ap_gateway.host.memory.storage, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
948 get=DEFAULT, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
949 getPubsubNode=DEFAULT, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
950 deletePubsubItems=DEFAULT, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
951 ) as mock_objs: |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
952 mock_objs["get"].return_value=None |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
953 cached_node = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
954 mock_objs["getPubsubNode"].return_value=cached_node |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
955 subscription = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
956 subscription.state = SubscriptionState.SUBSCRIBED |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
957 subscription.subscriber = TEST_JID |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
958 cached_node.subscriptions = [subscription] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
959 with patch.object( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
960 ap_gateway.pubsub_service, "notifyRetract" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
961 ) as notifyRetract: |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
962 # we simulate a received Delete activity |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
963 await ap_gateway.newAPDeleteItem( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
964 client=client, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
965 destinee=None, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
966 node=ap_gateway._m.namespace, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
967 item=ap_item |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
968 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
969 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
970 # item is deleted from database |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
971 deletePubsubItems = mock_objs["deletePubsubItems"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
972 assert deletePubsubItems.call_count == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
973 assert deletePubsubItems.call_args.args[1] == [ap_item["id"]] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
974 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
975 # retraction notification is sent to subscribers |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
976 assert notifyRetract.call_count == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
977 assert notifyRetract.call_args.args[0] == client.jid |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
978 assert notifyRetract.call_args.args[1] == ap_gateway._m.namespace |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
979 notifications = notifyRetract.call_args.args[2] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
980 assert len(notifications) == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
981 subscriber, __, item_elts = notifications[0] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
982 assert subscriber == TEST_JID |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
983 assert len(item_elts) == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
984 item_elt = item_elts[0] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
985 assert isinstance(item_elt, domish.Element) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
986 assert item_elt.name == "item" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
987 assert item_elt["id"] == ap_item["id"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
988 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
989 @ed |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
990 async def test_message_retract_to_ap_delete(self, ap_gateway, monkeypatch): |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
991 """Message retract requests are converted to AP delete activity""" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
992 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
993 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
994 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
995 # origin ID is the ID of the message to retract |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
996 origin_id = "mess_retract_123" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
997 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
998 # we call retractByOriginId to get the message element of a retraction request |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
999 fake_client = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1000 fake_client.jid = TEST_JID |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1001 dest_jid = ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1002 ap_gateway._r.retractByOriginId(fake_client, dest_jid, origin_id) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1003 # message_retract_elt is the message which would be sent for a retraction |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1004 message_retract_elt = fake_client.send.call_args.args[0] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1005 apply_to_elt = next(message_retract_elt.elements(NS_FASTEN, "apply-to")) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1006 retract_elt = apply_to_elt.retract |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1007 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1008 with patch.object(ap_gateway, "signAndPost") as signAndPost: |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1009 signAndPost.return_value = FakeTReqPostResponse() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1010 fake_fastened_elts = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1011 fake_fastened_elts.id = origin_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1012 # we simulate the reception of a retract event using the message element that |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1013 # we generated above |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1014 await ap_gateway._onMessageRetract( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1015 ap_gateway.client, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1016 message_retract_elt, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1017 retract_elt, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1018 fake_fastened_elts |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1019 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1020 url, actor_id, doc = signAndPost.call_args[0] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1021 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1022 # the AP delete activity must have been sent through signAndPost |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1023 # we check its values |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1024 jid_account = await ap_gateway.getAPAccountFromJidAndNode(TEST_JID, None) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1025 jid_actor_id = ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, jid_account) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1026 assert url == f"{TEST_BASE_URL}/users/{TEST_USER}/inbox" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1027 assert actor_id == jid_actor_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1028 assert doc["type"] == "Delete" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1029 assert doc["actor"] == jid_actor_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1030 obj = doc["object"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1031 assert obj["type"] == ap_const.TYPE_TOMBSTONE |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1032 url_item_id = ap_gateway.buildAPURL(ap_const.TYPE_ITEM, jid_account, origin_id) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1033 assert obj["id"] == url_item_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1034 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1035 @ed |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1036 async def test_ap_delete_to_message_retract(self, ap_gateway, monkeypatch): |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1037 """AP delete activity is converted to message retract""" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1038 # note: a message retract is used when suitable message is found in history, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1039 # otherwise it should be in pubsub cache and it's a pubsub retract (tested above |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1040 # by ``test_ap_delete_to_pubsub_retract``) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1041 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1042 # we don't want actual queries in database |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1043 retractDBHistory = AsyncMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1044 monkeypatch.setattr(ap_gateway._r, "retractDBHistory", retractDBHistory) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1045 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1046 client = ap_gateway.client.getVirtualClient( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1047 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1048 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1049 fake_send = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1050 monkeypatch.setattr(client, "send", fake_send) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1051 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1052 ap_item = { |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1053 "@context": "https://www.w3.org/ns/activitystreams", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1054 "actor": TEST_AP_ACTOR_ID, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1055 "id": "https://test.example/retract_123", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1056 "type": "Delete", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1057 "object": {"id": f"{TEST_AP_ACTOR_ID}/item/123", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1058 "type": "Tombstone"}, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1059 "to": ["https://www.w3.org/ns/activitystreams#Public"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1060 } |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1061 with patch.object(ap_gateway.host.memory.storage, "get") as storage_get: |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1062 fake_history = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1063 fake_history.source_jid = client.jid |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1064 fake_history.dest_jid = TEST_JID |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1065 fake_history.origin_id = ap_item["id"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1066 storage_get.return_value = fake_history |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1067 # we simulate a received Delete activity |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1068 await ap_gateway.newAPDeleteItem( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1069 client=client, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1070 destinee=None, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1071 node=ap_gateway._m.namespace, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1072 item=ap_item |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1073 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1074 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1075 # item is deleted from database |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1076 assert retractDBHistory.call_count == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1077 assert retractDBHistory.call_args.args[0] == client |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1078 assert retractDBHistory.call_args.args[1] == fake_history |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1079 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1080 # retraction notification is sent to destinee |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1081 assert fake_send.call_count == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1082 sent_elt = fake_send.call_args.args[0] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1083 assert sent_elt.name == "message" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1084 assert sent_elt["from"] == client.jid.full() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1085 assert sent_elt["to"] == TEST_JID.full() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1086 apply_to_elt = next(sent_elt.elements(NS_FASTEN, "apply-to")) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1087 assert apply_to_elt["id"] == ap_item["id"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1088 retract_elt = apply_to_elt.retract |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1089 assert retract_elt is not None |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1090 assert retract_elt.uri == NS_MESSAGE_RETRACT |