Merge branch 'feature/unrepeats' into 'develop'
[akkoma] / test / web / ostatus / ostatus_controller_test.exs
1 defmodule Pleroma.Web.OStatus.OStatusControllerTest do
2 use Pleroma.Web.ConnCase
3 import Pleroma.Factory
4 alias Pleroma.{User, Repo}
5 alias Pleroma.Web.OStatus.ActivityRepresenter
6
7 test "decodes a salmon", %{conn: conn} do
8 user = insert(:user)
9 salmon = File.read!("test/fixtures/salmon.xml")
10
11 conn =
12 conn
13 |> put_req_header("content-type", "application/atom+xml")
14 |> post("/users/#{user.nickname}/salmon", salmon)
15
16 assert response(conn, 200)
17 end
18
19 test "decodes a salmon with a changed magic key", %{conn: conn} do
20 user = insert(:user)
21 salmon = File.read!("test/fixtures/salmon.xml")
22
23 conn =
24 conn
25 |> put_req_header("content-type", "application/atom+xml")
26 |> post("/users/#{user.nickname}/salmon", salmon)
27
28 assert response(conn, 200)
29
30 # Set a wrong magic-key for a user so it has to refetch
31 salmon_user = User.get_by_ap_id("http://gs.example.org:4040/index.php/user/1")
32 # Wrong key
33 info =
34 salmon_user.info
35 |> Map.put(
36 "magic_key",
37 "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
38 )
39
40 Repo.update(User.info_changeset(salmon_user, %{info: info}))
41
42 conn =
43 build_conn()
44 |> put_req_header("content-type", "application/atom+xml")
45 |> post("/users/#{user.nickname}/salmon", salmon)
46
47 assert response(conn, 200)
48 end
49
50 test "gets a feed", %{conn: conn} do
51 note_activity = insert(:note_activity)
52 user = User.get_cached_by_ap_id(note_activity.data["actor"])
53
54 conn =
55 conn
56 |> get("/users/#{user.nickname}/feed.atom")
57
58 assert response(conn, 200) =~ note_activity.data["object"]["content"]
59 end
60
61 test "gets an object", %{conn: conn} do
62 note_activity = insert(:note_activity)
63 user = User.get_by_ap_id(note_activity.data["actor"])
64 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
65 url = "/objects/#{uuid}"
66
67 conn =
68 conn
69 |> get(url)
70
71 expected =
72 ActivityRepresenter.to_simple_form(note_activity, user, true)
73 |> ActivityRepresenter.wrap_with_entry()
74 |> :xmerl.export_simple(:xmerl_xml)
75 |> to_string
76
77 assert response(conn, 200) == expected
78 end
79
80 test "gets an activity", %{conn: conn} do
81 note_activity = insert(:note_activity)
82 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
83 url = "/activities/#{uuid}"
84
85 conn =
86 conn
87 |> get(url)
88
89 assert response(conn, 200)
90 end
91
92 test "gets a notice", %{conn: conn} do
93 note_activity = insert(:note_activity)
94 url = "/notice/#{note_activity.id}"
95
96 conn =
97 conn
98 |> get(url)
99
100 assert response(conn, 200)
101 end
102 end