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