allow users with admin:metrics to read app metrics
[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(
411 "http://mastodon.example.org/users/admin/statuses/99512778738411822/replies?min_id=99512778738411824&page=true",
412 _,
413 _,
414 _
415 ) do
416 {:ok, %Tesla.Env{status: 404, body: ""}}
417 end
418
419 def get("http://mastodon.example.org/users/relay", _, _, [
420 {"accept", "application/activity+json"}
421 ]) do
422 {:ok,
423 %Tesla.Env{
424 status: 200,
425 body: File.read!("test/fixtures/tesla_mock/relay@mastdon.example.org.json"),
426 headers: activitypub_object_headers()
427 }}
428 end
429
430 def get("http://mastodon.example.org/users/gargron", _, _, [
431 {"accept", "application/activity+json"}
432 ]) do
433 {:error, :nxdomain}
434 end
435
436 def get("https://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
437 {:ok,
438 %Tesla.Env{
439 status: 404,
440 body: ""
441 }}
442 end
443
444 def get("http://mastodon.sdf.org/.well-known/host-meta", _, _, _) do
445 {:ok,
446 %Tesla.Env{
447 status: 200,
448 body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta")
449 }}
450 end
451
452 def get("https://mastodon.sdf.org/.well-known/host-meta", _, _, _) do
453 {:ok,
454 %Tesla.Env{
455 status: 200,
456 body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta")
457 }}
458 end
459
460 def get(
461 "https://mastodon.sdf.org/.well-known/webfinger?resource=https://mastodon.sdf.org/users/snowdusk",
462 _,
463 _,
464 _
465 ) do
466 {:ok,
467 %Tesla.Env{
468 status: 200,
469 body: File.read!("test/fixtures/tesla_mock/snowdusk@sdf.org_host_meta.json")
470 }}
471 end
472
473 def get("http://mstdn.jp/.well-known/host-meta", _, _, _) do
474 {:ok,
475 %Tesla.Env{
476 status: 200,
477 body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta")
478 }}
479 end
480
481 def get("https://mstdn.jp/.well-known/host-meta", _, _, _) do
482 {:ok,
483 %Tesla.Env{
484 status: 200,
485 body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta")
486 }}
487 end
488
489 def get("https://mstdn.jp/.well-known/webfinger?resource=kpherox@mstdn.jp", _, _, _) do
490 {:ok,
491 %Tesla.Env{
492 status: 200,
493 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
494 }}
495 end
496
497 def get("http://mamot.fr/.well-known/host-meta", _, _, _) do
498 {:ok,
499 %Tesla.Env{
500 status: 200,
501 body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta")
502 }}
503 end
504
505 def get("https://mamot.fr/.well-known/host-meta", _, _, _) do
506 {:ok,
507 %Tesla.Env{
508 status: 200,
509 body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta")
510 }}
511 end
512
513 def get("http://pawoo.net/.well-known/host-meta", _, _, _) do
514 {:ok,
515 %Tesla.Env{
516 status: 200,
517 body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
518 }}
519 end
520
521 def get("https://pawoo.net/.well-known/host-meta", _, _, _) do
522 {:ok,
523 %Tesla.Env{
524 status: 200,
525 body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
526 }}
527 end
528
529 def get(
530 "https://pawoo.net/.well-known/webfinger?resource=https://pawoo.net/users/pekorino",
531 _,
532 _,
533 _
534 ) do
535 {:ok,
536 %Tesla.Env{
537 status: 200,
538 body: File.read!("test/fixtures/tesla_mock/pekorino@pawoo.net_host_meta.json"),
539 headers: activitypub_object_headers()
540 }}
541 end
542
543 def get("http://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
544 {:ok,
545 %Tesla.Env{
546 status: 200,
547 body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta")
548 }}
549 end
550
551 def get("https://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
552 {:ok,
553 %Tesla.Env{
554 status: 200,
555 body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta")
556 }}
557 end
558
559 def get("http://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do
560 {:ok,
561 %Tesla.Env{
562 status: 200,
563 body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta")
564 }}
565 end
566
567 def get("https://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do
568 {:ok,
569 %Tesla.Env{
570 status: 200,
571 body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta")
572 }}
573 end
574
575 def get(
576 "http://mastodon.example.org/@admin/99541947525187367",
577 _,
578 _,
579 _
580 ) do
581 {:ok,
582 %Tesla.Env{
583 status: 200,
584 body: File.read!("test/fixtures/mastodon-note-object.json"),
585 headers: activitypub_object_headers()
586 }}
587 end
588
589 def get("http://mastodon.example.org/@admin/99541947525187368", _, _, _) do
590 {:ok,
591 %Tesla.Env{
592 status: 404,
593 body: ""
594 }}
595 end
596
597 def get("https://shitposter.club/notice/7369654", _, _, _) do
598 {:ok,
599 %Tesla.Env{
600 status: 200,
601 body: File.read!("test/fixtures/tesla_mock/7369654.html")
602 }}
603 end
604
605 def get("https://mstdn.io/users/mayuutann", _, _, [{"accept", "application/activity+json"}]) do
606 {:ok,
607 %Tesla.Env{
608 status: 200,
609 body: File.read!("test/fixtures/tesla_mock/mayumayu.json"),
610 headers: activitypub_object_headers()
611 }}
612 end
613
614 def get(
615 "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
616 _,
617 _,
618 [{"accept", "application/activity+json"}]
619 ) do
620 {:ok,
621 %Tesla.Env{
622 status: 200,
623 body: File.read!("test/fixtures/tesla_mock/mayumayupost.json"),
624 headers: activitypub_object_headers()
625 }}
626 end
627
628 def get(url, _, _, [{"accept", "application/xrd+xml,application/jrd+json"}])
629 when url in [
630 "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
631 "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
632 ] do
633 {:ok,
634 %Tesla.Env{
635 status: 200,
636 body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
637 }}
638 end
639
640 def get(
641 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
642 _,
643 _,
644 [{"accept", "application/xrd+xml,application/jrd+json"}]
645 ) do
646 {:ok,
647 %Tesla.Env{
648 status: 200,
649 body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
650 }}
651 end
652
653 def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
654 {:ok, %Tesla.Env{status: 200}}
655 end
656
657 def get(
658 "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
659 _,
660 _,
661 [{"accept", "application/xrd+xml,application/jrd+json"}]
662 ) do
663 {:ok,
664 %Tesla.Env{
665 status: 200,
666 body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
667 }}
668 end
669
670 def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
671 {:ok,
672 %Tesla.Env{
673 status: 200,
674 body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
675 }}
676 end
677
678 def get("https://shitposter.club/notice/4027863", _, _, _) do
679 {:ok,
680 %Tesla.Env{
681 status: 200,
682 body: File.read!("test/fixtures/tesla_mock/7369654.html")
683 }}
684 end
685
686 def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
687 {:ok,
688 %Tesla.Env{
689 status: 200,
690 body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
691 }}
692 end
693
694 def get(
695 "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
696 _,
697 _,
698 [{"accept", "application/xrd+xml,application/jrd+json"}]
699 ) do
700 {:ok,
701 %Tesla.Env{
702 status: 200,
703 body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
704 }}
705 end
706
707 def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
708 {:ok,
709 %Tesla.Env{
710 status: 200,
711 body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
712 }}
713 end
714
715 def get(
716 "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
717 _,
718 _,
719 [{"accept", "application/xrd+xml,application/jrd+json"}]
720 ) do
721 {:ok,
722 %Tesla.Env{
723 status: 200,
724 body:
725 File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
726 }}
727 end
728
729 def get(
730 "https://mastodon.social/.well-known/webfinger?resource=acct:not_found@mastodon.social",
731 _,
732 _,
733 [{"accept", "application/xrd+xml,application/jrd+json"}]
734 ) do
735 {:ok, %Tesla.Env{status: 404}}
736 end
737
738 def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
739 {:ok,
740 %Tesla.Env{
741 status: 200,
742 body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
743 }}
744 end
745
746 def get(
747 "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
748 _,
749 _,
750 [{"accept", "application/xrd+xml,application/jrd+json"}]
751 ) do
752 {:ok,
753 %Tesla.Env{
754 status: 200,
755 body:
756 File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
757 }}
758 end
759
760 def get(
761 "http://gs.example.org:4040/index.php/user/1",
762 _,
763 _,
764 [{"accept", "application/activity+json"}]
765 ) do
766 {:ok, %Tesla.Env{status: 406, body: ""}}
767 end
768
769 def get("https://squeet.me/.well-known/host-meta", _, _, _) do
770 {:ok,
771 %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
772 end
773
774 def get(
775 "https://squeet.me/xrd?uri=lain@squeet.me",
776 _,
777 _,
778 [{"accept", "application/xrd+xml,application/jrd+json"}]
779 ) do
780 {:ok,
781 %Tesla.Env{
782 status: 200,
783 body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
784 }}
785 end
786
787 def get(
788 "https://social.heldscal.la/.well-known/webfinger?resource=acct:shp@social.heldscal.la",
789 _,
790 _,
791 [{"accept", "application/xrd+xml,application/jrd+json"}]
792 ) do
793 {:ok,
794 %Tesla.Env{
795 status: 200,
796 body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml"),
797 headers: [{"content-type", "application/xrd+xml"}]
798 }}
799 end
800
801 def get(
802 "https://social.heldscal.la/.well-known/webfinger?resource=acct:invalid_content@social.heldscal.la",
803 _,
804 _,
805 [{"accept", "application/xrd+xml,application/jrd+json"}]
806 ) do
807 {:ok, %Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/jrd+json"}]}}
808 end
809
810 def get("https://framatube.org/.well-known/host-meta", _, _, _) do
811 {:ok,
812 %Tesla.Env{
813 status: 200,
814 body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
815 }}
816 end
817
818 def get(
819 "https://framatube.org/main/xrd?uri=acct:framasoft@framatube.org",
820 _,
821 _,
822 [{"accept", "application/xrd+xml,application/jrd+json"}]
823 ) do
824 {:ok,
825 %Tesla.Env{
826 status: 200,
827 headers: [{"content-type", "application/jrd+json"}],
828 body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
829 }}
830 end
831
832 def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
833 {:ok,
834 %Tesla.Env{
835 status: 200,
836 body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
837 }}
838 end
839
840 def get(
841 "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
842 _,
843 _,
844 [{"accept", "application/xrd+xml,application/jrd+json"}]
845 ) do
846 {:ok,
847 %Tesla.Env{
848 status: 200,
849 body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json"),
850 headers: activitypub_object_headers()
851 }}
852 end
853
854 def get("https://status.alpicola.com/.well-known/host-meta", _, _, _) do
855 {:ok,
856 %Tesla.Env{
857 status: 200,
858 body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
859 }}
860 end
861
862 def get("https://macgirvin.com/.well-known/host-meta", _, _, _) do
863 {:ok,
864 %Tesla.Env{
865 status: 200,
866 body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
867 }}
868 end
869
870 def get("https://gerzilla.de/.well-known/host-meta", _, _, _) do
871 {:ok,
872 %Tesla.Env{
873 status: 200,
874 body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
875 }}
876 end
877
878 def get(
879 "https://gerzilla.de/xrd/?uri=acct:kaniini@gerzilla.de",
880 _,
881 _,
882 [{"accept", "application/xrd+xml,application/jrd+json"}]
883 ) do
884 {:ok,
885 %Tesla.Env{
886 status: 200,
887 headers: [{"content-type", "application/jrd+json"}],
888 body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
889 }}
890 end
891
892 def get(
893 "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
894 _,
895 _,
896 _
897 ) do
898 {:ok,
899 %Tesla.Env{
900 status: 200,
901 body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
902 }}
903 end
904
905 def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
906 {:ok,
907 %Tesla.Env{
908 status: 200,
909 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
910 }}
911 end
912
913 def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
914 {:ok,
915 %Tesla.Env{
916 status: 200,
917 body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
918 }}
919 end
920
921 def get("https://mastodon.social/users/lambadalambda", _, _, _) do
922 {:ok,
923 %Tesla.Env{
924 status: 200,
925 body: File.read!("test/fixtures/lambadalambda.json"),
926 headers: activitypub_object_headers()
927 }}
928 end
929
930 def get("https://mastodon.social/users/lambadalambda/collections/featured", _, _, _) do
931 {:ok,
932 %Tesla.Env{
933 status: 200,
934 body:
935 File.read!("test/fixtures/users_mock/masto_featured.json")
936 |> String.replace("{{domain}}", "mastodon.social")
937 |> String.replace("{{nickname}}", "lambadalambda"),
938 headers: activitypub_object_headers()
939 }}
940 end
941
942 def get("https://apfed.club/channel/indio", _, _, _) do
943 {:ok,
944 %Tesla.Env{
945 status: 200,
946 body: File.read!("test/fixtures/tesla_mock/osada-user-indio.json"),
947 headers: activitypub_object_headers()
948 }}
949 end
950
951 def get("https://social.heldscal.la/user/23211", _, _, [{"accept", "application/activity+json"}]) do
952 {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
953 end
954
955 def get("http://example.com/ogp", _, _, _) do
956 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
957 end
958
959 def get("https://example.com/ogp", _, _, _) do
960 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
961 end
962
963 def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
964 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
965 end
966
967 def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
968 {:ok,
969 %Tesla.Env{
970 status: 200,
971 body: File.read!("test/fixtures/users_mock/masto_closed_followers.json"),
972 headers: activitypub_object_headers()
973 }}
974 end
975
976 def get("http://localhost:4001/users/masto_closed/followers?page=1", _, _, _) do
977 {:ok,
978 %Tesla.Env{
979 status: 200,
980 body: File.read!("test/fixtures/users_mock/masto_closed_followers_page.json"),
981 headers: activitypub_object_headers()
982 }}
983 end
984
985 def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
986 {:ok,
987 %Tesla.Env{
988 status: 200,
989 body: File.read!("test/fixtures/users_mock/masto_closed_following.json"),
990 headers: activitypub_object_headers()
991 }}
992 end
993
994 def get("http://localhost:4001/users/masto_closed/following?page=1", _, _, _) do
995 {:ok,
996 %Tesla.Env{
997 status: 200,
998 body: File.read!("test/fixtures/users_mock/masto_closed_following_page.json"),
999 headers: activitypub_object_headers()
1000 }}
1001 end
1002
1003 def get("http://localhost:8080/followers/fuser3", _, _, _) do
1004 {:ok,
1005 %Tesla.Env{
1006 status: 200,
1007 body: File.read!("test/fixtures/users_mock/friendica_followers.json"),
1008 headers: activitypub_object_headers()
1009 }}
1010 end
1011
1012 def get("http://localhost:8080/following/fuser3", _, _, _) do
1013 {:ok,
1014 %Tesla.Env{
1015 status: 200,
1016 body: File.read!("test/fixtures/users_mock/friendica_following.json"),
1017 headers: activitypub_object_headers()
1018 }}
1019 end
1020
1021 def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
1022 {:ok,
1023 %Tesla.Env{
1024 status: 200,
1025 body: File.read!("test/fixtures/users_mock/pleroma_followers.json"),
1026 headers: activitypub_object_headers()
1027 }}
1028 end
1029
1030 def get("http://localhost:4001/users/fuser2/following", _, _, _) do
1031 {:ok,
1032 %Tesla.Env{
1033 status: 200,
1034 body: File.read!("test/fixtures/users_mock/pleroma_following.json"),
1035 headers: activitypub_object_headers()
1036 }}
1037 end
1038
1039 def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
1040 {:ok,
1041 %Tesla.Env{
1042 status: 504,
1043 body: ""
1044 }}
1045 end
1046
1047 def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
1048 {:ok,
1049 %Tesla.Env{
1050 status: 504,
1051 body: ""
1052 }}
1053 end
1054
1055 def get("http://example.com/ogp-missing-data", _, _, _) do
1056 {:ok,
1057 %Tesla.Env{
1058 status: 200,
1059 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
1060 }}
1061 end
1062
1063 def get("https://example.com/ogp-missing-data", _, _, _) do
1064 {:ok,
1065 %Tesla.Env{
1066 status: 200,
1067 body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
1068 }}
1069 end
1070
1071 def get("http://example.com/malformed", _, _, _) do
1072 {:ok,
1073 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
1074 end
1075
1076 def get("http://example.com/empty", _, _, _) do
1077 {:ok, %Tesla.Env{status: 200, body: "hello"}}
1078 end
1079
1080 def get("http://404.site" <> _, _, _, _) do
1081 {:ok,
1082 %Tesla.Env{
1083 status: 404,
1084 body: ""
1085 }}
1086 end
1087
1088 def get(
1089 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=acct:lain@zetsubou.xn--q9jyb4c",
1090 _,
1091 _,
1092 [{"accept", "application/xrd+xml,application/jrd+json"}]
1093 ) do
1094 {:ok,
1095 %Tesla.Env{
1096 status: 200,
1097 body: File.read!("test/fixtures/lain.xml"),
1098 headers: [{"content-type", "application/xrd+xml"}]
1099 }}
1100 end
1101
1102 def get(
1103 "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=acct:https://zetsubou.xn--q9jyb4c/users/lain",
1104 _,
1105 _,
1106 [{"accept", "application/xrd+xml,application/jrd+json"}]
1107 ) do
1108 {:ok,
1109 %Tesla.Env{
1110 status: 200,
1111 body: File.read!("test/fixtures/lain.xml"),
1112 headers: [{"content-type", "application/xrd+xml"}]
1113 }}
1114 end
1115
1116 def get("http://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
1117 {:ok,
1118 %Tesla.Env{
1119 status: 200,
1120 body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
1121 }}
1122 end
1123
1124 def get(
1125 "https://zetsubou.xn--q9jyb4c/.well-known/host-meta",
1126 _,
1127 _,
1128 _
1129 ) do
1130 {:ok,
1131 %Tesla.Env{
1132 status: 200,
1133 body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
1134 }}
1135 end
1136
1137 def get("http://lm.kazv.moe/.well-known/host-meta", _, _, _) do
1138 {:ok,
1139 %Tesla.Env{
1140 status: 200,
1141 body: File.read!("test/fixtures/tesla_mock/lm.kazv.moe_host_meta")
1142 }}
1143 end
1144
1145 def get("https://lm.kazv.moe/.well-known/host-meta", _, _, _) do
1146 {:ok,
1147 %Tesla.Env{
1148 status: 200,
1149 body: File.read!("test/fixtures/tesla_mock/lm.kazv.moe_host_meta")
1150 }}
1151 end
1152
1153 def get(
1154 "https://lm.kazv.moe/.well-known/webfinger?resource=acct:mewmew@lm.kazv.moe",
1155 _,
1156 _,
1157 [{"accept", "application/xrd+xml,application/jrd+json"}]
1158 ) do
1159 {:ok,
1160 %Tesla.Env{
1161 status: 200,
1162 body: File.read!("test/fixtures/tesla_mock/https___lm.kazv.moe_users_mewmew.xml"),
1163 headers: [{"content-type", "application/xrd+xml"}]
1164 }}
1165 end
1166
1167 def get("https://lm.kazv.moe/users/mewmew", _, _, _) do
1168 {:ok,
1169 %Tesla.Env{
1170 status: 200,
1171 body: File.read!("test/fixtures/tesla_mock/mewmew@lm.kazv.moe.json"),
1172 headers: activitypub_object_headers()
1173 }}
1174 end
1175
1176 def get("https://lm.kazv.moe/users/mewmew/collections/featured", _, _, _) do
1177 {:ok,
1178 %Tesla.Env{
1179 status: 200,
1180 body:
1181 File.read!("test/fixtures/users_mock/masto_featured.json")
1182 |> String.replace("{{domain}}", "lm.kazv.moe")
1183 |> String.replace("{{nickname}}", "mewmew"),
1184 headers: [{"content-type", "application/activity+json"}]
1185 }}
1186 end
1187
1188 def get("https://info.pleroma.site/activity.json", _, _, [
1189 {"accept", "application/activity+json"}
1190 ]) do
1191 {:ok,
1192 %Tesla.Env{
1193 status: 200,
1194 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity.json"),
1195 headers: activitypub_object_headers()
1196 }}
1197 end
1198
1199 def get("https://info.pleroma.site/activity.json", _, _, _) do
1200 {:ok, %Tesla.Env{status: 404, body: ""}}
1201 end
1202
1203 def get("https://info.pleroma.site/activity2.json", _, _, [
1204 {"accept", "application/activity+json"}
1205 ]) do
1206 {:ok,
1207 %Tesla.Env{
1208 status: 200,
1209 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json"),
1210 headers: activitypub_object_headers()
1211 }}
1212 end
1213
1214 def get("https://info.pleroma.site/activity2.json", _, _, _) do
1215 {:ok, %Tesla.Env{status: 404, body: ""}}
1216 end
1217
1218 def get("https://info.pleroma.site/activity3.json", _, _, [
1219 {"accept", "application/activity+json"}
1220 ]) do
1221 {:ok,
1222 %Tesla.Env{
1223 status: 200,
1224 body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json"),
1225 headers: activitypub_object_headers()
1226 }}
1227 end
1228
1229 def get("https://info.pleroma.site/activity3.json", _, _, _) do
1230 {:ok, %Tesla.Env{status: 404, body: ""}}
1231 end
1232
1233 def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp", _, _, _) do
1234 {:ok,
1235 %Tesla.Env{
1236 status: 200,
1237 body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml"),
1238 headers: [{"content-type", "application/xrd+xml"}]
1239 }}
1240 end
1241
1242 def get("https://10.111.10.1/notice/9kCP7V", _, _, _) do
1243 {:ok, %Tesla.Env{status: 200, body: ""}}
1244 end
1245
1246 def get("https://172.16.32.40/notice/9kCP7V", _, _, _) do
1247 {:ok, %Tesla.Env{status: 200, body: ""}}
1248 end
1249
1250 def get("https://192.168.10.40/notice/9kCP7V", _, _, _) do
1251 {:ok, %Tesla.Env{status: 200, body: ""}}
1252 end
1253
1254 def get("https://www.patreon.com/posts/mastodon-2-9-and-28121681", _, _, _) do
1255 {:ok, %Tesla.Env{status: 200, body: ""}}
1256 end
1257
1258 def get("http://mastodon.example.org/@admin/99541947525187367", _, _, _) do
1259 {:ok,
1260 %Tesla.Env{
1261 status: 200,
1262 body: File.read!("test/fixtures/mastodon-post-activity.json"),
1263 headers: activitypub_object_headers()
1264 }}
1265 end
1266
1267 def get("https://info.pleroma.site/activity4.json", _, _, _) do
1268 {:ok, %Tesla.Env{status: 500, body: "Error occurred"}}
1269 end
1270
1271 def get("http://example.com/rel_me/anchor", _, _, _) do
1272 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}}
1273 end
1274
1275 def get("http://example.com/rel_me/anchor_nofollow", _, _, _) do
1276 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}}
1277 end
1278
1279 def get("http://example.com/rel_me/link", _, _, _) do
1280 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}}
1281 end
1282
1283 def get("http://example.com/rel_me/null", _, _, _) do
1284 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}}
1285 end
1286
1287 def get("https://skippers-bin.com/notes/7x9tmrp97i", _, _, _) do
1288 {:ok,
1289 %Tesla.Env{
1290 status: 200,
1291 body: File.read!("test/fixtures/tesla_mock/misskey_poll_no_end_date.json"),
1292 headers: activitypub_object_headers()
1293 }}
1294 end
1295
1296 def get("https://example.org/emoji/firedfox.png", _, _, _) do
1297 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/image.jpg")}}
1298 end
1299
1300 def get("https://skippers-bin.com/users/7v1w1r8ce6", _, _, _) do
1301 {:ok,
1302 %Tesla.Env{
1303 status: 200,
1304 body: File.read!("test/fixtures/tesla_mock/sjw.json"),
1305 headers: activitypub_object_headers()
1306 }}
1307 end
1308
1309 def get("https://patch.cx/users/rin", _, _, _) do
1310 {:ok,
1311 %Tesla.Env{
1312 status: 200,
1313 body: File.read!("test/fixtures/tesla_mock/rin.json"),
1314 headers: activitypub_object_headers()
1315 }}
1316 end
1317
1318 def get(
1319 "https://channels.tests.funkwhale.audio/federation/music/uploads/42342395-0208-4fee-a38d-259a6dae0871",
1320 _,
1321 _,
1322 _
1323 ) do
1324 {:ok,
1325 %Tesla.Env{
1326 status: 200,
1327 body: File.read!("test/fixtures/tesla_mock/funkwhale_audio.json"),
1328 headers: activitypub_object_headers()
1329 }}
1330 end
1331
1332 def get("https://channels.tests.funkwhale.audio/federation/actors/compositions", _, _, _) do
1333 {:ok,
1334 %Tesla.Env{
1335 status: 200,
1336 body: File.read!("test/fixtures/tesla_mock/funkwhale_channel.json"),
1337 headers: activitypub_object_headers()
1338 }}
1339 end
1340
1341 def get("http://example.com/rel_me/error", _, _, _) do
1342 {:ok, %Tesla.Env{status: 404, body: ""}}
1343 end
1344
1345 def get("https://relay.mastodon.host/actor", _, _, _) do
1346 {:ok,
1347 %Tesla.Env{
1348 status: 200,
1349 body: File.read!("test/fixtures/relay/relay.json"),
1350 headers: activitypub_object_headers()
1351 }}
1352 end
1353
1354 def get("http://localhost:4001/", _, "", [{"accept", "text/html"}]) do
1355 {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/7369654.html")}}
1356 end
1357
1358 def get("https://osada.macgirvin.com/", _, "", [{"accept", "text/html"}]) do
1359 {:ok,
1360 %Tesla.Env{
1361 status: 200,
1362 body: File.read!("test/fixtures/tesla_mock/https___osada.macgirvin.com.html")
1363 }}
1364 end
1365
1366 def get("https://patch.cx/objects/a399c28e-c821-4820-bc3e-4afeb044c16f", _, _, _) do
1367 {:ok,
1368 %Tesla.Env{
1369 status: 200,
1370 body: File.read!("test/fixtures/tesla_mock/emoji-in-summary.json"),
1371 headers: activitypub_object_headers()
1372 }}
1373 end
1374
1375 def get("https://mk.absturztau.be/users/8ozbzjs3o8", _, _, _) do
1376 {:ok,
1377 %Tesla.Env{
1378 status: 200,
1379 body: File.read!("test/fixtures/tesla_mock/mametsuko@mk.absturztau.be.json"),
1380 headers: activitypub_object_headers()
1381 }}
1382 end
1383
1384 def get("https://p.helene.moe/users/helene", _, _, _) do
1385 {:ok,
1386 %Tesla.Env{
1387 status: 200,
1388 body: File.read!("test/fixtures/tesla_mock/helene@p.helene.moe.json"),
1389 headers: activitypub_object_headers()
1390 }}
1391 end
1392
1393 def get("https://mk.absturztau.be/notes/93e7nm8wqg", _, _, _) do
1394 {:ok,
1395 %Tesla.Env{
1396 status: 200,
1397 body: File.read!("test/fixtures/tesla_mock/mk.absturztau.be-93e7nm8wqg.json"),
1398 headers: activitypub_object_headers()
1399 }}
1400 end
1401
1402 def get("https://p.helene.moe/objects/fd5910ac-d9dc-412e-8d1d-914b203296c4", _, _, _) do
1403 {:ok,
1404 %Tesla.Env{
1405 status: 200,
1406 body: File.read!("test/fixtures/tesla_mock/p.helene.moe-AM7S6vZQmL6pI9TgPY.json"),
1407 headers: activitypub_object_headers()
1408 }}
1409 end
1410
1411 def get(url, query, body, headers) do
1412 {:error,
1413 "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
1414 end
1415
1416 # POST Requests
1417 #
1418
1419 def post(url, query \\ [], body \\ [], headers \\ [])
1420
1421 def post("https://relay.mastodon.host/inbox", _, _, _) do
1422 {:ok, %Tesla.Env{status: 200, body: ""}}
1423 end
1424
1425 def post("http://example.org/needs_refresh", _, _, _) do
1426 {:ok,
1427 %Tesla.Env{
1428 status: 200,
1429 body: ""
1430 }}
1431 end
1432
1433 def post("http://mastodon.example.org/inbox", _, _, _) do
1434 {:ok,
1435 %Tesla.Env{
1436 status: 200,
1437 body: ""
1438 }}
1439 end
1440
1441 def post("https://hubzilla.example.org/inbox", _, _, _) do
1442 {:ok,
1443 %Tesla.Env{
1444 status: 200,
1445 body: ""
1446 }}
1447 end
1448
1449 def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
1450 {:ok,
1451 %Tesla.Env{
1452 status: 200,
1453 body: ""
1454 }}
1455 end
1456
1457 def post("http://200.site" <> _, _, _, _) do
1458 {:ok,
1459 %Tesla.Env{
1460 status: 200,
1461 body: ""
1462 }}
1463 end
1464
1465 def post("http://connrefused.site" <> _, _, _, _) do
1466 {:error, :connrefused}
1467 end
1468
1469 def post("http://404.site" <> _, _, _, _) do
1470 {:ok,
1471 %Tesla.Env{
1472 status: 404,
1473 body: ""
1474 }}
1475 end
1476
1477 def post(url, query, body, headers) do
1478 {:error,
1479 "Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
1480 end
1481
1482 # Most of the rich media mocks are missing HEAD requests, so we just return 404.
1483 @rich_media_mocks [
1484 "https://example.com/ogp",
1485 "https://example.com/ogp-missing-data",
1486 "https://example.com/twitter-card"
1487 ]
1488 def head(url, _query, _body, _headers) when url in @rich_media_mocks do
1489 {:ok, %Tesla.Env{status: 404, body: ""}}
1490 end
1491
1492 def head(url, query, body, headers) do
1493 {:error,
1494 "Mock response not implemented for HEAD #{inspect(url)}, #{query}, #{inspect(body)}, #{inspect(headers)}"}
1495 end
1496 end