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