diff options
| author | lain <lain@soykaf.club> | 2019-09-13 16:31:27 +0200 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2019-09-13 16:31:27 +0200 | 
| commit | a7f31bf06cfe3f8e2549393f34d6573854d783c0 (patch) | |
| tree | f53d6747ee73044f7b342d3fdae3d30b5b5b3c90 /test/web/activity_pub | |
| parent | f649a2e972b70dfefb7bfc110b27a0194cda51c5 (diff) | |
| parent | 0d9609894f4f4557da2db62a33da1b8995c9e1d7 (diff) | |
| download | pleroma-a7f31bf06cfe3f8e2549393f34d6573854d783c0.tar.gz pleroma-a7f31bf06cfe3f8e2549393f34d6573854d783c0.zip | |
Merge remote-tracking branch 'origin/develop' into reactions
Diffstat (limited to 'test/web/activity_pub')
| -rw-r--r-- | test/web/activity_pub/activity_pub_controller_test.exs | 99 | ||||
| -rw-r--r-- | test/web/activity_pub/transmogrifier/follow_handling_test.exs | 19 | ||||
| -rw-r--r-- | test/web/activity_pub/transmogrifier_test.exs | 2 | 
3 files changed, 119 insertions, 1 deletions
| diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 5192e734f..9698c7099 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -175,6 +175,49 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        assert json_response(conn, 404)      end + +    test "it caches a response", %{conn: conn} do +      note = insert(:note) +      uuid = String.split(note.data["id"], "/") |> List.last() + +      conn1 = +        conn +        |> put_req_header("accept", "application/activity+json") +        |> get("/objects/#{uuid}") + +      assert json_response(conn1, :ok) +      assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"})) + +      conn2 = +        conn +        |> put_req_header("accept", "application/activity+json") +        |> get("/objects/#{uuid}") + +      assert json_response(conn1, :ok) == json_response(conn2, :ok) +      assert Enum.any?(conn2.resp_headers, &(&1 == {"x-cache", "HIT from Pleroma"})) +    end + +    test "cached purged after object deletion", %{conn: conn} do +      note = insert(:note) +      uuid = String.split(note.data["id"], "/") |> List.last() + +      conn1 = +        conn +        |> put_req_header("accept", "application/activity+json") +        |> get("/objects/#{uuid}") + +      assert json_response(conn1, :ok) +      assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"})) + +      Object.delete(note) + +      conn2 = +        conn +        |> put_req_header("accept", "application/activity+json") +        |> get("/objects/#{uuid}") + +      assert "Not found" == json_response(conn2, :not_found) +    end    end    describe "/object/:uuid/likes" do @@ -264,6 +307,51 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        assert json_response(conn, 404)      end + +    test "it caches a response", %{conn: conn} do +      activity = insert(:note_activity) +      uuid = String.split(activity.data["id"], "/") |> List.last() + +      conn1 = +        conn +        |> put_req_header("accept", "application/activity+json") +        |> get("/activities/#{uuid}") + +      assert json_response(conn1, :ok) +      assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"})) + +      conn2 = +        conn +        |> put_req_header("accept", "application/activity+json") +        |> get("/activities/#{uuid}") + +      assert json_response(conn1, :ok) == json_response(conn2, :ok) +      assert Enum.any?(conn2.resp_headers, &(&1 == {"x-cache", "HIT from Pleroma"})) +    end + +    test "cached purged after activity deletion", %{conn: conn} do +      user = insert(:user) +      {:ok, activity} = CommonAPI.post(user, %{"status" => "cofe"}) + +      uuid = String.split(activity.data["id"], "/") |> List.last() + +      conn1 = +        conn +        |> put_req_header("accept", "application/activity+json") +        |> get("/activities/#{uuid}") + +      assert json_response(conn1, :ok) +      assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"})) + +      Activity.delete_by_ap_id(activity.object.data["id"]) + +      conn2 = +        conn +        |> put_req_header("accept", "application/activity+json") +        |> get("/activities/#{uuid}") + +      assert "Not found" == json_response(conn2, :not_found) +    end    end    describe "/inbox" do @@ -365,6 +453,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        assert json_response(conn, 403)      end +    test "it doesn't crash without an authenticated user", %{conn: conn} do +      user = insert(:user) + +      conn = +        conn +        |> 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)        note_object = Object.normalize(note_activity) diff --git a/test/web/activity_pub/transmogrifier/follow_handling_test.exs b/test/web/activity_pub/transmogrifier/follow_handling_test.exs index 857d65564..fe89f7cb0 100644 --- a/test/web/activity_pub/transmogrifier/follow_handling_test.exs +++ b/test/web/activity_pub/transmogrifier/follow_handling_test.exs @@ -19,6 +19,25 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do    end    describe "handle_incoming" do +    test "it works for osada follow request" do +      user = insert(:user) + +      data = +        File.read!("test/fixtures/osada-follow-activity.json") +        |> Poison.decode!() +        |> Map.put("object", user.ap_id) + +      {:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data) + +      assert data["actor"] == "https://apfed.club/channel/indio" +      assert data["type"] == "Follow" +      assert data["id"] == "https://apfed.club/follow/9" + +      activity = Repo.get(Activity, activity.id) +      assert activity.data["state"] == "accept" +      assert User.following?(User.get_cached_by_ap_id(data["actor"]), user) +    end +      test "it works for incoming follow requests" do        user = insert(:user) diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 20d274a02..136c8034c 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -102,7 +102,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert capture_log(fn ->                 {:ok, _returned_activity} = Transmogrifier.handle_incoming(data) -             end) =~ "[error] Couldn't fetch \"\"https://404.site/whatever\"\", error: nil" +             end) =~ "[error] Couldn't fetch \"https://404.site/whatever\", error: nil"      end      test "it works for incoming notices" do | 
