Merge remote-tracking branch 'pleroma/develop' into cycles-router-api-routes
[akkoma] / test / support / http_request_mock.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule HttpRequestMock do
6 require Logger
7
8 def activitypub_object_headers, do: [{"content-type", "application/activity+json"}]
9
10 def request(
11 %Tesla.Env{
12 url: url,
13 method: method,
14 headers: headers,
15 query: query,
16 body: body
17 } = _env
18 ) do
19 with {:ok, res} <- apply(__MODULE__, method, [url, query, body, headers]) do
20 res
21 else
22 error ->
23 with {:error, message} <- error do
24 Logger.warn(to_string(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 headers: activitypub_object_headers()
41 }}
42 end
43
44 def get("https://shitposter.club/users/moonman", _, _, _) do
45 {:ok,
46 %Tesla.Env{
47 status: 200,
48 body: File.read!("test/fixtures/tesla_mock/moonman@shitposter.club.json"),
49 headers: activitypub_object_headers()
50 }}
51 end
52
53 def get("https://mastodon.social/users/emelie/statuses/101849165031453009", _, _, _) do
54 {:ok,
55 %Tesla.Env{
56 status: 200,
57 body: File.read!("test/fixtures/tesla_mock/status.emelie.json"),
58 headers: activitypub_object_headers()
59 }}
60 end
61
62 def get("https://mastodon.social/users/emelie/statuses/101849165031453404", _, _, _) do
63 {:ok,
64 %Tesla.Env{
65 status: 404,
66 body: ""
67 }}
68 end
69
70 def get("https://mastodon.social/users/emelie", _, _, _) do
71 {:ok,
72 %Tesla.Env{
73 status: 200,
74 body: File.read!("test/fixtures/tesla_mock/emelie.json"),
75 headers: activitypub_object_headers()
76 }}
77 end
78
79 def get("https://mastodon.social/users/not_found", _, _, _) do
80 {:ok, %Tesla.Env{status: 404}}
81 end
82
83 def get("https://mastodon.sdf.org/users/rinpatch", _, _, _) do
84 {:ok,
85 %Tesla.Env{
86 status: 200,
87 body: File.read!("test/fixtures/tesla_mock/rinpatch.json"),
88 headers: activitypub_object_headers()
89 }}
90 end
91
92 def get("https://mastodon.sdf.org/users/rinpatch/collections/featured", _, _, _) do
93 {:ok,
94 %Tesla.Env{
95 status: 200,
96 body:
97 File.read!("test/fixtures/users_mock/masto_featured.json")
98 |> String.replace("{{domain}}", "mastodon.sdf.org")
99 |> String.replace("{{nickname}}", "rinpatch"),
100 headers: [{"content-type", "application/activity+json"}]
101 }}
102 end
103
104 def get("https://patch.cx/objects/tesla_mock/poll_attachment", _, _, _) do
105 {:ok,
106 %Tesla.Env{
107 status: 200,
108 body: File.read!("test/fixtures/tesla_mock/poll_attachment.json"),
109 headers: activitypub_object_headers()
110 }}
111 end
112
113 def get(
114 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/emelie",
115 _,
116 _,
117 _
118 ) do
119 {:ok,
120 %Tesla.Env{
121 status: 200,
122 body: File.read!("test/fixtures/tesla_mock/webfinger_emelie.json"),
123 headers: activitypub_object_headers()
124 }}
125 end
126
127 def get(
128 "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",
129 _,
130 _,
131 [{"accept", "application/xrd+xml,application/jrd+json"}]
132 ) do
133 {:ok,
134 %Tesla.Env{
135 status: 200,
136 body: File.read!("test/fixtures/tesla_mock/mike@osada.macgirvin.com.json"),
137 headers: [{"content-type", "application/jrd+json"}]
138 }}
139 end
140
141 def get(
142 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
143 _,
144 _,
145 [{"accept", "application/xrd+xml,application/jrd+json"}]
146 ) do
147 {:ok,
148 %Tesla.Env{
149 status: 200,
150 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_29191.xml")
151 }}
152 end
153
154 def get(
155 "https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",
156 _,
157 _,
158 [{"accept", "application/xrd+xml,application/jrd+json"}]
159 ) do
160 {:ok,
161 %Tesla.Env{
162 status: 200,
163 body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml")
164 }}
165 end
166
167 def get(
168 "https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",
169 _,
170 _,
171 [{"accept", "application/xrd+xml,application/jrd+json"}]
172 ) do
173 {:ok,
174 %Tesla.Env{
175 status: 200,
176 body: File.read!("test/fixtures/tesla_mock/atarifrosch_webfinger.xml")
177 }}
178 end
179
180 def get(
181 "https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la",
182 _,
183 _,
184 [{"accept", "application/xrd+xml,application/jrd+json"}]
185 ) do
186 {:ok,
187 %Tesla.Env{
188 status: 200,
189 body: File.read!("test/fixtures/tesla_mock/nonexistant@social.heldscal.la.xml")
190 }}
191 end
192
193 def get(
194 "https://squeet.me/xrd/?uri=acct:lain@squeet.me",
195 _,
196 _,
197 [{"accept", "application/xrd+xml,application/jrd+json"}]
198 ) do
199 {:ok,
200 %Tesla.Env{
201 status: 200,
202 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml"),
203 headers: [{"content-type", "application/xrd+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 headers: activitypub_object_headers()
218 }}
219 end
220
221 def get("https://prismo.news/@mxb", _, _, _) do
222 {:ok,
223 %Tesla.Env{
224 status: 200,
225 body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json"),
226 headers: activitypub_object_headers()
227 }}
228 end
229
230 def get(
231 "https://hubzilla.example.org/channel/kaniini",
232 _,
233 _,
234 [{"accept", "application/activity+json"}]
235 ) do
236 {:ok,
237 %Tesla.Env{
238 status: 200,
239 body: File.read!("test/fixtures/tesla_mock/kaniini@hubzilla.example.org.json"),
240 headers: activitypub_object_headers()
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 headers: activitypub_object_headers()
250 }}
251 end
252
253 def get("https://n1u.moe/users/rye", _, _, [{"accept", "application/activity+json"}]) do
254 {:ok,
255 %Tesla.Env{
256 status: 200,
257 body: File.read!("test/fixtures/tesla_mock/rye.json"),
258 headers: activitypub_object_headers()
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 headers: activitypub_object_headers()
279 }}
280 end
281
282 def get("https://peertube.moe/accounts/7even", _, _, _) do
283 {:ok,
284 %Tesla.Env{
285 status: 200,
286 body: File.read!("test/fixtures/tesla_mock/7even.json"),
287 headers: activitypub_object_headers()
288 }}
289 end
290
291 def get("https://peertube.stream/accounts/createurs", _, _, _) do
292 {:ok,
293 %Tesla.Env{
294 status: 200,
295 body: File.read!("test/fixtures/peertube/actor-person.json"),
296 headers: activitypub_object_headers()
297 }}
298 end
299
300 def get("https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3", _, _, _) do
301 {:ok,
302 %Tesla.Env{
303 status: 200,
304 body: File.read!("test/fixtures/tesla_mock/peertube.moe-vid.json"),
305 headers: activitypub_object_headers()
306 }}
307 end
308
309 def get("https://framatube.org/accounts/framasoft", _, _, _) do
310 {:ok,
311 %Tesla.Env{
312 status: 200,
313 body: File.read!("test/fixtures/tesla_mock/https___framatube.org_accounts_framasoft.json"),
314 headers: activitypub_object_headers()
315 }}
316 end
317
318 def get("https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206", _, _, _) do
319 {:ok,
320 %Tesla.Env{
321 status: 200,
322 body: File.read!("test/fixtures/tesla_mock/framatube.org-video.json"),
323 headers: activitypub_object_headers()
324 }}
325 end
326
327 def get("https://peertube.social/accounts/craigmaloney", _, _, _) do
328 {:ok,
329 %Tesla.Env{
330 status: 200,
331 body: File.read!("test/fixtures/tesla_mock/craigmaloney.json"),
332 headers: activitypub_object_headers()
333 }}
334 end
335
336 def get("https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe", _, _, _) do
337 {:ok,
338 %Tesla.Env{
339 status: 200,
340 body: File.read!("test/fixtures/tesla_mock/peertube-social.json"),
341 headers: activitypub_object_headers()
342 }}
343 end
344
345 def get("https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39", _, _, [
346 {"accept", "application/activity+json"}
347 ]) do
348 {:ok,
349 %Tesla.Env{
350 status: 200,
351 body: File.read!("test/fixtures/tesla_mock/mobilizon.org-event.json"),
352 headers: activitypub_object_headers()
353 }}
354 end
355
356 def get("https://mobilizon.org/@tcit", _, _, [{"accept", "application/activity+json"}]) do
357 {:ok,
358 %Tesla.Env{
359 status: 200,
360 body: File.read!("test/fixtures/tesla_mock/mobilizon.org-user.json"),
361 headers: activitypub_object_headers()
362 }}
363 end
364
365 def get("https://baptiste.gelez.xyz/@/BaptisteGelez", _, _, _) do
366 {:ok,
367 %Tesla.Env{
368 status: 200,
369 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json"),
370 headers: activitypub_object_headers()
371 }}
372 end
373
374 def get("https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/", _, _, _) do
375 {:ok,
376 %Tesla.Env{
377 status: 200,
378 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json"),
379 headers: activitypub_object_headers()
380 }}
381 end
382
383 def get("https://wedistribute.org/wp-json/pterotype/v1/object/85810", _, _, _) do
384 {:ok,
385 %Tesla.Env{
386 status: 200,
387 body: File.read!("test/fixtures/tesla_mock/wedistribute-article.json"),
388 headers: activitypub_object_headers()
389 }}
390 end
391
392 def get("https://wedistribute.org/wp-json/pterotype/v1/actor/-blog", _, _, _) do
393 {:ok,
394 %Tesla.Env{
395 status: 200,
396 body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json"),
397 headers: activitypub_object_headers()
398 }}
399 end
400
401 def get("http://mastodon.example.org/users/admin", _, _, _) do
402 {:ok,
403 %Tesla.Env{
404 status: 200,
405 body: File.read!("test/fixtures/tesla_mock/admin@mastdon.example.org.json"),
406 headers: activitypub_object_headers()
407 }}
408 end
409
410 def get("http://mastodon.example.org/users/relay", _, _, [
411 {"accept", "application/activity+json"}
412 ]) do
413 {:ok,
414 %Tesla.Env{
415 status: 200,
416 body: File.read!("test/fixtures/tesla_mock/relay@mastdon.example.org.json"),
417 headers: activitypub_object_headers()
418 }}
419 end
420
421 def get("http://mastodon.example.org/users/gargron", _, _, [
422 {"accept", "application/activity+json"}
423 ]) do
424 {:error, :nxdomain}
425 end
426
427 def get("http://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
428 {:ok,
429 %Tesla.Env{
430 status: 404,
431 body: ""
432 }}
433 end
434
435 def get("https://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
436 {:ok,
437 %Tesla.Env{
438 status: 404,
439 body: ""
440 }}
441 end
442
443 def get("http://mastodon.sdf.org/.well-known/host-meta", _, _, _) do
444 {:ok,
445 %Tesla.Env{
446 status: 200,
447 body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta")
448 }}
449 end
450
451 def get("https://mastodon.sdf.org/.well-known/host-meta", _, _, _) do
452 {:ok,
453 %Tesla.Env{
454 status: 200,
455 body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta")
456 }}
457 end
458
459 def get(
460 "https://mastodon.sdf.org/.well-known/webfinger?resource=https://mastodon.sdf.org/users/snowdusk",
461 _,
462 _,
463 _
464 ) do
465 {:ok,
466 %Tesla.Env{
467 status: 200,
468 body: File.read!("test/fixtures/tesla_mock/snowdusk@sdf.org_host_meta.json")
469 }}
470 end
471
472 def get("http://mstdn.jp/.well-known/host-meta", _, _, _) do
473 {:ok,
474 %Tesla.Env{
475 status: 200,
476 body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta")
477 }}
478 end
479
480 def get("https://mstdn.jp/.well-known/host-meta", _, _, _) do
481 {:ok,
482 %Tesla.Env{
483 status: 200,
484 body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta")
485 }}
486 end
487
488 def get("https://mstdn.jp/.well-known/webfinger?resource=kpherox@mstdn.jp", _, _, _) do
489 {:ok,
490 %Tesla.Env{
491 status: 200,
492 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
493 }}
494 end
495
496 def get("http://mamot.fr/.well-known/host-meta", _, _, _) do
497 {:ok,
498 %Tesla.Env{
499 status: 200,
500 body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta")
501 }}
502 end
503
504 def get("https://mamot.fr/.well-known/host-meta", _, _, _) do
505 {:ok,
506 %Tesla.Env{
507 status: 200,
508 body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta")
509 }}
510 end
511
512 def get("http://pawoo.net/.well-known/host-meta", _, _, _) do
513 {:ok,
514 %Tesla.Env{
515 status: 200,
516 body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
517 }}
518 end
519
520 def get("https://pawoo.net/.well-known/host-meta", _, _, _) do
521 {:ok,
522 %Tesla.Env{
523 status: 200,
524 body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
525 }}
526 end
527
528 def get(
529 "https://pawoo.net/.well-known/webfinger?resource=https://pawoo.net/users/pekorino",
530 _,
531 _,
532 _
533 ) do
534 {:ok,
535 %Tesla.Env{
536 status: 200,
537 body: File.read!("test/fixtures/tesla_mock/pekorino@pawoo.net_host_meta.json"),
538 headers: activitypub_object_headers()
539 }}
540 end
541
542 def get("http://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
543 {:ok,
544 %Tesla.Env{
545 status: 200,
546 body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta")
547 }}
548 end
549
550 def get("https://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
551 {:ok,
552 %Tesla.Env{
553 status: 200,
554 body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta")
555 }}
556 end
557
558 def get("http://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do
559 {:ok,
560 %Tesla.Env{
561 status: 200,
562 body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta")
563 }}
564 end
565
566 def get("https://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do
567 {:ok,
568 %Tesla.Env{
569 status: 200,
570 body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta")
571 }}
572 end
573
574 def get(
575 "http://mastodon.example.org/@admin/99541947525187367",
576 _,
577 _,
578 _
579 ) do
580 {:ok,
581 %Tesla.Env{
582 status: 200,
583 body: File.read!("test/fixtures/mastodon-note-object.json"),
584 headers: activitypub_object_headers()
585 }}
586 end
587
588 def get("http://mastodon.example.org/@admin/99541947525187368", _, _, _) do
589 {:ok,
590 %Tesla.Env{
591 status: 404,
592 body: ""
593 }}
594 end
595
596 def get("https://shitposter.club/notice/7369654", _, _, _) do
597 {:ok,
598 %Tesla.Env{
599 status: 200,
600 body: File.read!("test/fixtures/tesla_mock/7369654.html")
601 }}
602 end
603
604 def get("https://mstdn.io/users/mayuutann", _, _, [{"accept", "application/activity+json"}]) do
605 {:ok,
606 %Tesla.Env{
607 status: 200,
608 body: File.read!("test/fixtures/tesla_mock/mayumayu.json"),
609 headers: activitypub_object_headers()
610 }}
611 end
612
613 def get(
614 "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
615 _,
616 _,
617 [{"accept", "application/activity+json"}]
618 ) do
619 {:ok,
620 %Tesla.Env{
621 status: 200,
622 body: File.read!("test/fixtures/tesla_mock/mayumayupost.json"),
623 headers: activitypub_object_headers()
624 }}
625 end
626
627 def get(url, _, _, [{"accept", "application/xrd+xml,application/jrd+json"}])
628 when url in [
629 "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
630 "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
631 ] do
632 {:ok,
633 %Tesla.Env{
634 status: 200,
635 body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
636 }}
637 end
638
639 def get(
640 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
641 _,
642 _,
643 [{"accept", "application/xrd+xml,application/jrd+json"}]
644 ) do
645 {:ok,
646 %Tesla.Env{
647 status: 200,
648 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
649 }}
650 end
651
652 def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
653 {:ok, %Tesla.Env{status: 200}}
654 end
655
656 def get(
657 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
658 _,
659 _,
660 [{"accept", "application/xrd+xml,application/jrd+json"}]
661 ) do
662 {:ok,
663 %Tesla.Env{
664 status: 200,
665 body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
666 }}
667 end
668
669 def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
670 {:ok,
671 %Tesla.Env{
672 status: 200,
673 body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
674 }}
675 end
676
677 def get("https://shitposter.club/notice/4027863", _, _, _) do
678 {:ok,
679 %Tesla.Env{
680 status: 200,
681 body: File.read!("test/fixtures/tesla_mock/7369654.html")
682 }}
683 end
684
685 def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
686 {:ok,
687 %Tesla.Env{
688 status: 200,
689 body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
690 }}
691 end
692
693 def get(
694 "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
695 _,
696 _,
697 [{"accept", "application/xrd+xml,application/jrd+json"}]
698 ) do
699 {:ok,
700 %Tesla.Env{
701 status: 200,
702 body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
703 }}
704 end
705
706 def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
707 {:ok,
708 %Tesla.Env{
709 status: 200,
710 body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
711 }}
712 end
713
714 def get(
715 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
716 _,
717 _,
718 [{"accept", "application/xrd+xml,application/jrd+json"}]
719 ) do
720 {:ok,
721 %Tesla.Env{
722 status: 200,
723 body:
724 File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
725 }}
726 end
727
728 def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
729 {:ok,
730 %Tesla.Env{
731 status: 200,
732 body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
733 }}
734 end
735
736 def get(
737 "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
738 _,
739 _,
740 [{"accept", "application/xrd+xml,application/jrd+json"}]
741 ) do
742 {:ok,
743 %Tesla.Env{
744 status: 200,
745 body:
746 File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
747 }}
748 end
749
750 def get(
751 "http://gs.example.org:4040/index.php/user/1",
752 _,
753 _,
754 [{"accept", "application/activity+json"}]
755 ) do
756 {:ok, %Tesla.Env{status: 406, body: ""}}
757 end
758
759 def get("http://squeet.me/.well-known/host-meta", _, _, _) do
760 {:ok,
761 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
762 end
763
764 def get(
765 "https://squeet.me/xrd?uri=lain@squeet.me",
766 _,
767 _,
768 [{"accept", "application/xrd+xml,application/jrd+json"}]
769 ) do
770 {:ok,
771 %Tesla.Env{
772 status: 200,
773 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
774 }}
775 end
776
777 def get(
778 "https://social.heldscal.la/.well-known/webfinger?resource=acct:shp@social.heldscal.la",
779 _,
780 _,
781 [{"accept", "application/xrd+xml,application/jrd+json"}]
782 ) do
783 {:ok,
784 %Tesla.Env{
785 status: 200,
786 body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml"),
787 headers: [{"content-type", "application/xrd+xml"}]
788 }}
789 end
790
791 def get(
792 "https://social.heldscal.la/.well-known/webfinger?resource=acct:invalid_content@social.heldscal.la",
793 _,
794 _,
795 [{"accept", "application/xrd+xml,application/jrd+json"}]
796 ) do
797 {:ok, %Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/jrd+json"}]}}
798 end
799
800 def get("http://framatube.org/.well-known/host-meta", _, _, _) do
801 {:ok,
802 %Tesla.Env{
803 status: 200,
804 body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
805 }}
806 end
807
808 def get(
809 "http://framatube.org/main/xrd?uri=acct:framasoft@framatube.org",
810 _,
811 _,
812 [{"accept", "application/xrd+xml,application/jrd+json"}]
813 ) do
814 {:ok,
815 %Tesla.Env{
816 status: 200,
817 headers: [{"content-type", "application/jrd+json"}],
818 body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
819 }}
820 end
821
822 def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
823 {:ok,
824 %Tesla.Env{
825 status: 200,
826 body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
827 }}
828 end
829
830 def get(
831 "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
832 _,
833 _,
834 [{"accept", "application/xrd+xml,application/jrd+json"}]
835 ) do
836 {:ok,
837 %Tesla.Env{
838 status: 200,
839 body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json"),
840 headers: activitypub_object_headers()
841 }}
842 end
843
844 def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
845 {:ok,
846 %Tesla.Env{
847 status: 200,
848 body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
849 }}
850 end
851
852 def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
853 {:ok,
854 %Tesla.Env{
855 status: 200,
856 body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
857 }}
858 end
859
860 def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
861 {:ok,
862 %Tesla.Env{
863 status: 200,
864 body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
865 }}
866 end
867
868 def get(
869 "https://gerzilla.de/xrd/?uri=acct:kaniini@gerzilla.de",
870 _,
871 _,
872 [{"accept", "application/xrd+xml,application/jrd+json"}]
873 ) do
874 {:ok,
875 %Tesla.Env{
876 status: 200,
877 headers: [{"content-type", "application/jrd+json"}],
878 body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
879 }}
880 end
881
882 def get(
883 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
884 _,
885 _,
886 _
887 ) do
888 {:ok,
889 %Tesla.Env{
890 status: 200,
891 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
892 }}
893 end
894
895 def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
896 {:ok,
897 %Tesla.Env{
898 status: 200,
899 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
900 }}
901 end
902
903 def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
904 {:ok,
905 %Tesla.Env{
906 status: 200,
907 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
908 }}
909 end
910
911 def get("https://mastodon.social/users/lambadalambda", _, _, _) do
912 {:ok,
913 %Tesla.Env{
914 status: 200,
915 body: File.read!("test/fixtures/lambadalambda.json"),
916 headers: activitypub_object_headers()
917 }}
918 end
919
920 def get("https://mastodon.social/users/lambadalambda/collections/featured", _, _, _) do
921 {:ok,
922 %Tesla.Env{
923 status: 200,
924 body:
925 File.read!("test/fixtures/users_mock/masto_featured.json")
926 |> String.replace("{{domain}}", "mastodon.social")
927 |> String.replace("{{nickname}}", "lambadalambda"),
928 headers: activitypub_object_headers()
929 }}
930 end
931
932 def get("https://apfed.club/channel/indio", _, _, _) do
933 {:ok,
934 %Tesla.Env{
935 status: 200,
936 body: File.read!("test/fixtures/tesla_mock/osada-user-indio.json"),
937 headers: activitypub_object_headers()
938 }}
939 end
940
941 def get("https://social.heldscal.la/user/23211", _, _, [{"accept", "application/activity+json"}]) do
942 {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
943 end
944
945 def get("http://example.com/ogp", _, _, _) do
946 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
947 end
948
949 def get("https://example.com/ogp", _, _, _) do
950 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
951 end
952
953 def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
954 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
955 end
956
957 def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
958 {:ok,
959 %Tesla.Env{
960 status: 200,
961 body: File.read!("test/fixtures/users_mock/masto_closed_followers.json"),
962 headers: activitypub_object_headers()
963 }}
964 end
965
966 def get("http://localhost:4001/users/masto_closed/followers?page=1", _, _, _) do
967 {:ok,
968 %Tesla.Env{
969 status: 200,
970 body: File.read!("test/fixtures/users_mock/masto_closed_followers_page.json"),
971 headers: activitypub_object_headers()
972 }}
973 end
974
975 def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
976 {:ok,
977 %Tesla.Env{
978 status: 200,
979 body: File.read!("test/fixtures/users_mock/masto_closed_following.json"),
980 headers: activitypub_object_headers()
981 }}
982 end
983
984 def get("http://localhost:4001/users/masto_closed/following?page=1", _, _, _) do
985 {:ok,
986 %Tesla.Env{
987 status: 200,
988 body: File.read!("test/fixtures/users_mock/masto_closed_following_page.json"),
989 headers: activitypub_object_headers()
990 }}
991 end
992
993 def get("http://localhost:8080/followers/fuser3", _, _, _) do
994 {:ok,
995 %Tesla.Env{
996 status: 200,
997 body: File.read!("test/fixtures/users_mock/friendica_followers.json"),
998 headers: activitypub_object_headers()
999 }}
1000 end
1001
1002 def get("http://localhost:8080/following/fuser3", _, _, _) do
1003 {:ok,
1004 %Tesla.Env{
1005 status: 200,
1006 body: File.read!("test/fixtures/users_mock/friendica_following.json"),
1007 headers: activitypub_object_headers()
1008 }}
1009 end
1010
1011 def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
1012 {:ok,
1013 %Tesla.Env{
1014 status: 200,
1015 body: File.read!("test/fixtures/users_mock/pleroma_followers.json"),
1016 headers: activitypub_object_headers()
1017 }}
1018 end
1019
1020 def get("http://localhost:4001/users/fuser2/following", _, _, _) do
1021 {:ok,
1022 %Tesla.Env{
1023 status: 200,
1024 body: File.read!("test/fixtures/users_mock/pleroma_following.json"),
1025 headers: activitypub_object_headers()
1026 }}
1027 end
1028
1029 def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
1030 {:ok,
1031 %Tesla.Env{
1032 status: 504,
1033 body: ""
1034 }}
1035 end
1036
1037 def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
1038 {:ok,
1039 %Tesla.Env{
1040 status: 504,
1041 body: ""
1042 }}
1043 end
1044
1045 def get("http://example.com/ogp-missing-data", _, _, _) do
1046 {:ok,
1047 %Tesla.Env{
1048 status: 200,
1049 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
1050 }}
1051 end
1052
1053 def get("https://example.com/ogp-missing-data", _, _, _) do
1054 {:ok,
1055 %Tesla.Env{
1056 status: 200,
1057 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
1058 }}
1059 end
1060
1061 def get("http://example.com/malformed", _, _, _) do
1062 {:ok,
1063 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
1064 end
1065
1066 def get("http://example.com/empty", _, _, _) do
1067 {:ok, %Tesla.Env{status: 200, body: "hello"}}
1068 end
1069
1070 def get("http://404.site" <> _, _, _, _) do
1071 {:ok,
1072 %Tesla.Env{
1073 status: 404,
1074 body: ""
1075 }}
1076 end
1077
1078 def get(
1079 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=acct:lain@zetsubou.xn--q9jyb4c",
1080 _,
1081 _,
1082 [{"accept", "application/xrd+xml,application/jrd+json"}]
1083 ) do
1084 {:ok,
1085 %Tesla.Env{
1086 status: 200,
1087 body: File.read!("test/fixtures/lain.xml"),
1088 headers: [{"content-type", "application/xrd+xml"}]
1089 }}
1090 end
1091
1092 def get(
1093 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=acct:https://zetsubou.xn--q9jyb4c/users/lain",
1094 _,
1095 _,
1096 [{"accept", "application/xrd+xml,application/jrd+json"}]
1097 ) do
1098 {:ok,
1099 %Tesla.Env{
1100 status: 200,
1101 body: File.read!("test/fixtures/lain.xml"),
1102 headers: [{"content-type", "application/xrd+xml"}]
1103 }}
1104 end
1105
1106 def get("http://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
1107 {:ok,
1108 %Tesla.Env{
1109 status: 200,
1110 body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
1111 }}
1112 end
1113
1114 def get(
1115 "https://zetsubou.xn--q9jyb4c/.well-known/host-meta",
1116 _,
1117 _,
1118 _
1119 ) do
1120 {:ok,
1121 %Tesla.Env{
1122 status: 200,
1123 body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
1124 }}
1125 end
1126
1127 def get("https://info.pleroma.site/activity.json", _, _, [
1128 {"accept", "application/activity+json"}
1129 ]) do
1130 {:ok,
1131 %Tesla.Env{
1132 status: 200,
1133 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity.json"),
1134 headers: activitypub_object_headers()
1135 }}
1136 end
1137
1138 def get("https://info.pleroma.site/activity.json", _, _, _) do
1139 {:ok, %Tesla.Env{status: 404, body: ""}}
1140 end
1141
1142 def get("https://info.pleroma.site/activity2.json", _, _, [
1143 {"accept", "application/activity+json"}
1144 ]) do
1145 {:ok,
1146 %Tesla.Env{
1147 status: 200,
1148 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json"),
1149 headers: activitypub_object_headers()
1150 }}
1151 end
1152
1153 def get("https://info.pleroma.site/activity2.json", _, _, _) do
1154 {:ok, %Tesla.Env{status: 404, body: ""}}
1155 end
1156
1157 def get("https://info.pleroma.site/activity3.json", _, _, [
1158 {"accept", "application/activity+json"}
1159 ]) do
1160 {:ok,
1161 %Tesla.Env{
1162 status: 200,
1163 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json"),
1164 headers: activitypub_object_headers()
1165 }}
1166 end
1167
1168 def get("https://info.pleroma.site/activity3.json", _, _, _) do
1169 {:ok, %Tesla.Env{status: 404, body: ""}}
1170 end
1171
1172 def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp", _, _, _) do
1173 {:ok,
1174 %Tesla.Env{
1175 status: 200,
1176 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml"),
1177 headers: [{"content-type", "application/xrd+xml"}]
1178 }}
1179 end
1180
1181 def get("https://10.111.10.1/notice/9kCP7V", _, _, _) do
1182 {:ok, %Tesla.Env{status: 200, body: ""}}
1183 end
1184
1185 def get("https://172.16.32.40/notice/9kCP7V", _, _, _) do
1186 {:ok, %Tesla.Env{status: 200, body: ""}}
1187 end
1188
1189 def get("https://192.168.10.40/notice/9kCP7V", _, _, _) do
1190 {:ok, %Tesla.Env{status: 200, body: ""}}
1191 end
1192
1193 def get("https://www.patreon.com/posts/mastodon-2-9-and-28121681", _, _, _) do
1194 {:ok, %Tesla.Env{status: 200, body: ""}}
1195 end
1196
1197 def get("http://mastodon.example.org/@admin/99541947525187367", _, _, _) do
1198 {:ok,
1199 %Tesla.Env{
1200 status: 200,
1201 body: File.read!("test/fixtures/mastodon-post-activity.json"),
1202 headers: activitypub_object_headers()
1203 }}
1204 end
1205
1206 def get("https://info.pleroma.site/activity4.json", _, _, _) do
1207 {:ok, %Tesla.Env{status: 500, body: "Error occurred"}}
1208 end
1209
1210 def get("http://example.com/rel_me/anchor", _, _, _) do
1211 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}}
1212 end
1213
1214 def get("http://example.com/rel_me/anchor_nofollow", _, _, _) do
1215 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}}
1216 end
1217
1218 def get("http://example.com/rel_me/link", _, _, _) do
1219 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}}
1220 end
1221
1222 def get("http://example.com/rel_me/null", _, _, _) do
1223 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}}
1224 end
1225
1226 def get("https://skippers-bin.com/notes/7x9tmrp97i", _, _, _) do
1227 {:ok,
1228 %Tesla.Env{
1229 status: 200,
1230 body: File.read!("test/fixtures/tesla_mock/misskey_poll_no_end_date.json"),
1231 headers: activitypub_object_headers()
1232 }}
1233 end
1234
1235 def get("https://example.org/emoji/firedfox.png", _, _, _) do
1236 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/image.jpg")}}
1237 end
1238
1239 def get("https://skippers-bin.com/users/7v1w1r8ce6", _, _, _) do
1240 {:ok,
1241 %Tesla.Env{
1242 status: 200,
1243 body: File.read!("test/fixtures/tesla_mock/sjw.json"),
1244 headers: activitypub_object_headers()
1245 }}
1246 end
1247
1248 def get("https://patch.cx/users/rin", _, _, _) do
1249 {:ok,
1250 %Tesla.Env{
1251 status: 200,
1252 body: File.read!("test/fixtures/tesla_mock/rin.json"),
1253 headers: activitypub_object_headers()
1254 }}
1255 end
1256
1257 def get(
1258 "https://channels.tests.funkwhale.audio/federation/music/uploads/42342395-0208-4fee-a38d-259a6dae0871",
1259 _,
1260 _,
1261 _
1262 ) do
1263 {:ok,
1264 %Tesla.Env{
1265 status: 200,
1266 body: File.read!("test/fixtures/tesla_mock/funkwhale_audio.json"),
1267 headers: activitypub_object_headers()
1268 }}
1269 end
1270
1271 def get("https://channels.tests.funkwhale.audio/federation/actors/compositions", _, _, _) do
1272 {:ok,
1273 %Tesla.Env{
1274 status: 200,
1275 body: File.read!("test/fixtures/tesla_mock/funkwhale_channel.json"),
1276 headers: activitypub_object_headers()
1277 }}
1278 end
1279
1280 def get("http://example.com/rel_me/error", _, _, _) do
1281 {:ok, %Tesla.Env{status: 404, body: ""}}
1282 end
1283
1284 def get("https://relay.mastodon.host/actor", _, _, _) do
1285 {:ok,
1286 %Tesla.Env{
1287 status: 200,
1288 body: File.read!("test/fixtures/relay/relay.json"),
1289 headers: activitypub_object_headers()
1290 }}
1291 end
1292
1293 def get("http://localhost:4001/", _, "", [{"accept", "text/html"}]) do
1294 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/7369654.html")}}
1295 end
1296
1297 def get("https://osada.macgirvin.com/", _, "", [{"accept", "text/html"}]) do
1298 {:ok,
1299 %Tesla.Env{
1300 status: 200,
1301 body: File.read!("test/fixtures/tesla_mock/https___osada.macgirvin.com.html")
1302 }}
1303 end
1304
1305 def get("https://patch.cx/objects/a399c28e-c821-4820-bc3e-4afeb044c16f", _, _, _) do
1306 {:ok,
1307 %Tesla.Env{
1308 status: 200,
1309 body: File.read!("test/fixtures/tesla_mock/emoji-in-summary.json"),
1310 headers: activitypub_object_headers()
1311 }}
1312 end
1313
1314 def get(url, query, body, headers) do
1315 {:error,
1316 "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
1317 inspect(headers)
1318 }"}
1319 end
1320
1321 # POST Requests
1322 #
1323
1324 def post(url, query \\ [], body \\ [], headers \\ [])
1325
1326 def post("https://relay.mastodon.host/inbox", _, _, _) do
1327 {:ok, %Tesla.Env{status: 200, body: ""}}
1328 end
1329
1330 def post("http://example.org/needs_refresh", _, _, _) do
1331 {:ok,
1332 %Tesla.Env{
1333 status: 200,
1334 body: ""
1335 }}
1336 end
1337
1338 def post("http://mastodon.example.org/inbox", _, _, _) do
1339 {:ok,
1340 %Tesla.Env{
1341 status: 200,
1342 body: ""
1343 }}
1344 end
1345
1346 def post("https://hubzilla.example.org/inbox", _, _, _) do
1347 {:ok,
1348 %Tesla.Env{
1349 status: 200,
1350 body: ""
1351 }}
1352 end
1353
1354 def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
1355 {:ok,
1356 %Tesla.Env{
1357 status: 200,
1358 body: ""
1359 }}
1360 end
1361
1362 def post("http://200.site" <> _, _, _, _) do
1363 {:ok,
1364 %Tesla.Env{
1365 status: 200,
1366 body: ""
1367 }}
1368 end
1369
1370 def post("http://connrefused.site" <> _, _, _, _) do
1371 {:error, :connrefused}
1372 end
1373
1374 def post("http://404.site" <> _, _, _, _) do
1375 {:ok,
1376 %Tesla.Env{
1377 status: 404,
1378 body: ""
1379 }}
1380 end
1381
1382 def post(url, query, body, headers) do
1383 {:error,
1384 "Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{
1385 inspect(headers)
1386 }"}
1387 end
1388
1389 # Most of the rich media mocks are missing HEAD requests, so we just return 404.
1390 @rich_media_mocks [
1391 "https://example.com/ogp",
1392 "https://example.com/ogp-missing-data",
1393 "https://example.com/twitter-card"
1394 ]
1395 def head(url, _query, _body, _headers) when url in @rich_media_mocks do
1396 {:ok, %Tesla.Env{status: 404, body: ""}}
1397 end
1398
1399 def head(url, query, body, headers) do
1400 {:error,
1401 "Mock response not implemented for HEAD #{inspect(url)}, #{query}, #{inspect(body)}, #{
1402 inspect(headers)
1403 }"}
1404 end
1405 end