Merge branch 'develop' into refactor/following-relationships
[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://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://baptiste.gelez.xyz/@/BaptisteGelez", _, _, _) do
312 {:ok,
313 %Tesla.Env{
314 status: 200,
315 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json")
316 }}
317 end
318
319 def get("https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/", _, _, _) do
320 {:ok,
321 %Tesla.Env{
322 status: 200,
323 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json")
324 }}
325 end
326
327 def get("https://wedistribute.org/wp-json/pterotype/v1/object/85810", _, _, _) do
328 {:ok,
329 %Tesla.Env{
330 status: 200,
331 body: File.read!("test/fixtures/tesla_mock/wedistribute-article.json")
332 }}
333 end
334
335 def get("https://wedistribute.org/wp-json/pterotype/v1/actor/-blog", _, _, _) do
336 {:ok,
337 %Tesla.Env{
338 status: 200,
339 body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")
340 }}
341 end
342
343 def get("http://mastodon.example.org/users/admin", _, _, Accept: "application/activity+json") do
344 {:ok,
345 %Tesla.Env{
346 status: 200,
347 body: File.read!("test/fixtures/tesla_mock/admin@mastdon.example.org.json")
348 }}
349 end
350
351 def get("http://mastodon.example.org/users/gargron", _, _, Accept: "application/activity+json") do
352 {:error, :nxdomain}
353 end
354
355 def get("http://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
356 {:ok,
357 %Tesla.Env{
358 status: 404,
359 body: ""
360 }}
361 end
362
363 def get("https://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
364 {:ok,
365 %Tesla.Env{
366 status: 404,
367 body: ""
368 }}
369 end
370
371 def get("http://mastodon.sdf.org/.well-known/host-meta", _, _, _) do
372 {:ok,
373 %Tesla.Env{
374 status: 200,
375 body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta")
376 }}
377 end
378
379 def get("https://mastodon.sdf.org/.well-known/host-meta", _, _, _) do
380 {:ok,
381 %Tesla.Env{
382 status: 200,
383 body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta")
384 }}
385 end
386
387 def get(
388 "https://mastodon.sdf.org/.well-known/webfinger?resource=https://mastodon.sdf.org/users/snowdusk",
389 _,
390 _,
391 _
392 ) do
393 {:ok,
394 %Tesla.Env{
395 status: 200,
396 body: File.read!("test/fixtures/tesla_mock/snowdusk@sdf.org_host_meta.json")
397 }}
398 end
399
400 def get("http://mstdn.jp/.well-known/host-meta", _, _, _) do
401 {:ok,
402 %Tesla.Env{
403 status: 200,
404 body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta")
405 }}
406 end
407
408 def get("https://mstdn.jp/.well-known/host-meta", _, _, _) do
409 {:ok,
410 %Tesla.Env{
411 status: 200,
412 body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta")
413 }}
414 end
415
416 def get("https://mstdn.jp/.well-known/webfinger?resource=kpherox@mstdn.jp", _, _, _) do
417 {:ok,
418 %Tesla.Env{
419 status: 200,
420 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
421 }}
422 end
423
424 def get("http://mamot.fr/.well-known/host-meta", _, _, _) do
425 {:ok,
426 %Tesla.Env{
427 status: 200,
428 body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta")
429 }}
430 end
431
432 def get("https://mamot.fr/.well-known/host-meta", _, _, _) do
433 {:ok,
434 %Tesla.Env{
435 status: 200,
436 body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta")
437 }}
438 end
439
440 def get(
441 "https://mamot.fr/.well-known/webfinger?resource=https://mamot.fr/users/Skruyb",
442 _,
443 _,
444 _
445 ) do
446 {:ok,
447 %Tesla.Env{
448 status: 200,
449 body: File.read!("test/fixtures/tesla_mock/skruyb@mamot.fr.atom")
450 }}
451 end
452
453 def get("http://pawoo.net/.well-known/host-meta", _, _, _) do
454 {:ok,
455 %Tesla.Env{
456 status: 200,
457 body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
458 }}
459 end
460
461 def get("https://pawoo.net/.well-known/host-meta", _, _, _) do
462 {:ok,
463 %Tesla.Env{
464 status: 200,
465 body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
466 }}
467 end
468
469 def get(
470 "https://pawoo.net/.well-known/webfinger?resource=https://pawoo.net/users/pekorino",
471 _,
472 _,
473 _
474 ) do
475 {:ok,
476 %Tesla.Env{
477 status: 200,
478 body: File.read!("test/fixtures/tesla_mock/pekorino@pawoo.net_host_meta.json")
479 }}
480 end
481
482 def get("http://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
483 {:ok,
484 %Tesla.Env{
485 status: 200,
486 body: File.read!("test/fixtures/tesla_mock/xn--q9jyb4c_host_meta")
487 }}
488 end
489
490 def get("https://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
491 {:ok,
492 %Tesla.Env{
493 status: 200,
494 body: File.read!("test/fixtures/tesla_mock/xn--q9jyb4c_host_meta")
495 }}
496 end
497
498 def get("http://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
499 {:ok,
500 %Tesla.Env{
501 status: 200,
502 body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta")
503 }}
504 end
505
506 def get("https://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
507 {:ok,
508 %Tesla.Env{
509 status: 200,
510 body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta")
511 }}
512 end
513
514 def get("http://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do
515 {:ok,
516 %Tesla.Env{
517 status: 200,
518 body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta")
519 }}
520 end
521
522 def get("https://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do
523 {:ok,
524 %Tesla.Env{
525 status: 200,
526 body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta")
527 }}
528 end
529
530 def get(
531 "http://mastodon.example.org/@admin/99541947525187367",
532 _,
533 _,
534 Accept: "application/activity+json"
535 ) do
536 {:ok,
537 %Tesla.Env{
538 status: 200,
539 body: File.read!("test/fixtures/mastodon-note-object.json")
540 }}
541 end
542
543 def get("http://mastodon.example.org/@admin/99541947525187368", _, _, _) do
544 {:ok,
545 %Tesla.Env{
546 status: 404,
547 body: ""
548 }}
549 end
550
551 def get("https://shitposter.club/notice/7369654", _, _, _) do
552 {:ok,
553 %Tesla.Env{
554 status: 200,
555 body: File.read!("test/fixtures/tesla_mock/7369654.html")
556 }}
557 end
558
559 def get("https://mstdn.io/users/mayuutann", _, _, Accept: "application/activity+json") do
560 {:ok,
561 %Tesla.Env{
562 status: 200,
563 body: File.read!("test/fixtures/tesla_mock/mayumayu.json")
564 }}
565 end
566
567 def get(
568 "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
569 _,
570 _,
571 Accept: "application/activity+json"
572 ) do
573 {:ok,
574 %Tesla.Env{
575 status: 200,
576 body: File.read!("test/fixtures/tesla_mock/mayumayupost.json")
577 }}
578 end
579
580 def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do
581 {:ok,
582 %Tesla.Env{
583 status: 200,
584 body:
585 File.read!(
586 "test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
587 )
588 }}
589 end
590
591 def get(url, _, _, Accept: "application/xrd+xml,application/jrd+json")
592 when url in [
593 "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
594 "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
595 ] do
596 {:ok,
597 %Tesla.Env{
598 status: 200,
599 body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
600 }}
601 end
602
603 def get("https://shitposter.club/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/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
610 )
611 }}
612 end
613
614 def get(
615 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
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/https___shitposter.club_user_1.xml")
624 }}
625 end
626
627 def get("https://shitposter.club/notice/2827873", _, _, _) do
628 {:ok,
629 %Tesla.Env{
630 status: 200,
631 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.json")
632 }}
633 end
634
635 def get("https://shitposter.club/api/statuses/show/2827873.atom", _, _, _) do
636 {:ok,
637 %Tesla.Env{
638 status: 200,
639 body:
640 File.read!(
641 "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
642 )
643 }}
644 end
645
646 def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
647 {:ok, %Tesla.Env{status: 200}}
648 end
649
650 def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _, _, _) do
651 {:ok,
652 %Tesla.Env{
653 status: 200,
654 body: File.read!("test/fixtures/tesla_mock/spc_5381.atom")
655 }}
656 end
657
658 def get(
659 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
660 _,
661 _,
662 Accept: "application/xrd+xml,application/jrd+json"
663 ) do
664 {:ok,
665 %Tesla.Env{
666 status: 200,
667 body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
668 }}
669 end
670
671 def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
672 {:ok,
673 %Tesla.Env{
674 status: 200,
675 body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
676 }}
677 end
678
679 def get("https://shitposter.club/api/statuses/show/7369654.atom", _, _, _) do
680 {:ok,
681 %Tesla.Env{
682 status: 200,
683 body: File.read!("test/fixtures/tesla_mock/7369654.atom")
684 }}
685 end
686
687 def get("https://shitposter.club/notice/4027863", _, _, _) do
688 {:ok,
689 %Tesla.Env{
690 status: 200,
691 body: File.read!("test/fixtures/tesla_mock/7369654.html")
692 }}
693 end
694
695 def get("https://social.sakamoto.gq/users/eal/feed.atom", _, _, _) do
696 {:ok,
697 %Tesla.Env{
698 status: 200,
699 body: File.read!("test/fixtures/tesla_mock/sakamoto_eal_feed.atom")
700 }}
701 end
702
703 def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
704 {:ok,
705 %Tesla.Env{
706 status: 200,
707 body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
708 }}
709 end
710
711 def get(
712 "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
713 _,
714 _,
715 Accept: "application/xrd+xml,application/jrd+json"
716 ) do
717 {:ok,
718 %Tesla.Env{
719 status: 200,
720 body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
721 }}
722 end
723
724 def get(
725 "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056",
726 _,
727 _,
728 Accept: "application/atom+xml"
729 ) do
730 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sakamoto.atom")}}
731 end
732
733 def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
734 {:ok,
735 %Tesla.Env{
736 status: 200,
737 body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
738 }}
739 end
740
741 def get(
742 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
743 _,
744 _,
745 Accept: "application/xrd+xml,application/jrd+json"
746 ) do
747 {:ok,
748 %Tesla.Env{
749 status: 200,
750 body:
751 File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
752 }}
753 end
754
755 def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
756 {:ok,
757 %Tesla.Env{
758 status: 200,
759 body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
760 }}
761 end
762
763 def get(
764 "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
765 _,
766 _,
767 Accept: "application/xrd+xml,application/jrd+json"
768 ) do
769 {:ok,
770 %Tesla.Env{
771 status: 200,
772 body:
773 File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
774 }}
775 end
776
777 def get(
778 "http://gs.example.org:4040/index.php/user/1",
779 _,
780 _,
781 Accept: "application/activity+json"
782 ) do
783 {:ok, %Tesla.Env{status: 406, body: ""}}
784 end
785
786 def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _, _, _) do
787 {:ok,
788 %Tesla.Env{
789 status: 200,
790 body:
791 File.read!(
792 "test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
793 )
794 }}
795 end
796
797 def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _, _, _) do
798 {:ok,
799 %Tesla.Env{
800 status: 200,
801 body:
802 File.read!(
803 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
804 )
805 }}
806 end
807
808 def get("http://squeet.me/.well-known/host-meta", _, _, _) do
809 {:ok,
810 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
811 end
812
813 def get(
814 "https://squeet.me/xrd?uri=lain@squeet.me",
815 _,
816 _,
817 Accept: "application/xrd+xml,application/jrd+json"
818 ) do
819 {:ok,
820 %Tesla.Env{
821 status: 200,
822 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
823 }}
824 end
825
826 def get(
827 "https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la",
828 _,
829 _,
830 Accept: "application/xrd+xml,application/jrd+json"
831 ) do
832 {:ok,
833 %Tesla.Env{
834 status: 200,
835 body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml")
836 }}
837 end
838
839 def get(
840 "https://social.heldscal.la/.well-known/webfinger?resource=invalid_content@social.heldscal.la",
841 _,
842 _,
843 Accept: "application/xrd+xml,application/jrd+json"
844 ) do
845 {:ok, %Tesla.Env{status: 200, body: ""}}
846 end
847
848 def get("http://framatube.org/.well-known/host-meta", _, _, _) do
849 {:ok,
850 %Tesla.Env{
851 status: 200,
852 body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
853 }}
854 end
855
856 def get(
857 "http://framatube.org/main/xrd?uri=framasoft@framatube.org",
858 _,
859 _,
860 Accept: "application/xrd+xml,application/jrd+json"
861 ) do
862 {:ok,
863 %Tesla.Env{
864 status: 200,
865 headers: [{"content-type", "application/json"}],
866 body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
867 }}
868 end
869
870 def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
871 {:ok,
872 %Tesla.Env{
873 status: 200,
874 body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
875 }}
876 end
877
878 def get(
879 "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
880 _,
881 _,
882 Accept: "application/xrd+xml,application/jrd+json"
883 ) do
884 {:ok,
885 %Tesla.Env{
886 status: 200,
887 body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json")
888 }}
889 end
890
891 def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
892 {:ok,
893 %Tesla.Env{
894 status: 200,
895 body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
896 }}
897 end
898
899 def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
900 {:ok,
901 %Tesla.Env{
902 status: 200,
903 body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
904 }}
905 end
906
907 def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
908 {:ok,
909 %Tesla.Env{
910 status: 200,
911 body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
912 }}
913 end
914
915 def get(
916 "https://gerzilla.de/xrd/?uri=kaniini@gerzilla.de",
917 _,
918 _,
919 Accept: "application/xrd+xml,application/jrd+json"
920 ) do
921 {:ok,
922 %Tesla.Env{
923 status: 200,
924 headers: [{"content-type", "application/json"}],
925 body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
926 }}
927 end
928
929 def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _, _, _) do
930 {:ok,
931 %Tesla.Env{
932 status: 200,
933 body:
934 File.read!(
935 "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
936 )
937 }}
938 end
939
940 def get(
941 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
942 _,
943 _,
944 _
945 ) do
946 {:ok,
947 %Tesla.Env{
948 status: 200,
949 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
950 }}
951 end
952
953 def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
954 {:ok,
955 %Tesla.Env{
956 status: 200,
957 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
958 }}
959 end
960
961 def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
962 {:ok,
963 %Tesla.Env{
964 status: 200,
965 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
966 }}
967 end
968
969 def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do
970 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}}
971 end
972
973 def get("https://mastodon.social/users/lambadalambda", _, _, _) do
974 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
975 end
976
977 def get("https://apfed.club/channel/indio", _, _, _) do
978 {:ok,
979 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/osada-user-indio.json")}}
980 end
981
982 def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
983 {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
984 end
985
986 def get("http://example.com/ogp", _, _, _) do
987 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
988 end
989
990 def get("https://example.com/ogp", _, _, _) do
991 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
992 end
993
994 def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
995 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
996 end
997
998 def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
999 {:ok,
1000 %Tesla.Env{
1001 status: 200,
1002 body: File.read!("test/fixtures/users_mock/masto_closed_followers.json")
1003 }}
1004 end
1005
1006 def get("http://localhost:4001/users/masto_closed/followers?page=1", _, _, _) do
1007 {:ok,
1008 %Tesla.Env{
1009 status: 200,
1010 body: File.read!("test/fixtures/users_mock/masto_closed_followers_page.json")
1011 }}
1012 end
1013
1014 def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
1015 {:ok,
1016 %Tesla.Env{
1017 status: 200,
1018 body: File.read!("test/fixtures/users_mock/masto_closed_following.json")
1019 }}
1020 end
1021
1022 def get("http://localhost:4001/users/masto_closed/following?page=1", _, _, _) do
1023 {:ok,
1024 %Tesla.Env{
1025 status: 200,
1026 body: File.read!("test/fixtures/users_mock/masto_closed_following_page.json")
1027 }}
1028 end
1029
1030 def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
1031 {:ok,
1032 %Tesla.Env{
1033 status: 200,
1034 body: File.read!("test/fixtures/users_mock/pleroma_followers.json")
1035 }}
1036 end
1037
1038 def get("http://localhost:4001/users/fuser2/following", _, _, _) do
1039 {:ok,
1040 %Tesla.Env{
1041 status: 200,
1042 body: File.read!("test/fixtures/users_mock/pleroma_following.json")
1043 }}
1044 end
1045
1046 def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
1047 {:ok,
1048 %Tesla.Env{
1049 status: 504,
1050 body: ""
1051 }}
1052 end
1053
1054 def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
1055 {:ok,
1056 %Tesla.Env{
1057 status: 504,
1058 body: ""
1059 }}
1060 end
1061
1062 def get("http://example.com/ogp-missing-data", _, _, _) do
1063 {:ok,
1064 %Tesla.Env{
1065 status: 200,
1066 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
1067 }}
1068 end
1069
1070 def get("https://example.com/ogp-missing-data", _, _, _) do
1071 {:ok,
1072 %Tesla.Env{
1073 status: 200,
1074 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
1075 }}
1076 end
1077
1078 def get("http://example.com/malformed", _, _, _) do
1079 {:ok,
1080 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
1081 end
1082
1083 def get("http://example.com/empty", _, _, _) do
1084 {:ok, %Tesla.Env{status: 200, body: "hello"}}
1085 end
1086
1087 def get("http://404.site" <> _, _, _, _) do
1088 {:ok,
1089 %Tesla.Env{
1090 status: 404,
1091 body: ""
1092 }}
1093 end
1094
1095 def get(
1096 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=lain@zetsubou.xn--q9jyb4c",
1097 _,
1098 _,
1099 Accept: "application/xrd+xml,application/jrd+json"
1100 ) do
1101 {:ok,
1102 %Tesla.Env{
1103 status: 200,
1104 body: File.read!("test/fixtures/lain.xml")
1105 }}
1106 end
1107
1108 def get(
1109 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=https://zetsubou.xn--q9jyb4c/users/lain",
1110 _,
1111 _,
1112 Accept: "application/xrd+xml,application/jrd+json"
1113 ) do
1114 {:ok,
1115 %Tesla.Env{
1116 status: 200,
1117 body: File.read!("test/fixtures/lain.xml")
1118 }}
1119 end
1120
1121 def get(
1122 "https://zetsubou.xn--q9jyb4c/.well-known/host-meta",
1123 _,
1124 _,
1125 _
1126 ) do
1127 {:ok,
1128 %Tesla.Env{
1129 status: 200,
1130 body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
1131 }}
1132 end
1133
1134 def get("https://info.pleroma.site/activity.json", _, _, Accept: "application/activity+json") do
1135 {:ok,
1136 %Tesla.Env{
1137 status: 200,
1138 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity.json")
1139 }}
1140 end
1141
1142 def get("https://info.pleroma.site/activity.json", _, _, _) do
1143 {:ok, %Tesla.Env{status: 404, body: ""}}
1144 end
1145
1146 def get("https://info.pleroma.site/activity2.json", _, _, Accept: "application/activity+json") do
1147 {:ok,
1148 %Tesla.Env{
1149 status: 200,
1150 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json")
1151 }}
1152 end
1153
1154 def get("https://info.pleroma.site/activity2.json", _, _, _) do
1155 {:ok, %Tesla.Env{status: 404, body: ""}}
1156 end
1157
1158 def get("https://info.pleroma.site/activity3.json", _, _, Accept: "application/activity+json") do
1159 {:ok,
1160 %Tesla.Env{
1161 status: 200,
1162 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json")
1163 }}
1164 end
1165
1166 def get("https://info.pleroma.site/activity3.json", _, _, _) do
1167 {:ok, %Tesla.Env{status: 404, body: ""}}
1168 end
1169
1170 def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp", _, _, _) do
1171 {:ok,
1172 %Tesla.Env{
1173 status: 200,
1174 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
1175 }}
1176 end
1177
1178 def get("http://example.com/rel_me/anchor", _, _, _) do
1179 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}}
1180 end
1181
1182 def get("http://example.com/rel_me/anchor_nofollow", _, _, _) do
1183 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}}
1184 end
1185
1186 def get("http://example.com/rel_me/link", _, _, _) do
1187 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}}
1188 end
1189
1190 def get("http://example.com/rel_me/null", _, _, _) do
1191 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}}
1192 end
1193
1194 def get("https://skippers-bin.com/notes/7x9tmrp97i", _, _, _) do
1195 {:ok,
1196 %Tesla.Env{
1197 status: 200,
1198 body: File.read!("test/fixtures/tesla_mock/misskey_poll_no_end_date.json")
1199 }}
1200 end
1201
1202 def get("https://skippers-bin.com/users/7v1w1r8ce6", _, _, _) do
1203 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sjw.json")}}
1204 end
1205
1206 def get("https://patch.cx/users/rin", _, _, _) do
1207 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/rin.json")}}
1208 end
1209
1210 def get(url, query, body, headers) do
1211 {:error,
1212 "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
1213 inspect(headers)
1214 }"}
1215 end
1216
1217 # POST Requests
1218 #
1219
1220 def post(url, query \\ [], body \\ [], headers \\ [])
1221
1222 def post("http://example.org/needs_refresh", _, _, _) do
1223 {:ok,
1224 %Tesla.Env{
1225 status: 200,
1226 body: ""
1227 }}
1228 end
1229
1230 def post("http://mastodon.example.org/inbox", _, _, _) do
1231 {:ok,
1232 %Tesla.Env{
1233 status: 200,
1234 body: ""
1235 }}
1236 end
1237
1238 def post("https://hubzilla.example.org/inbox", _, _, _) do
1239 {:ok,
1240 %Tesla.Env{
1241 status: 200,
1242 body: ""
1243 }}
1244 end
1245
1246 def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
1247 {:ok,
1248 %Tesla.Env{
1249 status: 200,
1250 body: ""
1251 }}
1252 end
1253
1254 def post("http://200.site" <> _, _, _, _) do
1255 {:ok,
1256 %Tesla.Env{
1257 status: 200,
1258 body: ""
1259 }}
1260 end
1261
1262 def post("http://connrefused.site" <> _, _, _, _) do
1263 {:error, :connrefused}
1264 end
1265
1266 def post("http://404.site" <> _, _, _, _) do
1267 {:ok,
1268 %Tesla.Env{
1269 status: 404,
1270 body: ""
1271 }}
1272 end
1273
1274 def post(url, query, body, headers) do
1275 {:error,
1276 "Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{
1277 inspect(headers)
1278 }"}
1279 end
1280 end