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.

1351 lines
34KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2019 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(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=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://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39", _, _,
  279. Accept: "application/activity+json"
  280. ) do
  281. {:ok,
  282. %Tesla.Env{
  283. status: 200,
  284. body: File.read!("test/fixtures/tesla_mock/mobilizon.org-event.json")
  285. }}
  286. end
  287. def get("https://mobilizon.org/@tcit", _, _, Accept: "application/activity+json") do
  288. {:ok,
  289. %Tesla.Env{
  290. status: 200,
  291. body: File.read!("test/fixtures/tesla_mock/mobilizon.org-user.json")
  292. }}
  293. end
  294. def get("https://baptiste.gelez.xyz/@/BaptisteGelez", _, _, _) do
  295. {:ok,
  296. %Tesla.Env{
  297. status: 200,
  298. body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json")
  299. }}
  300. end
  301. def get("https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/", _, _, _) do
  302. {:ok,
  303. %Tesla.Env{
  304. status: 200,
  305. body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json")
  306. }}
  307. end
  308. def get("https://wedistribute.org/wp-json/pterotype/v1/object/85810", _, _, _) do
  309. {:ok,
  310. %Tesla.Env{
  311. status: 200,
  312. body: File.read!("test/fixtures/tesla_mock/wedistribute-article.json")
  313. }}
  314. end
  315. def get("https://wedistribute.org/wp-json/pterotype/v1/actor/-blog", _, _, _) do
  316. {:ok,
  317. %Tesla.Env{
  318. status: 200,
  319. body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")
  320. }}
  321. end
  322. def get("http://mastodon.example.org/users/admin", _, _, Accept: "application/activity+json") do
  323. {:ok,
  324. %Tesla.Env{
  325. status: 200,
  326. body: File.read!("test/fixtures/tesla_mock/admin@mastdon.example.org.json")
  327. }}
  328. end
  329. def get("http://mastodon.example.org/users/relay", _, _, Accept: "application/activity+json") do
  330. {:ok,
  331. %Tesla.Env{
  332. status: 200,
  333. body: File.read!("test/fixtures/tesla_mock/relay@mastdon.example.org.json")
  334. }}
  335. end
  336. def get("http://mastodon.example.org/users/gargron", _, _, Accept: "application/activity+json") do
  337. {:error, :nxdomain}
  338. end
  339. def get("http://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
  340. {:ok,
  341. %Tesla.Env{
  342. status: 404,
  343. body: ""
  344. }}
  345. end
  346. def get("https://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
  347. {:ok,
  348. %Tesla.Env{
  349. status: 404,
  350. body: ""
  351. }}
  352. end
  353. def get("http://mastodon.sdf.org/.well-known/host-meta", _, _, _) do
  354. {:ok,
  355. %Tesla.Env{
  356. status: 200,
  357. body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta")
  358. }}
  359. end
  360. def get("https://mastodon.sdf.org/.well-known/host-meta", _, _, _) do
  361. {:ok,
  362. %Tesla.Env{
  363. status: 200,
  364. body: File.read!("test/fixtures/tesla_mock/sdf.org_host_meta")
  365. }}
  366. end
  367. def get(
  368. "https://mastodon.sdf.org/.well-known/webfinger?resource=https://mastodon.sdf.org/users/snowdusk",
  369. _,
  370. _,
  371. _
  372. ) do
  373. {:ok,
  374. %Tesla.Env{
  375. status: 200,
  376. body: File.read!("test/fixtures/tesla_mock/snowdusk@sdf.org_host_meta.json")
  377. }}
  378. end
  379. def get("http://mstdn.jp/.well-known/host-meta", _, _, _) do
  380. {:ok,
  381. %Tesla.Env{
  382. status: 200,
  383. body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta")
  384. }}
  385. end
  386. def get("https://mstdn.jp/.well-known/host-meta", _, _, _) do
  387. {:ok,
  388. %Tesla.Env{
  389. status: 200,
  390. body: File.read!("test/fixtures/tesla_mock/mstdn.jp_host_meta")
  391. }}
  392. end
  393. def get("https://mstdn.jp/.well-known/webfinger?resource=kpherox@mstdn.jp", _, _, _) do
  394. {:ok,
  395. %Tesla.Env{
  396. status: 200,
  397. body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
  398. }}
  399. end
  400. def get("http://mamot.fr/.well-known/host-meta", _, _, _) do
  401. {:ok,
  402. %Tesla.Env{
  403. status: 200,
  404. body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta")
  405. }}
  406. end
  407. def get("https://mamot.fr/.well-known/host-meta", _, _, _) do
  408. {:ok,
  409. %Tesla.Env{
  410. status: 200,
  411. body: File.read!("test/fixtures/tesla_mock/mamot.fr_host_meta")
  412. }}
  413. end
  414. def get(
  415. "https://mamot.fr/.well-known/webfinger?resource=https://mamot.fr/users/Skruyb",
  416. _,
  417. _,
  418. _
  419. ) do
  420. {:ok,
  421. %Tesla.Env{
  422. status: 200,
  423. body: File.read!("test/fixtures/tesla_mock/skruyb@mamot.fr.atom")
  424. }}
  425. end
  426. def get("http://pawoo.net/.well-known/host-meta", _, _, _) do
  427. {:ok,
  428. %Tesla.Env{
  429. status: 200,
  430. body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
  431. }}
  432. end
  433. def get("https://pawoo.net/.well-known/host-meta", _, _, _) do
  434. {:ok,
  435. %Tesla.Env{
  436. status: 200,
  437. body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
  438. }}
  439. end
  440. def get(
  441. "https://pawoo.net/.well-known/webfinger?resource=https://pawoo.net/users/pekorino",
  442. _,
  443. _,
  444. _
  445. ) do
  446. {:ok,
  447. %Tesla.Env{
  448. status: 200,
  449. body: File.read!("test/fixtures/tesla_mock/pekorino@pawoo.net_host_meta.json")
  450. }}
  451. end
  452. def get("http://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
  453. {:ok,
  454. %Tesla.Env{
  455. status: 200,
  456. body: File.read!("test/fixtures/tesla_mock/xn--q9jyb4c_host_meta")
  457. }}
  458. end
  459. def get("https://zetsubou.xn--q9jyb4c/.well-known/host-meta", _, _, _) do
  460. {:ok,
  461. %Tesla.Env{
  462. status: 200,
  463. body: File.read!("test/fixtures/tesla_mock/xn--q9jyb4c_host_meta")
  464. }}
  465. end
  466. def get("http://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
  467. {:ok,
  468. %Tesla.Env{
  469. status: 200,
  470. body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta")
  471. }}
  472. end
  473. def get("https://pleroma.soykaf.com/.well-known/host-meta", _, _, _) do
  474. {:ok,
  475. %Tesla.Env{
  476. status: 200,
  477. body: File.read!("test/fixtures/tesla_mock/soykaf.com_host_meta")
  478. }}
  479. end
  480. def get("http://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do
  481. {:ok,
  482. %Tesla.Env{
  483. status: 200,
  484. body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta")
  485. }}
  486. end
  487. def get("https://social.stopwatchingus-heidelberg.de/.well-known/host-meta", _, _, _) do
  488. {:ok,
  489. %Tesla.Env{
  490. status: 200,
  491. body: File.read!("test/fixtures/tesla_mock/stopwatchingus-heidelberg.de_host_meta")
  492. }}
  493. end
  494. def get(
  495. "http://mastodon.example.org/@admin/99541947525187367",
  496. _,
  497. _,
  498. Accept: "application/activity+json"
  499. ) do
  500. {:ok,
  501. %Tesla.Env{
  502. status: 200,
  503. body: File.read!("test/fixtures/mastodon-note-object.json")
  504. }}
  505. end
  506. def get("http://mastodon.example.org/@admin/99541947525187368", _, _, _) do
  507. {:ok,
  508. %Tesla.Env{
  509. status: 404,
  510. body: ""
  511. }}
  512. end
  513. def get("https://shitposter.club/notice/7369654", _, _, _) do
  514. {:ok,
  515. %Tesla.Env{
  516. status: 200,
  517. body: File.read!("test/fixtures/tesla_mock/7369654.html")
  518. }}
  519. end
  520. def get("https://mstdn.io/users/mayuutann", _, _, Accept: "application/activity+json") do
  521. {:ok,
  522. %Tesla.Env{
  523. status: 200,
  524. body: File.read!("test/fixtures/tesla_mock/mayumayu.json")
  525. }}
  526. end
  527. def get(
  528. "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
  529. _,
  530. _,
  531. Accept: "application/activity+json"
  532. ) do
  533. {:ok,
  534. %Tesla.Env{
  535. status: 200,
  536. body: File.read!("test/fixtures/tesla_mock/mayumayupost.json")
  537. }}
  538. end
  539. def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do
  540. {:ok,
  541. %Tesla.Env{
  542. status: 200,
  543. body:
  544. File.read!(
  545. "test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
  546. )
  547. }}
  548. end
  549. def get(url, _, _, Accept: "application/xrd+xml,application/jrd+json")
  550. when url in [
  551. "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
  552. "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
  553. ] do
  554. {:ok,
  555. %Tesla.Env{
  556. status: 200,
  557. body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
  558. }}
  559. end
  560. def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _, _, _) do
  561. {:ok,
  562. %Tesla.Env{
  563. status: 200,
  564. body:
  565. File.read!(
  566. "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
  567. )
  568. }}
  569. end
  570. def get(
  571. "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
  572. _,
  573. _,
  574. Accept: "application/xrd+xml,application/jrd+json"
  575. ) do
  576. {:ok,
  577. %Tesla.Env{
  578. status: 200,
  579. body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
  580. }}
  581. end
  582. def get("https://shitposter.club/notice/2827873", _, _, _) do
  583. {:ok,
  584. %Tesla.Env{
  585. status: 200,
  586. body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.json")
  587. }}
  588. end
  589. def get("https://shitposter.club/api/statuses/show/2827873.atom", _, _, _) do
  590. {:ok,
  591. %Tesla.Env{
  592. status: 200,
  593. body:
  594. File.read!(
  595. "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
  596. )
  597. }}
  598. end
  599. def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
  600. {:ok, %Tesla.Env{status: 200}}
  601. end
  602. def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _, _, _) do
  603. {:ok,
  604. %Tesla.Env{
  605. status: 200,
  606. body: File.read!("test/fixtures/tesla_mock/spc_5381.atom")
  607. }}
  608. end
  609. def get(
  610. "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
  611. _,
  612. _,
  613. Accept: "application/xrd+xml,application/jrd+json"
  614. ) do
  615. {:ok,
  616. %Tesla.Env{
  617. status: 200,
  618. body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
  619. }}
  620. end
  621. def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
  622. {:ok,
  623. %Tesla.Env{
  624. status: 200,
  625. body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
  626. }}
  627. end
  628. def get("https://shitposter.club/api/statuses/show/7369654.atom", _, _, _) do
  629. {:ok,
  630. %Tesla.Env{
  631. status: 200,
  632. body: File.read!("test/fixtures/tesla_mock/7369654.atom")
  633. }}
  634. end
  635. def get("https://shitposter.club/notice/4027863", _, _, _) do
  636. {:ok,
  637. %Tesla.Env{
  638. status: 200,
  639. body: File.read!("test/fixtures/tesla_mock/7369654.html")
  640. }}
  641. end
  642. def get("https://social.sakamoto.gq/users/eal/feed.atom", _, _, _) do
  643. {:ok,
  644. %Tesla.Env{
  645. status: 200,
  646. body: File.read!("test/fixtures/tesla_mock/sakamoto_eal_feed.atom")
  647. }}
  648. end
  649. def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
  650. {:ok,
  651. %Tesla.Env{
  652. status: 200,
  653. body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
  654. }}
  655. end
  656. def get(
  657. "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
  658. _,
  659. _,
  660. Accept: "application/xrd+xml,application/jrd+json"
  661. ) do
  662. {:ok,
  663. %Tesla.Env{
  664. status: 200,
  665. body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
  666. }}
  667. end
  668. def get(
  669. "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056",
  670. _,
  671. _,
  672. Accept: "application/atom+xml"
  673. ) do
  674. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sakamoto.atom")}}
  675. end
  676. def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
  677. {:ok,
  678. %Tesla.Env{
  679. status: 200,
  680. body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
  681. }}
  682. end
  683. def get(
  684. "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
  685. _,
  686. _,
  687. Accept: "application/xrd+xml,application/jrd+json"
  688. ) do
  689. {:ok,
  690. %Tesla.Env{
  691. status: 200,
  692. body:
  693. File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
  694. }}
  695. end
  696. def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
  697. {:ok,
  698. %Tesla.Env{
  699. status: 200,
  700. body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
  701. }}
  702. end
  703. def get(
  704. "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
  705. _,
  706. _,
  707. Accept: "application/xrd+xml,application/jrd+json"
  708. ) do
  709. {:ok,
  710. %Tesla.Env{
  711. status: 200,
  712. body:
  713. File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
  714. }}
  715. end
  716. def get(
  717. "http://gs.example.org:4040/index.php/user/1",
  718. _,
  719. _,
  720. Accept: "application/activity+json"
  721. ) do
  722. {:ok, %Tesla.Env{status: 406, body: ""}}
  723. end
  724. def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _, _, _) do
  725. {:ok,
  726. %Tesla.Env{
  727. status: 200,
  728. body:
  729. File.read!(
  730. "test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
  731. )
  732. }}
  733. end
  734. def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _, _, _) do
  735. {:ok,
  736. %Tesla.Env{
  737. status: 200,
  738. body:
  739. File.read!(
  740. "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
  741. )
  742. }}
  743. end
  744. def get("http://squeet.me/.well-known/host-meta", _, _, _) do
  745. {:ok,
  746. %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
  747. end
  748. def get(
  749. "https://squeet.me/xrd?uri=lain@squeet.me",
  750. _,
  751. _,
  752. Accept: "application/xrd+xml,application/jrd+json"
  753. ) do
  754. {:ok,
  755. %Tesla.Env{
  756. status: 200,
  757. body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
  758. }}
  759. end
  760. def get(
  761. "https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la",
  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/shp@social.heldscal.la.xml")
  770. }}
  771. end
  772. def get(
  773. "https://social.heldscal.la/.well-known/webfinger?resource=invalid_content@social.heldscal.la",
  774. _,
  775. _,
  776. Accept: "application/xrd+xml,application/jrd+json"
  777. ) do
  778. {:ok, %Tesla.Env{status: 200, body: ""}}
  779. end
  780. def get("http://framatube.org/.well-known/host-meta", _, _, _) do
  781. {:ok,
  782. %Tesla.Env{
  783. status: 200,
  784. body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
  785. }}
  786. end
  787. def get(
  788. "http://framatube.org/main/xrd?uri=framasoft@framatube.org",
  789. _,
  790. _,
  791. Accept: "application/xrd+xml,application/jrd+json"
  792. ) do
  793. {:ok,
  794. %Tesla.Env{
  795. status: 200,
  796. headers: [{"content-type", "application/json"}],
  797. body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
  798. }}
  799. end
  800. def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
  801. {:ok,
  802. %Tesla.Env{
  803. status: 200,
  804. body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
  805. }}
  806. end
  807. def get(
  808. "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
  809. _,
  810. _,
  811. Accept: "application/xrd+xml,application/jrd+json"
  812. ) do
  813. {:ok,
  814. %Tesla.Env{
  815. status: 200,
  816. body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json")
  817. }}
  818. end
  819. def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
  820. {:ok,
  821. %Tesla.Env{
  822. status: 200,
  823. body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
  824. }}
  825. end
  826. def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
  827. {:ok,
  828. %Tesla.Env{
  829. status: 200,
  830. body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
  831. }}
  832. end
  833. def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
  834. {:ok,
  835. %Tesla.Env{
  836. status: 200,
  837. body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
  838. }}
  839. end
  840. def get(
  841. "https://gerzilla.de/xrd/?uri=kaniini@gerzilla.de",
  842. _,
  843. _,
  844. Accept: "application/xrd+xml,application/jrd+json"
  845. ) do
  846. {:ok,
  847. %Tesla.Env{
  848. status: 200,
  849. headers: [{"content-type", "application/json"}],
  850. body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
  851. }}
  852. end
  853. def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _, _, _) do
  854. {:ok,
  855. %Tesla.Env{
  856. status: 200,
  857. body:
  858. File.read!(
  859. "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
  860. )
  861. }}
  862. end
  863. def get(
  864. "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
  865. _,
  866. _,
  867. _
  868. ) do
  869. {:ok,
  870. %Tesla.Env{
  871. status: 200,
  872. body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
  873. }}
  874. end
  875. def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
  876. {:ok,
  877. %Tesla.Env{
  878. status: 200,
  879. body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
  880. }}
  881. end
  882. def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
  883. {:ok,
  884. %Tesla.Env{
  885. status: 200,
  886. body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
  887. }}
  888. end
  889. def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do
  890. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}}
  891. end
  892. def get("https://mastodon.social/users/lambadalambda", _, _, _) do
  893. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
  894. end
  895. def get("https://apfed.club/channel/indio", _, _, _) do
  896. {:ok,
  897. %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/osada-user-indio.json")}}
  898. end
  899. def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
  900. {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
  901. end
  902. def get("http://example.com/ogp", _, _, _) do
  903. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
  904. end
  905. def get("https://example.com/ogp", _, _, _) do
  906. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
  907. end
  908. def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
  909. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
  910. end
  911. def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
  912. {:ok,
  913. %Tesla.Env{
  914. status: 200,
  915. body: File.read!("test/fixtures/users_mock/masto_closed_followers.json")
  916. }}
  917. end
  918. def get("http://localhost:4001/users/masto_closed/followers?page=1", _, _, _) do
  919. {:ok,
  920. %Tesla.Env{
  921. status: 200,
  922. body: File.read!("test/fixtures/users_mock/masto_closed_followers_page.json")
  923. }}
  924. end
  925. def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
  926. {:ok,
  927. %Tesla.Env{
  928. status: 200,
  929. body: File.read!("test/fixtures/users_mock/masto_closed_following.json")
  930. }}
  931. end
  932. def get("http://localhost:4001/users/masto_closed/following?page=1", _, _, _) do
  933. {:ok,
  934. %Tesla.Env{
  935. status: 200,
  936. body: File.read!("test/fixtures/users_mock/masto_closed_following_page.json")
  937. }}
  938. end
  939. def get("http://localhost:8080/followers/fuser3", _, _, _) do
  940. {:ok,
  941. %Tesla.Env{
  942. status: 200,
  943. body: File.read!("test/fixtures/users_mock/friendica_followers.json")
  944. }}
  945. end
  946. def get("http://localhost:8080/following/fuser3", _, _, _) do
  947. {:ok,
  948. %Tesla.Env{
  949. status: 200,
  950. body: File.read!("test/fixtures/users_mock/friendica_following.json")
  951. }}
  952. end
  953. def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
  954. {:ok,
  955. %Tesla.Env{
  956. status: 200,
  957. body: File.read!("test/fixtures/users_mock/pleroma_followers.json")
  958. }}
  959. end
  960. def get("http://localhost:4001/users/fuser2/following", _, _, _) do
  961. {:ok,
  962. %Tesla.Env{
  963. status: 200,
  964. body: File.read!("test/fixtures/users_mock/pleroma_following.json")
  965. }}
  966. end
  967. def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
  968. {:ok,
  969. %Tesla.Env{
  970. status: 504,
  971. body: ""
  972. }}
  973. end
  974. def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
  975. {:ok,
  976. %Tesla.Env{
  977. status: 504,
  978. body: ""
  979. }}
  980. end
  981. def get("http://example.com/ogp-missing-data", _, _, _) do
  982. {:ok,
  983. %Tesla.Env{
  984. status: 200,
  985. body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
  986. }}
  987. end
  988. def get("https://example.com/ogp-missing-data", _, _, _) do
  989. {:ok,
  990. %Tesla.Env{
  991. status: 200,
  992. body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
  993. }}
  994. end
  995. def get("http://example.com/malformed", _, _, _) do
  996. {:ok,
  997. %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
  998. end
  999. def get("http://example.com/empty", _, _, _) do
  1000. {:ok, %Tesla.Env{status: 200, body: "hello"}}
  1001. end
  1002. def get("http://404.site" <> _, _, _, _) do
  1003. {:ok,
  1004. %Tesla.Env{
  1005. status: 404,
  1006. body: ""
  1007. }}
  1008. end
  1009. def get(
  1010. "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=lain@zetsubou.xn--q9jyb4c",
  1011. _,
  1012. _,
  1013. Accept: "application/xrd+xml,application/jrd+json"
  1014. ) do
  1015. {:ok,
  1016. %Tesla.Env{
  1017. status: 200,
  1018. body: File.read!("test/fixtures/lain.xml")
  1019. }}
  1020. end
  1021. def get(
  1022. "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=https://zetsubou.xn--q9jyb4c/users/lain",
  1023. _,
  1024. _,
  1025. Accept: "application/xrd+xml,application/jrd+json"
  1026. ) do
  1027. {:ok,
  1028. %Tesla.Env{
  1029. status: 200,
  1030. body: File.read!("test/fixtures/lain.xml")
  1031. }}
  1032. end
  1033. def get(
  1034. "https://zetsubou.xn--q9jyb4c/.well-known/host-meta",
  1035. _,
  1036. _,
  1037. _
  1038. ) do
  1039. {:ok,
  1040. %Tesla.Env{
  1041. status: 200,
  1042. body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
  1043. }}
  1044. end
  1045. def get("https://info.pleroma.site/activity.json", _, _, Accept: "application/activity+json") do
  1046. {:ok,
  1047. %Tesla.Env{
  1048. status: 200,
  1049. body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity.json")
  1050. }}
  1051. end
  1052. def get("https://info.pleroma.site/activity.json", _, _, _) do
  1053. {:ok, %Tesla.Env{status: 404, body: ""}}
  1054. end
  1055. def get("https://info.pleroma.site/activity2.json", _, _, Accept: "application/activity+json") do
  1056. {:ok,
  1057. %Tesla.Env{
  1058. status: 200,
  1059. body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json")
  1060. }}
  1061. end
  1062. def get("https://info.pleroma.site/activity2.json", _, _, _) do
  1063. {:ok, %Tesla.Env{status: 404, body: ""}}
  1064. end
  1065. def get("https://info.pleroma.site/activity3.json", _, _, Accept: "application/activity+json") do
  1066. {:ok,
  1067. %Tesla.Env{
  1068. status: 200,
  1069. body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json")
  1070. }}
  1071. end
  1072. def get("https://info.pleroma.site/activity3.json", _, _, _) do
  1073. {:ok, %Tesla.Env{status: 404, body: ""}}
  1074. end
  1075. def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp", _, _, _) do
  1076. {:ok,
  1077. %Tesla.Env{
  1078. status: 200,
  1079. body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
  1080. }}
  1081. end
  1082. def get("https://10.111.10.1/notice/9kCP7V", _, _, _) do
  1083. {:ok, %Tesla.Env{status: 200, body: ""}}
  1084. end
  1085. def get("https://172.16.32.40/notice/9kCP7V", _, _, _) do
  1086. {:ok, %Tesla.Env{status: 200, body: ""}}
  1087. end
  1088. def get("https://192.168.10.40/notice/9kCP7V", _, _, _) do
  1089. {:ok, %Tesla.Env{status: 200, body: ""}}
  1090. end
  1091. def get("https://www.patreon.com/posts/mastodon-2-9-and-28121681", _, _, _) do
  1092. {:ok, %Tesla.Env{status: 200, body: ""}}
  1093. end
  1094. def get("http://mastodon.example.org/@admin/99541947525187367", _, _, _) do
  1095. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/mastodon-post-activity.json")}}
  1096. end
  1097. def get("https://info.pleroma.site/activity4.json", _, _, _) do
  1098. {:ok, %Tesla.Env{status: 500, body: "Error occurred"}}
  1099. end
  1100. def get("http://example.com/rel_me/anchor", _, _, _) do
  1101. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}}
  1102. end
  1103. def get("http://example.com/rel_me/anchor_nofollow", _, _, _) do
  1104. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}}
  1105. end
  1106. def get("http://example.com/rel_me/link", _, _, _) do
  1107. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}}
  1108. end
  1109. def get("http://example.com/rel_me/null", _, _, _) do
  1110. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}}
  1111. end
  1112. def get("https://skippers-bin.com/notes/7x9tmrp97i", _, _, _) do
  1113. {:ok,
  1114. %Tesla.Env{
  1115. status: 200,
  1116. body: File.read!("test/fixtures/tesla_mock/misskey_poll_no_end_date.json")
  1117. }}
  1118. end
  1119. def get("https://skippers-bin.com/users/7v1w1r8ce6", _, _, _) do
  1120. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sjw.json")}}
  1121. end
  1122. def get("https://patch.cx/users/rin", _, _, _) do
  1123. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/rin.json")}}
  1124. end
  1125. def get("http://example.com/rel_me/error", _, _, _) do
  1126. {:ok, %Tesla.Env{status: 404, body: ""}}
  1127. end
  1128. def get(url, query, body, headers) do
  1129. {:error,
  1130. "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
  1131. inspect(headers)
  1132. }"}
  1133. end
  1134. # POST Requests
  1135. #
  1136. def post(url, query \\ [], body \\ [], headers \\ [])
  1137. def post("http://example.org/needs_refresh", _, _, _) do
  1138. {:ok,
  1139. %Tesla.Env{
  1140. status: 200,
  1141. body: ""
  1142. }}
  1143. end
  1144. def post("http://mastodon.example.org/inbox", _, _, _) do
  1145. {:ok,
  1146. %Tesla.Env{
  1147. status: 200,
  1148. body: ""
  1149. }}
  1150. end
  1151. def post("https://hubzilla.example.org/inbox", _, _, _) do
  1152. {:ok,
  1153. %Tesla.Env{
  1154. status: 200,
  1155. body: ""
  1156. }}
  1157. end
  1158. def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
  1159. {:ok,
  1160. %Tesla.Env{
  1161. status: 200,
  1162. body: ""
  1163. }}
  1164. end
  1165. def post("http://200.site" <> _, _, _, _) do
  1166. {:ok,
  1167. %Tesla.Env{
  1168. status: 200,
  1169. body: ""
  1170. }}
  1171. end
  1172. def post("http://connrefused.site" <> _, _, _, _) do
  1173. {:error, :connrefused}
  1174. end
  1175. def post("http://404.site" <> _, _, _, _) do
  1176. {:ok,
  1177. %Tesla.Env{
  1178. status: 404,
  1179. body: ""
  1180. }}
  1181. end
  1182. def post(url, query, body, headers) do
  1183. {:error,
  1184. "Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{
  1185. inspect(headers)
  1186. }"}
  1187. end
  1188. end