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