implement Move activities (#45)
[akkoma] / test / support / http_request_mock.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule HttpRequestMock do
6 require Logger
7
8 def activitypub_object_headers, do: [{"content-type", "application/activity+json"}]
9
10 def request(
11 %Tesla.Env{
12 url: url,
13 method: method,
14 headers: headers,
15 query: query,
16 body: body
17 } = _env
18 ) do
19 with {:ok, res} <- apply(__MODULE__, method, [url, query, body, headers]) do
20 res
21 else
22 error ->
23 with {:error, message} <- error do
24 Logger.warn(to_string(message))
25 end
26
27 {_, _r} = error
28 end
29 end
30
31 # GET Requests
32 #
33 def get(url, query \\ [], body \\ [], headers \\ [])
34
35 def get("https://osada.macgirvin.com/channel/mike", _, _, _) do
36 {:ok,
37 %Tesla.Env{
38 status: 200,
39 body: File.read!("test/fixtures/tesla_mock/https___osada.macgirvin.com_channel_mike.json"),
40 headers: activitypub_object_headers()
41 }}
42 end
43
44 def get("https://shitposter.club/users/moonman", _, _, _) do
45 {:ok,
46 %Tesla.Env{
47 status: 200,
48 body: File.read!("test/fixtures/tesla_mock/moonman@shitposter.club.json"),
49 headers: activitypub_object_headers()
50 }}
51 end
52
53 def get("https://mastodon.social/users/emelie/statuses/101849165031453009", _, _, _) do
54 {:ok,
55 %Tesla.Env{
56 status: 200,
57 body: File.read!("test/fixtures/tesla_mock/status.emelie.json"),
58 headers: activitypub_object_headers()
59 }}
60 end
61
62 def get("https://mastodon.social/users/emelie/statuses/101849165031453404", _, _, _) do
63 {:ok,
64 %Tesla.Env{
65 status: 404,
66 body: ""
67 }}
68 end
69
70 def get("https://mastodon.social/users/emelie", _, _, _) do
71 {:ok,
72 %Tesla.Env{
73 status: 200,
74 body: File.read!("test/fixtures/tesla_mock/emelie.json"),
75 headers: activitypub_object_headers()
76 }}
77 end
78
79 def get("https://mastodon.social/users/not_found", _, _, _) do
80 {:ok, %Tesla.Env{status: 404}}
81 end
82
83 def get("https://mastodon.sdf.org/users/rinpatch", _, _, _) do
84 {:ok,
85 %Tesla.Env{
86 status: 200,
87 body: File.read!("test/fixtures/tesla_mock/rinpatch.json"),
88 headers: activitypub_object_headers()
89 }}
90 end
91
92 def get("https://mastodon.sdf.org/users/rinpatch/collections/featured", _, _, _) do
93 {:ok,
94 %Tesla.Env{
95 status: 200,
96 body:
97 File.read!("test/fixtures/users_mock/masto_featured.json")
98 |> String.replace("{{domain}}", "mastodon.sdf.org")
99 |> String.replace("{{nickname}}", "rinpatch"),
100 headers: [{"content-type", "application/activity+json"}]
101 }}
102 end
103
104 def get("https://patch.cx/objects/tesla_mock/poll_attachment", _, _, _) do
105 {:ok,
106 %Tesla.Env{
107 status: 200,
108 body: File.read!("test/fixtures/tesla_mock/poll_attachment.json"),
109 headers: activitypub_object_headers()
110 }}
111 end
112
113 def get(
114 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/emelie",
115 _,
116 _,
117 _
118 ) do
119 {:ok,
120 %Tesla.Env{
121 status: 200,
122 body: File.read!("test/fixtures/tesla_mock/webfinger_emelie.json"),
123 headers: activitypub_object_headers()
124 }}
125 end
126
127 def get(
128 "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",
129 _,
130 _,
131 [{"accept", "application/xrd+xml,application/jrd+json"}]
132 ) do
133 {:ok,
134 %Tesla.Env{
135 status: 200,
136 body: File.read!("test/fixtures/tesla_mock/mike@osada.macgirvin.com.json"),
137 headers: [{"content-type", "application/jrd+json"}]
138 }}
139 end
140
141 def get(
142 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
143 _,
144 _,
145 [{"accept", "application/xrd+xml,application/jrd+json"}]
146 ) do
147 {:ok,
148 %Tesla.Env{
149 status: 200,
150 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_29191.xml")
151 }}
152 end
153
154 def get(
155 "https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",
156 _,
157 _,
158 [{"accept", "application/xrd+xml,application/jrd+json"}]
159 ) do
160 {:ok,
161 %Tesla.Env{
162 status: 200,
163 body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml")
164 }}
165 end
166
167 def get(
168 "https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",
169 _,
170 _,
171 [{"accept", "application/xrd+xml,application/jrd+json"}]
172 ) do
173 {:ok,
174 %Tesla.Env{
175 status: 200,
176 body: File.read!("test/fixtures/tesla_mock/atarifrosch_webfinger.xml")
177 }}
178 end
179
180 def get(
181 "https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la",
182 _,
183 _,
184 [{"accept", "application/xrd+xml,application/jrd+json"}]
185 ) do
186 {:ok,
187 %Tesla.Env{
188 status: 200,
189 body: File.read!("test/fixtures/tesla_mock/nonexistant@social.heldscal.la.xml")
190 }}
191 end
192
193 def get(
194 "https://squeet.me/xrd/?uri=acct:lain@squeet.me",
195 _,
196 _,
197 [{"accept", "application/xrd+xml,application/jrd+json"}]
198 ) do
199 {:ok,
200 %Tesla.Env{
201 status: 200,
202 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml"),
203 headers: [{"content-type", "application/xrd+xml"}]
204 }}
205 end
206
207 def get(
208 "https://mst3k.interlinked.me/users/luciferMysticus",
209 _,
210 _,
211 [{"accept", "application/activity+json"}]
212 ) do
213 {:ok,
214 %Tesla.Env{
215 status: 200,
216 body: File.read!("test/fixtures/tesla_mock/lucifermysticus.json"),
217 headers: activitypub_object_headers()
218 }}
219 end
220
221 def get("https://prismo.news/@mxb", _, _, _) do
222 {:ok,
223 %Tesla.Env{
224 status: 200,
225 body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json"),
226 headers: activitypub_object_headers()
227 }}
228 end
229
230 def get(
231 "https://hubzilla.example.org/channel/kaniini",
232 _,
233 _,
234 [{"accept", "application/activity+json"}]
235 ) do
236 {:ok,
237 %Tesla.Env{
238 status: 200,
239 body: File.read!("test/fixtures/tesla_mock/kaniini@hubzilla.example.org.json"),
240 headers: activitypub_object_headers()
241 }}
242 end
243
244 def get("https://niu.moe/users/rye", _, _, [{"accept", "application/activity+json"}]) do
245 {:ok,
246 %Tesla.Env{
247 status: 200,
248 body: File.read!("test/fixtures/tesla_mock/rye.json"),
249 headers: activitypub_object_headers()
250 }}
251 end
252
253 def get("https://n1u.moe/users/rye", _, _, [{"accept", "application/activity+json"}]) do
254 {:ok,
255 %Tesla.Env{
256 status: 200,
257 body: File.read!("test/fixtures/tesla_mock/rye.json"),
258 headers: activitypub_object_headers()
259 }}
260 end
261
262 def get("http://mastodon.example.org/users/admin/statuses/100787282858396771", _, _, _) do
263 {:ok,
264 %Tesla.Env{
265 status: 200,
266 body:
267 File.read!(
268 "test/fixtures/tesla_mock/http___mastodon.example.org_users_admin_status_1234.json"
269 )
270 }}
271 end
272
273 def get("https://puckipedia.com/", _, _, [{"accept", "application/activity+json"}]) do
274 {:ok,
275 %Tesla.Env{
276 status: 200,
277 body: File.read!("test/fixtures/tesla_mock/puckipedia.com.json"),
278 headers: activitypub_object_headers()
279 }}
280 end
281
282 def get("https://peertube.moe/accounts/7even", _, _, _) do
283 {:ok,
284 %Tesla.Env{
285 status: 200,
286 body: File.read!("test/fixtures/tesla_mock/7even.json"),
287 headers: activitypub_object_headers()
288 }}
289 end
290
291 def get("https://peertube.stream/accounts/createurs", _, _, _) do
292 {:ok,
293 %Tesla.Env{
294 status: 200,
295 body: File.read!("test/fixtures/peertube/actor-person.json"),
296 headers: activitypub_object_headers()
297 }}
298 end
299
300 def get("https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3", _, _, _) do
301 {:ok,
302 %Tesla.Env{
303 status: 200,
304 body: File.read!("test/fixtures/tesla_mock/peertube.moe-vid.json"),
305 headers: activitypub_object_headers()
306 }}
307 end
308
309 def get("https://framatube.org/accounts/framasoft", _, _, _) do
310 {:ok,
311 %Tesla.Env{
312 status: 200,
313 body: File.read!("test/fixtures/tesla_mock/https___framatube.org_accounts_framasoft.json"),
314 headers: activitypub_object_headers()
315 }}
316 end
317
318 def get("https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206", _, _, _) do
319 {:ok,
320 %Tesla.Env{
321 status: 200,
322 body: File.read!("test/fixtures/tesla_mock/framatube.org-video.json"),
323 headers: activitypub_object_headers()
324 }}
325 end
326
327 def get("https://peertube.social/accounts/craigmaloney", _, _, _) do
328 {:ok,
329 %Tesla.Env{
330 status: 200,
331 body: File.read!("test/fixtures/tesla_mock/craigmaloney.json"),
332 headers: activitypub_object_headers()
333 }}
334 end
335
336 def get("https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe", _, _, _) do
337 {:ok,
338 %Tesla.Env{
339 status: 200,
340 body: File.read!("test/fixtures/tesla_mock/peertube-social.json"),
341 headers: activitypub_object_headers()
342 }}
343 end
344
345 def get("https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39", _, _, [
346 {"accept", "application/activity+json"}
347 ]) do
348 {:ok,
349 %Tesla.Env{
350 status: 200,
351 body: File.read!("test/fixtures/tesla_mock/mobilizon.org-event.json"),
352 headers: activitypub_object_headers()
353 }}
354 end
355
356 def get("https://mobilizon.org/@tcit", _, _, [{"accept", "application/activity+json"}]) do
357 {:ok,
358 %Tesla.Env{
359 status: 200,
360 body: File.read!("test/fixtures/tesla_mock/mobilizon.org-user.json"),
361 headers: activitypub_object_headers()
362 }}
363 end
364
365 def get("https://baptiste.gelez.xyz/@/BaptisteGelez", _, _, _) do
366 {:ok,
367 %Tesla.Env{
368 status: 200,
369 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json"),
370 headers: activitypub_object_headers()
371 }}
372 end
373
374 def get("https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/", _, _, _) do
375 {:ok,
376 %Tesla.Env{
377 status: 200,
378 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json"),
379 headers: activitypub_object_headers()
380 }}
381 end
382
383 def get("https://wedistribute.org/wp-json/pterotype/v1/object/85810", _, _, _) do
384 {:ok,
385 %Tesla.Env{
386 status: 200,
387 body: File.read!("test/fixtures/tesla_mock/wedistribute-article.json"),
388 headers: activitypub_object_headers()
389 }}
390 end
391
392 def get("https://wedistribute.org/wp-json/pterotype/v1/actor/-blog", _, _, _) do
393 {:ok,
394 %Tesla.Env{
395 status: 200,
396 body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json"),
397 headers: activitypub_object_headers()
398 }}
399 end
400
401 def get("http://mastodon.example.org/users/admin", _, _, _) do
402 {:ok,
403 %Tesla.Env{
404 status: 200,
405 body: File.read!("test/fixtures/tesla_mock/admin@mastdon.example.org.json"),
406 headers: activitypub_object_headers()
407 }}
408 end
409
410 def get("http://mastodon.example.org/users/relay", _, _, [
411 {"accept", "application/activity+json"}
412 ]) do
413 {:ok,
414 %Tesla.Env{
415 status: 200,
416 body: File.read!("test/fixtures/tesla_mock/relay@mastdon.example.org.json"),
417 headers: activitypub_object_headers()
418 }}
419 end
420
421 def get("http://mastodon.example.org/users/gargron", _, _, [
422 {"accept", "application/activity+json"}
423 ]) do
424 {:error, :nxdomain}
425 end
426
427 def get("http://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
428 {:ok,
429 %Tesla.Env{
430 status: 404,
431 body: ""
432 }}
433 end
434
435 def get("https://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
436 {:ok,
437 %Tesla.Env{
438 status: 404,
439 body: ""
440 }}
441 end
442
443 def get("http://mastodon.sdf.org/.well-known/host-meta", _, _, _) do
444 {:ok,
445 %Tesla.Env{
446 status: 200,
447 body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta")
448 }}
449 end
450
451 def get("https://mastodon.sdf.org/.well-known/host-meta", _, _, _) do
452 {:ok,
453 %Tesla.Env{
454 status: 200,
455 body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta")
456 }}
457 end
458
459 def get(
460 "https://mastodon.sdf.org/.well-known/webfinger?resource=https://mastodon.sdf.org/users/snowdusk",
461 _,
462 _,
463 _
464 ) do
465 {:ok,
466 %Tesla.Env{
467 status: 200,
468 body: File.read!("test/fixtures/tesla_mock/snowdusk@sdf.org_host_meta.json")
469 }}
470 end
471
472 def get("http://mstdn.jp/.well-known/host-meta", _, _, _) do
473 {:ok,
474 %Tesla.Env{
475 status: 200,
476 body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta")
477 }}
478 end
479
480 def get("https://mstdn.jp/.well-known/host-meta", _, _, _) do
481 {:ok,
482 %Tesla.Env{
483 status: 200,
484 body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta")
485 }}
486 end
487
488 def get("https://mstdn.jp/.well-known/webfinger?resource=kpherox@mstdn.jp", _, _, _) do
489 {:ok,
490 %Tesla.Env{
491 status: 200,
492 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
493 }}
494 end
495
496 def get("http://mamot.fr/.well-known/host-meta", _, _, _) do
497 {:ok,
498 %Tesla.Env{
499 status: 200,
500 body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta")
501 }}
502 end
503
504 def get("https://mamot.fr/.well-known/host-meta", _, _, _) do
505 {:ok,
506 %Tesla.Env{
507 status: 200,
508 body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta")
509 }}
510 end
511
512 def get("http://pawoo.net/.well-known/host-meta", _, _, _) do
513 {:ok,
514 %Tesla.Env{
515 status: 200,
516 body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
517 }}
518 end
519
520 def get("https://pawoo.net/.well-known/host-meta", _, _, _) do
521 {:ok,
522 %Tesla.Env{
523 status: 200,
524 body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
525 }}
526 end
527
528 def get(
529 "https://pawoo.net/.well-known/webfinger?resource=https://pawoo.net/users/pekorino",
530 _,
531 _,
532 _
533 ) do
534 {:ok,
535 %Tesla.Env{
536 status: 200,
537 body: File.read!("test/fixtures/tesla_mock/pekorino@pawoo.net_host_meta.json"),
538 headers: activitypub_object_headers()
539 }}
540 end
541
542 def get("http://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
543 {:ok,
544 %Tesla.Env{
545 status: 200,
546 body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta")
547 }}
548 end
549
550 def get("https://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
551 {:ok,
552 %Tesla.Env{
553 status: 200,
554 body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta")
555 }}
556 end
557
558 def get("http://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do
559 {:ok,
560 %Tesla.Env{
561 status: 200,
562 body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta")
563 }}
564 end
565
566 def get("https://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do
567 {:ok,
568 %Tesla.Env{
569 status: 200,
570 body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta")
571 }}
572 end
573
574 def get(
575 "http://mastodon.example.org/@admin/99541947525187367",
576 _,
577 _,
578 _
579 ) do
580 {:ok,
581 %Tesla.Env{
582 status: 200,
583 body: File.read!("test/fixtures/mastodon-note-object.json"),
584 headers: activitypub_object_headers()
585 }}
586 end
587
588 def get("http://mastodon.example.org/@admin/99541947525187368", _, _, _) do
589 {:ok,
590 %Tesla.Env{
591 status: 404,
592 body: ""
593 }}
594 end
595
596 def get("https://shitposter.club/notice/7369654", _, _, _) do
597 {:ok,
598 %Tesla.Env{
599 status: 200,
600 body: File.read!("test/fixtures/tesla_mock/7369654.html")
601 }}
602 end
603
604 def get("https://mstdn.io/users/mayuutann", _, _, [{"accept", "application/activity+json"}]) do
605 {:ok,
606 %Tesla.Env{
607 status: 200,
608 body: File.read!("test/fixtures/tesla_mock/mayumayu.json"),
609 headers: activitypub_object_headers()
610 }}
611 end
612
613 def get(
614 "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
615 _,
616 _,
617 [{"accept", "application/activity+json"}]
618 ) do
619 {:ok,
620 %Tesla.Env{
621 status: 200,
622 body: File.read!("test/fixtures/tesla_mock/mayumayupost.json"),
623 headers: activitypub_object_headers()
624 }}
625 end
626
627 def get(url, _, _, [{"accept", "application/xrd+xml,application/jrd+json"}])
628 when url in [
629 "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
630 "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
631 ] do
632 {:ok,
633 %Tesla.Env{
634 status: 200,
635 body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
636 }}
637 end
638
639 def get(
640 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
641 _,
642 _,
643 [{"accept", "application/xrd+xml,application/jrd+json"}]
644 ) do
645 {:ok,
646 %Tesla.Env{
647 status: 200,
648 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
649 }}
650 end
651
652 def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
653 {:ok, %Tesla.Env{status: 200}}
654 end
655
656 def get(
657 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
658 _,
659 _,
660 [{"accept", "application/xrd+xml,application/jrd+json"}]
661 ) do
662 {:ok,
663 %Tesla.Env{
664 status: 200,
665 body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
666 }}
667 end
668
669 def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
670 {:ok,
671 %Tesla.Env{
672 status: 200,
673 body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
674 }}
675 end
676
677 def get("https://shitposter.club/notice/4027863", _, _, _) do
678 {:ok,
679 %Tesla.Env{
680 status: 200,
681 body: File.read!("test/fixtures/tesla_mock/7369654.html")
682 }}
683 end
684
685 def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
686 {:ok,
687 %Tesla.Env{
688 status: 200,
689 body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
690 }}
691 end
692
693 def get(
694 "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
695 _,
696 _,
697 [{"accept", "application/xrd+xml,application/jrd+json"}]
698 ) do
699 {:ok,
700 %Tesla.Env{
701 status: 200,
702 body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
703 }}
704 end
705
706 def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
707 {:ok,
708 %Tesla.Env{
709 status: 200,
710 body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
711 }}
712 end
713
714 def get(
715 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
716 _,
717 _,
718 [{"accept", "application/xrd+xml,application/jrd+json"}]
719 ) do
720 {:ok,
721 %Tesla.Env{
722 status: 200,
723 body:
724 File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
725 }}
726 end
727
728 def get(
729 "https://mastodon.social/.well-known/webfinger?resource=acct:not_found@mastodon.social",
730 _,
731 _,
732 [{"accept", "application/xrd+xml,application/jrd+json"}]
733 ) do
734 {:ok, %Tesla.Env{status: 404}}
735 end
736
737 def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
738 {:ok,
739 %Tesla.Env{
740 status: 200,
741 body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
742 }}
743 end
744
745 def get(
746 "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
747 _,
748 _,
749 [{"accept", "application/xrd+xml,application/jrd+json"}]
750 ) do
751 {:ok,
752 %Tesla.Env{
753 status: 200,
754 body:
755 File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
756 }}
757 end
758
759 def get(
760 "http://gs.example.org:4040/index.php/user/1",
761 _,
762 _,
763 [{"accept", "application/activity+json"}]
764 ) do
765 {:ok, %Tesla.Env{status: 406, body: ""}}
766 end
767
768 def get("http://squeet.me/.well-known/host-meta", _, _, _) do
769 {:ok,
770 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
771 end
772
773 def get(
774 "https://squeet.me/xrd?uri=lain@squeet.me",
775 _,
776 _,
777 [{"accept", "application/xrd+xml,application/jrd+json"}]
778 ) do
779 {:ok,
780 %Tesla.Env{
781 status: 200,
782 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
783 }}
784 end
785
786 def get(
787 "https://social.heldscal.la/.well-known/webfinger?resource=acct:shp@social.heldscal.la",
788 _,
789 _,
790 [{"accept", "application/xrd+xml,application/jrd+json"}]
791 ) do
792 {:ok,
793 %Tesla.Env{
794 status: 200,
795 body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml"),
796 headers: [{"content-type", "application/xrd+xml"}]
797 }}
798 end
799
800 def get(
801 "https://social.heldscal.la/.well-known/webfinger?resource=acct:invalid_content@social.heldscal.la",
802 _,
803 _,
804 [{"accept", "application/xrd+xml,application/jrd+json"}]
805 ) do
806 {:ok, %Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/jrd+json"}]}}
807 end
808
809 def get("http://framatube.org/.well-known/host-meta", _, _, _) do
810 {:ok,
811 %Tesla.Env{
812 status: 200,
813 body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
814 }}
815 end
816
817 def get(
818 "http://framatube.org/main/xrd?uri=acct:framasoft@framatube.org",
819 _,
820 _,
821 [{"accept", "application/xrd+xml,application/jrd+json"}]
822 ) do
823 {:ok,
824 %Tesla.Env{
825 status: 200,
826 headers: [{"content-type", "application/jrd+json"}],
827 body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
828 }}
829 end
830
831 def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
832 {:ok,
833 %Tesla.Env{
834 status: 200,
835 body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
836 }}
837 end
838
839 def get(
840 "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
841 _,
842 _,
843 [{"accept", "application/xrd+xml,application/jrd+json"}]
844 ) do
845 {:ok,
846 %Tesla.Env{
847 status: 200,
848 body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json"),
849 headers: activitypub_object_headers()
850 }}
851 end
852
853 def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
854 {:ok,
855 %Tesla.Env{
856 status: 200,
857 body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
858 }}
859 end
860
861 def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
862 {:ok,
863 %Tesla.Env{
864 status: 200,
865 body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
866 }}
867 end
868
869 def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
870 {:ok,
871 %Tesla.Env{
872 status: 200,
873 body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
874 }}
875 end
876
877 def get(
878 "https://gerzilla.de/xrd/?uri=acct:kaniini@gerzilla.de",
879 _,
880 _,
881 [{"accept", "application/xrd+xml,application/jrd+json"}]
882 ) do
883 {:ok,
884 %Tesla.Env{
885 status: 200,
886 headers: [{"content-type", "application/jrd+json"}],
887 body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
888 }}
889 end
890
891 def get(
892 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
893 _,
894 _,
895 _
896 ) do
897 {:ok,
898 %Tesla.Env{
899 status: 200,
900 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
901 }}
902 end
903
904 def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
905 {:ok,
906 %Tesla.Env{
907 status: 200,
908 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
909 }}
910 end
911
912 def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
913 {:ok,
914 %Tesla.Env{
915 status: 200,
916 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
917 }}
918 end
919
920 def get("https://mastodon.social/users/lambadalambda", _, _, _) do
921 {:ok,
922 %Tesla.Env{
923 status: 200,
924 body: File.read!("test/fixtures/lambadalambda.json"),
925 headers: activitypub_object_headers()
926 }}
927 end
928
929 def get("https://mastodon.social/users/lambadalambda/collections/featured", _, _, _) do
930 {:ok,
931 %Tesla.Env{
932 status: 200,
933 body:
934 File.read!("test/fixtures/users_mock/masto_featured.json")
935 |> String.replace("{{domain}}", "mastodon.social")
936 |> String.replace("{{nickname}}", "lambadalambda"),
937 headers: activitypub_object_headers()
938 }}
939 end
940
941 def get("https://apfed.club/channel/indio", _, _, _) do
942 {:ok,
943 %Tesla.Env{
944 status: 200,
945 body: File.read!("test/fixtures/tesla_mock/osada-user-indio.json"),
946 headers: activitypub_object_headers()
947 }}
948 end
949
950 def get("https://social.heldscal.la/user/23211", _, _, [{"accept", "application/activity+json"}]) do
951 {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
952 end
953
954 def get("http://example.com/ogp", _, _, _) do
955 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
956 end
957
958 def get("https://example.com/ogp", _, _, _) do
959 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
960 end
961
962 def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
963 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
964 end
965
966 def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
967 {:ok,
968 %Tesla.Env{
969 status: 200,
970 body: File.read!("test/fixtures/users_mock/masto_closed_followers.json"),
971 headers: activitypub_object_headers()
972 }}
973 end
974
975 def get("http://localhost:4001/users/masto_closed/followers?page=1", _, _, _) do
976 {:ok,
977 %Tesla.Env{
978 status: 200,
979 body: File.read!("test/fixtures/users_mock/masto_closed_followers_page.json"),
980 headers: activitypub_object_headers()
981 }}
982 end
983
984 def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
985 {:ok,
986 %Tesla.Env{
987 status: 200,
988 body: File.read!("test/fixtures/users_mock/masto_closed_following.json"),
989 headers: activitypub_object_headers()
990 }}
991 end
992
993 def get("http://localhost:4001/users/masto_closed/following?page=1", _, _, _) do
994 {:ok,
995 %Tesla.Env{
996 status: 200,
997 body: File.read!("test/fixtures/users_mock/masto_closed_following_page.json"),
998 headers: activitypub_object_headers()
999 }}
1000 end
1001
1002 def get("http://localhost:8080/followers/fuser3", _, _, _) do
1003 {:ok,
1004 %Tesla.Env{
1005 status: 200,
1006 body: File.read!("test/fixtures/users_mock/friendica_followers.json"),
1007 headers: activitypub_object_headers()
1008 }}
1009 end
1010
1011 def get("http://localhost:8080/following/fuser3", _, _, _) do
1012 {:ok,
1013 %Tesla.Env{
1014 status: 200,
1015 body: File.read!("test/fixtures/users_mock/friendica_following.json"),
1016 headers: activitypub_object_headers()
1017 }}
1018 end
1019
1020 def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
1021 {:ok,
1022 %Tesla.Env{
1023 status: 200,
1024 body: File.read!("test/fixtures/users_mock/pleroma_followers.json"),
1025 headers: activitypub_object_headers()
1026 }}
1027 end
1028
1029 def get("http://localhost:4001/users/fuser2/following", _, _, _) do
1030 {:ok,
1031 %Tesla.Env{
1032 status: 200,
1033 body: File.read!("test/fixtures/users_mock/pleroma_following.json"),
1034 headers: activitypub_object_headers()
1035 }}
1036 end
1037
1038 def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
1039 {:ok,
1040 %Tesla.Env{
1041 status: 504,
1042 body: ""
1043 }}
1044 end
1045
1046 def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
1047 {:ok,
1048 %Tesla.Env{
1049 status: 504,
1050 body: ""
1051 }}
1052 end
1053
1054 def get("http://example.com/ogp-missing-data", _, _, _) do
1055 {:ok,
1056 %Tesla.Env{
1057 status: 200,
1058 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
1059 }}
1060 end
1061
1062 def get("https://example.com/ogp-missing-data", _, _, _) do
1063 {:ok,
1064 %Tesla.Env{
1065 status: 200,
1066 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
1067 }}
1068 end
1069
1070 def get("http://example.com/malformed", _, _, _) do
1071 {:ok,
1072 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
1073 end
1074
1075 def get("http://example.com/empty", _, _, _) do
1076 {:ok, %Tesla.Env{status: 200, body: "hello"}}
1077 end
1078
1079 def get("http://404.site" <> _, _, _, _) do
1080 {:ok,
1081 %Tesla.Env{
1082 status: 404,
1083 body: ""
1084 }}
1085 end
1086
1087 def get(
1088 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=acct:lain@zetsubou.xn--q9jyb4c",
1089 _,
1090 _,
1091 [{"accept", "application/xrd+xml,application/jrd+json"}]
1092 ) do
1093 {:ok,
1094 %Tesla.Env{
1095 status: 200,
1096 body: File.read!("test/fixtures/lain.xml"),
1097 headers: [{"content-type", "application/xrd+xml"}]
1098 }}
1099 end
1100
1101 def get(
1102 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=acct:https://zetsubou.xn--q9jyb4c/users/lain",
1103 _,
1104 _,
1105 [{"accept", "application/xrd+xml,application/jrd+json"}]
1106 ) do
1107 {:ok,
1108 %Tesla.Env{
1109 status: 200,
1110 body: File.read!("test/fixtures/lain.xml"),
1111 headers: [{"content-type", "application/xrd+xml"}]
1112 }}
1113 end
1114
1115 def get("http://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
1116 {:ok,
1117 %Tesla.Env{
1118 status: 200,
1119 body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
1120 }}
1121 end
1122
1123 def get(
1124 "https://zetsubou.xn--q9jyb4c/.well-known/host-meta",
1125 _,
1126 _,
1127 _
1128 ) do
1129 {:ok,
1130 %Tesla.Env{
1131 status: 200,
1132 body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
1133 }}
1134 end
1135
1136 def get("http://lm.kazv.moe/.well-known/host-meta", _, _, _) do
1137 {:ok,
1138 %Tesla.Env{
1139 status: 200,
1140 body: File.read!("test/fixtures/tesla_mock/lm.kazv.moe_host_meta")
1141 }}
1142 end
1143
1144 def get("https://lm.kazv.moe/.well-known/host-meta", _, _, _) do
1145 {:ok,
1146 %Tesla.Env{
1147 status: 200,
1148 body: File.read!("test/fixtures/tesla_mock/lm.kazv.moe_host_meta")
1149 }}
1150 end
1151
1152 def get(
1153 "https://lm.kazv.moe/.well-known/webfinger?resource=acct:mewmew@lm.kazv.moe",
1154 _,
1155 _,
1156 [{"accept", "application/xrd+xml,application/jrd+json"}]
1157 ) do
1158 {:ok,
1159 %Tesla.Env{
1160 status: 200,
1161 body: File.read!("test/fixtures/tesla_mock/https___lm.kazv.moe_users_mewmew.xml"),
1162 headers: [{"content-type", "application/xrd+xml"}]
1163 }}
1164 end
1165
1166 def get("https://lm.kazv.moe/users/mewmew", _, _, _) do
1167 {:ok,
1168 %Tesla.Env{
1169 status: 200,
1170 body: File.read!("test/fixtures/tesla_mock/mewmew@lm.kazv.moe.json"),
1171 headers: activitypub_object_headers()
1172 }}
1173 end
1174
1175 def get("https://lm.kazv.moe/users/mewmew/collections/featured", _, _, _) do
1176 {:ok,
1177 %Tesla.Env{
1178 status: 200,
1179 body:
1180 File.read!("test/fixtures/users_mock/masto_featured.json")
1181 |> String.replace("{{domain}}", "lm.kazv.moe")
1182 |> String.replace("{{nickname}}", "mewmew"),
1183 headers: [{"content-type", "application/activity+json"}]
1184 }}
1185 end
1186
1187 def get("https://info.pleroma.site/activity.json", _, _, [
1188 {"accept", "application/activity+json"}
1189 ]) do
1190 {:ok,
1191 %Tesla.Env{
1192 status: 200,
1193 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity.json"),
1194 headers: activitypub_object_headers()
1195 }}
1196 end
1197
1198 def get("https://info.pleroma.site/activity.json", _, _, _) do
1199 {:ok, %Tesla.Env{status: 404, body: ""}}
1200 end
1201
1202 def get("https://info.pleroma.site/activity2.json", _, _, [
1203 {"accept", "application/activity+json"}
1204 ]) do
1205 {:ok,
1206 %Tesla.Env{
1207 status: 200,
1208 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json"),
1209 headers: activitypub_object_headers()
1210 }}
1211 end
1212
1213 def get("https://info.pleroma.site/activity2.json", _, _, _) do
1214 {:ok, %Tesla.Env{status: 404, body: ""}}
1215 end
1216
1217 def get("https://info.pleroma.site/activity3.json", _, _, [
1218 {"accept", "application/activity+json"}
1219 ]) do
1220 {:ok,
1221 %Tesla.Env{
1222 status: 200,
1223 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json"),
1224 headers: activitypub_object_headers()
1225 }}
1226 end
1227
1228 def get("https://info.pleroma.site/activity3.json", _, _, _) do
1229 {:ok, %Tesla.Env{status: 404, body: ""}}
1230 end
1231
1232 def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp", _, _, _) do
1233 {:ok,
1234 %Tesla.Env{
1235 status: 200,
1236 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml"),
1237 headers: [{"content-type", "application/xrd+xml"}]
1238 }}
1239 end
1240
1241 def get("https://10.111.10.1/notice/9kCP7V", _, _, _) do
1242 {:ok, %Tesla.Env{status: 200, body: ""}}
1243 end
1244
1245 def get("https://172.16.32.40/notice/9kCP7V", _, _, _) do
1246 {:ok, %Tesla.Env{status: 200, body: ""}}
1247 end
1248
1249 def get("https://192.168.10.40/notice/9kCP7V", _, _, _) do
1250 {:ok, %Tesla.Env{status: 200, body: ""}}
1251 end
1252
1253 def get("https://www.patreon.com/posts/mastodon-2-9-and-28121681", _, _, _) do
1254 {:ok, %Tesla.Env{status: 200, body: ""}}
1255 end
1256
1257 def get("http://mastodon.example.org/@admin/99541947525187367", _, _, _) do
1258 {:ok,
1259 %Tesla.Env{
1260 status: 200,
1261 body: File.read!("test/fixtures/mastodon-post-activity.json"),
1262 headers: activitypub_object_headers()
1263 }}
1264 end
1265
1266 def get("https://info.pleroma.site/activity4.json", _, _, _) do
1267 {:ok, %Tesla.Env{status: 500, body: "Error occurred"}}
1268 end
1269
1270 def get("http://example.com/rel_me/anchor", _, _, _) do
1271 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}}
1272 end
1273
1274 def get("http://example.com/rel_me/anchor_nofollow", _, _, _) do
1275 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}}
1276 end
1277
1278 def get("http://example.com/rel_me/link", _, _, _) do
1279 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}}
1280 end
1281
1282 def get("http://example.com/rel_me/null", _, _, _) do
1283 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}}
1284 end
1285
1286 def get("https://skippers-bin.com/notes/7x9tmrp97i", _, _, _) do
1287 {:ok,
1288 %Tesla.Env{
1289 status: 200,
1290 body: File.read!("test/fixtures/tesla_mock/misskey_poll_no_end_date.json"),
1291 headers: activitypub_object_headers()
1292 }}
1293 end
1294
1295 def get("https://example.org/emoji/firedfox.png", _, _, _) do
1296 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/image.jpg")}}
1297 end
1298
1299 def get("https://skippers-bin.com/users/7v1w1r8ce6", _, _, _) do
1300 {:ok,
1301 %Tesla.Env{
1302 status: 200,
1303 body: File.read!("test/fixtures/tesla_mock/sjw.json"),
1304 headers: activitypub_object_headers()
1305 }}
1306 end
1307
1308 def get("https://patch.cx/users/rin", _, _, _) do
1309 {:ok,
1310 %Tesla.Env{
1311 status: 200,
1312 body: File.read!("test/fixtures/tesla_mock/rin.json"),
1313 headers: activitypub_object_headers()
1314 }}
1315 end
1316
1317 def get(
1318 "https://channels.tests.funkwhale.audio/federation/music/uploads/42342395-0208-4fee-a38d-259a6dae0871",
1319 _,
1320 _,
1321 _
1322 ) do
1323 {:ok,
1324 %Tesla.Env{
1325 status: 200,
1326 body: File.read!("test/fixtures/tesla_mock/funkwhale_audio.json"),
1327 headers: activitypub_object_headers()
1328 }}
1329 end
1330
1331 def get("https://channels.tests.funkwhale.audio/federation/actors/compositions", _, _, _) do
1332 {:ok,
1333 %Tesla.Env{
1334 status: 200,
1335 body: File.read!("test/fixtures/tesla_mock/funkwhale_channel.json"),
1336 headers: activitypub_object_headers()
1337 }}
1338 end
1339
1340 def get("http://example.com/rel_me/error", _, _, _) do
1341 {:ok, %Tesla.Env{status: 404, body: ""}}
1342 end
1343
1344 def get("https://relay.mastodon.host/actor", _, _, _) do
1345 {:ok,
1346 %Tesla.Env{
1347 status: 200,
1348 body: File.read!("test/fixtures/relay/relay.json"),
1349 headers: activitypub_object_headers()
1350 }}
1351 end
1352
1353 def get("http://localhost:4001/", _, "", [{"accept", "text/html"}]) do
1354 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/7369654.html")}}
1355 end
1356
1357 def get("https://osada.macgirvin.com/", _, "", [{"accept", "text/html"}]) do
1358 {:ok,
1359 %Tesla.Env{
1360 status: 200,
1361 body: File.read!("test/fixtures/tesla_mock/https___osada.macgirvin.com.html")
1362 }}
1363 end
1364
1365 def get("https://patch.cx/objects/a399c28e-c821-4820-bc3e-4afeb044c16f", _, _, _) do
1366 {:ok,
1367 %Tesla.Env{
1368 status: 200,
1369 body: File.read!("test/fixtures/tesla_mock/emoji-in-summary.json"),
1370 headers: activitypub_object_headers()
1371 }}
1372 end
1373
1374 def get(url, query, body, headers) do
1375 {:error,
1376 "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
1377 end
1378
1379 # POST Requests
1380 #
1381
1382 def post(url, query \\ [], body \\ [], headers \\ [])
1383
1384 def post("https://relay.mastodon.host/inbox", _, _, _) do
1385 {:ok, %Tesla.Env{status: 200, body: ""}}
1386 end
1387
1388 def post("http://example.org/needs_refresh", _, _, _) do
1389 {:ok,
1390 %Tesla.Env{
1391 status: 200,
1392 body: ""
1393 }}
1394 end
1395
1396 def post("http://mastodon.example.org/inbox", _, _, _) do
1397 {:ok,
1398 %Tesla.Env{
1399 status: 200,
1400 body: ""
1401 }}
1402 end
1403
1404 def post("https://hubzilla.example.org/inbox", _, _, _) do
1405 {:ok,
1406 %Tesla.Env{
1407 status: 200,
1408 body: ""
1409 }}
1410 end
1411
1412 def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
1413 {:ok,
1414 %Tesla.Env{
1415 status: 200,
1416 body: ""
1417 }}
1418 end
1419
1420 def post("http://200.site" <> _, _, _, _) do
1421 {:ok,
1422 %Tesla.Env{
1423 status: 200,
1424 body: ""
1425 }}
1426 end
1427
1428 def post("http://connrefused.site" <> _, _, _, _) do
1429 {:error, :connrefused}
1430 end
1431
1432 def post("http://404.site" <> _, _, _, _) do
1433 {:ok,
1434 %Tesla.Env{
1435 status: 404,
1436 body: ""
1437 }}
1438 end
1439
1440 def post(url, query, body, headers) do
1441 {:error,
1442 "Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
1443 end
1444
1445 # Most of the rich media mocks are missing HEAD requests, so we just return 404.
1446 @rich_media_mocks [
1447 "https://example.com/ogp",
1448 "https://example.com/ogp-missing-data",
1449 "https://example.com/twitter-card"
1450 ]
1451 def head(url, _query, _body, _headers) when url in @rich_media_mocks do
1452 {:ok, %Tesla.Env{status: 404, body: ""}}
1453 end
1454
1455 def head(url, query, body, headers) do
1456 {:error,
1457 "Mock response not implemented for HEAD #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
1458 end
1459 end