Lint
[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://peertube.social/accounts/craigmaloney", _, _, _) do
312 {:ok,
313 %Tesla.Env{
314 status: 200,
315 body: File.read!("test/fixtures/tesla_mock/craigmaloney.json")
316 }}
317 end
318
319 def get("https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe", _, _, _) do
320 {:ok,
321 %Tesla.Env{
322 status: 200,
323 body: File.read!("test/fixtures/tesla_mock/peertube-social.json")
324 }}
325 end
326
327 def get("https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39", _, _, [
328 {"accept", "application/activity+json"}
329 ]) do
330 {:ok,
331 %Tesla.Env{
332 status: 200,
333 body: File.read!("test/fixtures/tesla_mock/mobilizon.org-event.json")
334 }}
335 end
336
337 def get("https://mobilizon.org/@tcit", _, _, [{"accept", "application/activity+json"}]) do
338 {:ok,
339 %Tesla.Env{
340 status: 200,
341 body: File.read!("test/fixtures/tesla_mock/mobilizon.org-user.json")
342 }}
343 end
344
345 def get("https://baptiste.gelez.xyz/@/BaptisteGelez", _, _, _) do
346 {:ok,
347 %Tesla.Env{
348 status: 200,
349 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json")
350 }}
351 end
352
353 def get("https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/", _, _, _) do
354 {:ok,
355 %Tesla.Env{
356 status: 200,
357 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json")
358 }}
359 end
360
361 def get("https://wedistribute.org/wp-json/pterotype/v1/object/85810", _, _, _) do
362 {:ok,
363 %Tesla.Env{
364 status: 200,
365 body: File.read!("test/fixtures/tesla_mock/wedistribute-article.json")
366 }}
367 end
368
369 def get("https://wedistribute.org/wp-json/pterotype/v1/actor/-blog", _, _, _) do
370 {:ok,
371 %Tesla.Env{
372 status: 200,
373 body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")
374 }}
375 end
376
377 def get("http://mastodon.example.org/users/admin", _, _, _) do
378 {:ok,
379 %Tesla.Env{
380 status: 200,
381 body: File.read!("test/fixtures/tesla_mock/admin@mastdon.example.org.json")
382 }}
383 end
384
385 def get("http://mastodon.example.org/users/relay", _, _, [
386 {"accept", "application/activity+json"}
387 ]) do
388 {:ok,
389 %Tesla.Env{
390 status: 200,
391 body: File.read!("test/fixtures/tesla_mock/relay@mastdon.example.org.json")
392 }}
393 end
394
395 def get("http://mastodon.example.org/users/gargron", _, _, [
396 {"accept", "application/activity+json"}
397 ]) do
398 {:error, :nxdomain}
399 end
400
401 def get("http://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
402 {:ok,
403 %Tesla.Env{
404 status: 404,
405 body: ""
406 }}
407 end
408
409 def get("https://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
410 {:ok,
411 %Tesla.Env{
412 status: 404,
413 body: ""
414 }}
415 end
416
417 def get("http://mastodon.sdf.org/.well-known/host-meta", _, _, _) do
418 {:ok,
419 %Tesla.Env{
420 status: 200,
421 body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta")
422 }}
423 end
424
425 def get("https://mastodon.sdf.org/.well-known/host-meta", _, _, _) do
426 {:ok,
427 %Tesla.Env{
428 status: 200,
429 body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta")
430 }}
431 end
432
433 def get(
434 "https://mastodon.sdf.org/.well-known/webfinger?resource=https://mastodon.sdf.org/users/snowdusk",
435 _,
436 _,
437 _
438 ) do
439 {:ok,
440 %Tesla.Env{
441 status: 200,
442 body: File.read!("test/fixtures/tesla_mock/snowdusk@sdf.org_host_meta.json")
443 }}
444 end
445
446 def get("http://mstdn.jp/.well-known/host-meta", _, _, _) do
447 {:ok,
448 %Tesla.Env{
449 status: 200,
450 body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta")
451 }}
452 end
453
454 def get("https://mstdn.jp/.well-known/host-meta", _, _, _) do
455 {:ok,
456 %Tesla.Env{
457 status: 200,
458 body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta")
459 }}
460 end
461
462 def get("https://mstdn.jp/.well-known/webfinger?resource=kpherox@mstdn.jp", _, _, _) do
463 {:ok,
464 %Tesla.Env{
465 status: 200,
466 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
467 }}
468 end
469
470 def get("http://mamot.fr/.well-known/host-meta", _, _, _) do
471 {:ok,
472 %Tesla.Env{
473 status: 200,
474 body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta")
475 }}
476 end
477
478 def get("https://mamot.fr/.well-known/host-meta", _, _, _) do
479 {:ok,
480 %Tesla.Env{
481 status: 200,
482 body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta")
483 }}
484 end
485
486 def get(
487 "https://mamot.fr/.well-known/webfinger?resource=https://mamot.fr/users/Skruyb",
488 _,
489 _,
490 _
491 ) do
492 {:ok,
493 %Tesla.Env{
494 status: 200,
495 body: File.read!("test/fixtures/tesla_mock/skruyb@mamot.fr.atom")
496 }}
497 end
498
499 def get("http://pawoo.net/.well-known/host-meta", _, _, _) do
500 {:ok,
501 %Tesla.Env{
502 status: 200,
503 body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
504 }}
505 end
506
507 def get("https://pawoo.net/.well-known/host-meta", _, _, _) do
508 {:ok,
509 %Tesla.Env{
510 status: 200,
511 body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
512 }}
513 end
514
515 def get(
516 "https://pawoo.net/.well-known/webfinger?resource=https://pawoo.net/users/pekorino",
517 _,
518 _,
519 _
520 ) do
521 {:ok,
522 %Tesla.Env{
523 status: 200,
524 body: File.read!("test/fixtures/tesla_mock/pekorino@pawoo.net_host_meta.json")
525 }}
526 end
527
528 def get("http://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
529 {:ok,
530 %Tesla.Env{
531 status: 200,
532 body: File.read!("test/fixtures/tesla_mock/xn--q9jyb4c_host_meta")
533 }}
534 end
535
536 def get("https://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
537 {:ok,
538 %Tesla.Env{
539 status: 200,
540 body: File.read!("test/fixtures/tesla_mock/xn--q9jyb4c_host_meta")
541 }}
542 end
543
544 def get("http://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
545 {:ok,
546 %Tesla.Env{
547 status: 200,
548 body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta")
549 }}
550 end
551
552 def get("https://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
553 {:ok,
554 %Tesla.Env{
555 status: 200,
556 body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta")
557 }}
558 end
559
560 def get("http://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do
561 {:ok,
562 %Tesla.Env{
563 status: 200,
564 body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta")
565 }}
566 end
567
568 def get("https://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do
569 {:ok,
570 %Tesla.Env{
571 status: 200,
572 body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta")
573 }}
574 end
575
576 def get(
577 "http://mastodon.example.org/@admin/99541947525187367",
578 _,
579 _,
580 _
581 ) do
582 {:ok,
583 %Tesla.Env{
584 status: 200,
585 body: File.read!("test/fixtures/mastodon-note-object.json")
586 }}
587 end
588
589 def get("http://mastodon.example.org/@admin/99541947525187368", _, _, _) do
590 {:ok,
591 %Tesla.Env{
592 status: 404,
593 body: ""
594 }}
595 end
596
597 def get("https://shitposter.club/notice/7369654", _, _, _) do
598 {:ok,
599 %Tesla.Env{
600 status: 200,
601 body: File.read!("test/fixtures/tesla_mock/7369654.html")
602 }}
603 end
604
605 def get("https://mstdn.io/users/mayuutann", _, _, [{"accept", "application/activity+json"}]) do
606 {:ok,
607 %Tesla.Env{
608 status: 200,
609 body: File.read!("test/fixtures/tesla_mock/mayumayu.json")
610 }}
611 end
612
613 def get(
614 "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
615 _,
616 _,
617 [{"accept", "application/activity+json"}]
618 ) do
619 {:ok,
620 %Tesla.Env{
621 status: 200,
622 body: File.read!("test/fixtures/tesla_mock/mayumayupost.json")
623 }}
624 end
625
626 def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do
627 {:ok,
628 %Tesla.Env{
629 status: 200,
630 body:
631 File.read!(
632 "test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
633 )
634 }}
635 end
636
637 def get(url, _, _, [{"accept", "application/xrd+xml,application/jrd+json"}])
638 when url in [
639 "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
640 "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
641 ] do
642 {:ok,
643 %Tesla.Env{
644 status: 200,
645 body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
646 }}
647 end
648
649 def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _, _, _) do
650 {:ok,
651 %Tesla.Env{
652 status: 200,
653 body:
654 File.read!(
655 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
656 )
657 }}
658 end
659
660 def get(
661 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
662 _,
663 _,
664 [{"accept", "application/xrd+xml,application/jrd+json"}]
665 ) do
666 {:ok,
667 %Tesla.Env{
668 status: 200,
669 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
670 }}
671 end
672
673 def get("https://shitposter.club/notice/2827873", _, _, _) do
674 {:ok,
675 %Tesla.Env{
676 status: 200,
677 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.json")
678 }}
679 end
680
681 def get("https://shitposter.club/api/statuses/show/2827873.atom", _, _, _) do
682 {:ok,
683 %Tesla.Env{
684 status: 200,
685 body:
686 File.read!(
687 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
688 )
689 }}
690 end
691
692 def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
693 {:ok, %Tesla.Env{status: 200}}
694 end
695
696 def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _, _, _) do
697 {:ok,
698 %Tesla.Env{
699 status: 200,
700 body: File.read!("test/fixtures/tesla_mock/spc_5381.atom")
701 }}
702 end
703
704 def get(
705 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
706 _,
707 _,
708 [{"accept", "application/xrd+xml,application/jrd+json"}]
709 ) do
710 {:ok,
711 %Tesla.Env{
712 status: 200,
713 body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
714 }}
715 end
716
717 def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
718 {:ok,
719 %Tesla.Env{
720 status: 200,
721 body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
722 }}
723 end
724
725 def get("https://shitposter.club/api/statuses/show/7369654.atom", _, _, _) do
726 {:ok,
727 %Tesla.Env{
728 status: 200,
729 body: File.read!("test/fixtures/tesla_mock/7369654.atom")
730 }}
731 end
732
733 def get("https://shitposter.club/notice/4027863", _, _, _) do
734 {:ok,
735 %Tesla.Env{
736 status: 200,
737 body: File.read!("test/fixtures/tesla_mock/7369654.html")
738 }}
739 end
740
741 def get("https://social.sakamoto.gq/users/eal/feed.atom", _, _, _) do
742 {:ok,
743 %Tesla.Env{
744 status: 200,
745 body: File.read!("test/fixtures/tesla_mock/sakamoto_eal_feed.atom")
746 }}
747 end
748
749 def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
750 {:ok,
751 %Tesla.Env{
752 status: 200,
753 body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
754 }}
755 end
756
757 def get(
758 "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
759 _,
760 _,
761 [{"accept", "application/xrd+xml,application/jrd+json"}]
762 ) do
763 {:ok,
764 %Tesla.Env{
765 status: 200,
766 body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
767 }}
768 end
769
770 def get(
771 "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056",
772 _,
773 _,
774 [{"accept", "application/atom+xml"}]
775 ) do
776 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sakamoto.atom")}}
777 end
778
779 def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
780 {:ok,
781 %Tesla.Env{
782 status: 200,
783 body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
784 }}
785 end
786
787 def get(
788 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
789 _,
790 _,
791 [{"accept", "application/xrd+xml,application/jrd+json"}]
792 ) do
793 {:ok,
794 %Tesla.Env{
795 status: 200,
796 body:
797 File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
798 }}
799 end
800
801 def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
802 {:ok,
803 %Tesla.Env{
804 status: 200,
805 body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
806 }}
807 end
808
809 def get(
810 "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
811 _,
812 _,
813 [{"accept", "application/xrd+xml,application/jrd+json"}]
814 ) do
815 {:ok,
816 %Tesla.Env{
817 status: 200,
818 body:
819 File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
820 }}
821 end
822
823 def get(
824 "http://gs.example.org:4040/index.php/user/1",
825 _,
826 _,
827 [{"accept", "application/activity+json"}]
828 ) do
829 {:ok, %Tesla.Env{status: 406, body: ""}}
830 end
831
832 def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _, _, _) do
833 {:ok,
834 %Tesla.Env{
835 status: 200,
836 body:
837 File.read!(
838 "test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
839 )
840 }}
841 end
842
843 def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _, _, _) do
844 {:ok,
845 %Tesla.Env{
846 status: 200,
847 body:
848 File.read!(
849 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
850 )
851 }}
852 end
853
854 def get("http://squeet.me/.well-known/host-meta", _, _, _) do
855 {:ok,
856 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
857 end
858
859 def get(
860 "https://squeet.me/xrd?uri=lain@squeet.me",
861 _,
862 _,
863 [{"accept", "application/xrd+xml,application/jrd+json"}]
864 ) do
865 {:ok,
866 %Tesla.Env{
867 status: 200,
868 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
869 }}
870 end
871
872 def get(
873 "https://social.heldscal.la/.well-known/webfinger?resource=acct:shp@social.heldscal.la",
874 _,
875 _,
876 [{"accept", "application/xrd+xml,application/jrd+json"}]
877 ) do
878 {:ok,
879 %Tesla.Env{
880 status: 200,
881 body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml")
882 }}
883 end
884
885 def get(
886 "https://social.heldscal.la/.well-known/webfinger?resource=acct:invalid_content@social.heldscal.la",
887 _,
888 _,
889 [{"accept", "application/xrd+xml,application/jrd+json"}]
890 ) do
891 {:ok, %Tesla.Env{status: 200, body: ""}}
892 end
893
894 def get("http://framatube.org/.well-known/host-meta", _, _, _) do
895 {:ok,
896 %Tesla.Env{
897 status: 200,
898 body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
899 }}
900 end
901
902 def get(
903 "http://framatube.org/main/xrd?uri=acct:framasoft@framatube.org",
904 _,
905 _,
906 [{"accept", "application/xrd+xml,application/jrd+json"}]
907 ) do
908 {:ok,
909 %Tesla.Env{
910 status: 200,
911 headers: [{"content-type", "application/json"}],
912 body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
913 }}
914 end
915
916 def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
917 {:ok,
918 %Tesla.Env{
919 status: 200,
920 body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
921 }}
922 end
923
924 def get(
925 "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
926 _,
927 _,
928 [{"accept", "application/xrd+xml,application/jrd+json"}]
929 ) do
930 {:ok,
931 %Tesla.Env{
932 status: 200,
933 body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json")
934 }}
935 end
936
937 def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
938 {:ok,
939 %Tesla.Env{
940 status: 200,
941 body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
942 }}
943 end
944
945 def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
946 {:ok,
947 %Tesla.Env{
948 status: 200,
949 body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
950 }}
951 end
952
953 def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
954 {:ok,
955 %Tesla.Env{
956 status: 200,
957 body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
958 }}
959 end
960
961 def get(
962 "https://gerzilla.de/xrd/?uri=acct:kaniini@gerzilla.de",
963 _,
964 _,
965 [{"accept", "application/xrd+xml,application/jrd+json"}]
966 ) do
967 {:ok,
968 %Tesla.Env{
969 status: 200,
970 headers: [{"content-type", "application/json"}],
971 body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
972 }}
973 end
974
975 def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _, _, _) do
976 {:ok,
977 %Tesla.Env{
978 status: 200,
979 body:
980 File.read!(
981 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
982 )
983 }}
984 end
985
986 def get(
987 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
988 _,
989 _,
990 _
991 ) do
992 {:ok,
993 %Tesla.Env{
994 status: 200,
995 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
996 }}
997 end
998
999 def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
1000 {:ok,
1001 %Tesla.Env{
1002 status: 200,
1003 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
1004 }}
1005 end
1006
1007 def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
1008 {:ok,
1009 %Tesla.Env{
1010 status: 200,
1011 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
1012 }}
1013 end
1014
1015 def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do
1016 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}}
1017 end
1018
1019 def get("https://mastodon.social/users/lambadalambda", _, _, _) do
1020 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
1021 end
1022
1023 def get("https://apfed.club/channel/indio", _, _, _) do
1024 {:ok,
1025 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/osada-user-indio.json")}}
1026 end
1027
1028 def get("https://social.heldscal.la/user/23211", _, _, [{"accept", "application/activity+json"}]) do
1029 {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
1030 end
1031
1032 def get("http://example.com/ogp", _, _, _) do
1033 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
1034 end
1035
1036 def get("https://example.com/ogp", _, _, _) do
1037 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
1038 end
1039
1040 def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
1041 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
1042 end
1043
1044 def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
1045 {:ok,
1046 %Tesla.Env{
1047 status: 200,
1048 body: File.read!("test/fixtures/users_mock/masto_closed_followers.json")
1049 }}
1050 end
1051
1052 def get("http://localhost:4001/users/masto_closed/followers?page=1", _, _, _) do
1053 {:ok,
1054 %Tesla.Env{
1055 status: 200,
1056 body: File.read!("test/fixtures/users_mock/masto_closed_followers_page.json")
1057 }}
1058 end
1059
1060 def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
1061 {:ok,
1062 %Tesla.Env{
1063 status: 200,
1064 body: File.read!("test/fixtures/users_mock/masto_closed_following.json")
1065 }}
1066 end
1067
1068 def get("http://localhost:4001/users/masto_closed/following?page=1", _, _, _) do
1069 {:ok,
1070 %Tesla.Env{
1071 status: 200,
1072 body: File.read!("test/fixtures/users_mock/masto_closed_following_page.json")
1073 }}
1074 end
1075
1076 def get("http://localhost:8080/followers/fuser3", _, _, _) do
1077 {:ok,
1078 %Tesla.Env{
1079 status: 200,
1080 body: File.read!("test/fixtures/users_mock/friendica_followers.json")
1081 }}
1082 end
1083
1084 def get("http://localhost:8080/following/fuser3", _, _, _) do
1085 {:ok,
1086 %Tesla.Env{
1087 status: 200,
1088 body: File.read!("test/fixtures/users_mock/friendica_following.json")
1089 }}
1090 end
1091
1092 def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
1093 {:ok,
1094 %Tesla.Env{
1095 status: 200,
1096 body: File.read!("test/fixtures/users_mock/pleroma_followers.json")
1097 }}
1098 end
1099
1100 def get("http://localhost:4001/users/fuser2/following", _, _, _) do
1101 {:ok,
1102 %Tesla.Env{
1103 status: 200,
1104 body: File.read!("test/fixtures/users_mock/pleroma_following.json")
1105 }}
1106 end
1107
1108 def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
1109 {:ok,
1110 %Tesla.Env{
1111 status: 504,
1112 body: ""
1113 }}
1114 end
1115
1116 def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
1117 {:ok,
1118 %Tesla.Env{
1119 status: 504,
1120 body: ""
1121 }}
1122 end
1123
1124 def get("http://example.com/ogp-missing-data", _, _, _) do
1125 {:ok,
1126 %Tesla.Env{
1127 status: 200,
1128 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
1129 }}
1130 end
1131
1132 def get("https://example.com/ogp-missing-data", _, _, _) do
1133 {:ok,
1134 %Tesla.Env{
1135 status: 200,
1136 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
1137 }}
1138 end
1139
1140 def get("http://example.com/malformed", _, _, _) do
1141 {:ok,
1142 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
1143 end
1144
1145 def get("http://example.com/empty", _, _, _) do
1146 {:ok, %Tesla.Env{status: 200, body: "hello"}}
1147 end
1148
1149 def get("http://404.site" <> _, _, _, _) do
1150 {:ok,
1151 %Tesla.Env{
1152 status: 404,
1153 body: ""
1154 }}
1155 end
1156
1157 def get(
1158 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=acct:lain@zetsubou.xn--q9jyb4c",
1159 _,
1160 _,
1161 [{"accept", "application/xrd+xml,application/jrd+json"}]
1162 ) do
1163 {:ok,
1164 %Tesla.Env{
1165 status: 200,
1166 body: File.read!("test/fixtures/lain.xml")
1167 }}
1168 end
1169
1170 def get(
1171 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=acct:https://zetsubou.xn--q9jyb4c/users/lain",
1172 _,
1173 _,
1174 [{"accept", "application/xrd+xml,application/jrd+json"}]
1175 ) do
1176 {:ok,
1177 %Tesla.Env{
1178 status: 200,
1179 body: File.read!("test/fixtures/lain.xml")
1180 }}
1181 end
1182
1183 def get(
1184 "https://zetsubou.xn--q9jyb4c/.well-known/host-meta",
1185 _,
1186 _,
1187 _
1188 ) do
1189 {:ok,
1190 %Tesla.Env{
1191 status: 200,
1192 body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
1193 }}
1194 end
1195
1196 def get("https://info.pleroma.site/activity.json", _, _, [
1197 {"accept", "application/activity+json"}
1198 ]) do
1199 {:ok,
1200 %Tesla.Env{
1201 status: 200,
1202 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity.json")
1203 }}
1204 end
1205
1206 def get("https://info.pleroma.site/activity.json", _, _, _) do
1207 {:ok, %Tesla.Env{status: 404, body: ""}}
1208 end
1209
1210 def get("https://info.pleroma.site/activity2.json", _, _, [
1211 {"accept", "application/activity+json"}
1212 ]) do
1213 {:ok,
1214 %Tesla.Env{
1215 status: 200,
1216 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json")
1217 }}
1218 end
1219
1220 def get("https://info.pleroma.site/activity2.json", _, _, _) do
1221 {:ok, %Tesla.Env{status: 404, body: ""}}
1222 end
1223
1224 def get("https://info.pleroma.site/activity3.json", _, _, [
1225 {"accept", "application/activity+json"}
1226 ]) do
1227 {:ok,
1228 %Tesla.Env{
1229 status: 200,
1230 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json")
1231 }}
1232 end
1233
1234 def get("https://info.pleroma.site/activity3.json", _, _, _) do
1235 {:ok, %Tesla.Env{status: 404, body: ""}}
1236 end
1237
1238 def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp", _, _, _) do
1239 {:ok,
1240 %Tesla.Env{
1241 status: 200,
1242 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
1243 }}
1244 end
1245
1246 def get("https://10.111.10.1/notice/9kCP7V", _, _, _) do
1247 {:ok, %Tesla.Env{status: 200, body: ""}}
1248 end
1249
1250 def get("https://172.16.32.40/notice/9kCP7V", _, _, _) do
1251 {:ok, %Tesla.Env{status: 200, body: ""}}
1252 end
1253
1254 def get("https://192.168.10.40/notice/9kCP7V", _, _, _) do
1255 {:ok, %Tesla.Env{status: 200, body: ""}}
1256 end
1257
1258 def get("https://www.patreon.com/posts/mastodon-2-9-and-28121681", _, _, _) do
1259 {:ok, %Tesla.Env{status: 200, body: ""}}
1260 end
1261
1262 def get("http://mastodon.example.org/@admin/99541947525187367", _, _, _) do
1263 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/mastodon-post-activity.json")}}
1264 end
1265
1266 def get("https://info.pleroma.site/activity4.json", _, _, _) do
1267 {:ok, %Tesla.Env{status: 500, body: "Error occurred"}}
1268 end
1269
1270 def get("http://example.com/rel_me/anchor", _, _, _) do
1271 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}}
1272 end
1273
1274 def get("http://example.com/rel_me/anchor_nofollow", _, _, _) do
1275 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}}
1276 end
1277
1278 def get("http://example.com/rel_me/link", _, _, _) do
1279 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}}
1280 end
1281
1282 def get("http://example.com/rel_me/null", _, _, _) do
1283 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}}
1284 end
1285
1286 def get("https://skippers-bin.com/notes/7x9tmrp97i", _, _, _) do
1287 {:ok,
1288 %Tesla.Env{
1289 status: 200,
1290 body: File.read!("test/fixtures/tesla_mock/misskey_poll_no_end_date.json")
1291 }}
1292 end
1293
1294 def get("https://example.org/emoji/firedfox.png", _, _, _) do
1295 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/image.jpg")}}
1296 end
1297
1298 def get("https://skippers-bin.com/users/7v1w1r8ce6", _, _, _) do
1299 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sjw.json")}}
1300 end
1301
1302 def get("https://patch.cx/users/rin", _, _, _) do
1303 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/rin.json")}}
1304 end
1305
1306 def get(
1307 "https://channels.tests.funkwhale.audio/federation/music/uploads/42342395-0208-4fee-a38d-259a6dae0871",
1308 _,
1309 _,
1310 _
1311 ) do
1312 {:ok,
1313 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/funkwhale_audio.json")}}
1314 end
1315
1316 def get("https://channels.tests.funkwhale.audio/federation/actors/compositions", _, _, _) do
1317 {:ok,
1318 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/funkwhale_channel.json")}}
1319 end
1320
1321 def get("http://example.com/rel_me/error", _, _, _) do
1322 {:ok, %Tesla.Env{status: 404, body: ""}}
1323 end
1324
1325 def get("https://relay.mastodon.host/actor", _, _, _) do
1326 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/relay/relay.json")}}
1327 end
1328
1329 def get(url, query, body, headers) do
1330 {:error,
1331 "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
1332 inspect(headers)
1333 }"}
1334 end
1335
1336 # POST Requests
1337 #
1338
1339 def post(url, query \\ [], body \\ [], headers \\ [])
1340
1341 def post("https://relay.mastodon.host/inbox", _, _, _) do
1342 {:ok, %Tesla.Env{status: 200, body: ""}}
1343 end
1344
1345 def post("http://example.org/needs_refresh", _, _, _) do
1346 {:ok,
1347 %Tesla.Env{
1348 status: 200,
1349 body: ""
1350 }}
1351 end
1352
1353 def post("http://mastodon.example.org/inbox", _, _, _) do
1354 {:ok,
1355 %Tesla.Env{
1356 status: 200,
1357 body: ""
1358 }}
1359 end
1360
1361 def post("https://hubzilla.example.org/inbox", _, _, _) do
1362 {:ok,
1363 %Tesla.Env{
1364 status: 200,
1365 body: ""
1366 }}
1367 end
1368
1369 def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
1370 {:ok,
1371 %Tesla.Env{
1372 status: 200,
1373 body: ""
1374 }}
1375 end
1376
1377 def post("http://200.site" <> _, _, _, _) do
1378 {:ok,
1379 %Tesla.Env{
1380 status: 200,
1381 body: ""
1382 }}
1383 end
1384
1385 def post("http://connrefused.site" <> _, _, _, _) do
1386 {:error, :connrefused}
1387 end
1388
1389 def post("http://404.site" <> _, _, _, _) do
1390 {:ok,
1391 %Tesla.Env{
1392 status: 404,
1393 body: ""
1394 }}
1395 end
1396
1397 def post(url, query, body, headers) do
1398 {:error,
1399 "Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{
1400 inspect(headers)
1401 }"}
1402 end
1403 end