1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 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
23 with {:error, message} <- error do
33 def get(url, query \\ [], body \\ [], headers \\ [])
35 def get("https://osada.macgirvin.com/channel/mike", _, _, _) do
39 body: File.read!("test/fixtures/tesla_mock/https___osada.macgirvin.com_channel_mike.json")
43 def get("https://mastodon.social/users/emelie/statuses/101849165031453009", _, _, _) do
47 body: File.read!("test/fixtures/tesla_mock/status.emelie.json")
51 def get("https://mastodon.social/users/emelie", _, _, _) do
55 body: File.read!("test/fixtures/tesla_mock/emelie.json")
59 def get("https://mastodon.social/users/not_found", _, _, _) do
60 {:ok, %Tesla.Env{status: 404}}
63 def get("https://mastodon.sdf.org/users/rinpatch", _, _, _) do
67 body: File.read!("test/fixtures/tesla_mock/rinpatch.json")
72 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/emelie",
80 body: File.read!("test/fixtures/tesla_mock/webfinger_emelie.json")
84 def get("https://mastodon.social/users/emelie.atom", _, _, _) do
88 body: File.read!("test/fixtures/tesla_mock/emelie.atom")
93 "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",
96 Accept: "application/xrd+xml,application/jrd+json"
101 body: File.read!("test/fixtures/tesla_mock/mike@osada.macgirvin.com.json")
106 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
109 Accept: "application/xrd+xml,application/jrd+json"
114 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_29191.xml")
118 def get("https://pawoo.net/users/pekorino.atom", _, _, _) do
122 body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.atom")
127 "https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",
130 Accept: "application/xrd+xml,application/jrd+json"
135 body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml")
140 "https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom",
148 body: File.read!("test/fixtures/tesla_mock/atarifrosch_feed.xml")
153 "https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",
156 Accept: "application/xrd+xml,application/jrd+json"
161 body: File.read!("test/fixtures/tesla_mock/atarifrosch_webfinger.xml")
165 def get("https://mamot.fr/users/Skruyb.atom", _, _, _) do
169 body: File.read!("test/fixtures/tesla_mock/https___mamot.fr_users_Skruyb.atom")
174 "https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/users/Skruyb",
177 Accept: "application/xrd+xml,application/jrd+json"
182 body: File.read!("test/fixtures/tesla_mock/skruyb@mamot.fr.atom")
187 "https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la",
190 Accept: "application/xrd+xml,application/jrd+json"
195 body: File.read!("test/fixtures/tesla_mock/nonexistant@social.heldscal.la.xml")
200 "https://squeet.me/xrd/?uri=lain@squeet.me",
203 Accept: "application/xrd+xml,application/jrd+json"
208 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
213 "https://mst3k.interlinked.me/users/luciferMysticus",
216 Accept: "application/activity+json"
221 body: File.read!("test/fixtures/tesla_mock/lucifermysticus.json")
225 def get("https://prismo.news/@mxb", _, _, _) do
229 body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json")
234 "https://hubzilla.example.org/channel/kaniini",
237 Accept: "application/activity+json"
242 body: File.read!("test/fixtures/tesla_mock/kaniini@hubzilla.example.org.json")
246 def get("https://niu.moe/users/rye", _, _, Accept: "application/activity+json") do
250 body: File.read!("test/fixtures/tesla_mock/rye.json")
254 def get("https://n1u.moe/users/rye", _, _, Accept: "application/activity+json") do
258 body: File.read!("test/fixtures/tesla_mock/rye.json")
262 def get("http://mastodon.example.org/users/admin/statuses/100787282858396771", _, _, _) do
268 "test/fixtures/tesla_mock/http___mastodon.example.org_users_admin_status_1234.json"
273 def get("https://puckipedia.com/", _, _, Accept: "application/activity+json") do
277 body: File.read!("test/fixtures/tesla_mock/puckipedia.com.json")
281 def get("https://peertube.moe/accounts/7even", _, _, _) do
285 body: File.read!("test/fixtures/tesla_mock/7even.json")
289 def get("https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3", _, _, _) do
293 body: File.read!("test/fixtures/tesla_mock/peertube.moe-vid.json")
297 def get("https://baptiste.gelez.xyz/@/BaptisteGelez", _, _, _) do
301 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json")
305 def get("https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/", _, _, _) do
309 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json")
313 def get("https://wedistribute.org/wp-json/pterotype/v1/object/85810", _, _, _) do
317 body: File.read!("test/fixtures/tesla_mock/wedistribute-article.json")
321 def get("https://wedistribute.org/wp-json/pterotype/v1/actor/-blog", _, _, _) do
325 body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")
329 def get("http://mastodon.example.org/users/admin", _, _, Accept: "application/activity+json") do
333 body: File.read!("test/fixtures/tesla_mock/admin@mastdon.example.org.json")
337 def get("http://mastodon.example.org/users/gargron", _, _, Accept: "application/activity+json") do
342 "http://mastodon.example.org/@admin/99541947525187367",
345 Accept: "application/activity+json"
350 body: File.read!("test/fixtures/mastodon-note-object.json")
354 def get("https://shitposter.club/notice/7369654", _, _, _) do
358 body: File.read!("test/fixtures/tesla_mock/7369654.html")
362 def get("https://mstdn.io/users/mayuutann", _, _, Accept: "application/activity+json") do
366 body: File.read!("test/fixtures/tesla_mock/mayumayu.json")
371 "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
374 Accept: "application/activity+json"
379 body: File.read!("test/fixtures/tesla_mock/mayumayupost.json")
383 def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do
389 "test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
394 def get(url, _, _, Accept: "application/xrd+xml,application/jrd+json")
396 "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
397 "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
402 body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
406 def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _, _, _) do
412 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
418 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
421 Accept: "application/xrd+xml,application/jrd+json"
426 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
430 def get("https://shitposter.club/notice/2827873", _, _, _) do
434 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.html")
438 def get("https://shitposter.club/api/statuses/show/2827873.atom", _, _, _) do
444 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
449 def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
450 {:ok, %Tesla.Env{status: 200}}
453 def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _, _, _) do
457 body: File.read!("test/fixtures/tesla_mock/spc_5381.atom")
462 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
465 Accept: "application/xrd+xml,application/jrd+json"
470 body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
474 def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
478 body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
482 def get("https://shitposter.club/api/statuses/show/7369654.atom", _, _, _) do
486 body: File.read!("test/fixtures/tesla_mock/7369654.atom")
490 def get("https://shitposter.club/notice/4027863", _, _, _) do
494 body: File.read!("test/fixtures/tesla_mock/7369654.html")
498 def get("https://social.sakamoto.gq/users/eal/feed.atom", _, _, _) do
502 body: File.read!("test/fixtures/tesla_mock/sakamoto_eal_feed.atom")
506 def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
510 body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
515 "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
518 Accept: "application/xrd+xml,application/jrd+json"
523 body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
528 "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056",
531 Accept: "application/atom+xml"
533 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sakamoto.atom")}}
536 def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
540 body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
545 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
548 Accept: "application/xrd+xml,application/jrd+json"
554 File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
558 def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
562 body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
567 "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
570 Accept: "application/xrd+xml,application/jrd+json"
576 File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
581 "http://gs.example.org:4040/index.php/user/1",
584 Accept: "application/activity+json"
586 {:ok, %Tesla.Env{status: 406, body: ""}}
589 def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _, _, _) do
595 "test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
600 def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _, _, _) do
606 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
611 def get("http://squeet.me/.well-known/host-meta", _, _, _) do
613 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
617 "https://squeet.me/xrd?uri=lain@squeet.me",
620 Accept: "application/xrd+xml,application/jrd+json"
625 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
630 "https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la",
633 Accept: "application/xrd+xml,application/jrd+json"
638 body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml")
643 "https://social.heldscal.la/.well-known/webfinger?resource=invalid_content@social.heldscal.la",
646 Accept: "application/xrd+xml,application/jrd+json"
648 {:ok, %Tesla.Env{status: 200, body: ""}}
651 def get("http://framatube.org/.well-known/host-meta", _, _, _) do
655 body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
660 "http://framatube.org/main/xrd?uri=framasoft@framatube.org",
663 Accept: "application/xrd+xml,application/jrd+json"
668 headers: [{"content-type", "application/json"}],
669 body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
673 def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
677 body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
682 "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
685 Accept: "application/xrd+xml,application/jrd+json"
690 body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json")
694 def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
698 body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
702 def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
706 body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
710 def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
714 body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
719 "https://gerzilla.de/xrd/?uri=kaniini@gerzilla.de",
722 Accept: "application/xrd+xml,application/jrd+json"
727 headers: [{"content-type", "application/json"}],
728 body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
732 def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _, _, _) do
738 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
744 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
752 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
756 def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
760 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
764 def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
768 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
772 def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do
773 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}}
776 def get("https://mastodon.social/users/lambadalambda", _, _, _) do
777 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
780 def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
781 {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
784 def get("http://example.com/ogp", _, _, _) do
785 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
788 def get("https://example.com/ogp", _, _, _) do
789 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
792 def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
793 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
796 def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
800 body: File.read!("test/fixtures/users_mock/masto_closed_followers.json")
804 def get("http://localhost:4001/users/masto_closed/followers?page=1", _, _, _) do
808 body: File.read!("test/fixtures/users_mock/masto_closed_followers_page.json")
812 def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
816 body: File.read!("test/fixtures/users_mock/masto_closed_following.json")
820 def get("http://localhost:4001/users/masto_closed/following?page=1", _, _, _) do
824 body: File.read!("test/fixtures/users_mock/masto_closed_following_page.json")
828 def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
832 body: File.read!("test/fixtures/users_mock/pleroma_followers.json")
836 def get("http://localhost:4001/users/fuser2/following", _, _, _) do
840 body: File.read!("test/fixtures/users_mock/pleroma_following.json")
844 def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
852 def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
860 def get("http://example.com/ogp-missing-data", _, _, _) do
864 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
868 def get("https://example.com/ogp-missing-data", _, _, _) do
872 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
876 def get("http://example.com/malformed", _, _, _) do
878 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
881 def get("http://example.com/empty", _, _, _) do
882 {:ok, %Tesla.Env{status: 200, body: "hello"}}
885 def get("http://404.site" <> _, _, _, _) do
894 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=lain@zetsubou.xn--q9jyb4c",
897 Accept: "application/xrd+xml,application/jrd+json"
902 body: File.read!("test/fixtures/lain.xml")
907 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=https://zetsubou.xn--q9jyb4c/users/lain",
910 Accept: "application/xrd+xml,application/jrd+json"
915 body: File.read!("test/fixtures/lain.xml")
920 "https://zetsubou.xn--q9jyb4c/.well-known/host-meta",
928 body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
932 def get("https://info.pleroma.site/activity.json", _, _, Accept: "application/activity+json") do
936 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity.json")
940 def get("https://info.pleroma.site/activity.json", _, _, _) do
941 {:ok, %Tesla.Env{status: 404, body: ""}}
944 def get("https://info.pleroma.site/activity2.json", _, _, Accept: "application/activity+json") do
948 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json")
952 def get("https://info.pleroma.site/activity2.json", _, _, _) do
953 {:ok, %Tesla.Env{status: 404, body: ""}}
956 def get("https://info.pleroma.site/activity3.json", _, _, Accept: "application/activity+json") do
960 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json")
964 def get("https://info.pleroma.site/activity3.json", _, _, _) do
965 {:ok, %Tesla.Env{status: 404, body: ""}}
968 def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp", _, _, _) do
972 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
976 def get("http://example.com/rel_me/anchor", _, _, _) do
977 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}}
980 def get("http://example.com/rel_me/anchor_nofollow", _, _, _) do
981 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}}
984 def get("http://example.com/rel_me/link", _, _, _) do
985 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}}
988 def get("http://example.com/rel_me/null", _, _, _) do
989 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}}
992 def get(url, query, body, headers) do
994 "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
1002 def post(url, query \\ [], body \\ [], headers \\ [])
1004 def post("http://example.org/needs_refresh", _, _, _) do
1012 def post("http://mastodon.example.org/inbox", _, _, _) do
1020 def post("https://hubzilla.example.org/inbox", _, _, _) do
1028 def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
1036 def post("http://200.site" <> _, _, _, _) do
1044 def post("http://connrefused.site" <> _, _, _, _) do
1045 {:error, :connrefused}
1048 def post("http://404.site" <> _, _, _, _) do
1056 def post(url, query, body, headers) do
1058 "Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{