Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1420 lines
37KB

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