diff options
| author | lain <lain@soykaf.club> | 2019-05-01 18:40:41 +0200 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2019-05-01 18:40:41 +0200 | 
| commit | 45f790becc2cc63ac000c6432fe8c84e0b589822 (patch) | |
| tree | 724d0e8ce5f10807cc25efc2434454bf38c5a52c /test/web/common_api | |
| parent | 4908e0eeee2ecb58b204198c20720d52548b6f4a (diff) | |
| parent | d107919b3d8b2275ddb7b17846cab182682098a7 (diff) | |
| download | pleroma-45f790becc2cc63ac000c6432fe8c84e0b589822.tar.gz pleroma-45f790becc2cc63ac000c6432fe8c84e0b589822.zip | |
Merge remote-tracking branch 'origin/develop' into conversations_three
Diffstat (limited to 'test/web/common_api')
| -rw-r--r-- | test/web/common_api/common_api_test.exs | 25 | ||||
| -rw-r--r-- | test/web/common_api/common_api_utils_test.exs | 35 | 
2 files changed, 45 insertions, 15 deletions
| diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index 34aa5bf18..a5b07c446 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -5,6 +5,7 @@  defmodule Pleroma.Web.CommonAPITest do    use Pleroma.DataCase    alias Pleroma.Activity +  alias Pleroma.Object    alias Pleroma.User    alias Pleroma.Web.CommonAPI @@ -32,24 +33,26 @@ defmodule Pleroma.Web.CommonAPITest do      user = insert(:user)      {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu #2HU"}) -    assert activity.data["object"]["tag"] == ["2hu"] +    object = Object.normalize(activity.data["object"]) + +    assert object.data["tag"] == ["2hu"]    end    test "it adds emoji in the object" do      user = insert(:user) -    {:ok, activity} = CommonAPI.post(user, %{"status" => ":moominmamma:"}) +    {:ok, activity} = CommonAPI.post(user, %{"status" => ":firefox:"}) -    assert activity.data["object"]["emoji"]["moominmamma"] +    assert Object.normalize(activity).data["emoji"]["firefox"]    end    test "it adds emoji when updating profiles" do -    user = insert(:user, %{name: ":karjalanpiirakka:"}) +    user = insert(:user, %{name: ":firefox:"})      CommonAPI.update(user)      user = User.get_cached_by_ap_id(user.ap_id) -    [karjalanpiirakka] = user.info.source_data["tag"] +    [firefox] = user.info.source_data["tag"] -    assert karjalanpiirakka["name"] == ":karjalanpiirakka:" +    assert firefox["name"] == ":firefox:"    end    describe "posting" do @@ -64,8 +67,9 @@ defmodule Pleroma.Web.CommonAPITest do            "content_type" => "text/html"          }) -      content = activity.data["object"]["content"] -      assert content == "<p><b>2hu</b></p>alert('xss')" +      object = Object.normalize(activity.data["object"]) + +      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 @@ -79,8 +83,9 @@ defmodule Pleroma.Web.CommonAPITest do            "content_type" => "text/markdown"          }) -      content = activity.data["object"]["content"] -      assert content == "<p><b>2hu</b></p>alert('xss')" +      object = Object.normalize(activity.data["object"]) + +      assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"      end    end diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index f0c59d5c3..ab4c62b35 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -37,21 +37,21 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do    end    test "parses emoji from name and bio" do -    {:ok, user} = UserBuilder.insert(%{name: ":karjalanpiirakka:", bio: ":perkele:"}) +    {:ok, user} = UserBuilder.insert(%{name: ":blank:", bio: ":firefox:"})      expected = [        %{          "type" => "Emoji", -        "icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}/finmoji/128px/perkele-128.png"}, -        "name" => ":perkele:" +        "icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}/emoji/Firefox.gif"}, +        "name" => ":firefox:"        },        %{          "type" => "Emoji",          "icon" => %{            "type" => "Image", -          "url" => "#{Endpoint.url()}/finmoji/128px/karjalanpiirakka-128.png" +          "url" => "#{Endpoint.url()}/emoji/blank.png"          }, -        "name" => ":karjalanpiirakka:" +        "name" => ":blank:"        }      ] @@ -119,6 +119,31 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do        assert output == expected      end +    test "works for bare text/bbcode" do +      text = "[b]hello world[/b]" +      expected = "<strong>hello world</strong>" + +      {output, [], []} = Utils.format_input(text, "text/bbcode") + +      assert output == expected + +      text = "[b]hello world![/b]\n\nsecond paragraph!" +      expected = "<strong>hello world!</strong><br>\n<br>\nsecond paragraph!" + +      {output, [], []} = Utils.format_input(text, "text/bbcode") + +      assert output == expected + +      text = "[b]hello world![/b]\n\n<strong>second paragraph!</strong>" + +      expected = +        "<strong>hello world!</strong><br>\n<br>\n<strong>second paragraph!</strong>" + +      {output, [], []} = Utils.format_input(text, "text/bbcode") + +      assert output == expected +    end +      test "works for text/markdown with mentions" do        {:ok, user} =          UserBuilder.insert(%{nickname: "user__test", ap_id: "http://foo.com/user__test"}) | 
