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