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", _, _, _) do
53 body: File.read!("test/fixtures/tesla_mock/emelie.json")
57 def get("https://mastodon.social/users/not_found", _, _, _) do
58 {:ok, %Tesla.Env{status: 404}}
61 def get("https://mastodon.sdf.org/users/rinpatch", _, _, _) do
65 body: File.read!("test/fixtures/tesla_mock/rinpatch.json")
70 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/emelie",
78 body: File.read!("test/fixtures/tesla_mock/webfinger_emelie.json")
82 def get("https://mastodon.social/users/emelie.atom", _, _, _) do
86 body: File.read!("test/fixtures/tesla_mock/emelie.atom")
91 "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",
94 Accept: "application/xrd+xml,application/jrd+json"
99 body: File.read!("test/fixtures/tesla_mock/mike@osada.macgirvin.com.json")
104 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
107 Accept: "application/xrd+xml,application/jrd+json"
112 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_29191.xml")
116 def get("https://pawoo.net/users/pekorino.atom", _, _, _) do
120 body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.atom")
125 "https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",
128 Accept: "application/xrd+xml,application/jrd+json"
133 body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml")
138 "https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom",
146 body: File.read!("test/fixtures/tesla_mock/atarifrosch_feed.xml")
151 "https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",
154 Accept: "application/xrd+xml,application/jrd+json"
159 body: File.read!("test/fixtures/tesla_mock/atarifrosch_webfinger.xml")
163 def get("https://mamot.fr/users/Skruyb.atom", _, _, _) do
167 body: File.read!("test/fixtures/tesla_mock/https___mamot.fr_users_Skruyb.atom")
172 "https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/users/Skruyb",
175 Accept: "application/xrd+xml,application/jrd+json"
180 body: File.read!("test/fixtures/tesla_mock/skruyb@mamot.fr.atom")
185 "https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la",
188 Accept: "application/xrd+xml,application/jrd+json"
193 body: File.read!("test/fixtures/tesla_mock/nonexistant@social.heldscal.la.xml")
198 "https://squeet.me/xrd/?uri=lain@squeet.me",
201 Accept: "application/xrd+xml,application/jrd+json"
206 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
211 "https://mst3k.interlinked.me/users/luciferMysticus",
214 Accept: "application/activity+json"
219 body: File.read!("test/fixtures/tesla_mock/lucifermysticus.json")
223 def get("https://prismo.news/@mxb", _, _, _) do
227 body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json")
232 "https://hubzilla.example.org/channel/kaniini",
235 Accept: "application/activity+json"
240 body: File.read!("test/fixtures/tesla_mock/kaniini@hubzilla.example.org.json")
244 def get("https://niu.moe/users/rye", _, _, Accept: "application/activity+json") do
248 body: File.read!("test/fixtures/tesla_mock/rye.json")
252 def get("https://n1u.moe/users/rye", _, _, Accept: "application/activity+json") do
256 body: File.read!("test/fixtures/tesla_mock/rye.json")
260 def get("http://mastodon.example.org/users/admin/statuses/100787282858396771", _, _, _) do
266 "test/fixtures/tesla_mock/http___mastodon.example.org_users_admin_status_1234.json"
271 def get("https://puckipedia.com/", _, _, Accept: "application/activity+json") do
275 body: File.read!("test/fixtures/tesla_mock/puckipedia.com.json")
279 def get("https://peertube.moe/accounts/7even", _, _, _) do
283 body: File.read!("test/fixtures/tesla_mock/7even.json")
287 def get("https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3", _, _, _) do
291 body: File.read!("test/fixtures/tesla_mock/peertube.moe-vid.json")
295 def get("https://baptiste.gelez.xyz/@/BaptisteGelez", _, _, _) do
299 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json")
303 def get("https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/", _, _, _) do
307 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json")
311 def get("https://wedistribute.org/wp-json/pterotype/v1/object/85810", _, _, _) do
315 body: File.read!("test/fixtures/tesla_mock/wedistribute-article.json")
319 def get("https://wedistribute.org/wp-json/pterotype/v1/actor/-blog", _, _, _) do
323 body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")
327 def get("http://mastodon.example.org/users/admin", _, _, Accept: "application/activity+json") do
331 body: File.read!("test/fixtures/tesla_mock/admin@mastdon.example.org.json")
335 def get("http://mastodon.example.org/users/gargron", _, _, Accept: "application/activity+json") do
340 "http://mastodon.example.org/@admin/99541947525187367",
343 Accept: "application/activity+json"
348 body: File.read!("test/fixtures/mastodon-note-object.json")
352 def get("https://shitposter.club/notice/7369654", _, _, _) do
356 body: File.read!("test/fixtures/tesla_mock/7369654.html")
360 def get("https://mstdn.io/users/mayuutann", _, _, Accept: "application/activity+json") do
364 body: File.read!("test/fixtures/tesla_mock/mayumayu.json")
369 "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
372 Accept: "application/activity+json"
377 body: File.read!("test/fixtures/tesla_mock/mayumayupost.json")
381 def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do
387 "test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
392 def get(url, _, _, Accept: "application/xrd+xml,application/jrd+json")
394 "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
395 "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
400 body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
404 def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _, _, _) do
410 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
416 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
419 Accept: "application/xrd+xml,application/jrd+json"
424 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
428 def get("https://shitposter.club/notice/2827873", _, _, _) do
432 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.html")
436 def get("https://shitposter.club/api/statuses/show/2827873.atom", _, _, _) do
442 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
447 def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
448 {:ok, %Tesla.Env{status: 200}}
451 def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _, _, _) do
455 body: File.read!("test/fixtures/tesla_mock/spc_5381.atom")
460 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
463 Accept: "application/xrd+xml,application/jrd+json"
468 body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
472 def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
476 body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
480 def get("https://shitposter.club/api/statuses/show/7369654.atom", _, _, _) do
484 body: File.read!("test/fixtures/tesla_mock/7369654.atom")
488 def get("https://shitposter.club/notice/4027863", _, _, _) do
492 body: File.read!("test/fixtures/tesla_mock/7369654.html")
496 def get("https://social.sakamoto.gq/users/eal/feed.atom", _, _, _) do
500 body: File.read!("test/fixtures/tesla_mock/sakamoto_eal_feed.atom")
504 def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
508 body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
513 "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
516 Accept: "application/xrd+xml,application/jrd+json"
521 body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
526 "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056",
529 Accept: "application/atom+xml"
531 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sakamoto.atom")}}
534 def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
538 body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
543 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
546 Accept: "application/xrd+xml,application/jrd+json"
552 File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
556 def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
560 body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
565 "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
568 Accept: "application/xrd+xml,application/jrd+json"
574 File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
579 "http://gs.example.org:4040/index.php/user/1",
582 Accept: "application/activity+json"
584 {:ok, %Tesla.Env{status: 406, body: ""}}
587 def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _, _, _) do
593 "test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
598 def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _, _, _) do
604 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
609 def get("http://squeet.me/.well-known/host-meta", _, _, _) do
611 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
615 "https://squeet.me/xrd?uri=lain@squeet.me",
618 Accept: "application/xrd+xml,application/jrd+json"
623 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
628 "https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la",
631 Accept: "application/xrd+xml,application/jrd+json"
636 body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml")
641 "https://social.heldscal.la/.well-known/webfinger?resource=invalid_content@social.heldscal.la",
644 Accept: "application/xrd+xml,application/jrd+json"
646 {:ok, %Tesla.Env{status: 200, body: ""}}
649 def get("http://framatube.org/.well-known/host-meta", _, _, _) do
653 body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
658 "http://framatube.org/main/xrd?uri=framasoft@framatube.org",
661 Accept: "application/xrd+xml,application/jrd+json"
666 headers: [{"content-type", "application/json"}],
667 body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
671 def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
675 body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
680 "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
683 Accept: "application/xrd+xml,application/jrd+json"
688 body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json")
692 def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
696 body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
700 def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
704 body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
708 def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
712 body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
717 "https://gerzilla.de/xrd/?uri=kaniini@gerzilla.de",
720 Accept: "application/xrd+xml,application/jrd+json"
725 headers: [{"content-type", "application/json"}],
726 body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
730 def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _, _, _) do
736 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
742 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
750 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
754 def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
758 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
762 def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
766 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
770 def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do
771 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}}
774 def get("https://mastodon.social/users/lambadalambda", _, _, _) do
775 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
778 def get("https://apfed.club/channel/indio", _, _, _) do
780 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/osada-user-indio.json")}}
783 def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
784 {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
787 def get("http://example.com/ogp", _, _, _) do
788 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
791 def get("https://example.com/ogp", _, _, _) do
792 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
795 def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
796 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
799 def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
803 body: File.read!("test/fixtures/users_mock/masto_closed_followers.json")
807 def get("http://localhost:4001/users/masto_closed/followers?page=1", _, _, _) do
811 body: File.read!("test/fixtures/users_mock/masto_closed_followers_page.json")
815 def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
819 body: File.read!("test/fixtures/users_mock/masto_closed_following.json")
823 def get("http://localhost:4001/users/masto_closed/following?page=1", _, _, _) do
827 body: File.read!("test/fixtures/users_mock/masto_closed_following_page.json")
831 def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
835 body: File.read!("test/fixtures/users_mock/pleroma_followers.json")
839 def get("http://localhost:4001/users/fuser2/following", _, _, _) do
843 body: File.read!("test/fixtures/users_mock/pleroma_following.json")
847 def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
855 def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
863 def get("http://example.com/ogp-missing-data", _, _, _) do
867 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
871 def get("https://example.com/ogp-missing-data", _, _, _) do
875 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
879 def get("http://example.com/malformed", _, _, _) do
881 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
884 def get("http://example.com/empty", _, _, _) do
885 {:ok, %Tesla.Env{status: 200, body: "hello"}}
888 def get("http://404.site" <> _, _, _, _) do
897 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=lain@zetsubou.xn--q9jyb4c",
900 Accept: "application/xrd+xml,application/jrd+json"
905 body: File.read!("test/fixtures/lain.xml")
910 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=https://zetsubou.xn--q9jyb4c/users/lain",
913 Accept: "application/xrd+xml,application/jrd+json"
918 body: File.read!("test/fixtures/lain.xml")
923 "https://zetsubou.xn--q9jyb4c/.well-known/host-meta",
931 body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
935 def get("https://info.pleroma.site/activity.json", _, _, Accept: "application/activity+json") do
939 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity.json")
943 def get("https://info.pleroma.site/activity.json", _, _, _) do
944 {:ok, %Tesla.Env{status: 404, body: ""}}
947 def get("https://info.pleroma.site/activity2.json", _, _, Accept: "application/activity+json") do
951 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json")
955 def get("https://info.pleroma.site/activity2.json", _, _, _) do
956 {:ok, %Tesla.Env{status: 404, body: ""}}
959 def get("https://info.pleroma.site/activity3.json", _, _, Accept: "application/activity+json") do
963 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json")
967 def get("https://info.pleroma.site/activity3.json", _, _, _) do
968 {:ok, %Tesla.Env{status: 404, body: ""}}
971 def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp", _, _, _) do
975 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
979 def get("http://example.com/rel_me/anchor", _, _, _) do
980 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}}
983 def get("http://example.com/rel_me/anchor_nofollow", _, _, _) do
984 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}}
987 def get("http://example.com/rel_me/link", _, _, _) do
988 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}}
991 def get("http://example.com/rel_me/null", _, _, _) do
992 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}}
995 def get("https://skippers-bin.com/notes/7x9tmrp97i", _, _, _) do
999 body: File.read!("test/fixtures/tesla_mock/misskey_poll_no_end_date.json")
1003 def get("https://skippers-bin.com/users/7v1w1r8ce6", _, _, _) do
1004 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sjw.json")}}
1007 def get("https://patch.cx/users/rin", _, _, _) do
1008 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/rin.json")}}
1011 def get(url, query, body, headers) do
1013 "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
1021 def post(url, query \\ [], body \\ [], headers \\ [])
1023 def post("http://example.org/needs_refresh", _, _, _) do
1031 def post("http://mastodon.example.org/inbox", _, _, _) do
1039 def post("https://hubzilla.example.org/inbox", _, _, _) do
1047 def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
1055 def post("http://200.site" <> _, _, _, _) do
1063 def post("http://connrefused.site" <> _, _, _, _) do
1064 {:error, :connrefused}
1067 def post("http://404.site" <> _, _, _, _) do
1075 def post(url, query, body, headers) do
1077 "Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{