eva
[akkoma] / test / web / ostatus / ostatus_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.OStatusTest do
6 use Pleroma.DataCase
7 alias Pleroma.Activity
8 alias Pleroma.Instances
9 alias Pleroma.Object
10 alias Pleroma.Repo
11 alias Pleroma.User
12 alias Pleroma.Web.OStatus
13 alias Pleroma.Web.XML
14
15 import ExUnit.CaptureLog
16 import Mock
17 import Pleroma.Factory
18
19 setup_all do
20 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
21 :ok
22 end
23
24 test "don't insert create notes twice" do
25 incoming = File.read!("test/fixtures/incoming_note_activity.xml")
26 {:ok, [activity]} = OStatus.handle_incoming(incoming)
27 assert {:ok, [activity]} == OStatus.handle_incoming(incoming)
28 end
29
30 test "handle incoming note - GS, Salmon" do
31 incoming = File.read!("test/fixtures/incoming_note_activity.xml")
32 {:ok, [activity]} = OStatus.handle_incoming(incoming)
33 object = Object.normalize(activity)
34
35 user = User.get_cached_by_ap_id(activity.data["actor"])
36 assert user.info.note_count == 1
37 assert activity.data["type"] == "Create"
38 assert object.data["type"] == "Note"
39
40 assert object.data["id"] == "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note"
41
42 assert activity.data["published"] == "2017-04-23T14:51:03+00:00"
43 assert object.data["published"] == "2017-04-23T14:51:03+00:00"
44
45 assert activity.data["context"] ==
46 "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
47
48 assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"]
49 assert object.data["emoji"] == %{"marko" => "marko.png", "reimu" => "reimu.png"}
50 assert activity.local == false
51 end
52
53 test "handle incoming notes - GS, subscription" do
54 incoming = File.read!("test/fixtures/ostatus_incoming_post.xml")
55 {:ok, [activity]} = OStatus.handle_incoming(incoming)
56 object = Object.normalize(activity)
57
58 assert activity.data["type"] == "Create"
59 assert object.data["type"] == "Note"
60 assert object.data["actor"] == "https://social.heldscal.la/user/23211"
61 assert object.data["content"] == "Will it blend?"
62 user = User.get_cached_by_ap_id(activity.data["actor"])
63 assert User.ap_followers(user) in activity.data["to"]
64 assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
65 end
66
67 test "handle incoming notes with attachments - GS, subscription" do
68 incoming = File.read!("test/fixtures/incoming_websub_gnusocial_attachments.xml")
69 {:ok, [activity]} = OStatus.handle_incoming(incoming)
70 object = Object.normalize(activity)
71
72 assert activity.data["type"] == "Create"
73 assert object.data["type"] == "Note"
74 assert object.data["actor"] == "https://social.heldscal.la/user/23211"
75 assert object.data["attachment"] |> length == 2
76 assert object.data["external_url"] == "https://social.heldscal.la/notice/2020923"
77 assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
78 end
79
80 test "handle incoming notes with tags" do
81 incoming = File.read!("test/fixtures/ostatus_incoming_post_tag.xml")
82 {:ok, [activity]} = OStatus.handle_incoming(incoming)
83 object = Object.normalize(activity)
84
85 assert object.data["tag"] == ["nsfw"]
86 assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
87 end
88
89 test "handle incoming notes - Mastodon, salmon, reply" do
90 # It uses the context of the replied to object
91 Repo.insert!(%Object{
92 data: %{
93 "id" => "https://pleroma.soykaf.com/objects/c237d966-ac75-4fe3-a87a-d89d71a3a7a4",
94 "context" => "2hu"
95 }
96 })
97
98 incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
99 {:ok, [activity]} = OStatus.handle_incoming(incoming)
100 object = Object.normalize(activity)
101
102 assert activity.data["type"] == "Create"
103 assert object.data["type"] == "Note"
104 assert object.data["actor"] == "https://mastodon.social/users/lambadalambda"
105 assert activity.data["context"] == "2hu"
106 assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
107 end
108
109 test "handle incoming notes - Mastodon, with CW" do
110 incoming = File.read!("test/fixtures/mastodon-note-cw.xml")
111 {:ok, [activity]} = OStatus.handle_incoming(incoming)
112 object = Object.normalize(activity)
113
114 assert activity.data["type"] == "Create"
115 assert object.data["type"] == "Note"
116 assert object.data["actor"] == "https://mastodon.social/users/lambadalambda"
117 assert object.data["summary"] == "technologic"
118 assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
119 end
120
121 test "handle incoming unlisted messages, put public into cc" do
122 incoming = File.read!("test/fixtures/mastodon-note-unlisted.xml")
123 {:ok, [activity]} = OStatus.handle_incoming(incoming)
124 object = Object.normalize(activity)
125
126 refute "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
127 assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["cc"]
128 refute "https://www.w3.org/ns/activitystreams#Public" in object.data["to"]
129 assert "https://www.w3.org/ns/activitystreams#Public" in object.data["cc"]
130 end
131
132 test "handle incoming retweets - Mastodon, with CW" do
133 incoming = File.read!("test/fixtures/cw_retweet.xml")
134 {:ok, [[_activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
135 retweeted_object = Object.normalize(retweeted_activity)
136
137 assert retweeted_object.data["summary"] == "Hey."
138 end
139
140 test "handle incoming notes - GS, subscription, reply" do
141 incoming = File.read!("test/fixtures/ostatus_incoming_reply.xml")
142 {:ok, [activity]} = OStatus.handle_incoming(incoming)
143 object = Object.normalize(activity)
144
145 assert activity.data["type"] == "Create"
146 assert object.data["type"] == "Note"
147 assert object.data["actor"] == "https://social.heldscal.la/user/23211"
148
149 assert object.data["content"] ==
150 "@<a href=\"https://gs.archae.me/user/4687\" class=\"h-card u-url p-nickname mention\" title=\"shpbot\">shpbot</a> why not indeed."
151
152 assert object.data["inReplyTo"] ==
153 "tag:gs.archae.me,2017-04-30:noticeId=778260:objectType=note"
154
155 assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
156 end
157
158 test "handle incoming retweets - GS, subscription" do
159 incoming = File.read!("test/fixtures/share-gs.xml")
160 {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
161
162 assert activity.data["type"] == "Announce"
163 assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
164 assert activity.data["object"] == retweeted_activity.data["object"]
165 assert "https://pleroma.soykaf.com/users/lain" in activity.data["to"]
166 refute activity.local
167
168 retweeted_activity = Activity.get_by_id(retweeted_activity.id)
169 retweeted_object = Object.normalize(retweeted_activity)
170 assert retweeted_activity.data["type"] == "Create"
171 assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
172 refute retweeted_activity.local
173 assert retweeted_object.data["announcement_count"] == 1
174 assert String.contains?(retweeted_object.data["content"], "mastodon")
175 refute String.contains?(retweeted_object.data["content"], "Test account")
176 end
177
178 test "handle incoming retweets - GS, subscription - local message" do
179 incoming = File.read!("test/fixtures/share-gs-local.xml")
180 note_activity = insert(:note_activity)
181 object = Object.normalize(note_activity)
182 user = User.get_cached_by_ap_id(note_activity.data["actor"])
183
184 incoming =
185 incoming
186 |> String.replace("LOCAL_ID", object.data["id"])
187 |> String.replace("LOCAL_USER", user.ap_id)
188
189 {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
190
191 assert activity.data["type"] == "Announce"
192 assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
193 assert activity.data["object"] == object.data["id"]
194 assert user.ap_id in activity.data["to"]
195 refute activity.local
196
197 retweeted_activity = Activity.get_by_id(retweeted_activity.id)
198 assert note_activity.id == retweeted_activity.id
199 assert retweeted_activity.data["type"] == "Create"
200 assert retweeted_activity.data["actor"] == user.ap_id
201 assert retweeted_activity.local
202 assert Object.normalize(retweeted_activity).data["announcement_count"] == 1
203 end
204
205 test "handle incoming retweets - Mastodon, salmon" do
206 incoming = File.read!("test/fixtures/share.xml")
207 {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
208 retweeted_object = Object.normalize(retweeted_activity)
209
210 assert activity.data["type"] == "Announce"
211 assert activity.data["actor"] == "https://mastodon.social/users/lambadalambda"
212 assert activity.data["object"] == retweeted_activity.data["object"]
213
214 assert activity.data["id"] ==
215 "tag:mastodon.social,2017-05-03:objectId=4934452:objectType=Status"
216
217 refute activity.local
218 assert retweeted_activity.data["type"] == "Create"
219 assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
220 refute retweeted_activity.local
221 refute String.contains?(retweeted_object.data["content"], "Test account")
222 end
223
224 test "handle incoming favorites - GS, websub" do
225 capture_log(fn ->
226 incoming = File.read!("test/fixtures/favorite.xml")
227 {:ok, [[activity, favorited_activity]]} = OStatus.handle_incoming(incoming)
228
229 assert activity.data["type"] == "Like"
230 assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
231 assert activity.data["object"] == favorited_activity.data["object"]
232
233 assert activity.data["id"] ==
234 "tag:social.heldscal.la,2017-05-05:fave:23211:comment:2061643:2017-05-05T09:12:50+00:00"
235
236 refute activity.local
237 assert favorited_activity.data["type"] == "Create"
238 assert favorited_activity.data["actor"] == "https://shitposter.club/user/1"
239
240 assert favorited_activity.data["object"] ==
241 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
242
243 refute favorited_activity.local
244 end)
245 end
246
247 test "handle conversation references" do
248 incoming = File.read!("test/fixtures/mastodon_conversation.xml")
249 {:ok, [activity]} = OStatus.handle_incoming(incoming)
250
251 assert activity.data["context"] ==
252 "tag:mastodon.social,2017-08-28:objectId=7876885:objectType=Conversation"
253 end
254
255 test "handle incoming favorites with locally available object - GS, websub" do
256 note_activity = insert(:note_activity)
257 object = Object.normalize(note_activity)
258
259 incoming =
260 File.read!("test/fixtures/favorite_with_local_note.xml")
261 |> String.replace("localid", object.data["id"])
262
263 {:ok, [[activity, favorited_activity]]} = OStatus.handle_incoming(incoming)
264
265 assert activity.data["type"] == "Like"
266 assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
267 assert activity.data["object"] == object.data["id"]
268 refute activity.local
269 assert note_activity.id == favorited_activity.id
270 assert favorited_activity.local
271 end
272
273 test_with_mock "handle incoming replies, fetching replied-to activities if we don't have them",
274 OStatus,
275 [:passthrough],
276 [] do
277 incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
278 {:ok, [activity]} = OStatus.handle_incoming(incoming)
279 object = Object.normalize(activity, false)
280
281 assert activity.data["type"] == "Create"
282 assert object.data["type"] == "Note"
283
284 assert object.data["inReplyTo"] ==
285 "http://pleroma.example.org:4000/objects/55bce8fc-b423-46b1-af71-3759ab4670bc"
286
287 assert "http://pleroma.example.org:4000/users/lain5" in activity.data["to"]
288
289 assert object.data["id"] == "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note"
290
291 assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
292
293 assert called(OStatus.fetch_activity_from_url(object.data["inReplyTo"], :_))
294 end
295
296 test_with_mock "handle incoming replies, not fetching replied-to activities beyond max_replies_depth",
297 OStatus,
298 [:passthrough],
299 [] do
300 incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
301
302 with_mock Pleroma.Web.Federator,
303 allowed_incoming_reply_depth?: fn _ -> false end do
304 {:ok, [activity]} = OStatus.handle_incoming(incoming)
305 object = Object.normalize(activity, false)
306
307 refute called(OStatus.fetch_activity_from_url(object.data["inReplyTo"], :_))
308 end
309 end
310
311 test "handle incoming follows" do
312 incoming = File.read!("test/fixtures/follow.xml")
313 {:ok, [activity]} = OStatus.handle_incoming(incoming)
314 assert activity.data["type"] == "Follow"
315
316 assert activity.data["id"] ==
317 "tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00"
318
319 assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
320 assert activity.data["object"] == "https://pawoo.net/users/pekorino"
321 refute activity.local
322
323 follower = User.get_cached_by_ap_id(activity.data["actor"])
324 followed = User.get_cached_by_ap_id(activity.data["object"])
325
326 assert User.following?(follower, followed)
327 end
328
329 test "refuse following over OStatus if the followed's account is locked" do
330 incoming = File.read!("test/fixtures/follow.xml")
331 _user = insert(:user, info: %{locked: true}, ap_id: "https://pawoo.net/users/pekorino")
332
333 {:ok, [{:error, "It's not possible to follow locked accounts over OStatus"}]} =
334 OStatus.handle_incoming(incoming)
335 end
336
337 test "handle incoming unfollows with existing follow" do
338 incoming_follow = File.read!("test/fixtures/follow.xml")
339 {:ok, [_activity]} = OStatus.handle_incoming(incoming_follow)
340
341 incoming = File.read!("test/fixtures/unfollow.xml")
342 {:ok, [activity]} = OStatus.handle_incoming(incoming)
343
344 assert activity.data["type"] == "Undo"
345
346 assert activity.data["id"] ==
347 "undo:tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00"
348
349 assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
350 embedded_object = activity.data["object"]
351 assert is_map(embedded_object)
352 assert embedded_object["type"] == "Follow"
353 assert embedded_object["object"] == "https://pawoo.net/users/pekorino"
354 refute activity.local
355
356 follower = User.get_cached_by_ap_id(activity.data["actor"])
357 followed = User.get_cached_by_ap_id(embedded_object["object"])
358
359 refute User.following?(follower, followed)
360 end
361
362 test "it clears `unreachable` federation status of the sender" do
363 incoming_reaction_xml = File.read!("test/fixtures/share-gs.xml")
364 doc = XML.parse_document(incoming_reaction_xml)
365 actor_uri = XML.string_from_xpath("//author/uri[1]", doc)
366 reacted_to_author_uri = XML.string_from_xpath("//author/uri[2]", doc)
367
368 Instances.set_consistently_unreachable(actor_uri)
369 Instances.set_consistently_unreachable(reacted_to_author_uri)
370 refute Instances.reachable?(actor_uri)
371 refute Instances.reachable?(reacted_to_author_uri)
372
373 {:ok, _} = OStatus.handle_incoming(incoming_reaction_xml)
374 assert Instances.reachable?(actor_uri)
375 refute Instances.reachable?(reacted_to_author_uri)
376 end
377
378 describe "new remote user creation" do
379 test "returns local users" do
380 local_user = insert(:user)
381 {:ok, user} = OStatus.find_or_make_user(local_user.ap_id)
382
383 assert user == local_user
384 end
385
386 test "tries to use the information in poco fields" do
387 uri = "https://social.heldscal.la/user/23211"
388
389 {:ok, user} = OStatus.find_or_make_user(uri)
390
391 user = User.get_cached_by_id(user.id)
392 assert user.name == "Constance Variable"
393 assert user.nickname == "lambadalambda@social.heldscal.la"
394 assert user.local == false
395 assert user.info.uri == uri
396 assert user.ap_id == uri
397 assert user.bio == "Call me Deacon Blues."
398 assert user.avatar["type"] == "Image"
399
400 {:ok, user_again} = OStatus.find_or_make_user(uri)
401
402 assert user == user_again
403 end
404
405 test "find_or_make_user sets all the nessary input fields" do
406 uri = "https://social.heldscal.la/user/23211"
407 {:ok, user} = OStatus.find_or_make_user(uri)
408
409 assert user.info ==
410 %User.Info{
411 id: user.info.id,
412 ap_enabled: false,
413 background: %{},
414 banner: %{},
415 blocks: [],
416 deactivated: false,
417 default_scope: "public",
418 domain_blocks: [],
419 follower_count: 0,
420 is_admin: false,
421 is_moderator: false,
422 keys: nil,
423 locked: false,
424 no_rich_text: false,
425 note_count: 0,
426 settings: nil,
427 source_data: %{},
428 hub: "https://social.heldscal.la/main/push/hub",
429 magic_key:
430 "RSA.uzg6r1peZU0vXGADWxGJ0PE34WvmhjUmydbX5YYdOiXfODVLwCMi1umGoqUDm-mRu4vNEdFBVJU1CpFA7dKzWgIsqsa501i2XqElmEveXRLvNRWFB6nG03Q5OUY2as8eE54BJm0p20GkMfIJGwP6TSFb-ICp3QjzbatuSPJ6xCE=.AQAB",
431 salmon: "https://social.heldscal.la/main/salmon/user/23211",
432 topic: "https://social.heldscal.la/api/statuses/user_timeline/23211.atom",
433 uri: "https://social.heldscal.la/user/23211"
434 }
435 end
436
437 test "find_make_or_update_actor takes an author element and returns an updated user" do
438 uri = "https://social.heldscal.la/user/23211"
439
440 {:ok, user} = OStatus.find_or_make_user(uri)
441 old_name = user.name
442 old_bio = user.bio
443 change = Ecto.Changeset.change(user, %{avatar: nil, bio: nil, name: nil})
444
445 {:ok, user} = Repo.update(change)
446 refute user.avatar
447
448 doc = XML.parse_document(File.read!("test/fixtures/23211.atom"))
449 [author] = :xmerl_xpath.string('//author[1]', doc)
450 {:ok, user} = OStatus.find_make_or_update_actor(author)
451 assert user.avatar["type"] == "Image"
452 assert user.name == old_name
453 assert user.bio == old_bio
454
455 {:ok, user_again} = OStatus.find_make_or_update_actor(author)
456 assert user_again == user
457 end
458
459 test "find_or_make_user disallows protocol downgrade" do
460 user = insert(:user, %{local: true})
461 {:ok, user} = OStatus.find_or_make_user(user.ap_id)
462
463 assert User.ap_enabled?(user)
464
465 user =
466 insert(:user, %{
467 ap_id: "https://social.heldscal.la/user/23211",
468 info: %{ap_enabled: true},
469 local: false
470 })
471
472 assert User.ap_enabled?(user)
473
474 {:ok, user} = OStatus.find_or_make_user(user.ap_id)
475 assert User.ap_enabled?(user)
476 end
477
478 test "find_make_or_update_actor disallows protocol downgrade" do
479 user = insert(:user, %{local: true})
480 {:ok, user} = OStatus.find_or_make_user(user.ap_id)
481
482 assert User.ap_enabled?(user)
483
484 user =
485 insert(:user, %{
486 ap_id: "https://social.heldscal.la/user/23211",
487 info: %{ap_enabled: true},
488 local: false
489 })
490
491 assert User.ap_enabled?(user)
492
493 {:ok, user} = OStatus.find_or_make_user(user.ap_id)
494 assert User.ap_enabled?(user)
495
496 doc = XML.parse_document(File.read!("test/fixtures/23211.atom"))
497 [author] = :xmerl_xpath.string('//author[1]', doc)
498 {:error, :invalid_protocol} = OStatus.find_make_or_update_actor(author)
499 end
500 end
501
502 describe "gathering user info from a user id" do
503 test "it returns user info in a hash" do
504 user = "shp@social.heldscal.la"
505
506 # TODO: make test local
507 {:ok, data} = OStatus.gather_user_info(user)
508
509 expected = %{
510 "hub" => "https://social.heldscal.la/main/push/hub",
511 "magic_key" =>
512 "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
513 "name" => "shp",
514 "nickname" => "shp",
515 "salmon" => "https://social.heldscal.la/main/salmon/user/29191",
516 "subject" => "acct:shp@social.heldscal.la",
517 "topic" => "https://social.heldscal.la/api/statuses/user_timeline/29191.atom",
518 "uri" => "https://social.heldscal.la/user/29191",
519 "host" => "social.heldscal.la",
520 "fqn" => user,
521 "bio" => "cofe",
522 "avatar" => %{
523 "type" => "Image",
524 "url" => [
525 %{
526 "href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg",
527 "mediaType" => "image/jpeg",
528 "type" => "Link"
529 }
530 ]
531 },
532 "subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}",
533 "ap_id" => nil
534 }
535
536 assert data == expected
537 end
538
539 test "it works with the uri" do
540 user = "https://social.heldscal.la/user/29191"
541
542 # TODO: make test local
543 {:ok, data} = OStatus.gather_user_info(user)
544
545 expected = %{
546 "hub" => "https://social.heldscal.la/main/push/hub",
547 "magic_key" =>
548 "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
549 "name" => "shp",
550 "nickname" => "shp",
551 "salmon" => "https://social.heldscal.la/main/salmon/user/29191",
552 "subject" => "https://social.heldscal.la/user/29191",
553 "topic" => "https://social.heldscal.la/api/statuses/user_timeline/29191.atom",
554 "uri" => "https://social.heldscal.la/user/29191",
555 "host" => "social.heldscal.la",
556 "fqn" => user,
557 "bio" => "cofe",
558 "avatar" => %{
559 "type" => "Image",
560 "url" => [
561 %{
562 "href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg",
563 "mediaType" => "image/jpeg",
564 "type" => "Link"
565 }
566 ]
567 },
568 "subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}",
569 "ap_id" => nil
570 }
571
572 assert data == expected
573 end
574 end
575
576 describe "fetching a status by it's HTML url" do
577 test "it builds a missing status from an html url" do
578 capture_log(fn ->
579 url = "https://shitposter.club/notice/2827873"
580 {:ok, [activity]} = OStatus.fetch_activity_from_url(url)
581
582 assert activity.data["actor"] == "https://shitposter.club/user/1"
583
584 assert activity.data["object"] ==
585 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
586 end)
587 end
588
589 test "it works for atom notes, too" do
590 url = "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056"
591 {:ok, [activity]} = OStatus.fetch_activity_from_url(url)
592 assert activity.data["actor"] == "https://social.sakamoto.gq/users/eal"
593 assert activity.data["object"] == url
594 end
595 end
596
597 test "it doesn't add nil in the to field" do
598 incoming = File.read!("test/fixtures/nil_mention_entry.xml")
599 {:ok, [activity]} = OStatus.handle_incoming(incoming)
600
601 assert activity.data["to"] == [
602 "http://localhost:4001/users/atarifrosch@social.stopwatchingus-heidelberg.de/followers",
603 "https://www.w3.org/ns/activitystreams#Public"
604 ]
605 end
606
607 describe "is_representable?" do
608 test "Note objects are representable" do
609 note_activity = insert(:note_activity)
610
611 assert OStatus.is_representable?(note_activity)
612 end
613
614 test "Article objects are not representable" do
615 note_activity = insert(:note_activity)
616 note_object = Object.normalize(note_activity)
617
618 note_data =
619 note_object.data
620 |> Map.put("type", "Article")
621
622 Cachex.clear(:object_cache)
623
624 cs = Object.change(note_object, %{data: note_data})
625 {:ok, _article_object} = Repo.update(cs)
626
627 # the underlying object is now an Article instead of a note, so this should fail
628 refute OStatus.is_representable?(note_activity)
629 end
630 end
631 end