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