7a87a2b357056b97b84ddbc9066c6a17b0084cbf
[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("http://mastodon.example.org/@admin/99541947525187368", _, _, _) do
353 {:ok,
354 %Tesla.Env{
355 status: 404,
356 body: ""
357 }}
358 end
359
360 def get("https://shitposter.club/notice/7369654", _, _, _) do
361 {:ok,
362 %Tesla.Env{
363 status: 200,
364 body: File.read!("test/fixtures/tesla_mock/7369654.html")
365 }}
366 end
367
368 def get("https://mstdn.io/users/mayuutann", _, _, Accept: "application/activity+json") do
369 {:ok,
370 %Tesla.Env{
371 status: 200,
372 body: File.read!("test/fixtures/tesla_mock/mayumayu.json")
373 }}
374 end
375
376 def get(
377 "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
378 _,
379 _,
380 Accept: "application/activity+json"
381 ) do
382 {:ok,
383 %Tesla.Env{
384 status: 200,
385 body: File.read!("test/fixtures/tesla_mock/mayumayupost.json")
386 }}
387 end
388
389 def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do
390 {:ok,
391 %Tesla.Env{
392 status: 200,
393 body:
394 File.read!(
395 "test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
396 )
397 }}
398 end
399
400 def get(url, _, _, Accept: "application/xrd+xml,application/jrd+json")
401 when url in [
402 "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
403 "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
404 ] do
405 {:ok,
406 %Tesla.Env{
407 status: 200,
408 body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
409 }}
410 end
411
412 def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _, _, _) do
413 {:ok,
414 %Tesla.Env{
415 status: 200,
416 body:
417 File.read!(
418 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
419 )
420 }}
421 end
422
423 def get(
424 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
425 _,
426 _,
427 Accept: "application/xrd+xml,application/jrd+json"
428 ) do
429 {:ok,
430 %Tesla.Env{
431 status: 200,
432 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
433 }}
434 end
435
436 def get("https://shitposter.club/notice/2827873", _, _, _) do
437 {:ok,
438 %Tesla.Env{
439 status: 200,
440 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.html")
441 }}
442 end
443
444 def get("https://shitposter.club/api/statuses/show/2827873.atom", _, _, _) do
445 {:ok,
446 %Tesla.Env{
447 status: 200,
448 body:
449 File.read!(
450 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
451 )
452 }}
453 end
454
455 def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
456 {:ok, %Tesla.Env{status: 200}}
457 end
458
459 def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _, _, _) do
460 {:ok,
461 %Tesla.Env{
462 status: 200,
463 body: File.read!("test/fixtures/tesla_mock/spc_5381.atom")
464 }}
465 end
466
467 def get(
468 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
469 _,
470 _,
471 Accept: "application/xrd+xml,application/jrd+json"
472 ) do
473 {:ok,
474 %Tesla.Env{
475 status: 200,
476 body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
477 }}
478 end
479
480 def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
481 {:ok,
482 %Tesla.Env{
483 status: 200,
484 body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
485 }}
486 end
487
488 def get("https://shitposter.club/api/statuses/show/7369654.atom", _, _, _) do
489 {:ok,
490 %Tesla.Env{
491 status: 200,
492 body: File.read!("test/fixtures/tesla_mock/7369654.atom")
493 }}
494 end
495
496 def get("https://shitposter.club/notice/4027863", _, _, _) do
497 {:ok,
498 %Tesla.Env{
499 status: 200,
500 body: File.read!("test/fixtures/tesla_mock/7369654.html")
501 }}
502 end
503
504 def get("https://social.sakamoto.gq/users/eal/feed.atom", _, _, _) do
505 {:ok,
506 %Tesla.Env{
507 status: 200,
508 body: File.read!("test/fixtures/tesla_mock/sakamoto_eal_feed.atom")
509 }}
510 end
511
512 def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
513 {:ok,
514 %Tesla.Env{
515 status: 200,
516 body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
517 }}
518 end
519
520 def get(
521 "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
522 _,
523 _,
524 Accept: "application/xrd+xml,application/jrd+json"
525 ) do
526 {:ok,
527 %Tesla.Env{
528 status: 200,
529 body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
530 }}
531 end
532
533 def get(
534 "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056",
535 _,
536 _,
537 Accept: "application/atom+xml"
538 ) do
539 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sakamoto.atom")}}
540 end
541
542 def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
543 {:ok,
544 %Tesla.Env{
545 status: 200,
546 body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
547 }}
548 end
549
550 def get(
551 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
552 _,
553 _,
554 Accept: "application/xrd+xml,application/jrd+json"
555 ) do
556 {:ok,
557 %Tesla.Env{
558 status: 200,
559 body:
560 File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
561 }}
562 end
563
564 def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
565 {:ok,
566 %Tesla.Env{
567 status: 200,
568 body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
569 }}
570 end
571
572 def get(
573 "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
574 _,
575 _,
576 Accept: "application/xrd+xml,application/jrd+json"
577 ) do
578 {:ok,
579 %Tesla.Env{
580 status: 200,
581 body:
582 File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
583 }}
584 end
585
586 def get(
587 "http://gs.example.org:4040/index.php/user/1",
588 _,
589 _,
590 Accept: "application/activity+json"
591 ) do
592 {:ok, %Tesla.Env{status: 406, body: ""}}
593 end
594
595 def get("http://gs.example.org/index.php/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/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
602 )
603 }}
604 end
605
606 def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _, _, _) do
607 {:ok,
608 %Tesla.Env{
609 status: 200,
610 body:
611 File.read!(
612 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
613 )
614 }}
615 end
616
617 def get("http://squeet.me/.well-known/host-meta", _, _, _) do
618 {:ok,
619 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
620 end
621
622 def get(
623 "https://squeet.me/xrd?uri=lain@squeet.me",
624 _,
625 _,
626 Accept: "application/xrd+xml,application/jrd+json"
627 ) do
628 {:ok,
629 %Tesla.Env{
630 status: 200,
631 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
632 }}
633 end
634
635 def get(
636 "https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la",
637 _,
638 _,
639 Accept: "application/xrd+xml,application/jrd+json"
640 ) do
641 {:ok,
642 %Tesla.Env{
643 status: 200,
644 body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml")
645 }}
646 end
647
648 def get(
649 "https://social.heldscal.la/.well-known/webfinger?resource=invalid_content@social.heldscal.la",
650 _,
651 _,
652 Accept: "application/xrd+xml,application/jrd+json"
653 ) do
654 {:ok, %Tesla.Env{status: 200, body: ""}}
655 end
656
657 def get("http://framatube.org/.well-known/host-meta", _, _, _) do
658 {:ok,
659 %Tesla.Env{
660 status: 200,
661 body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
662 }}
663 end
664
665 def get(
666 "http://framatube.org/main/xrd?uri=framasoft@framatube.org",
667 _,
668 _,
669 Accept: "application/xrd+xml,application/jrd+json"
670 ) do
671 {:ok,
672 %Tesla.Env{
673 status: 200,
674 headers: [{"content-type", "application/json"}],
675 body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
676 }}
677 end
678
679 def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
680 {:ok,
681 %Tesla.Env{
682 status: 200,
683 body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
684 }}
685 end
686
687 def get(
688 "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
689 _,
690 _,
691 Accept: "application/xrd+xml,application/jrd+json"
692 ) do
693 {:ok,
694 %Tesla.Env{
695 status: 200,
696 body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json")
697 }}
698 end
699
700 def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
701 {:ok,
702 %Tesla.Env{
703 status: 200,
704 body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
705 }}
706 end
707
708 def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
709 {:ok,
710 %Tesla.Env{
711 status: 200,
712 body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
713 }}
714 end
715
716 def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
717 {:ok,
718 %Tesla.Env{
719 status: 200,
720 body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
721 }}
722 end
723
724 def get(
725 "https://gerzilla.de/xrd/?uri=kaniini@gerzilla.de",
726 _,
727 _,
728 Accept: "application/xrd+xml,application/jrd+json"
729 ) do
730 {:ok,
731 %Tesla.Env{
732 status: 200,
733 headers: [{"content-type", "application/json"}],
734 body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
735 }}
736 end
737
738 def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _, _, _) do
739 {:ok,
740 %Tesla.Env{
741 status: 200,
742 body:
743 File.read!(
744 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
745 )
746 }}
747 end
748
749 def get(
750 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
751 _,
752 _,
753 _
754 ) do
755 {:ok,
756 %Tesla.Env{
757 status: 200,
758 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
759 }}
760 end
761
762 def get("http://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://social.heldscal.la/.well-known/host-meta", _, _, _) do
771 {:ok,
772 %Tesla.Env{
773 status: 200,
774 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
775 }}
776 end
777
778 def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do
779 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}}
780 end
781
782 def get("https://mastodon.social/users/lambadalambda", _, _, _) do
783 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
784 end
785
786 def get("https://apfed.club/channel/indio", _, _, _) do
787 {:ok,
788 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/osada-user-indio.json")}}
789 end
790
791 def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
792 {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
793 end
794
795 def get("http://example.com/ogp", _, _, _) do
796 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
797 end
798
799 def get("https://example.com/ogp", _, _, _) do
800 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
801 end
802
803 def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
804 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
805 end
806
807 def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
808 {:ok,
809 %Tesla.Env{
810 status: 200,
811 body: File.read!("test/fixtures/users_mock/masto_closed_followers.json")
812 }}
813 end
814
815 def get("http://localhost:4001/users/masto_closed/followers?page=1", _, _, _) do
816 {:ok,
817 %Tesla.Env{
818 status: 200,
819 body: File.read!("test/fixtures/users_mock/masto_closed_followers_page.json")
820 }}
821 end
822
823 def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
824 {:ok,
825 %Tesla.Env{
826 status: 200,
827 body: File.read!("test/fixtures/users_mock/masto_closed_following.json")
828 }}
829 end
830
831 def get("http://localhost:4001/users/masto_closed/following?page=1", _, _, _) do
832 {:ok,
833 %Tesla.Env{
834 status: 200,
835 body: File.read!("test/fixtures/users_mock/masto_closed_following_page.json")
836 }}
837 end
838
839 def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
840 {:ok,
841 %Tesla.Env{
842 status: 200,
843 body: File.read!("test/fixtures/users_mock/pleroma_followers.json")
844 }}
845 end
846
847 def get("http://localhost:4001/users/fuser2/following", _, _, _) do
848 {:ok,
849 %Tesla.Env{
850 status: 200,
851 body: File.read!("test/fixtures/users_mock/pleroma_following.json")
852 }}
853 end
854
855 def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
856 {:ok,
857 %Tesla.Env{
858 status: 504,
859 body: ""
860 }}
861 end
862
863 def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
864 {:ok,
865 %Tesla.Env{
866 status: 504,
867 body: ""
868 }}
869 end
870
871 def get("http://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("https://example.com/ogp-missing-data", _, _, _) do
880 {:ok,
881 %Tesla.Env{
882 status: 200,
883 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
884 }}
885 end
886
887 def get("http://example.com/malformed", _, _, _) do
888 {:ok,
889 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
890 end
891
892 def get("http://example.com/empty", _, _, _) do
893 {:ok, %Tesla.Env{status: 200, body: "hello"}}
894 end
895
896 def get("http://404.site" <> _, _, _, _) do
897 {:ok,
898 %Tesla.Env{
899 status: 404,
900 body: ""
901 }}
902 end
903
904 def get(
905 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=lain@zetsubou.xn--q9jyb4c",
906 _,
907 _,
908 Accept: "application/xrd+xml,application/jrd+json"
909 ) do
910 {:ok,
911 %Tesla.Env{
912 status: 200,
913 body: File.read!("test/fixtures/lain.xml")
914 }}
915 end
916
917 def get(
918 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=https://zetsubou.xn--q9jyb4c/users/lain",
919 _,
920 _,
921 Accept: "application/xrd+xml,application/jrd+json"
922 ) do
923 {:ok,
924 %Tesla.Env{
925 status: 200,
926 body: File.read!("test/fixtures/lain.xml")
927 }}
928 end
929
930 def get(
931 "https://zetsubou.xn--q9jyb4c/.well-known/host-meta",
932 _,
933 _,
934 _
935 ) do
936 {:ok,
937 %Tesla.Env{
938 status: 200,
939 body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
940 }}
941 end
942
943 def get("https://info.pleroma.site/activity.json", _, _, Accept: "application/activity+json") do
944 {:ok,
945 %Tesla.Env{
946 status: 200,
947 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity.json")
948 }}
949 end
950
951 def get("https://info.pleroma.site/activity.json", _, _, _) do
952 {:ok, %Tesla.Env{status: 404, body: ""}}
953 end
954
955 def get("https://info.pleroma.site/activity2.json", _, _, Accept: "application/activity+json") do
956 {:ok,
957 %Tesla.Env{
958 status: 200,
959 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json")
960 }}
961 end
962
963 def get("https://info.pleroma.site/activity2.json", _, _, _) do
964 {:ok, %Tesla.Env{status: 404, body: ""}}
965 end
966
967 def get("https://info.pleroma.site/activity3.json", _, _, Accept: "application/activity+json") do
968 {:ok,
969 %Tesla.Env{
970 status: 200,
971 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json")
972 }}
973 end
974
975 def get("https://info.pleroma.site/activity3.json", _, _, _) do
976 {:ok, %Tesla.Env{status: 404, body: ""}}
977 end
978
979 def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp", _, _, _) do
980 {:ok,
981 %Tesla.Env{
982 status: 200,
983 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
984 }}
985 end
986
987 def get("http://example.com/rel_me/anchor", _, _, _) do
988 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}}
989 end
990
991 def get("http://example.com/rel_me/anchor_nofollow", _, _, _) do
992 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}}
993 end
994
995 def get("http://example.com/rel_me/link", _, _, _) do
996 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}}
997 end
998
999 def get("http://example.com/rel_me/null", _, _, _) do
1000 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}}
1001 end
1002
1003 def get("https://skippers-bin.com/notes/7x9tmrp97i", _, _, _) do
1004 {:ok,
1005 %Tesla.Env{
1006 status: 200,
1007 body: File.read!("test/fixtures/tesla_mock/misskey_poll_no_end_date.json")
1008 }}
1009 end
1010
1011 def get("https://skippers-bin.com/users/7v1w1r8ce6", _, _, _) do
1012 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sjw.json")}}
1013 end
1014
1015 def get("https://patch.cx/users/rin", _, _, _) do
1016 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/rin.json")}}
1017 end
1018
1019 def get(url, query, body, headers) do
1020 {:error,
1021 "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
1022 inspect(headers)
1023 }"}
1024 end
1025
1026 # POST Requests
1027 #
1028
1029 def post(url, query \\ [], body \\ [], headers \\ [])
1030
1031 def post("http://example.org/needs_refresh", _, _, _) do
1032 {:ok,
1033 %Tesla.Env{
1034 status: 200,
1035 body: ""
1036 }}
1037 end
1038
1039 def post("http://mastodon.example.org/inbox", _, _, _) do
1040 {:ok,
1041 %Tesla.Env{
1042 status: 200,
1043 body: ""
1044 }}
1045 end
1046
1047 def post("https://hubzilla.example.org/inbox", _, _, _) do
1048 {:ok,
1049 %Tesla.Env{
1050 status: 200,
1051 body: ""
1052 }}
1053 end
1054
1055 def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
1056 {:ok,
1057 %Tesla.Env{
1058 status: 200,
1059 body: ""
1060 }}
1061 end
1062
1063 def post("http://200.site" <> _, _, _, _) do
1064 {:ok,
1065 %Tesla.Env{
1066 status: 200,
1067 body: ""
1068 }}
1069 end
1070
1071 def post("http://connrefused.site" <> _, _, _, _) do
1072 {:error, :connrefused}
1073 end
1074
1075 def post("http://404.site" <> _, _, _, _) do
1076 {:ok,
1077 %Tesla.Env{
1078 status: 404,
1079 body: ""
1080 }}
1081 end
1082
1083 def post(url, query, body, headers) do
1084 {:error,
1085 "Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{
1086 inspect(headers)
1087 }"}
1088 end
1089 end