diff options
| author | Maksim Pechnikov <parallel588@gmail.com> | 2019-11-04 20:24:53 +0300 | 
|---|---|---|
| committer | Maksim Pechnikov <parallel588@gmail.com> | 2019-11-04 20:24:53 +0300 | 
| commit | ff6c727739484df31335d2675fbd2446cc5435e1 (patch) | |
| tree | 165d76253331566af22476d80dd44b7e2bb6013d /test | |
| parent | 57995fa8cf26c9d5cd31969b59dbafb9f8c8fdc7 (diff) | |
| parent | fee127696308dbec9cff6b2a9b399cf2877cf445 (diff) | |
| download | pleroma-ff6c727739484df31335d2675fbd2446cc5435e1.tar.gz pleroma-ff6c727739484df31335d2675fbd2446cc5435e1.zip | |
Merge branch 'develop' into issue/1276
Diffstat (limited to 'test')
| -rw-r--r-- | test/emoji/formatter_test.exs | 7 | ||||
| -rw-r--r-- | test/html_test.exs | 44 | ||||
| -rw-r--r-- | test/support/http_request_mock.ex | 28 | ||||
| -rw-r--r-- | test/user_search_test.exs | 7 | ||||
| -rw-r--r-- | test/user_test.exs | 65 | ||||
| -rw-r--r-- | test/web/activity_pub/activity_pub_test.exs | 123 | ||||
| -rw-r--r-- | test/web/activity_pub/mrf/normalize_markup_test.exs | 10 | ||||
| -rw-r--r-- | test/web/activity_pub/transmogrifier_test.exs | 34 | ||||
| -rw-r--r-- | test/web/activity_pub/utils_test.exs | 11 | ||||
| -rw-r--r-- | test/web/admin_api/admin_api_controller_test.exs | 27 | ||||
| -rw-r--r-- | test/web/common_api/common_api_test.exs | 20 | ||||
| -rw-r--r-- | test/web/mastodon_api/views/conversation_view_test.exs | 1 | ||||
| -rw-r--r-- | test/web/mastodon_api/views/status_view_test.exs | 34 | ||||
| -rw-r--r-- | test/web/rel_me_test.exs | 4 | ||||
| -rw-r--r-- | test/web/streamer/streamer_test.exs | 30 | 
15 files changed, 336 insertions, 109 deletions
| diff --git a/test/emoji/formatter_test.exs b/test/emoji/formatter_test.exs index 6d25fc453..fda80d470 100644 --- a/test/emoji/formatter_test.exs +++ b/test/emoji/formatter_test.exs @@ -12,7 +12,7 @@ defmodule Pleroma.Emoji.FormatterTest do        text = "I love :firefox:"        expected_result = -        "I love <img class=\"emoji\" alt=\"firefox\" title=\"firefox\" src=\"/emoji/Firefox.gif\" />" +        "I love <img class=\"emoji\" alt=\"firefox\" title=\"firefox\" src=\"/emoji/Firefox.gif\"/>"        assert Formatter.emojify(text) == expected_result      end @@ -28,10 +28,7 @@ defmodule Pleroma.Emoji.FormatterTest do          }          |> Pleroma.Emoji.build() -      expected_result = -        "I love <img class=\"emoji\" alt=\"\" title=\"\" src=\"https://placehold.it/1x1\" />" - -      assert Formatter.emojify(text, [{custom_emoji.code, custom_emoji}]) == expected_result +      refute Formatter.emojify(text, [{custom_emoji.code, custom_emoji}]) =~ text      end    end diff --git a/test/html_test.exs b/test/html_test.exs index 306ad3b3b..f0869534c 100644 --- a/test/html_test.exs +++ b/test/html_test.exs @@ -21,31 +21,31 @@ defmodule Pleroma.HTMLTest do    """    @html_onerror_sample """ -    <img src="http://example.com/image.jpg" onerror="alert('hacked')"> +  <img src="http://example.com/image.jpg" onerror="alert('hacked')">    """    @html_span_class_sample """ -    <span class="animate-spin">hi</span> +  <span class="animate-spin">hi</span>    """    @html_span_microformats_sample """ -    <span class="h-card"><a class="u-url mention">@<span>foo</span></a></span> +  <span class="h-card"><a class="u-url mention">@<span>foo</span></a></span>    """    @html_span_invalid_microformats_sample """ -    <span class="h-card"><a class="u-url mention animate-spin">@<span>foo</span></a></span> +  <span class="h-card"><a class="u-url mention animate-spin">@<span>foo</span></a></span>    """    describe "StripTags scrubber" do      test "works as expected" do        expected = """ -      this is in bold +        this is in bold          this is a paragraph          this is a linebreak -        this is a link with allowed "rel" attribute: example.com -        this is a link with not allowed "rel" attribute: example.com +        this is a link with allowed "rel" attribute: example.com +        this is a link with not allowed "rel" attribute: example.com          this is an image:  -        alert('hacked') +        alert('hacked')        """        assert expected == HTML.strip_tags(@html_sample) @@ -61,13 +61,13 @@ defmodule Pleroma.HTMLTest do    describe "TwitterText scrubber" do      test "normalizes HTML as expected" do        expected = """ -      this is in bold +        this is in bold          <p>this is a paragraph</p> -        this is a linebreak<br /> -        this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a> -        this is a link with not allowed "rel" attribute: <a href="http://example.com/">example.com</a> -        this is an image: <img src="http://example.com/image.jpg" /><br /> -        alert('hacked') +        this is a linebreak<br/> +        this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a> +        this is a link with not allowed "rel" attribute: <a href="http://example.com/">example.com</a> +        this is an image: <img src="http://example.com/image.jpg"/><br/> +        alert('hacked')        """        assert expected == HTML.filter_tags(@html_sample, Pleroma.HTML.Scrubber.TwitterText) @@ -75,7 +75,7 @@ defmodule Pleroma.HTMLTest do      test "does not allow attribute-based XSS" do        expected = """ -      <img src="http://example.com/image.jpg" /> +      <img src="http://example.com/image.jpg"/>        """        assert expected == HTML.filter_tags(@html_onerror_sample, Pleroma.HTML.Scrubber.TwitterText) @@ -115,13 +115,13 @@ defmodule Pleroma.HTMLTest do    describe "default scrubber" do      test "normalizes HTML as expected" do        expected = """ -      <b>this is in bold</b> +        <b>this is in bold</b>          <p>this is a paragraph</p> -        this is a linebreak<br /> -        this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a> -        this is a link with not allowed "rel" attribute: <a href="http://example.com/">example.com</a> -        this is an image: <img src="http://example.com/image.jpg" /><br /> -        alert('hacked') +        this is a linebreak<br/> +        this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a> +        this is a link with not allowed "rel" attribute: <a href="http://example.com/">example.com</a> +        this is an image: <img src="http://example.com/image.jpg"/><br/> +        alert('hacked')        """        assert expected == HTML.filter_tags(@html_sample, Pleroma.HTML.Scrubber.Default) @@ -129,7 +129,7 @@ defmodule Pleroma.HTMLTest do      test "does not allow attribute-based XSS" do        expected = """ -      <img src="http://example.com/image.jpg" /> +      <img src="http://example.com/image.jpg"/>        """        assert expected == HTML.filter_tags(@html_onerror_sample, Pleroma.HTML.Scrubber.Default) diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index eba22c40b..965335e96 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -1183,6 +1183,30 @@ defmodule HttpRequestMock do       }}    end +  def get("https://10.111.10.1/notice/9kCP7V", _, _, _) do +    {:ok, %Tesla.Env{status: 200, body: ""}} +  end + +  def get("https://172.16.32.40/notice/9kCP7V", _, _, _) do +    {:ok, %Tesla.Env{status: 200, body: ""}} +  end + +  def get("https://192.168.10.40/notice/9kCP7V", _, _, _) do +    {:ok, %Tesla.Env{status: 200, body: ""}} +  end + +  def get("https://www.patreon.com/posts/mastodon-2-9-and-28121681", _, _, _) do +    {:ok, %Tesla.Env{status: 200, body: ""}} +  end + +  def get("http://mastodon.example.org/@admin/99541947525187367", _, _, _) do +    {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/mastodon-post-activity.json")}} +  end + +  def get("https://info.pleroma.site/activity4.json", _, _, _) do +    {:ok, %Tesla.Env{status: 500, body: "Error occurred"}} +  end +    def get("http://example.com/rel_me/anchor", _, _, _) do      {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}}    end @@ -1215,6 +1239,10 @@ defmodule HttpRequestMock do      {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/rin.json")}}    end +  def get("http://example.com/rel_me/error", _, _, _) do +    {:ok, %Tesla.Env{status: 404, body: ""}} +  end +    def get(url, query, body, headers) do      {:error,       "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{ diff --git a/test/user_search_test.exs b/test/user_search_test.exs index 78a02d536..721af1e5b 100644 --- a/test/user_search_test.exs +++ b/test/user_search_test.exs @@ -51,13 +51,6 @@ defmodule Pleroma.UserSearchTest do        end)      end -    test "finds users, preferring nickname matches over name matches" do -      u1 = insert(:user, %{name: "lain", nickname: "nick1"}) -      u2 = insert(:user, %{nickname: "lain", name: "nick1"}) - -      assert [u2.id, u1.id] == Enum.map(User.search("lain"), & &1.id) -    end -      test "finds users, considering density of matched tokens" do        u1 = insert(:user, %{name: "Bar Bar plus Word Word"})        u2 = insert(:user, %{name: "Word Word Bar Bar Bar"}) diff --git a/test/user_test.exs b/test/user_test.exs index 188295a86..6b1b24ce5 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -878,27 +878,50 @@ defmodule Pleroma.UserTest do      end    end -  test "get recipients from activity" do -    actor = insert(:user) -    user = insert(:user, local: true) -    user_two = insert(:user, local: false) -    addressed = insert(:user, local: true) -    addressed_remote = insert(:user, local: false) - -    {:ok, activity} = -      CommonAPI.post(actor, %{ -        "status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}" -      }) - -    assert Enum.map([actor, addressed], & &1.ap_id) -- -             Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == [] - -    {:ok, user} = User.follow(user, actor) -    {:ok, _user_two} = User.follow(user_two, actor) -    recipients = User.get_recipients_from_activity(activity) -    assert length(recipients) == 3 -    assert user in recipients -    assert addressed in recipients +  describe "get_recipients_from_activity" do +    test "get recipients" do +      actor = insert(:user) +      user = insert(:user, local: true) +      user_two = insert(:user, local: false) +      addressed = insert(:user, local: true) +      addressed_remote = insert(:user, local: false) + +      {:ok, activity} = +        CommonAPI.post(actor, %{ +          "status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}" +        }) + +      assert Enum.map([actor, addressed], & &1.ap_id) -- +               Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == [] + +      {:ok, user} = User.follow(user, actor) +      {:ok, _user_two} = User.follow(user_two, actor) +      recipients = User.get_recipients_from_activity(activity) +      assert length(recipients) == 3 +      assert user in recipients +      assert addressed in recipients +    end + +    test "has following" do +      actor = insert(:user) +      user = insert(:user) +      user_two = insert(:user) +      addressed = insert(:user, local: true) + +      {:ok, activity} = +        CommonAPI.post(actor, %{ +          "status" => "hey @#{addressed.nickname}" +        }) + +      assert Enum.map([actor, addressed], & &1.ap_id) -- +               Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == [] + +      {:ok, _actor} = User.follow(actor, user) +      {:ok, _actor} = User.follow(actor, user_two) +      recipients = User.get_recipients_from_activity(activity) +      assert length(recipients) == 2 +      assert addressed in recipients +    end    end    describe ".deactivate" do diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 0e5eb0c50..f29b8cc74 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -10,6 +10,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do    alias Pleroma.User    alias Pleroma.Web.ActivityPub.ActivityPub    alias Pleroma.Web.ActivityPub.Utils +  alias Pleroma.Web.AdminAPI.AccountView    alias Pleroma.Web.CommonAPI    import Pleroma.Factory @@ -1281,35 +1282,99 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do      assert 3 = length(activities)    end -  test "it can create a Flag activity" do -    reporter = insert(:user) -    target_account = insert(:user) -    {:ok, activity} = CommonAPI.post(target_account, %{"status" => "foobar"}) -    context = Utils.generate_context_id() -    content = "foobar" - -    reporter_ap_id = reporter.ap_id -    target_ap_id = target_account.ap_id -    activity_ap_id = activity.data["id"] - -    assert {:ok, activity} = -             ActivityPub.flag(%{ -               actor: reporter, -               context: context, -               account: target_account, -               statuses: [activity], -               content: content -             }) - -    assert %Activity{ -             actor: ^reporter_ap_id, -             data: %{ -               "type" => "Flag", -               "content" => ^content, -               "context" => ^context, -               "object" => [^target_ap_id, ^activity_ap_id] -             } -           } = activity +  describe "flag/1" do +    setup do +      reporter = insert(:user) +      target_account = insert(:user) +      content = "foobar" +      {:ok, activity} = CommonAPI.post(target_account, %{"status" => content}) +      context = Utils.generate_context_id() + +      reporter_ap_id = reporter.ap_id +      target_ap_id = target_account.ap_id +      activity_ap_id = activity.data["id"] + +      activity_with_object = Activity.get_by_ap_id_with_object(activity_ap_id) + +      {:ok, +       %{ +         reporter: reporter, +         context: context, +         target_account: target_account, +         reported_activity: activity, +         content: content, +         activity_ap_id: activity_ap_id, +         activity_with_object: activity_with_object, +         reporter_ap_id: reporter_ap_id, +         target_ap_id: target_ap_id +       }} +    end + +    test "it can create a Flag activity", +         %{ +           reporter: reporter, +           context: context, +           target_account: target_account, +           reported_activity: reported_activity, +           content: content, +           activity_ap_id: activity_ap_id, +           activity_with_object: activity_with_object, +           reporter_ap_id: reporter_ap_id, +           target_ap_id: target_ap_id +         } do +      assert {:ok, activity} = +               ActivityPub.flag(%{ +                 actor: reporter, +                 context: context, +                 account: target_account, +                 statuses: [reported_activity], +                 content: content +               }) + +      note_obj = %{ +        "type" => "Note", +        "id" => activity_ap_id, +        "content" => content, +        "published" => activity_with_object.object.data["published"], +        "actor" => AccountView.render("show.json", %{user: target_account}) +      } + +      assert %Activity{ +               actor: ^reporter_ap_id, +               data: %{ +                 "type" => "Flag", +                 "content" => ^content, +                 "context" => ^context, +                 "object" => [^target_ap_id, ^note_obj] +               } +             } = activity +    end + +    test_with_mock "strips status data from Flag, before federating it", +                   %{ +                     reporter: reporter, +                     context: context, +                     target_account: target_account, +                     reported_activity: reported_activity, +                     content: content +                   }, +                   Utils, +                   [:passthrough], +                   [] do +      {:ok, activity} = +        ActivityPub.flag(%{ +          actor: reporter, +          context: context, +          account: target_account, +          statuses: [reported_activity], +          content: content +        }) + +      new_data = +        put_in(activity.data, ["object"], [target_account.ap_id, reported_activity.data["id"]]) + +      assert_called(Utils.maybe_federate(%{activity | data: new_data})) +    end    end    test "fetch_activities/2 returns activities addressed to a list " do diff --git a/test/web/activity_pub/mrf/normalize_markup_test.exs b/test/web/activity_pub/mrf/normalize_markup_test.exs index 3916a1f35..0207be56b 100644 --- a/test/web/activity_pub/mrf/normalize_markup_test.exs +++ b/test/web/activity_pub/mrf/normalize_markup_test.exs @@ -20,11 +20,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkupTest do      expected = """      <b>this is in bold</b>      <p>this is a paragraph</p> -    this is a linebreak<br /> -    this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a> -    this is a link with not allowed "rel" attribute: <a href="http://example.com/">example.com</a> -    this is an image: <img src="http://example.com/image.jpg" /><br /> -    alert('hacked') +    this is a linebreak<br/> +    this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a> +    this is a link with not allowed "rel" attribute: <a href="http://example.com/">example.com</a> +    this is an image: <img src="http://example.com/image.jpg"/><br/> +    alert('hacked')      """      message = %{"type" => "Create", "object" => %{"content" => @html_sample}} diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index d920b969a..4645eb39d 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do    alias Pleroma.User    alias Pleroma.Web.ActivityPub.ActivityPub    alias Pleroma.Web.ActivityPub.Transmogrifier +  alias Pleroma.Web.AdminAPI.AccountView    alias Pleroma.Web.CommonAPI    import Mock @@ -746,7 +747,10 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do          |> Poison.decode!()          |> Map.put("actor", ap_id) -      assert :error == Transmogrifier.handle_incoming(data) +      assert capture_log(fn -> +               assert :error == Transmogrifier.handle_incoming(data) +             end) =~ "Object containment failed" +        assert User.get_cached_by_ap_id(ap_id)      end @@ -1109,10 +1113,18 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})        object = Object.normalize(activity) +      note_obj = %{ +        "type" => "Note", +        "id" => activity.data["id"], +        "content" => "test post", +        "published" => object.data["published"], +        "actor" => AccountView.render("show.json", %{user: user}) +      } +        message = %{          "@context" => "https://www.w3.org/ns/activitystreams",          "cc" => [user.ap_id], -        "object" => [user.ap_id, object.data["id"]], +        "object" => [user.ap_id, activity.data["id"]],          "type" => "Flag",          "content" => "blocked AND reported!!!",          "actor" => other_user.ap_id @@ -1120,7 +1132,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert {:ok, activity} = Transmogrifier.handle_incoming(message) -      assert activity.data["object"] == [user.ap_id, object.data["id"]] +      assert activity.data["object"] == [user.ap_id, note_obj]        assert activity.data["content"] == "blocked AND reported!!!"        assert activity.data["actor"] == other_user.ap_id        assert activity.data["cc"] == [user.ap_id] @@ -1428,7 +1440,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do          "type" => "Announce"        } -      :error = Transmogrifier.handle_incoming(data) +      assert capture_log(fn -> +               :error = Transmogrifier.handle_incoming(data) +             end) =~ "Object containment failed"      end      test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" do @@ -1441,7 +1455,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do          "type" => "Announce"        } -      :error = Transmogrifier.handle_incoming(data) +      assert capture_log(fn -> +               :error = Transmogrifier.handle_incoming(data) +             end) =~ "Object containment failed"      end      test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" do @@ -1454,7 +1470,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do          "type" => "Announce"        } -      :error = Transmogrifier.handle_incoming(data) +      assert capture_log(fn -> +               :error = Transmogrifier.handle_incoming(data) +             end) =~ "Object containment failed"      end    end @@ -1757,7 +1775,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do    describe "get_obj_helper/2" do      test "returns nil when cannot normalize object" do -      refute Transmogrifier.get_obj_helper("test-obj-id") +      assert capture_log(fn -> +               refute Transmogrifier.get_obj_helper("test-obj-id") +             end) =~ "Unsupported URI scheme"      end      test "returns {:ok, %Object{}} for success case" do diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs index c1b000fac..586eb1d2f 100644 --- a/test/web/activity_pub/utils_test.exs +++ b/test/web/activity_pub/utils_test.exs @@ -10,6 +10,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do    alias Pleroma.User    alias Pleroma.Web.ActivityPub.ActivityPub    alias Pleroma.Web.ActivityPub.Utils +  alias Pleroma.Web.AdminAPI.AccountView    alias Pleroma.Web.CommonAPI    import Pleroma.Factory @@ -581,11 +582,19 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do            %{}          ) +      note_obj = %{ +        "type" => "Note", +        "id" => activity_ap_id, +        "content" => content, +        "published" => activity.object.data["published"], +        "actor" => AccountView.render("show.json", %{user: target_account}) +      } +        assert %{                 "type" => "Flag",                 "content" => ^content,                 "context" => ^context, -               "object" => [^target_ap_id, ^activity_ap_id], +               "object" => [^target_ap_id, ^note_obj],                 "state" => "open"               } = res      end diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 22c989892..045c87e95 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -13,6 +13,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do    alias Pleroma.Tests.ObanHelpers    alias Pleroma.User    alias Pleroma.UserInviteToken +  alias Pleroma.Web.ActivityPub.Relay    alias Pleroma.Web.CommonAPI    alias Pleroma.Web.MediaProxy    import Pleroma.Factory @@ -1044,6 +1045,32 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do                 ]               }      end + +    test "it omits relay user", %{admin: admin} do +      assert %User{} = Relay.get_actor() + +      conn = +        build_conn() +        |> assign(:user, admin) +        |> get("/api/pleroma/admin/users") + +      assert json_response(conn, 200) == %{ +               "count" => 1, +               "page_size" => 50, +               "users" => [ +                 %{ +                   "deactivated" => admin.deactivated, +                   "id" => admin.id, +                   "nickname" => admin.nickname, +                   "roles" => %{"admin" => true, "moderator" => false}, +                   "local" => true, +                   "tags" => [], +                   "avatar" => User.avatar_url(admin) |> MediaProxy.url(), +                   "display_name" => HTML.strip_tags(admin.name || admin.nickname) +                 } +               ] +             } +    end    end    test "PATCH /api/pleroma/admin/users/activate" do diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index 1d2f20617..8e6fbd7f0 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -10,6 +10,7 @@ defmodule Pleroma.Web.CommonAPITest do    alias Pleroma.User    alias Pleroma.Web.ActivityPub.ActivityPub    alias Pleroma.Web.ActivityPub.Visibility +  alias Pleroma.Web.AdminAPI.AccountView    alias Pleroma.Web.CommonAPI    import Pleroma.Factory @@ -140,7 +141,7 @@ defmodule Pleroma.Web.CommonAPITest do        object = Object.normalize(activity) -      assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')" +      assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"      end      test "it filters out obviously bad tags when accepting a post as Markdown" do @@ -156,7 +157,7 @@ defmodule Pleroma.Web.CommonAPITest do        object = Object.normalize(activity) -      assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')" +      assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"      end      test "it does not allow replies to direct messages that are not direct messages themselves" do @@ -385,6 +386,14 @@ defmodule Pleroma.Web.CommonAPITest do          "status_ids" => [activity.id]        } +      note_obj = %{ +        "type" => "Note", +        "id" => activity_ap_id, +        "content" => "foobar", +        "published" => activity.object.data["published"], +        "actor" => AccountView.render("show.json", %{user: target_user}) +      } +        assert {:ok, flag_activity} = CommonAPI.report(reporter, report_data)        assert %Activity{ @@ -392,7 +401,7 @@ defmodule Pleroma.Web.CommonAPITest do                 data: %{                   "type" => "Flag",                   "content" => ^comment, -                 "object" => [^target_ap_id, ^activity_ap_id], +                 "object" => [^target_ap_id, ^note_obj],                   "state" => "open"                 }               } = flag_activity @@ -412,6 +421,11 @@ defmodule Pleroma.Web.CommonAPITest do        {:ok, report} = CommonAPI.update_report_state(report_id, "resolved")        assert report.data["state"] == "resolved" + +      [reported_user, activity_id] = report.data["object"] + +      assert reported_user == target_user.ap_id +      assert activity_id == activity.data["id"]      end      test "does not update report state when state is unsupported" do diff --git a/test/web/mastodon_api/views/conversation_view_test.exs b/test/web/mastodon_api/views/conversation_view_test.exs index a2a880705..6ed22597d 100644 --- a/test/web/mastodon_api/views/conversation_view_test.exs +++ b/test/web/mastodon_api/views/conversation_view_test.exs @@ -30,5 +30,6 @@ defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do      assert [account] = conversation.accounts      assert account.id == other_user.id +    assert conversation.last_status.pleroma.direct_conversation_id == participation.id    end  end diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs index c200ad8fe..d46ecc646 100644 --- a/test/web/mastodon_api/views/status_view_test.exs +++ b/test/web/mastodon_api/views/status_view_test.exs @@ -7,6 +7,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do    alias Pleroma.Activity    alias Pleroma.Bookmark +  alias Pleroma.Conversation.Participation +  alias Pleroma.HTML    alias Pleroma.Object    alias Pleroma.Repo    alias Pleroma.User @@ -22,10 +24,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      :ok    end -  test "returns the direct conversation id when given the `with_conversation_id` option" do +  test "loads and returns the direct conversation id when given the `with_direct_conversation_id` option" do      user = insert(:user)      {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"}) +    [participation] = Participation.for_user(user)      status =        StatusView.render("show.json", @@ -34,7 +37,26 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do          for: user        ) -    assert status[:pleroma][:direct_conversation_id] +    assert status[:pleroma][:direct_conversation_id] == participation.id + +    status = StatusView.render("show.json", activity: activity, for: user) +    assert status[:pleroma][:direct_conversation_id] == nil +  end + +  test "returns the direct conversation id when given the `direct_conversation_id` option" do +    user = insert(:user) + +    {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"}) +    [participation] = Participation.for_user(user) + +    status = +      StatusView.render("show.json", +        activity: activity, +        direct_conversation_id: participation.id, +        for: user +      ) + +    assert status[:pleroma][:direct_conversation_id] == participation.id    end    test "returns a temporary ap_id based user for activities missing db users" do @@ -107,7 +129,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do        in_reply_to_account_id: nil,        card: nil,        reblog: nil, -      content: HtmlSanitizeEx.basic_html(object_data["content"]), +      content: HTML.filter_tags(object_data["content"]),        created_at: created_at,        reblogs_count: 0,        replies_count: 0, @@ -119,7 +141,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do        pinned: false,        sensitive: false,        poll: nil, -      spoiler_text: HtmlSanitizeEx.basic_html(object_data["summary"]), +      spoiler_text: HTML.filter_tags(object_data["summary"]),        visibility: "public",        media_attachments: [],        mentions: [], @@ -146,8 +168,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do          local: true,          conversation_id: convo_id,          in_reply_to_account_acct: nil, -        content: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["content"])}, -        spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["summary"])}, +        content: %{"text/plain" => HTML.strip_tags(object_data["content"])}, +        spoiler_text: %{"text/plain" => HTML.strip_tags(object_data["summary"])},          expires_at: nil,          direct_conversation_id: nil,          thread_muted: false diff --git a/test/web/rel_me_test.exs b/test/web/rel_me_test.exs index 2251fed16..77b5d5dc6 100644 --- a/test/web/rel_me_test.exs +++ b/test/web/rel_me_test.exs @@ -14,7 +14,9 @@ defmodule Pleroma.Web.RelMeTest do      hrefs = ["https://social.example.org/users/lain"]      assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/null") == {:ok, []} -    assert {:error, _} = Pleroma.Web.RelMe.parse("http://example.com/rel_me/error") + +    assert {:ok, %Tesla.Env{status: 404}} = +             Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")      assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/link") == {:ok, hrefs}      assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor") == {:ok, hrefs} diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs index cb1015171..80a7541b2 100644 --- a/test/web/streamer/streamer_test.exs +++ b/test/web/streamer/streamer_test.exs @@ -7,6 +7,7 @@ defmodule Pleroma.Web.StreamerTest do    import Pleroma.Factory +  alias Pleroma.Conversation.Participation    alias Pleroma.List    alias Pleroma.User    alias Pleroma.Web.CommonAPI @@ -110,6 +111,24 @@ defmodule Pleroma.Web.StreamerTest do        Streamer.stream("user:notification", notif)        Task.await(task)      end + +    test "it sends follow activities to the 'user:notification' stream", %{ +      user: user +    } do +      user2 = insert(:user) +      task = Task.async(fn -> assert_receive {:text, _}, 4_000 end) + +      Streamer.add_socket( +        "user:notification", +        %{transport_pid: task.pid, assigns: %{user: user}} +      ) + +      {:ok, _follower, _followed, _activity} = CommonAPI.follow(user2, user) + +      # We don't directly pipe the notification to the streamer as it's already +      # generated as a side effect of CommonAPI.follow(). +      Task.await(task) +    end    end    test "it sends to public" do @@ -463,7 +482,14 @@ defmodule Pleroma.Web.StreamerTest do        task =          Task.async(fn -> -          assert_receive {:text, _received_event}, 4_000 +          assert_receive {:text, received_event}, 4_000 + +          assert %{"event" => "conversation", "payload" => received_payload} = +                   Jason.decode!(received_event) + +          assert %{"last_status" => last_status} = Jason.decode!(received_payload) +          [participation] = Participation.for_user(user) +          assert last_status["pleroma"]["direct_conversation_id"] == participation.id          end)        Streamer.add_socket( @@ -480,7 +506,7 @@ defmodule Pleroma.Web.StreamerTest do        Task.await(task)      end -    test "it doesn't send conversation update to the 'direct' streamj when the last message in the conversation is deleted" do +    test "it doesn't send conversation update to the 'direct' stream when the last message in the conversation is deleted" do        user = insert(:user)        another_user = insert(:user) | 
