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