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