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