diff options
author | kaniini <nenolod@gmail.com> | 2018-12-30 19:50:15 +0000 |
---|---|---|
committer | kaniini <nenolod@gmail.com> | 2018-12-30 19:50:15 +0000 |
commit | dfde2622d0c14195392e306fadc7c729c68da273 (patch) | |
tree | 1be5f183475db92bac294e453c3bebb67492786d /test | |
parent | f5d7b0003ea200d13abca2cbd4e4f59db9658231 (diff) | |
parent | f40562b4e1ff213b88c8b6edf57431bfb1b804ac (diff) | |
download | pleroma-dfde2622d0c14195392e306fadc7c729c68da273.tar.gz pleroma-dfde2622d0c14195392e306fadc7c729c68da273.zip |
Merge branch 'activitypub-c2s' into 'develop'
Activitypub c2s
See merge request pleroma/pleroma!608
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/activitypub-client-post-activity.json | 9 | ||||
-rw-r--r-- | test/web/activity_pub/activity_pub_controller_test.exs | 54 |
2 files changed, 63 insertions, 0 deletions
diff --git a/test/fixtures/activitypub-client-post-activity.json b/test/fixtures/activitypub-client-post-activity.json new file mode 100644 index 000000000..c985e072b --- /dev/null +++ b/test/fixtures/activitypub-client-post-activity.json @@ -0,0 +1,9 @@ +{ + "@context": ["https://www.w3.org/ns/activitystreams", {"@language": "en-GB"}], + "type": "Create", + "object": { + "type": "Note", + "content": "It's a note" + }, + "to": ["https://www.w3.org/ns/activitystreams#Public"] +} diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 9fdf15505..cb95e0e09 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -112,6 +112,32 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do :timer.sleep(500) assert Activity.get_by_ap_id(data["id"]) end + + test "it rejects reads from other users", %{conn: conn} do + user = insert(:user) + otheruser = insert(:user) + + conn = + conn + |> assign(:user, otheruser) + |> put_req_header("accept", "application/activity+json") + |> get("/users/#{user.nickname}/inbox") + + assert json_response(conn, 403) + end + + test "it returns a note activity in a collection", %{conn: conn} do + note_activity = insert(:direct_note_activity) + user = User.get_cached_by_ap_id(hd(note_activity.data["to"])) + + conn = + conn + |> assign(:user, user) + |> put_req_header("accept", "application/activity+json") + |> get("/users/#{user.nickname}/inbox") + + assert response(conn, 200) =~ note_activity.data["object"]["content"] + end end describe "/users/:nickname/outbox" do @@ -138,6 +164,34 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do assert response(conn, 200) =~ announce_activity.data["object"] end + + test "it rejects posts from other users", %{conn: conn} do + data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!() + user = insert(:user) + otheruser = insert(:user) + + conn = + conn + |> assign(:user, otheruser) + |> put_req_header("content-type", "application/activity+json") + |> post("/users/#{user.nickname}/outbox", data) + + assert json_response(conn, 403) + end + + test "it inserts an incoming activity into the database", %{conn: conn} do + data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!() + user = insert(:user) + + conn = + conn + |> assign(:user, user) + |> put_req_header("content-type", "application/activity+json") + |> post("/users/#{user.nickname}/outbox", data) + + result = json_response(conn, 201) + assert Activity.get_by_ap_id(result["id"]) + end end describe "/users/:nickname/followers" do |