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