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