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