Increase tests on AP C2S

Related: https://git.pleroma.social/pleroma/pleroma/-/issues/954
This commit is contained in:
Haelwenn (lanodan) Monnier 2020-04-30 18:55:25 +02:00 committed by rinpatch
parent 38541d99ea
commit 797dd3f581

View file

@ -652,9 +652,25 @@ test "it returns an announce activity in a collection", %{conn: conn} do
assert response(conn, 200) =~ announce_activity.data["object"] assert response(conn, 200) =~ announce_activity.data["object"]
end end
end
test "it rejects posts from other users", %{conn: conn} do describe "POST /users/:nickname/outbox (C2S)" do
data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!() setup do
[
activity: %{
"@context" => "https://www.w3.org/ns/activitystreams",
"type" => "Create",
"object" => %{"type" => "Note", "content" => "AP C2S test"},
"to" => "https://www.w3.org/ns/activitystreams#Public",
"cc" => []
}
]
end
test "it rejects posts from other users / unauthenticated users", %{
conn: conn,
activity: activity
} do
user = insert(:user) user = insert(:user)
otheruser = insert(:user) otheruser = insert(:user)
@ -662,39 +678,61 @@ test "it rejects posts from other users", %{conn: conn} do
conn conn
|> assign(:user, otheruser) |> assign(:user, otheruser)
|> put_req_header("content-type", "application/activity+json") |> put_req_header("content-type", "application/activity+json")
|> post("/users/#{user.nickname}/outbox", data) |> post("/users/#{user.nickname}/outbox", activity)
assert json_response(conn, 403) assert json_response(conn, 403)
end end
test "it inserts an incoming create activity into the database", %{conn: conn} do test "it inserts an incoming create activity into the database", %{
data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!() conn: conn,
activity: activity
} do
user = insert(:user) user = insert(:user)
conn = result =
conn conn
|> assign(:user, user) |> assign(:user, user)
|> put_req_header("content-type", "application/activity+json") |> put_req_header("content-type", "application/activity+json")
|> post("/users/#{user.nickname}/outbox", data) |> post("/users/#{user.nickname}/outbox", activity)
|> json_response(201)
result = json_response(conn, 201)
assert Activity.get_by_ap_id(result["id"]) assert Activity.get_by_ap_id(result["id"])
assert result["object"]
assert %Object{data: object} = Object.normalize(result["object"])
assert object["content"] == activity["object"]["content"]
end end
test "it rejects an incoming activity with bogus type", %{conn: conn} do test "it inserts an incoming sensitive activity into the database", %{
data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!() conn: conn,
activity: activity
} do
user = insert(:user) user = insert(:user)
object = Map.put(activity["object"], "sensitive", true)
activity = Map.put(activity, "object", object)
data = result =
data conn
|> Map.put("type", "BadType") |> assign(:user, user)
|> put_req_header("content-type", "application/activity+json")
|> post("/users/#{user.nickname}/outbox", activity)
|> json_response(201)
assert Activity.get_by_ap_id(result["id"])
assert result["object"]
assert %Object{data: object} = Object.normalize(result["object"])
assert object["sensitive"] == activity["object"]["sensitive"]
assert object["content"] == activity["object"]["content"]
end
test "it rejects an incoming activity with bogus type", %{conn: conn, activity: activity} do
user = insert(:user)
activity = Map.put(activity, "type", "BadType")
conn = conn =
conn conn
|> assign(:user, user) |> assign(:user, user)
|> put_req_header("content-type", "application/activity+json") |> put_req_header("content-type", "application/activity+json")
|> post("/users/#{user.nickname}/outbox", data) |> post("/users/#{user.nickname}/outbox", activity)
assert json_response(conn, 400) assert json_response(conn, 400)
end end