diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/fixtures/activitypub-client-post-activity.json | 9 | ||||
| -rw-r--r-- | test/user_test.exs | 4 | ||||
| -rw-r--r-- | test/web/activity_pub/activity_pub_controller_test.exs | 54 | ||||
| -rw-r--r-- | test/web/retry_queue_test.exs | 31 | ||||
| -rw-r--r-- | test/web/twitter_api/views/user_view_test.exs | 19 | 
5 files changed, 102 insertions, 15 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/user_test.exs b/test/user_test.exs index 4680850ea..869e9196d 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -706,10 +706,10 @@ defmodule Pleroma.UserTest do    end    describe "per-user rich-text filtering" do -    test "html_filter_policy returns nil when rich-text is enabled" do +    test "html_filter_policy returns default policies, when rich-text is enabled" do        user = insert(:user) -      assert nil == User.html_filter_policy(user) +      assert Pleroma.Config.get([:markup, :scrub_policy]) == User.html_filter_policy(user)      end      test "html_filter_policy returns TwitterText scrubber when rich-text is disabled" do 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 diff --git a/test/web/retry_queue_test.exs b/test/web/retry_queue_test.exs index 9351b6c24..ecb3ce5d0 100644 --- a/test/web/retry_queue_test.exs +++ b/test/web/retry_queue_test.exs @@ -3,7 +3,8 @@  # SPDX-License-Identifier: AGPL-3.0-only  defmodule MockActivityPub do -  def publish_one(ret) do +  def publish_one({ret, waiter}) do +    send(waiter, :complete)      {ret, "success"}    end  end @@ -15,21 +16,33 @@ defmodule Pleroma.Web.Federator.RetryQueueTest do    @small_retry_count 0    @hopeless_retry_count 10 +  setup do +    RetryQueue.reset_stats() +  end + +  test "RetryQueue responds to stats request" do +    assert %{delivered: 0, dropped: 0} == RetryQueue.get_stats() +  end +    test "failed posts are retried" do      {:retry, _timeout} = RetryQueue.get_retry_params(@small_retry_count) -    assert {:noreply, %{delivered: 1}} == -             RetryQueue.handle_info({:send, :ok, MockActivityPub, @small_retry_count}, %{ -               delivered: 0 -             }) +    wait_task = +      Task.async(fn -> +        receive do +          :complete -> :ok +        end +      end) + +    RetryQueue.enqueue({:ok, wait_task.pid}, MockActivityPub, @small_retry_count) +    Task.await(wait_task) +    assert %{delivered: 1, dropped: 0} == RetryQueue.get_stats()    end    test "posts that have been tried too many times are dropped" do      {:drop, _timeout} = RetryQueue.get_retry_params(@hopeless_retry_count) -    assert {:noreply, %{dropped: 1}} == -             RetryQueue.handle_cast({:maybe_enqueue, %{}, nil, @hopeless_retry_count}, %{ -               dropped: 0 -             }) +    RetryQueue.enqueue({:ok, nil}, MockActivityPub, @hopeless_retry_count) +    assert %{delivered: 0, dropped: 1} == RetryQueue.get_stats()    end  end diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 32e9466e1..5f7481eb6 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -90,7 +90,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do        "follows_you" => false,        "statusnet_blocking" => false,        "rights" => %{ -        "delete_others_notice" => false +        "delete_others_notice" => false, +        "admin" => false        },        "statusnet_profile_url" => user.ap_id,        "cover_photo" => banner, @@ -135,7 +136,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do        "follows_you" => false,        "statusnet_blocking" => false,        "rights" => %{ -        "delete_others_notice" => false +        "delete_others_notice" => false, +        "admin" => false        },        "statusnet_profile_url" => user.ap_id,        "cover_photo" => banner, @@ -181,7 +183,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do        "follows_you" => true,        "statusnet_blocking" => false,        "rights" => %{ -        "delete_others_notice" => false +        "delete_others_notice" => false, +        "admin" => false        },        "statusnet_profile_url" => follower.ap_id,        "cover_photo" => banner, @@ -207,6 +210,13 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do      assert represented["rights"]["delete_others_notice"]    end +  test "a user that is a admin" do +    user = insert(:user, %{info: %{is_admin: true}}) +    represented = UserView.render("show.json", %{user: user, for: user}) + +    assert represented["rights"]["admin"] +  end +    test "A blocked user for the blocker" do      user = insert(:user)      blocker = insert(:user) @@ -234,7 +244,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do        "follows_you" => false,        "statusnet_blocking" => true,        "rights" => %{ -        "delete_others_notice" => false +        "delete_others_notice" => false, +        "admin" => false        },        "statusnet_profile_url" => user.ap_id,        "cover_photo" => banner, | 
