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