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.

1039 lines
26KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2018 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. {_, _r} = error ->
  19. # Logger.warn(r)
  20. error
  21. end
  22. end
  23. # GET Requests
  24. #
  25. def get(url, query \\ [], body \\ [], headers \\ [])
  26. def get("https://osada.macgirvin.com/channel/mike", _, _, _) do
  27. {:ok,
  28. %Tesla.Env{
  29. status: 200,
  30. body: File.read!("test/fixtures/tesla_mock/https___osada.macgirvin.com_channel_mike.json")
  31. }}
  32. end
  33. def get("https://mastodon.social/users/emelie/statuses/101849165031453009", _, _, _) do
  34. {:ok,
  35. %Tesla.Env{
  36. status: 200,
  37. body: File.read!("test/fixtures/tesla_mock/status.emelie.json")
  38. }}
  39. end
  40. def get("https://mastodon.social/users/emelie", _, _, _) do
  41. {:ok,
  42. %Tesla.Env{
  43. status: 200,
  44. body: File.read!("test/fixtures/tesla_mock/emelie.json")
  45. }}
  46. end
  47. def get("https://mastodon.social/users/not_found", _, _, _) do
  48. {:ok, %Tesla.Env{status: 404}}
  49. end
  50. def get("https://mastodon.sdf.org/users/rinpatch", _, _, _) do
  51. {:ok,
  52. %Tesla.Env{
  53. status: 200,
  54. body: File.read!("test/fixtures/tesla_mock/rinpatch.json")
  55. }}
  56. end
  57. def get(
  58. "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/emelie",
  59. _,
  60. _,
  61. _
  62. ) do
  63. {:ok,
  64. %Tesla.Env{
  65. status: 200,
  66. body: File.read!("test/fixtures/tesla_mock/webfinger_emelie.json")
  67. }}
  68. end
  69. def get("https://mastodon.social/users/emelie.atom", _, _, _) do
  70. {:ok,
  71. %Tesla.Env{
  72. status: 200,
  73. body: File.read!("test/fixtures/tesla_mock/emelie.atom")
  74. }}
  75. end
  76. def get(
  77. "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",
  78. _,
  79. _,
  80. Accept: "application/xrd+xml,application/jrd+json"
  81. ) do
  82. {:ok,
  83. %Tesla.Env{
  84. status: 200,
  85. body: File.read!("test/fixtures/tesla_mock/mike@osada.macgirvin.com.json")
  86. }}
  87. end
  88. def get(
  89. "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
  90. _,
  91. _,
  92. Accept: "application/xrd+xml,application/jrd+json"
  93. ) do
  94. {:ok,
  95. %Tesla.Env{
  96. status: 200,
  97. body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_29191.xml")
  98. }}
  99. end
  100. def get("https://pawoo.net/users/pekorino.atom", _, _, _) do
  101. {:ok,
  102. %Tesla.Env{
  103. status: 200,
  104. body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.atom")
  105. }}
  106. end
  107. def get(
  108. "https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",
  109. _,
  110. _,
  111. Accept: "application/xrd+xml,application/jrd+json"
  112. ) do
  113. {:ok,
  114. %Tesla.Env{
  115. status: 200,
  116. body: File.read!("test/fixtures/tesla_mock/https___pawoo.net_users_pekorino.xml")
  117. }}
  118. end
  119. def get(
  120. "https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom",
  121. _,
  122. _,
  123. _
  124. ) do
  125. {:ok,
  126. %Tesla.Env{
  127. status: 200,
  128. body: File.read!("test/fixtures/tesla_mock/atarifrosch_feed.xml")
  129. }}
  130. end
  131. def get(
  132. "https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",
  133. _,
  134. _,
  135. Accept: "application/xrd+xml,application/jrd+json"
  136. ) do
  137. {:ok,
  138. %Tesla.Env{
  139. status: 200,
  140. body: File.read!("test/fixtures/tesla_mock/atarifrosch_webfinger.xml")
  141. }}
  142. end
  143. def get("https://mamot.fr/users/Skruyb.atom", _, _, _) do
  144. {:ok,
  145. %Tesla.Env{
  146. status: 200,
  147. body: File.read!("test/fixtures/tesla_mock/https___mamot.fr_users_Skruyb.atom")
  148. }}
  149. end
  150. def get(
  151. "https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/users/Skruyb",
  152. _,
  153. _,
  154. Accept: "application/xrd+xml,application/jrd+json"
  155. ) do
  156. {:ok,
  157. %Tesla.Env{
  158. status: 200,
  159. body: File.read!("test/fixtures/tesla_mock/skruyb@mamot.fr.atom")
  160. }}
  161. end
  162. def get(
  163. "https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la",
  164. _,
  165. _,
  166. Accept: "application/xrd+xml,application/jrd+json"
  167. ) do
  168. {:ok,
  169. %Tesla.Env{
  170. status: 200,
  171. body: File.read!("test/fixtures/tesla_mock/nonexistant@social.heldscal.la.xml")
  172. }}
  173. end
  174. def get(
  175. "https://squeet.me/xrd/?uri=lain@squeet.me",
  176. _,
  177. _,
  178. Accept: "application/xrd+xml,application/jrd+json"
  179. ) do
  180. {:ok,
  181. %Tesla.Env{
  182. status: 200,
  183. body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
  184. }}
  185. end
  186. def get(
  187. "https://mst3k.interlinked.me/users/luciferMysticus",
  188. _,
  189. _,
  190. Accept: "application/activity+json"
  191. ) do
  192. {:ok,
  193. %Tesla.Env{
  194. status: 200,
  195. body: File.read!("test/fixtures/tesla_mock/lucifermysticus.json")
  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. }}
  204. end
  205. def get(
  206. "https://hubzilla.example.org/channel/kaniini",
  207. _,
  208. _,
  209. Accept: "application/activity+json"
  210. ) do
  211. {:ok,
  212. %Tesla.Env{
  213. status: 200,
  214. body: File.read!("test/fixtures/tesla_mock/kaniini@hubzilla.example.org.json")
  215. }}
  216. end
  217. def get("https://niu.moe/users/rye", _, _, Accept: "application/activity+json") do
  218. {:ok,
  219. %Tesla.Env{
  220. status: 200,
  221. body: File.read!("test/fixtures/tesla_mock/rye.json")
  222. }}
  223. end
  224. def get("https://n1u.moe/users/rye", _, _, Accept: "application/activity+json") do
  225. {:ok,
  226. %Tesla.Env{
  227. status: 200,
  228. body: File.read!("test/fixtures/tesla_mock/rye.json")
  229. }}
  230. end
  231. def get("http://mastodon.example.org/users/admin/statuses/100787282858396771", _, _, _) do
  232. {:ok,
  233. %Tesla.Env{
  234. status: 200,
  235. body:
  236. File.read!(
  237. "test/fixtures/tesla_mock/http___mastodon.example.org_users_admin_status_1234.json"
  238. )
  239. }}
  240. end
  241. def get("https://puckipedia.com/", _, _, Accept: "application/activity+json") do
  242. {:ok,
  243. %Tesla.Env{
  244. status: 200,
  245. body: File.read!("test/fixtures/tesla_mock/puckipedia.com.json")
  246. }}
  247. end
  248. def get("https://peertube.moe/accounts/7even", _, _, _) do
  249. {:ok,
  250. %Tesla.Env{
  251. status: 200,
  252. body: File.read!("test/fixtures/tesla_mock/7even.json")
  253. }}
  254. end
  255. def get("https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3", _, _, _) do
  256. {:ok,
  257. %Tesla.Env{
  258. status: 200,
  259. body: File.read!("test/fixtures/tesla_mock/peertube.moe-vid.json")
  260. }}
  261. end
  262. def get("https://baptiste.gelez.xyz/@/BaptisteGelez", _, _, _) do
  263. {:ok,
  264. %Tesla.Env{
  265. status: 200,
  266. body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json")
  267. }}
  268. end
  269. def get("https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/", _, _, _) do
  270. {:ok,
  271. %Tesla.Env{
  272. status: 200,
  273. body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json")
  274. }}
  275. end
  276. def get("https://wedistribute.org/wp-json/pterotype/v1/object/85810", _, _, _) do
  277. {:ok,
  278. %Tesla.Env{
  279. status: 200,
  280. body: File.read!("test/fixtures/tesla_mock/wedistribute-article.json")
  281. }}
  282. end
  283. def get("https://wedistribute.org/wp-json/pterotype/v1/actor/-blog", _, _, _) do
  284. {:ok,
  285. %Tesla.Env{
  286. status: 200,
  287. body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")
  288. }}
  289. end
  290. def get("http://mastodon.example.org/users/admin", _, _, Accept: "application/activity+json") do
  291. {:ok,
  292. %Tesla.Env{
  293. status: 200,
  294. body: File.read!("test/fixtures/tesla_mock/admin@mastdon.example.org.json")
  295. }}
  296. end
  297. def get("http://mastodon.example.org/users/gargron", _, _, Accept: "application/activity+json") do
  298. {:error, :nxdomain}
  299. end
  300. def get(
  301. "http://mastodon.example.org/@admin/99541947525187367",
  302. _,
  303. _,
  304. Accept: "application/activity+json"
  305. ) do
  306. {:ok,
  307. %Tesla.Env{
  308. status: 200,
  309. body: File.read!("test/fixtures/mastodon-note-object.json")
  310. }}
  311. end
  312. def get("https://shitposter.club/notice/7369654", _, _, _) do
  313. {:ok,
  314. %Tesla.Env{
  315. status: 200,
  316. body: File.read!("test/fixtures/tesla_mock/7369654.html")
  317. }}
  318. end
  319. def get("https://mstdn.io/users/mayuutann", _, _, Accept: "application/activity+json") do
  320. {:ok,
  321. %Tesla.Env{
  322. status: 200,
  323. body: File.read!("test/fixtures/tesla_mock/mayumayu.json")
  324. }}
  325. end
  326. def get(
  327. "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
  328. _,
  329. _,
  330. Accept: "application/activity+json"
  331. ) do
  332. {:ok,
  333. %Tesla.Env{
  334. status: 200,
  335. body: File.read!("test/fixtures/tesla_mock/mayumayupost.json")
  336. }}
  337. end
  338. def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do
  339. {:ok,
  340. %Tesla.Env{
  341. status: 200,
  342. body:
  343. File.read!(
  344. "test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
  345. )
  346. }}
  347. end
  348. def get(url, _, _, Accept: "application/xrd+xml,application/jrd+json")
  349. when url in [
  350. "https://pleroma.soykaf.com/.well-known/webfinger?resource=acct:https://pleroma.soykaf.com/users/lain",
  351. "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain"
  352. ] do
  353. {:ok,
  354. %Tesla.Env{
  355. status: 200,
  356. body: File.read!("test/fixtures/tesla_mock/https___pleroma.soykaf.com_users_lain.xml")
  357. }}
  358. end
  359. def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _, _, _) do
  360. {:ok,
  361. %Tesla.Env{
  362. status: 200,
  363. body:
  364. File.read!(
  365. "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
  366. )
  367. }}
  368. end
  369. def get(
  370. "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
  371. _,
  372. _,
  373. Accept: "application/xrd+xml,application/jrd+json"
  374. ) do
  375. {:ok,
  376. %Tesla.Env{
  377. status: 200,
  378. body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_user_1.xml")
  379. }}
  380. end
  381. def get("https://shitposter.club/notice/2827873", _, _, _) do
  382. {:ok,
  383. %Tesla.Env{
  384. status: 200,
  385. body: File.read!("test/fixtures/tesla_mock/https___shitposter.club_notice_2827873.html")
  386. }}
  387. end
  388. def get("https://shitposter.club/api/statuses/show/2827873.atom", _, _, _) do
  389. {:ok,
  390. %Tesla.Env{
  391. status: 200,
  392. body:
  393. File.read!(
  394. "test/fixtures/tesla_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
  395. )
  396. }}
  397. end
  398. def get("https://testing.pleroma.lol/objects/b319022a-4946-44c5-9de9-34801f95507b", _, _, _) do
  399. {:ok, %Tesla.Env{status: 200}}
  400. end
  401. def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _, _, _) do
  402. {:ok,
  403. %Tesla.Env{
  404. status: 200,
  405. body: File.read!("test/fixtures/tesla_mock/spc_5381.atom")
  406. }}
  407. end
  408. def get(
  409. "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
  410. _,
  411. _,
  412. Accept: "application/xrd+xml,application/jrd+json"
  413. ) do
  414. {:ok,
  415. %Tesla.Env{
  416. status: 200,
  417. body: File.read!("test/fixtures/tesla_mock/spc_5381_xrd.xml")
  418. }}
  419. end
  420. def get("http://shitposter.club/.well-known/host-meta", _, _, _) do
  421. {:ok,
  422. %Tesla.Env{
  423. status: 200,
  424. body: File.read!("test/fixtures/tesla_mock/shitposter.club_host_meta")
  425. }}
  426. end
  427. def get("https://shitposter.club/api/statuses/show/7369654.atom", _, _, _) do
  428. {:ok,
  429. %Tesla.Env{
  430. status: 200,
  431. body: File.read!("test/fixtures/tesla_mock/7369654.atom")
  432. }}
  433. end
  434. def get("https://shitposter.club/notice/4027863", _, _, _) do
  435. {:ok,
  436. %Tesla.Env{
  437. status: 200,
  438. body: File.read!("test/fixtures/tesla_mock/7369654.html")
  439. }}
  440. end
  441. def get("https://social.sakamoto.gq/users/eal/feed.atom", _, _, _) do
  442. {:ok,
  443. %Tesla.Env{
  444. status: 200,
  445. body: File.read!("test/fixtures/tesla_mock/sakamoto_eal_feed.atom")
  446. }}
  447. end
  448. def get("http://social.sakamoto.gq/.well-known/host-meta", _, _, _) do
  449. {:ok,
  450. %Tesla.Env{
  451. status: 200,
  452. body: File.read!("test/fixtures/tesla_mock/social.sakamoto.gq_host_meta")
  453. }}
  454. end
  455. def get(
  456. "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
  457. _,
  458. _,
  459. Accept: "application/xrd+xml,application/jrd+json"
  460. ) do
  461. {:ok,
  462. %Tesla.Env{
  463. status: 200,
  464. body: File.read!("test/fixtures/tesla_mock/eal_sakamoto.xml")
  465. }}
  466. end
  467. def get(
  468. "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056",
  469. _,
  470. _,
  471. Accept: "application/atom+xml"
  472. ) do
  473. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sakamoto.atom")}}
  474. end
  475. def get("http://mastodon.social/.well-known/host-meta", _, _, _) do
  476. {:ok,
  477. %Tesla.Env{
  478. status: 200,
  479. body: File.read!("test/fixtures/tesla_mock/mastodon.social_host_meta")
  480. }}
  481. end
  482. def get(
  483. "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
  484. _,
  485. _,
  486. Accept: "application/xrd+xml,application/jrd+json"
  487. ) do
  488. {:ok,
  489. %Tesla.Env{
  490. status: 200,
  491. body:
  492. File.read!("test/fixtures/tesla_mock/https___mastodon.social_users_lambadalambda.xml")
  493. }}
  494. end
  495. def get("http://gs.example.org/.well-known/host-meta", _, _, _) do
  496. {:ok,
  497. %Tesla.Env{
  498. status: 200,
  499. body: File.read!("test/fixtures/tesla_mock/gs.example.org_host_meta")
  500. }}
  501. end
  502. def get(
  503. "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
  504. _,
  505. _,
  506. Accept: "application/xrd+xml,application/jrd+json"
  507. ) do
  508. {:ok,
  509. %Tesla.Env{
  510. status: 200,
  511. body:
  512. File.read!("test/fixtures/tesla_mock/http___gs.example.org_4040_index.php_user_1.xml")
  513. }}
  514. end
  515. def get(
  516. "http://gs.example.org:4040/index.php/user/1",
  517. _,
  518. _,
  519. Accept: "application/activity+json"
  520. ) do
  521. {:ok, %Tesla.Env{status: 406, body: ""}}
  522. end
  523. def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _, _, _) do
  524. {:ok,
  525. %Tesla.Env{
  526. status: 200,
  527. body:
  528. File.read!(
  529. "test/fixtures/tesla_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
  530. )
  531. }}
  532. end
  533. def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _, _, _) do
  534. {:ok,
  535. %Tesla.Env{
  536. status: 200,
  537. body:
  538. File.read!(
  539. "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
  540. )
  541. }}
  542. end
  543. def get("http://squeet.me/.well-known/host-meta", _, _, _) do
  544. {:ok,
  545. %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/squeet.me_host_meta")}}
  546. end
  547. def get(
  548. "https://squeet.me/xrd?uri=lain@squeet.me",
  549. _,
  550. _,
  551. Accept: "application/xrd+xml,application/jrd+json"
  552. ) do
  553. {:ok,
  554. %Tesla.Env{
  555. status: 200,
  556. body: File.read!("test/fixtures/tesla_mock/lain_squeet.me_webfinger.xml")
  557. }}
  558. end
  559. def get(
  560. "https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la",
  561. _,
  562. _,
  563. Accept: "application/xrd+xml,application/jrd+json"
  564. ) do
  565. {:ok,
  566. %Tesla.Env{
  567. status: 200,
  568. body: File.read!("test/fixtures/tesla_mock/shp@social.heldscal.la.xml")
  569. }}
  570. end
  571. def get(
  572. "https://social.heldscal.la/.well-known/webfinger?resource=invalid_content@social.heldscal.la",
  573. _,
  574. _,
  575. Accept: "application/xrd+xml,application/jrd+json"
  576. ) do
  577. {:ok, %Tesla.Env{status: 200, body: ""}}
  578. end
  579. def get("http://framatube.org/.well-known/host-meta", _, _, _) do
  580. {:ok,
  581. %Tesla.Env{
  582. status: 200,
  583. body: File.read!("test/fixtures/tesla_mock/framatube.org_host_meta")
  584. }}
  585. end
  586. def get(
  587. "http://framatube.org/main/xrd?uri=framasoft@framatube.org",
  588. _,
  589. _,
  590. Accept: "application/xrd+xml,application/jrd+json"
  591. ) do
  592. {:ok,
  593. %Tesla.Env{
  594. status: 200,
  595. headers: [{"content-type", "application/json"}],
  596. body: File.read!("test/fixtures/tesla_mock/framasoft@framatube.org.json")
  597. }}
  598. end
  599. def get("http://gnusocial.de/.well-known/host-meta", _, _, _) do
  600. {:ok,
  601. %Tesla.Env{
  602. status: 200,
  603. body: File.read!("test/fixtures/tesla_mock/gnusocial.de_host_meta")
  604. }}
  605. end
  606. def get(
  607. "http://gnusocial.de/main/xrd?uri=winterdienst@gnusocial.de",
  608. _,
  609. _,
  610. Accept: "application/xrd+xml,application/jrd+json"
  611. ) do
  612. {:ok,
  613. %Tesla.Env{
  614. status: 200,
  615. body: File.read!("test/fixtures/tesla_mock/winterdienst_webfinger.json")
  616. }}
  617. end
  618. def get("http://status.alpicola.com/.well-known/host-meta", _, _, _) do
  619. {:ok,
  620. %Tesla.Env{
  621. status: 200,
  622. body: File.read!("test/fixtures/tesla_mock/status.alpicola.com_host_meta")
  623. }}
  624. end
  625. def get("http://macgirvin.com/.well-known/host-meta", _, _, _) do
  626. {:ok,
  627. %Tesla.Env{
  628. status: 200,
  629. body: File.read!("test/fixtures/tesla_mock/macgirvin.com_host_meta")
  630. }}
  631. end
  632. def get("http://gerzilla.de/.well-known/host-meta", _, _, _) do
  633. {:ok,
  634. %Tesla.Env{
  635. status: 200,
  636. body: File.read!("test/fixtures/tesla_mock/gerzilla.de_host_meta")
  637. }}
  638. end
  639. def get(
  640. "https://gerzilla.de/xrd/?uri=kaniini@gerzilla.de",
  641. _,
  642. _,
  643. Accept: "application/xrd+xml,application/jrd+json"
  644. ) do
  645. {:ok,
  646. %Tesla.Env{
  647. status: 200,
  648. headers: [{"content-type", "application/json"}],
  649. body: File.read!("test/fixtures/tesla_mock/kaniini@gerzilla.de.json")
  650. }}
  651. end
  652. def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _, _, _) do
  653. {:ok,
  654. %Tesla.Env{
  655. status: 200,
  656. body:
  657. File.read!(
  658. "test/fixtures/tesla_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
  659. )
  660. }}
  661. end
  662. def get(
  663. "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
  664. _,
  665. _,
  666. _
  667. ) do
  668. {:ok,
  669. %Tesla.Env{
  670. status: 200,
  671. body: File.read!("test/fixtures/tesla_mock/https___social.heldscal.la_user_23211.xml")
  672. }}
  673. end
  674. def get("http://social.heldscal.la/.well-known/host-meta", _, _, _) do
  675. {:ok,
  676. %Tesla.Env{
  677. status: 200,
  678. body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
  679. }}
  680. end
  681. def get("https://social.heldscal.la/.well-known/host-meta", _, _, _) do
  682. {:ok,
  683. %Tesla.Env{
  684. status: 200,
  685. body: File.read!("test/fixtures/tesla_mock/social.heldscal.la_host_meta")
  686. }}
  687. end
  688. def get("https://mastodon.social/users/lambadalambda.atom", _, _, _) do
  689. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}}
  690. end
  691. def get("https://mastodon.social/users/lambadalambda", _, _, _) do
  692. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
  693. end
  694. def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
  695. {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
  696. end
  697. def get("http://example.com/ogp", _, _, _) do
  698. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
  699. end
  700. def get("https://example.com/ogp", _, _, _) do
  701. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
  702. end
  703. def get("https://pleroma.local/notice/9kCP7V", _, _, _) do
  704. {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
  705. end
  706. def get("http://localhost:4001/users/masto_closed/followers", _, _, _) do
  707. {:ok,
  708. %Tesla.Env{
  709. status: 200,
  710. body: File.read!("test/fixtures/users_mock/masto_closed_followers.json")
  711. }}
  712. end
  713. def get("http://localhost:4001/users/masto_closed/followers?page=1", _, _, _) do
  714. {:ok,
  715. %Tesla.Env{
  716. status: 200,
  717. body: File.read!("test/fixtures/users_mock/masto_closed_followers_page.json")
  718. }}
  719. end
  720. def get("http://localhost:4001/users/masto_closed/following", _, _, _) do
  721. {:ok,
  722. %Tesla.Env{
  723. status: 200,
  724. body: File.read!("test/fixtures/users_mock/masto_closed_following.json")
  725. }}
  726. end
  727. def get("http://localhost:4001/users/masto_closed/following?page=1", _, _, _) do
  728. {:ok,
  729. %Tesla.Env{
  730. status: 200,
  731. body: File.read!("test/fixtures/users_mock/masto_closed_following_page.json")
  732. }}
  733. end
  734. def get("http://localhost:4001/users/fuser2/followers", _, _, _) do
  735. {:ok,
  736. %Tesla.Env{
  737. status: 200,
  738. body: File.read!("test/fixtures/users_mock/pleroma_followers.json")
  739. }}
  740. end
  741. def get("http://localhost:4001/users/fuser2/following", _, _, _) do
  742. {:ok,
  743. %Tesla.Env{
  744. status: 200,
  745. body: File.read!("test/fixtures/users_mock/pleroma_following.json")
  746. }}
  747. end
  748. def get("http://domain-with-errors:4001/users/fuser1/followers", _, _, _) do
  749. {:ok,
  750. %Tesla.Env{
  751. status: 504,
  752. body: ""
  753. }}
  754. end
  755. def get("http://domain-with-errors:4001/users/fuser1/following", _, _, _) do
  756. {:ok,
  757. %Tesla.Env{
  758. status: 504,
  759. body: ""
  760. }}
  761. end
  762. def get("http://example.com/ogp-missing-data", _, _, _) do
  763. {:ok,
  764. %Tesla.Env{
  765. status: 200,
  766. body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
  767. }}
  768. end
  769. def get("https://example.com/ogp-missing-data", _, _, _) do
  770. {:ok,
  771. %Tesla.Env{
  772. status: 200,
  773. body: File.read!("test/fixtures/rich_media/ogp-missing-data.html")
  774. }}
  775. end
  776. def get("http://example.com/malformed", _, _, _) do
  777. {:ok,
  778. %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/malformed-data.html")}}
  779. end
  780. def get("http://example.com/empty", _, _, _) do
  781. {:ok, %Tesla.Env{status: 200, body: "hello"}}
  782. end
  783. def get("http://404.site" <> _, _, _, _) do
  784. {:ok,
  785. %Tesla.Env{
  786. status: 404,
  787. body: ""
  788. }}
  789. end
  790. def get(
  791. "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=lain@zetsubou.xn--q9jyb4c",
  792. _,
  793. _,
  794. Accept: "application/xrd+xml,application/jrd+json"
  795. ) do
  796. {:ok,
  797. %Tesla.Env{
  798. status: 200,
  799. body: File.read!("test/fixtures/lain.xml")
  800. }}
  801. end
  802. def get(
  803. "https://zetsubou.xn--q9jyb4c/.well-known/webfinger?resource=https://zetsubou.xn--q9jyb4c/users/lain",
  804. _,
  805. _,
  806. Accept: "application/xrd+xml,application/jrd+json"
  807. ) do
  808. {:ok,
  809. %Tesla.Env{
  810. status: 200,
  811. body: File.read!("test/fixtures/lain.xml")
  812. }}
  813. end
  814. def get(
  815. "https://zetsubou.xn--q9jyb4c/.well-known/host-meta",
  816. _,
  817. _,
  818. _
  819. ) do
  820. {:ok,
  821. %Tesla.Env{
  822. status: 200,
  823. body: File.read!("test/fixtures/host-meta-zetsubou.xn--q9jyb4c.xml")
  824. }}
  825. end
  826. def get("https://info.pleroma.site/activity.json", _, _, Accept: "application/activity+json") do
  827. {:ok,
  828. %Tesla.Env{
  829. status: 200,
  830. body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity.json")
  831. }}
  832. end
  833. def get("https://info.pleroma.site/activity.json", _, _, _) do
  834. {:ok, %Tesla.Env{status: 404, body: ""}}
  835. end
  836. def get("https://info.pleroma.site/activity2.json", _, _, Accept: "application/activity+json") do
  837. {:ok,
  838. %Tesla.Env{
  839. status: 200,
  840. body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity2.json")
  841. }}
  842. end
  843. def get("https://info.pleroma.site/activity2.json", _, _, _) do
  844. {:ok, %Tesla.Env{status: 404, body: ""}}
  845. end
  846. def get("https://info.pleroma.site/activity3.json", _, _, Accept: "application/activity+json") do
  847. {:ok,
  848. %Tesla.Env{
  849. status: 200,
  850. body: File.read!("test/fixtures/tesla_mock/https__info.pleroma.site_activity3.json")
  851. }}
  852. end
  853. def get("https://info.pleroma.site/activity3.json", _, _, _) do
  854. {:ok, %Tesla.Env{status: 404, body: ""}}
  855. end
  856. def get("https://mstdn.jp/.well-known/webfinger?resource=acct:kpherox@mstdn.jp", _, _, _) do
  857. {:ok,
  858. %Tesla.Env{
  859. status: 200,
  860. body: File.read!("test/fixtures/tesla_mock/kpherox@mstdn.jp.xml")
  861. }}
  862. end
  863. def get(url, query, body, headers) do
  864. {:error,
  865. "Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{
  866. inspect(headers)
  867. }"}
  868. end
  869. # POST Requests
  870. #
  871. def post(url, query \\ [], body \\ [], headers \\ [])
  872. def post("http://example.org/needs_refresh", _, _, _) do
  873. {:ok,
  874. %Tesla.Env{
  875. status: 200,
  876. body: ""
  877. }}
  878. end
  879. def post("http://mastodon.example.org/inbox", _, _, _) do
  880. {:ok,
  881. %Tesla.Env{
  882. status: 200,
  883. body: ""
  884. }}
  885. end
  886. def post("https://hubzilla.example.org/inbox", _, _, _) do
  887. {:ok,
  888. %Tesla.Env{
  889. status: 200,
  890. body: ""
  891. }}
  892. end
  893. def post("http://gs.example.org/index.php/main/salmon/user/1", _, _, _) do
  894. {:ok,
  895. %Tesla.Env{
  896. status: 200,
  897. body: ""
  898. }}
  899. end
  900. def post("http://200.site" <> _, _, _, _) do
  901. {:ok,
  902. %Tesla.Env{
  903. status: 200,
  904. body: ""
  905. }}
  906. end
  907. def post("http://connrefused.site" <> _, _, _, _) do
  908. {:error, :connrefused}
  909. end
  910. def post("http://404.site" <> _, _, _, _) do
  911. {:ok,
  912. %Tesla.Env{
  913. status: 404,
  914. body: ""
  915. }}
  916. end
  917. def post(url, _query, _body, _headers) do
  918. {:error, "Not implemented the mock response for post #{inspect(url)}"}
  919. end
  920. end