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