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