First
[anni] / test / support / http_request_mock.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 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("https://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("http://mastodon.sdf.org/.well-known/host-meta", _, _, _) do
436     {:ok,
437      %Tesla.Env{
438        status: 200,
439        body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta")
440      }}
441   end
442
443   def get("https://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(
452         "https://mastodon.sdf.org/.well-known/webfinger?resource=https://mastodon.sdf.org/users/snowdusk",
453         _,
454         _,
455         _
456       ) do
457     {:ok,
458      %Tesla.Env{
459        status: 200,
460        body: File.read!("test/fixtures/tesla_mock/snowdusk@sdf.org_host_meta.json")
461      }}
462   end
463
464   def get("http://mstdn.jp/.well-known/host-meta", _, _, _) do
465     {:ok,
466      %Tesla.Env{
467        status: 200,
468        body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta")
469      }}
470   end
471
472   def get("https://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/webfinger?resource=kpherox@mstdn.jp", _, _, _) do
481     {:ok,
482      %Tesla.Env{
483        status: 200,
484        body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
485      }}
486   end
487
488   def get("http://mamot.fr/.well-known/host-meta", _, _, _) do
489     {:ok,
490      %Tesla.Env{
491        status: 200,
492        body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta")
493      }}
494   end
495
496   def get("https://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("http://pawoo.net/.well-known/host-meta", _, _, _) do
505     {:ok,
506      %Tesla.Env{
507        status: 200,
508        body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
509      }}
510   end
511
512   def get("https://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(
521         "https://pawoo.net/.well-known/webfinger?resource=https://pawoo.net/users/pekorino",
522         _,
523         _,
524         _
525       ) do
526     {:ok,
527      %Tesla.Env{
528        status: 200,
529        body: File.read!("test/fixtures/tesla_mock/pekorino@pawoo.net_host_meta.json"),
530        headers: activitypub_object_headers()
531      }}
532   end
533
534   def get("http://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
535     {:ok,
536      %Tesla.Env{
537        status: 200,
538        body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta")
539      }}
540   end
541
542   def get("https://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("http://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do
551     {:ok,
552      %Tesla.Env{
553        status: 200,
554        body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta")
555      }}
556   end
557
558   def get("https://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(
567         "http://mastodon.example.org/@admin/99541947525187367",
568         _,
569         _,
570         _
571       ) do
572     {:ok,
573      %Tesla.Env{
574        status: 200,
575        body: File.read!("test/fixtures/mastodon-note-object.json"),
576        headers: activitypub_object_headers()
577      }}
578   end
579
580   def get("http://mastodon.example.org/@admin/99541947525187368", _, _, _) do
581     {:ok,
582      %Tesla.Env{
583        status: 404,
584        body: ""
585      }}
586   end
587
588   def get("https://shitposter.club/notice/7369654", _, _, _) do
589     {:ok,
590      %Tesla.Env{
591        status: 200,
592        body: File.read!("test/fixtures/tesla_mock/7369654.html")
593      }}
594   end
595
596   def get("https://mstdn.io/users/mayuutann", _, _, [{"accept", "application/activity+json"}]) do
597     {:ok,
598      %Tesla.Env{
599        status: 200,
600        body: File.read!("test/fixtures/tesla_mock/mayumayu.json"),
601        headers: activitypub_object_headers()
602      }}
603   end
604
605   def get(
606         "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
607         _,
608         _,
609         [{"accept", "application/activity+json"}]
610       ) do
611     {:ok,
612      %Tesla.Env{
613        status: 200,
614        body: File.read!("test/fixtures/tesla_mock/mayumayupost.json"),
615        headers: activitypub_object_headers()
616      }}
617   end
618
619   def get(url, _, _, [{"accept", "application/xrd+xml,application/jrd+json"}])
620       when url in [
621              "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
622              "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
623            ] do
624     {:ok,
625      %Tesla.Env{
626        status: 200,
627        body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
628      }}
629   end
630
631   def get(
632         "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
633         _,
634         _,
635         [{"accept", "application/xrd+xml,application/jrd+json"}]
636       ) do
637     {:ok,
638      %Tesla.Env{
639        status: 200,
640        body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
641      }}
642   end
643
644   def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
645     {:ok, %Tesla.Env{status: 200}}
646   end
647
648   def get(
649         "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
650         _,
651         _,
652         [{"accept", "application/xrd+xml,application/jrd+json"}]
653       ) do
654     {:ok,
655      %Tesla.Env{
656        status: 200,
657        body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
658      }}
659   end
660
661   def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
662     {:ok,
663      %Tesla.Env{
664        status: 200,
665        body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
666      }}
667   end
668
669   def get("https://shitposter.club/notice/4027863", _, _, _) do
670     {:ok,
671      %Tesla.Env{
672        status: 200,
673        body: File.read!("test/fixtures/tesla_mock/7369654.html")
674      }}
675   end
676
677   def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
678     {:ok,
679      %Tesla.Env{
680        status: 200,
681        body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
682      }}
683   end
684
685   def get(
686         "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
687         _,
688         _,
689         [{"accept", "application/xrd+xml,application/jrd+json"}]
690       ) do
691     {:ok,
692      %Tesla.Env{
693        status: 200,
694        body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
695      }}
696   end
697
698   def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
699     {:ok,
700      %Tesla.Env{
701        status: 200,
702        body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
703      }}
704   end
705
706   def get(
707         "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
708         _,
709         _,
710         [{"accept", "application/xrd+xml,application/jrd+json"}]
711       ) do
712     {:ok,
713      %Tesla.Env{
714        status: 200,
715        body:
716          File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
717      }}
718   end
719
720   def get(
721         "https://mastodon.social/.well-known/webfinger?resource=acct:not_found@mastodon.social",
722         _,
723         _,
724         [{"accept", "application/xrd+xml,application/jrd+json"}]
725       ) do
726     {:ok, %Tesla.Env{status: 404}}
727   end
728
729   def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
730     {:ok,
731      %Tesla.Env{
732        status: 200,
733        body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
734      }}
735   end
736
737   def get(
738         "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
739         _,
740         _,
741         [{"accept", "application/xrd+xml,application/jrd+json"}]
742       ) do
743     {:ok,
744      %Tesla.Env{
745        status: 200,
746        body:
747          File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
748      }}
749   end
750
751   def get(
752         "http://gs.example.org:4040/index.php/user/1",
753         _,
754         _,
755         [{"accept", "application/activity+json"}]
756       ) do
757     {:ok, %Tesla.Env{status: 406, body: ""}}
758   end
759
760   def get("https://squeet.me/.well-known/host-meta", _, _, _) do
761     {:ok,
762      %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
763   end
764
765   def get(
766         "https://squeet.me/xrd?uri=lain@squeet.me",
767         _,
768         _,
769         [{"accept", "application/xrd+xml,application/jrd+json"}]
770       ) do
771     {:ok,
772      %Tesla.Env{
773        status: 200,
774        body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
775      }}
776   end
777
778   def get(
779         "https://social.heldscal.la/.well-known/webfinger?resource=acct:shp@social.heldscal.la",
780         _,
781         _,
782         [{"accept", "application/xrd+xml,application/jrd+json"}]
783       ) do
784     {:ok,
785      %Tesla.Env{
786        status: 200,
787        body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml"),
788        headers: [{"content-type", "application/xrd+xml"}]
789      }}
790   end
791
792   def get(
793         "https://social.heldscal.la/.well-known/webfinger?resource=acct:invalid_content@social.heldscal.la",
794         _,
795         _,
796         [{"accept", "application/xrd+xml,application/jrd+json"}]
797       ) do
798     {:ok, %Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/jrd+json"}]}}
799   end
800
801   def get("https://framatube.org/.well-known/host-meta", _, _, _) do
802     {:ok,
803      %Tesla.Env{
804        status: 200,
805        body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
806      }}
807   end
808
809   def get(
810         "https://framatube.org/main/xrd?uri=acct:framasoft@framatube.org",
811         _,
812         _,
813         [{"accept", "application/xrd+xml,application/jrd+json"}]
814       ) do
815     {:ok,
816      %Tesla.Env{
817        status: 200,
818        headers: [{"content-type", "application/jrd+json"}],
819        body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
820      }}
821   end
822
823   def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
824     {:ok,
825      %Tesla.Env{
826        status: 200,
827        body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
828      }}
829   end
830
831   def get(
832         "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
833         _,
834         _,
835         [{"accept", "application/xrd+xml,application/jrd+json"}]
836       ) do
837     {:ok,
838      %Tesla.Env{
839        status: 200,
840        body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json"),
841        headers: activitypub_object_headers()
842      }}
843   end
844
845   def get("https://status.alpicola.com/.well-known/host-meta", _, _, _) do
846     {:ok,
847      %Tesla.Env{
848        status: 200,
849        body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
850      }}
851   end
852
853   def get("https://macgirvin.com/.well-known/host-meta", _, _, _) do
854     {:ok,
855      %Tesla.Env{
856        status: 200,
857        body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
858      }}
859   end
860
861   def get("https://gerzilla.de/.well-known/host-meta", _, _, _) do
862     {:ok,
863      %Tesla.Env{
864        status: 200,
865        body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
866      }}
867   end
868
869   def get(
870         "https://gerzilla.de/xrd/?uri=acct:kaniini@gerzilla.de",
871         _,
872         _,
873         [{"accept", "application/xrd+xml,application/jrd+json"}]
874       ) do
875     {:ok,
876      %Tesla.Env{
877        status: 200,
878        headers: [{"content-type", "application/jrd+json"}],
879        body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
880      }}
881   end
882
883   def get(
884         "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
885         _,
886         _,
887         _
888       ) do
889     {:ok,
890      %Tesla.Env{
891        status: 200,
892        body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
893      }}
894   end
895
896   def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
897     {:ok,
898      %Tesla.Env{
899        status: 200,
900        body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
901      }}
902   end
903
904   def get("https://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://mastodon.social/users/lambadalambda", _, _, _) do
913     {:ok,
914      %Tesla.Env{
915        status: 200,
916        body: File.read!("test/fixtures/lambadalambda.json"),
917        headers: activitypub_object_headers()
918      }}
919   end
920
921   def get("https://mastodon.social/users/lambadalambda/collections/featured", _, _, _) do
922     {:ok,
923      %Tesla.Env{
924        status: 200,
925        body:
926          File.read!("test/fixtures/users_mock/masto_featured.json")
927          |> String.replace("{{domain}}", "mastodon.social")
928          |> String.replace("{{nickname}}", "lambadalambda"),
929        headers: activitypub_object_headers()
930      }}
931   end
932
933   def get("https://apfed.club/channel/indio", _, _, _) do
934     {:ok,
935      %Tesla.Env{
936        status: 200,
937        body: File.read!("test/fixtures/tesla_mock/osada-user-indio.json"),
938        headers: activitypub_object_headers()
939      }}
940   end
941
942   def get("https://social.heldscal.la/user/23211", _, _, [{"accept", "application/activity+json"}]) do
943     {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
944   end
945
946   def get("http://example.com/ogp", _, _, _) do
947     {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
948   end
949
950   def get("https://example.com/ogp", _, _, _) do
951     {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
952   end
953
954   def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
955     {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
956   end
957
958   def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
959     {:ok,
960      %Tesla.Env{
961        status: 200,
962        body: File.read!("test/fixtures/users_mock/masto_closed_followers.json"),
963        headers: activitypub_object_headers()
964      }}
965   end
966
967   def get("http://localhost:4001/users/masto_closed/followers?page=1", _, _, _) do
968     {:ok,
969      %Tesla.Env{
970        status: 200,
971        body: File.read!("test/fixtures/users_mock/masto_closed_followers_page.json"),
972        headers: activitypub_object_headers()
973      }}
974   end
975
976   def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
977     {:ok,
978      %Tesla.Env{
979        status: 200,
980        body: File.read!("test/fixtures/users_mock/masto_closed_following.json"),
981        headers: activitypub_object_headers()
982      }}
983   end
984
985   def get("http://localhost:4001/users/masto_closed/following?page=1", _, _, _) do
986     {:ok,
987      %Tesla.Env{
988        status: 200,
989        body: File.read!("test/fixtures/users_mock/masto_closed_following_page.json"),
990        headers: activitypub_object_headers()
991      }}
992   end
993
994   def get("http://localhost:8080/followers/fuser3", _, _, _) do
995     {:ok,
996      %Tesla.Env{
997        status: 200,
998        body: File.read!("test/fixtures/users_mock/friendica_followers.json"),
999        headers: activitypub_object_headers()
1000      }}
1001   end
1002
1003   def get("http://localhost:8080/following/fuser3", _, _, _) do
1004     {:ok,
1005      %Tesla.Env{
1006        status: 200,
1007        body: File.read!("test/fixtures/users_mock/friendica_following.json"),
1008        headers: activitypub_object_headers()
1009      }}
1010   end
1011
1012   def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
1013     {:ok,
1014      %Tesla.Env{
1015        status: 200,
1016        body: File.read!("test/fixtures/users_mock/pleroma_followers.json"),
1017        headers: activitypub_object_headers()
1018      }}
1019   end
1020
1021   def get("http://localhost:4001/users/fuser2/following", _, _, _) do
1022     {:ok,
1023      %Tesla.Env{
1024        status: 200,
1025        body: File.read!("test/fixtures/users_mock/pleroma_following.json"),
1026        headers: activitypub_object_headers()
1027      }}
1028   end
1029
1030   def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
1031     {:ok,
1032      %Tesla.Env{
1033        status: 504,
1034        body: ""
1035      }}
1036   end
1037
1038   def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
1039     {:ok,
1040      %Tesla.Env{
1041        status: 504,
1042        body: ""
1043      }}
1044   end
1045
1046   def get("http://example.com/ogp-missing-data", _, _, _) do
1047     {:ok,
1048      %Tesla.Env{
1049        status: 200,
1050        body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
1051      }}
1052   end
1053
1054   def get("https://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("http://example.com/malformed", _, _, _) do
1063     {:ok,
1064      %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
1065   end
1066
1067   def get("http://example.com/empty", _, _, _) do
1068     {:ok, %Tesla.Env{status: 200, body: "hello"}}
1069   end
1070
1071   def get("http://404.site" <> _, _, _, _) do
1072     {:ok,
1073      %Tesla.Env{
1074        status: 404,
1075        body: ""
1076      }}
1077   end
1078
1079   def get("https://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("https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb", _, _, _) do
1375     {:ok,
1376      %Tesla.Env{
1377        status: 200,
1378        body: File.read!("test/fixtures/tesla_mock/gleasonator-AG3RzWfwEKKrY63qj2.json"),
1379        headers: activitypub_object_headers()
1380      }}
1381   end
1382
1383   def get("https://gleasonator.com/users/macgirvin", _, _, _) do
1384     {:ok,
1385      %Tesla.Env{
1386        status: 200,
1387        body: File.read!("test/fixtures/tesla_mock/macgirvin@gleasonator.com.json"),
1388        headers: activitypub_object_headers()
1389      }}
1390   end
1391
1392   def get("https://gleasonator.com/users/macgirvin/collections/featured", _, _, _) do
1393     {:ok,
1394      %Tesla.Env{
1395        status: 200,
1396        body:
1397          File.read!("test/fixtures/users_mock/masto_featured.json")
1398          |> String.replace("{{domain}}", "gleasonator.com")
1399          |> String.replace("{{nickname}}", "macgirvin"),
1400        headers: activitypub_object_headers()
1401      }}
1402   end
1403
1404   def get("https://mk.absturztau.be/users/8ozbzjs3o8", _, _, _) do
1405     {:ok,
1406      %Tesla.Env{
1407        status: 200,
1408        body: File.read!("test/fixtures/tesla_mock/mametsuko@mk.absturztau.be.json"),
1409        headers: activitypub_object_headers()
1410      }}
1411   end
1412
1413   def get("https://p.helene.moe/users/helene", _, _, _) do
1414     {:ok,
1415      %Tesla.Env{
1416        status: 200,
1417        body: File.read!("test/fixtures/tesla_mock/helene@p.helene.moe.json"),
1418        headers: activitypub_object_headers()
1419      }}
1420   end
1421
1422   def get("https://mk.absturztau.be/notes/93e7nm8wqg", _, _, _) do
1423     {:ok,
1424      %Tesla.Env{
1425        status: 200,
1426        body: File.read!("test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg.json"),
1427        headers: activitypub_object_headers()
1428      }}
1429   end
1430
1431   def get("https://mk.absturztau.be/notes/93e7nm8wqg/activity", _, _, _) do
1432     {:ok,
1433      %Tesla.Env{
1434        status: 200,
1435        body: File.read!("test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg-activity.json"),
1436        headers: activitypub_object_headers()
1437      }}
1438   end
1439
1440   def get("https://p.helene.moe/objects/fd5910ac-d9dc-412e-8d1d-914b203296c4", _, _, _) do
1441     {:ok,
1442      %Tesla.Env{
1443        status: 200,
1444        body: File.read!("test/fixtures/tesla_mock/p.helene.moe-AM7S6vZQmL6pI9TgPY.json"),
1445        headers: activitypub_object_headers()
1446      }}
1447   end
1448
1449   def get(url, query, body, headers) do
1450     {:error,
1451      "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
1452   end
1453
1454   # POST Requests
1455   #
1456
1457   def post(url, query \\ [], body \\ [], headers \\ [])
1458
1459   def post("https://relay.mastodon.host/inbox", _, _, _) do
1460     {:ok, %Tesla.Env{status: 200, body: ""}}
1461   end
1462
1463   def post("http://example.org/needs_refresh", _, _, _) do
1464     {:ok,
1465      %Tesla.Env{
1466        status: 200,
1467        body: ""
1468      }}
1469   end
1470
1471   def post("http://mastodon.example.org/inbox", _, _, _) do
1472     {:ok,
1473      %Tesla.Env{
1474        status: 200,
1475        body: ""
1476      }}
1477   end
1478
1479   def post("https://hubzilla.example.org/inbox", _, _, _) do
1480     {:ok,
1481      %Tesla.Env{
1482        status: 200,
1483        body: ""
1484      }}
1485   end
1486
1487   def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
1488     {:ok,
1489      %Tesla.Env{
1490        status: 200,
1491        body: ""
1492      }}
1493   end
1494
1495   def post("http://200.site" <> _, _, _, _) do
1496     {:ok,
1497      %Tesla.Env{
1498        status: 200,
1499        body: ""
1500      }}
1501   end
1502
1503   def post("http://connrefused.site" <> _, _, _, _) do
1504     {:error, :connrefused}
1505   end
1506
1507   def post("http://404.site" <> _, _, _, _) do
1508     {:ok,
1509      %Tesla.Env{
1510        status: 404,
1511        body: ""
1512      }}
1513   end
1514
1515   def post(url, query, body, headers) do
1516     {:error,
1517      "Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
1518   end
1519
1520   # Most of the rich media mocks are missing HEAD requests, so we just return 404.
1521   @rich_media_mocks [
1522     "https://example.com/ogp",
1523     "https://example.com/ogp-missing-data",
1524     "https://example.com/twitter-card"
1525   ]
1526   def head(url, _query, _body, _headers) when url in @rich_media_mocks do
1527     {:ok, %Tesla.Env{status: 404, body: ""}}
1528   end
1529
1530   def head(url, query, body, headers) do
1531     {:error,
1532      "Mock response not implemented for HEAD #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
1533   end
1534 end