logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

http_request_mock.ex (48907B)


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