make_moderator.ex: set cache on update
[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 "404s on private objects", %{conn: conn} do
81 note_activity = insert(:direct_note_activity)
82 user = User.get_by_ap_id(note_activity.data["actor"])
83 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
84 url = "/objects/#{uuid}"
85
86 conn =
87 conn
88 |> get(url)
89
90 assert response(conn, 404)
91 end
92
93 test "gets an activity", %{conn: conn} do
94 note_activity = insert(:note_activity)
95 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
96 url = "/activities/#{uuid}"
97
98 conn =
99 conn
100 |> get(url)
101
102 assert response(conn, 200)
103 end
104
105 test "404s on private activities", %{conn: conn} do
106 note_activity = insert(:direct_note_activity)
107 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
108 url = "/activities/#{uuid}"
109
110 conn =
111 conn
112 |> get(url)
113
114 assert response(conn, 404)
115 end
116
117 test "gets a notice", %{conn: conn} do
118 note_activity = insert(:note_activity)
119 url = "/notice/#{note_activity.id}"
120
121 conn =
122 conn
123 |> get(url)
124
125 assert response(conn, 200)
126 end
127
128 test "404s a private notice", %{conn: conn} do
129 note_activity = insert(:direct_note_activity)
130 url = "/notice/#{note_activity.id}"
131
132 conn =
133 conn
134 |> get(url)
135
136 assert response(conn, 404)
137 end
138 end