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