logo

pleroma

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

tag_controller_test.exs (7713B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.Feed.TagControllerTest do
  5. use Pleroma.Web.ConnCase
  6. import Pleroma.Factory
  7. import SweetXml
  8. alias Pleroma.Object
  9. alias Pleroma.Web.CommonAPI
  10. alias Pleroma.Web.Feed.FeedView
  11. setup do: clear_config([:feed])
  12. test "gets a feed (ATOM)", %{conn: conn} do
  13. clear_config(
  14. [:feed, :post_title],
  15. %{max_length: 25, omission: "..."}
  16. )
  17. user = insert(:user)
  18. {:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"})
  19. object = Object.normalize(activity1, fetch: false)
  20. object_data =
  21. Map.put(object.data, "attachment", [
  22. %{
  23. "url" => [
  24. %{
  25. "href" =>
  26. "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
  27. "mediaType" => "video/mp4",
  28. "type" => "Link"
  29. }
  30. ]
  31. }
  32. ])
  33. object
  34. |> Ecto.Changeset.change(data: object_data)
  35. |> Pleroma.Repo.update()
  36. {:ok, activity2} = CommonAPI.post(user, %{status: "42 This is :moominmamma #PleromaArt"})
  37. {:ok, _activity3} = CommonAPI.post(user, %{status: "This is :moominmamma"})
  38. response =
  39. conn
  40. |> put_req_header("accept", "application/atom+xml")
  41. |> get(tag_feed_path(conn, :feed, "pleromaart.atom"))
  42. |> response(200)
  43. xml = parse(response)
  44. assert xpath(xml, ~x"//feed/title/text()") == ~c"#pleromaart"
  45. assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
  46. ~c"42 This is :moominmamm...",
  47. ~c"yeah #PleromaArt"
  48. ]
  49. assert xpath(xml, ~x"//feed/entry/author/name/text()"ls) == [user.nickname, user.nickname]
  50. conn =
  51. conn
  52. |> put_req_header("accept", "application/atom+xml")
  53. |> get("/tags/pleromaart.atom", %{"max_id" => activity2.id})
  54. assert get_resp_header(conn, "content-type") == ["application/atom+xml; charset=utf-8"]
  55. resp = response(conn, 200)
  56. xml = parse(resp)
  57. assert xpath(xml, ~x"//feed/title/text()") == ~c"#pleromaart"
  58. assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
  59. ~c"yeah #PleromaArt"
  60. ]
  61. end
  62. test "gets a feed (RSS)", %{conn: conn} do
  63. clear_config(
  64. [:feed, :post_title],
  65. %{max_length: 25, omission: "..."}
  66. )
  67. user = insert(:user)
  68. {:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"})
  69. object = Object.normalize(activity1, fetch: false)
  70. object_data =
  71. Map.put(object.data, "attachment", [
  72. %{
  73. "url" => [
  74. %{
  75. "href" =>
  76. "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
  77. "mediaType" => "video/mp4",
  78. "type" => "Link"
  79. }
  80. ]
  81. }
  82. ])
  83. object
  84. |> Ecto.Changeset.change(data: object_data)
  85. |> Pleroma.Repo.update()
  86. {:ok, activity2} = CommonAPI.post(user, %{status: "42 This is :moominmamma #PleromaArt"})
  87. {:ok, _activity3} = CommonAPI.post(user, %{status: "This is :moominmamma"})
  88. response =
  89. conn
  90. |> put_req_header("accept", "application/rss+xml")
  91. |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
  92. |> response(200)
  93. xml = parse(response)
  94. assert xpath(xml, ~x"//channel/title/text()") == ~c"#pleromaart"
  95. assert xpath(xml, ~x"//channel/description/text()"s) ==
  96. "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
  97. assert xpath(xml, ~x"//channel/link/text()") ==
  98. ~c"#{Pleroma.Web.Endpoint.url()}/tags/pleromaart.rss"
  99. assert xpath(xml, ~x"//channel/webfeeds:logo/text()") ==
  100. ~c"#{Pleroma.Web.Endpoint.url()}/static/logo.svg"
  101. assert xpath(xml, ~x"//channel/item/title/text()"l) == [
  102. ~c"42 This is :moominmamm...",
  103. ~c"yeah #PleromaArt"
  104. ]
  105. assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [
  106. FeedView.to_rfc2822(activity2.data["published"]),
  107. FeedView.to_rfc2822(activity1.data["published"])
  108. ]
  109. assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [
  110. "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4"
  111. ]
  112. obj1 = Object.normalize(activity1, fetch: false)
  113. obj2 = Object.normalize(activity2, fetch: false)
  114. assert xpath(xml, ~x"//channel/item/description/text()"sl) == [
  115. HtmlEntities.decode(FeedView.activity_content(obj2.data)),
  116. HtmlEntities.decode(FeedView.activity_content(obj1.data))
  117. ]
  118. response =
  119. conn
  120. |> put_req_header("accept", "application/rss+xml")
  121. |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
  122. |> response(200)
  123. xml = parse(response)
  124. assert xpath(xml, ~x"//channel/title/text()") == ~c"#pleromaart"
  125. assert xpath(xml, ~x"//channel/description/text()"s) ==
  126. "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
  127. conn =
  128. conn
  129. |> put_req_header("accept", "application/rss+xml")
  130. |> get("/tags/pleromaart.rss", %{"max_id" => activity2.id})
  131. assert get_resp_header(conn, "content-type") == ["application/rss+xml; charset=utf-8"]
  132. resp = response(conn, 200)
  133. xml = parse(resp)
  134. assert xpath(xml, ~x"//channel/title/text()") == ~c"#pleromaart"
  135. assert xpath(xml, ~x"//channel/item/title/text()"l) == [
  136. ~c"yeah #PleromaArt"
  137. ]
  138. end
  139. describe "private instance" do
  140. setup do: clear_config([:instance, :public], false)
  141. test "returns 404 for tags feed", %{conn: conn} do
  142. conn
  143. |> put_req_header("accept", "application/rss+xml")
  144. |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
  145. |> response(404)
  146. end
  147. end
  148. describe "restricted for unauthenticated" do
  149. test "returns 404 when local timeline is disabled", %{conn: conn} do
  150. clear_config([:restrict_unauthenticated, :timelines], %{local: true, federated: false})
  151. conn
  152. |> put_req_header("accept", "application/rss+xml")
  153. |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
  154. |> response(404)
  155. end
  156. test "returns local posts only when federated timeline is disabled", %{conn: conn} do
  157. clear_config([:restrict_unauthenticated, :timelines], %{local: false, federated: true})
  158. local_user = insert(:user)
  159. remote_user = insert(:user, local: false)
  160. local_note =
  161. insert(:note,
  162. user: local_user,
  163. data: %{
  164. "content" => "local post #PleromaArt",
  165. "summary" => "",
  166. "tag" => ["pleromaart"]
  167. }
  168. )
  169. remote_note =
  170. insert(:note,
  171. user: remote_user,
  172. data: %{
  173. "content" => "remote post #PleromaArt",
  174. "summary" => "",
  175. "tag" => ["pleromaart"]
  176. },
  177. local: false
  178. )
  179. insert(:note_activity, user: local_user, note: local_note)
  180. insert(:note_activity, user: remote_user, note: remote_note, local: false)
  181. response =
  182. conn
  183. |> put_req_header("accept", "application/rss+xml")
  184. |> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
  185. |> response(200)
  186. xml = parse(response)
  187. assert xpath(xml, ~x"//channel/title/text()") == ~c"#pleromaart"
  188. assert xpath(xml, ~x"//channel/item/title/text()"l) == [
  189. ~c"local post #PleromaArt"
  190. ]
  191. end
  192. end
  193. end