1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule HttpRequestMock do
17 with {:ok, res} <- apply(__MODULE__, method, [url, query, body, headers]) do
21 with {:error, message} <- error do
31 def get(url, query \\ [], body \\ [], headers \\ [])
33 def get("https://osada.macgirvin.com/channel/mike", _, _, _) do
37 body: File.read!("test/fixtures/tesla_mock/https___osada.macgirvin.com_channel_mike.json")
41 def get("https://mastodon.social/users/emelie/statuses/101849165031453009", _, _, _) do
45 body: File.read!("test/fixtures/tesla_mock/status.emelie.json")
49 def get("https://mastodon.social/users/emelie/statuses/101849165031453404", _, _, _) do
57 def get("https://mastodon.social/users/emelie", _, _, _) do
61 body: File.read!("test/fixtures/tesla_mock/emelie.json")
65 def get("https://mastodon.social/users/not_found", _, _, _) do
66 {:ok, %Tesla.Env{status: 404}}
69 def get("https://mastodon.sdf.org/users/rinpatch", _, _, _) do
73 body: File.read!("test/fixtures/tesla_mock/rinpatch.json")
78 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/emelie",
86 body: File.read!("test/fixtures/tesla_mock/webfinger_emelie.json")
90 def get("https://mastodon.social/users/emelie.atom", _, _, _) do
94 body: File.read!("test/fixtures/tesla_mock/emelie.atom")
99 "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",
102 Accept: "application/xrd+xml,application/jrd+json"
107 body: File.read!("test/fixtures/tesla_mock/mike@osada.macgirvin.com.json")
112 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
115 Accept: "application/xrd+xml,application/jrd+json"
120 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_29191.xml")
124 def get("https://pawoo.net/users/pekorino.atom", _, _, _) do
128 body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.atom")
133 "https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",
136 Accept: "application/xrd+xml,application/jrd+json"
141 body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml")
146 "https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom",
154 body: File.read!("test/fixtures/tesla_mock/atarifrosch_feed.xml")
159 "https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",
162 Accept: "application/xrd+xml,application/jrd+json"
167 body: File.read!("test/fixtures/tesla_mock/atarifrosch_webfinger.xml")
171 def get("https://mamot.fr/users/Skruyb.atom", _, _, _) do
175 body: File.read!("test/fixtures/tesla_mock/https___mamot.fr_users_Skruyb.atom")
180 "https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/users/Skruyb",
183 Accept: "application/xrd+xml,application/jrd+json"
188 body: File.read!("test/fixtures/tesla_mock/skruyb@mamot.fr.atom")
193 "https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la",
196 Accept: "application/xrd+xml,application/jrd+json"
201 body: File.read!("test/fixtures/tesla_mock/nonexistant@social.heldscal.la.xml")
206 "https://squeet.me/xrd/?uri=lain@squeet.me",
209 Accept: "application/xrd+xml,application/jrd+json"
214 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
219 "https://mst3k.interlinked.me/users/luciferMysticus",
222 Accept: "application/activity+json"
227 body: File.read!("test/fixtures/tesla_mock/lucifermysticus.json")
231 def get("https://prismo.news/@mxb", _, _, _) do
235 body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json")
240 "https://hubzilla.example.org/channel/kaniini",
243 Accept: "application/activity+json"
248 body: File.read!("test/fixtures/tesla_mock/kaniini@hubzilla.example.org.json")
252 def get("https://niu.moe/users/rye", _, _, Accept: "application/activity+json") do
256 body: File.read!("test/fixtures/tesla_mock/rye.json")
260 def get("https://n1u.moe/users/rye", _, _, Accept: "application/activity+json") do
264 body: File.read!("test/fixtures/tesla_mock/rye.json")
268 def get("http://mastodon.example.org/users/admin/statuses/100787282858396771", _, _, _) do
274 "test/fixtures/tesla_mock/http___mastodon.example.org_users_admin_status_1234.json"
279 def get("https://puckipedia.com/", _, _, Accept: "application/activity+json") do
283 body: File.read!("test/fixtures/tesla_mock/puckipedia.com.json")
287 def get("https://peertube.moe/accounts/7even", _, _, _) do
291 body: File.read!("test/fixtures/tesla_mock/7even.json")
295 def get("https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3", _, _, _) do
299 body: File.read!("test/fixtures/tesla_mock/peertube.moe-vid.json")
303 def get("https://baptiste.gelez.xyz/@/BaptisteGelez", _, _, _) do
307 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json")
311 def get("https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/", _, _, _) do
315 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json")
319 def get("https://wedistribute.org/wp-json/pterotype/v1/object/85810", _, _, _) do
323 body: File.read!("test/fixtures/tesla_mock/wedistribute-article.json")
327 def get("https://wedistribute.org/wp-json/pterotype/v1/actor/-blog", _, _, _) do
331 body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")
335 def get("http://mastodon.example.org/users/admin", _, _, Accept: "application/activity+json") do
339 body: File.read!("test/fixtures/tesla_mock/admin@mastdon.example.org.json")
343 def get("http://mastodon.example.org/users/gargron", _, _, Accept: "application/activity+json") do
348 "http://mastodon.example.org/@admin/99541947525187367",
351 Accept: "application/activity+json"
356 body: File.read!("test/fixtures/mastodon-note-object.json")
360 def get("http://mastodon.example.org/@admin/99541947525187368", _, _, _) do
368 def get("https://shitposter.club/notice/7369654", _, _, _) do
372 body: File.read!("test/fixtures/tesla_mock/7369654.html")
376 def get("https://mstdn.io/users/mayuutann", _, _, Accept: "application/activity+json") do
380 body: File.read!("test/fixtures/tesla_mock/mayumayu.json")
385 "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
388 Accept: "application/activity+json"
393 body: File.read!("test/fixtures/tesla_mock/mayumayupost.json")
397 def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do
403 "test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
408 def get(url, _, _, Accept: "application/xrd+xml,application/jrd+json")
410 "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
411 "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
416 body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
420 def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _, _, _) do
426 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
432 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
435 Accept: "application/xrd+xml,application/jrd+json"
440 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
444 def get("https://shitposter.club/notice/2827873", _, _, _) do
448 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.html")
452 def get("https://shitposter.club/api/statuses/show/2827873.atom", _, _, _) do
458 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
463 def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
464 {:ok, %Tesla.Env{status: 200}}
467 def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _, _, _) do
471 body: File.read!("test/fixtures/tesla_mock/spc_5381.atom")
476 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
479 Accept: "application/xrd+xml,application/jrd+json"
484 body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
488 def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
492 body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
496 def get("https://shitposter.club/api/statuses/show/7369654.atom", _, _, _) do
500 body: File.read!("test/fixtures/tesla_mock/7369654.atom")
504 def get("https://shitposter.club/notice/4027863", _, _, _) do
508 body: File.read!("test/fixtures/tesla_mock/7369654.html")
512 def get("https://social.sakamoto.gq/users/eal/feed.atom", _, _, _) do
516 body: File.read!("test/fixtures/tesla_mock/sakamoto_eal_feed.atom")
520 def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
524 body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
529 "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
532 Accept: "application/xrd+xml,application/jrd+json"
537 body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
542 "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056",
545 Accept: "application/atom+xml"
547 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sakamoto.atom")}}
550 def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
554 body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
559 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
562 Accept: "application/xrd+xml,application/jrd+json"
568 File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
572 def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
576 body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
581 "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
584 Accept: "application/xrd+xml,application/jrd+json"
590 File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
595 "http://gs.example.org:4040/index.php/user/1",
598 Accept: "application/activity+json"
600 {:ok, %Tesla.Env{status: 406, body: ""}}
603 def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _, _, _) do
609 "test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
614 def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _, _, _) do
620 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
625 def get("http://squeet.me/.well-known/host-meta", _, _, _) do
627 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
631 "https://squeet.me/xrd?uri=lain@squeet.me",
634 Accept: "application/xrd+xml,application/jrd+json"
639 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
644 "https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la",
647 Accept: "application/xrd+xml,application/jrd+json"
652 body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml")
657 "https://social.heldscal.la/.well-known/webfinger?resource=invalid_content@social.heldscal.la",
660 Accept: "application/xrd+xml,application/jrd+json"
662 {:ok, %Tesla.Env{status: 200, body: ""}}
665 def get("http://framatube.org/.well-known/host-meta", _, _, _) do
669 body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
674 "http://framatube.org/main/xrd?uri=framasoft@framatube.org",
677 Accept: "application/xrd+xml,application/jrd+json"
682 headers: [{"content-type", "application/json"}],
683 body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
687 def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
691 body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
696 "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
699 Accept: "application/xrd+xml,application/jrd+json"
704 body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json")
708 def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
712 body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
716 def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
720 body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
724 def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
728 body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
733 "https://gerzilla.de/xrd/?uri=kaniini@gerzilla.de",
736 Accept: "application/xrd+xml,application/jrd+json"
741 headers: [{"content-type", "application/json"}],
742 body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
746 def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _, _, _) do
752 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
758 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
766 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
770 def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
774 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
778 def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
782 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
786 def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do
787 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}}
790 def get("https://mastodon.social/users/lambadalambda", _, _, _) do
791 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
794 def get("https://apfed.club/channel/indio", _, _, _) do
796 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/osada-user-indio.json")}}
799 def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
800 {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
803 def get("http://example.com/ogp", _, _, _) do
804 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
807 def get("https://example.com/ogp", _, _, _) do
808 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
811 def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
812 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
815 def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
819 body: File.read!("test/fixtures/users_mock/masto_closed_followers.json")
823 def get("http://localhost:4001/users/masto_closed/followers?page=1", _, _, _) do
827 body: File.read!("test/fixtures/users_mock/masto_closed_followers_page.json")
831 def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
835 body: File.read!("test/fixtures/users_mock/masto_closed_following.json")
839 def get("http://localhost:4001/users/masto_closed/following?page=1", _, _, _) do
843 body: File.read!("test/fixtures/users_mock/masto_closed_following_page.json")
847 def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
851 body: File.read!("test/fixtures/users_mock/pleroma_followers.json")
855 def get("http://localhost:4001/users/fuser2/following", _, _, _) do
859 body: File.read!("test/fixtures/users_mock/pleroma_following.json")
863 def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
871 def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
879 def get("http://example.com/ogp-missing-data", _, _, _) do
883 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
887 def get("https://example.com/ogp-missing-data", _, _, _) do
891 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
895 def get("http://example.com/malformed", _, _, _) do
897 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
900 def get("http://example.com/empty", _, _, _) do
901 {:ok, %Tesla.Env{status: 200, body: "hello"}}
904 def get("http://404.site" <> _, _, _, _) do
913 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=lain@zetsubou.xn--q9jyb4c",
916 Accept: "application/xrd+xml,application/jrd+json"
921 body: File.read!("test/fixtures/lain.xml")
926 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=https://zetsubou.xn--q9jyb4c/users/lain",
929 Accept: "application/xrd+xml,application/jrd+json"
934 body: File.read!("test/fixtures/lain.xml")
939 "https://zetsubou.xn--q9jyb4c/.well-known/host-meta",
947 body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
951 def get("https://info.pleroma.site/activity.json", _, _, Accept: "application/activity+json") do
955 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity.json")
959 def get("https://info.pleroma.site/activity.json", _, _, _) do
960 {:ok, %Tesla.Env{status: 404, body: ""}}
963 def get("https://info.pleroma.site/activity2.json", _, _, Accept: "application/activity+json") do
967 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json")
971 def get("https://info.pleroma.site/activity2.json", _, _, _) do
972 {:ok, %Tesla.Env{status: 404, body: ""}}
975 def get("https://info.pleroma.site/activity3.json", _, _, Accept: "application/activity+json") do
979 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json")
983 def get("https://info.pleroma.site/activity3.json", _, _, _) do
984 {:ok, %Tesla.Env{status: 404, body: ""}}
987 def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp", _, _, _) do
991 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
995 def get("http://example.com/rel_me/anchor", _, _, _) do
996 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}}
999 def get("http://example.com/rel_me/anchor_nofollow", _, _, _) do
1000 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}}
1003 def get("http://example.com/rel_me/link", _, _, _) do
1004 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}}
1007 def get("http://example.com/rel_me/null", _, _, _) do
1008 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}}
1011 def get("https://skippers-bin.com/notes/7x9tmrp97i", _, _, _) do
1015 body: File.read!("test/fixtures/tesla_mock/misskey_poll_no_end_date.json")
1019 def get("https://skippers-bin.com/users/7v1w1r8ce6", _, _, _) do
1020 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sjw.json")}}
1023 def get("https://patch.cx/users/rin", _, _, _) do
1024 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/rin.json")}}
1027 def get(url, query, body, headers) do
1029 "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
1037 def post(url, query \\ [], body \\ [], headers \\ [])
1039 def post("http://example.org/needs_refresh", _, _, _) do
1047 def post("http://mastodon.example.org/inbox", _, _, _) do
1055 def post("https://hubzilla.example.org/inbox", _, _, _) do
1063 def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
1071 def post("http://200.site" <> _, _, _, _) do
1079 def post("http://connrefused.site" <> _, _, _, _) do
1080 {:error, :connrefused}
1083 def post("http://404.site" <> _, _, _, _) do
1091 def post(url, query, body, headers) do
1093 "Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{