diff options
Diffstat (limited to 'test/web')
| -rw-r--r-- | test/web/activity_pub/activity_pub_controller_test.exs | 7 | ||||
| -rw-r--r-- | test/web/activity_pub/transmogrifier_test.exs | 4 | ||||
| -rw-r--r-- | test/web/activity_pub/views/object_view_test.exs | 1 | ||||
| -rw-r--r-- | test/web/federator_test.exs | 7 | ||||
| -rw-r--r-- | test/web/mastodon_api/mastodon_api_controller_test.exs | 28 | ||||
| -rw-r--r-- | test/web/mastodon_api/status_view_test.exs | 18 | ||||
| -rw-r--r-- | test/web/node_info_test.exs | 32 | ||||
| -rw-r--r-- | test/web/plugs/federating_plug_test.exs | 33 | ||||
| -rw-r--r-- | test/web/twitter_api/twitter_api_controller_test.exs | 100 | ||||
| -rw-r--r-- | test/web/twitter_api/twitter_api_test.exs | 2 | 
10 files changed, 220 insertions, 12 deletions
| diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 5b46bbe76..1c24b348c 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -4,12 +4,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do    alias Pleroma.Web.ActivityPub.{UserView, ObjectView}    alias Pleroma.{Repo, User}    alias Pleroma.Activity -  alias Pleroma.Config    describe "/relay" do      test "with the relay active, it returns the relay user", %{conn: conn} do -      Config.put([:instance, :allow_relay], true) -        res =          conn          |> get(activity_pub_path(conn, :relay)) @@ -19,12 +16,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do      end      test "with the relay disabled, it returns 404", %{conn: conn} do -      Config.put([:instance, :allow_relay], false) +      Pleroma.Config.put([:instance, :allow_relay], false)        res =          conn          |> get(activity_pub_path(conn, :relay))          |> json_response(404) + +      Pleroma.Config.put([:instance, :allow_relay], true)      end    end diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 14b02eb71..6e4820dbc 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -703,7 +703,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})        {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data) -      assert modified["@context"] == "https://www.w3.org/ns/activitystreams" +      assert modified["@context"] == +               Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"] +        assert modified["object"]["conversation"] == modified["context"]      end diff --git a/test/web/activity_pub/views/object_view_test.exs b/test/web/activity_pub/views/object_view_test.exs index 6a1311be7..7e08dff5d 100644 --- a/test/web/activity_pub/views/object_view_test.exs +++ b/test/web/activity_pub/views/object_view_test.exs @@ -13,5 +13,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do      assert result["to"] == note.data["to"]      assert result["content"] == note.data["content"]      assert result["type"] == "Note" +    assert result["@context"]    end  end diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs index 966702935..c709d1181 100644 --- a/test/web/federator_test.exs +++ b/test/web/federator_test.exs @@ -1,7 +1,6 @@  defmodule Pleroma.Web.FederatorTest do    alias Pleroma.Web.Federator    alias Pleroma.Web.CommonAPI -  alias Pleroma.Config    use Pleroma.DataCase    import Pleroma.Factory    import Mock @@ -40,8 +39,6 @@ defmodule Pleroma.Web.FederatorTest do        activity: activity,        relay_mock: relay_mock      } do -      Config.put([:instance, :allow_relay], true) -        with_mocks([relay_mock]) do          Federator.handle(:publish, activity)        end @@ -53,13 +50,15 @@ defmodule Pleroma.Web.FederatorTest do        activity: activity,        relay_mock: relay_mock      } do -      Config.put([:instance, :allow_relay], false) +      Pleroma.Config.put([:instance, :allow_relay], false)        with_mocks([relay_mock]) do          Federator.handle(:publish, activity)        end        refute_received :relay_publish + +      Pleroma.Config.put([:instance, :allow_relay], true)      end    end  end diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 42a43f129..3f9324fcc 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -198,6 +198,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do      assert activity.data["object"]["inReplyToStatusId"] == replied_to.id    end +  test "posting a status with an invalid in_reply_to_id", %{conn: conn} do +    user = insert(:user) + +    conn = +      conn +      |> assign(:user, user) +      |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => ""}) + +    assert %{"content" => "xD", "id" => id} = json_response(conn, 200) + +    activity = Repo.get(Activity, id) + +    assert activity +  end +    test "verify_credentials", %{conn: conn} do      user = insert(:user) @@ -929,11 +944,20 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do        {:ok, [_activity]} =          OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873") -      conn = +      nconn =          conn          |> get("/api/v1/timelines/tag/2hu") -      assert [%{"id" => id}] = json_response(conn, 200) +      assert [%{"id" => id}] = json_response(nconn, 200) + +      assert id == to_string(activity.id) + +      # works for different capitalization too +      nconn = +        conn +        |> get("/api/v1/timelines/tag/2HU") + +      assert [%{"id" => id}] = json_response(nconn, 200)        assert id == to_string(activity.id)      end) diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index b9c019206..31554a07d 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -7,6 +7,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do    alias Pleroma.Web.CommonAPI    import Pleroma.Factory +  test "a note with null content" do +    note = insert(:note_activity) + +    data = +      note.data +      |> put_in(["object", "content"], nil) + +    note = +      note +      |> Map.put(:data, data) + +    user = User.get_cached_by_ap_id(note.data["actor"]) + +    status = StatusView.render("status.json", %{activity: note}) + +    assert status.content == "" +  end +    test "a note activity" do      note = insert(:note_activity)      user = User.get_cached_by_ap_id(note.data["actor"]) diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs index d48f40e47..a6376453c 100644 --- a/test/web/node_info_test.exs +++ b/test/web/node_info_test.exs @@ -14,4 +14,36 @@ defmodule Pleroma.Web.NodeInfoTest do      assert user.ap_id in result["metadata"]["staffAccounts"]    end + +  test "returns 404 when federation is disabled" do +    instance = +      Application.get_env(:pleroma, :instance) +      |> Keyword.put(:federating, false) + +    Application.put_env(:pleroma, :instance, instance) + +    conn +    |> get("/.well-known/nodeinfo") +    |> json_response(404) + +    conn +    |> get("/nodeinfo/2.0.json") +    |> json_response(404) + +    instance = +      Application.get_env(:pleroma, :instance) +      |> Keyword.put(:federating, true) + +    Application.put_env(:pleroma, :instance, instance) +  end + +  test "returns 200 when federation is enabled" do +    conn +    |> get("/.well-known/nodeinfo") +    |> json_response(200) + +    conn +    |> get("/nodeinfo/2.0.json") +    |> json_response(200) +  end  end diff --git a/test/web/plugs/federating_plug_test.exs b/test/web/plugs/federating_plug_test.exs new file mode 100644 index 000000000..1455a1c46 --- /dev/null +++ b/test/web/plugs/federating_plug_test.exs @@ -0,0 +1,33 @@ +defmodule Pleroma.Web.FederatingPlugTest do +  use Pleroma.Web.ConnCase + +  test "returns and halt the conn when federating is disabled" do +    instance = +      Application.get_env(:pleroma, :instance) +      |> Keyword.put(:federating, false) + +    Application.put_env(:pleroma, :instance, instance) + +    conn = +      build_conn() +      |> Pleroma.Web.FederatingPlug.call(%{}) + +    assert conn.status == 404 +    assert conn.halted + +    instance = +      Application.get_env(:pleroma, :instance) +      |> Keyword.put(:federating, true) + +    Application.put_env(:pleroma, :instance, instance) +  end + +  test "does nothing when federating is enabled" do +    conn = +      build_conn() +      |> Pleroma.Web.FederatingPlug.call(%{}) + +    refute conn.status +    refute conn.halted +  end +end diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 87bcdaf71..13480c21b 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -100,6 +100,56 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do        assert length(response) == 10      end + +    test "returns 403 to unauthenticated request when the instance is not public" do +      instance = +        Application.get_env(:pleroma, :instance) +        |> Keyword.put(:public, false) + +      Application.put_env(:pleroma, :instance, instance) + +      conn +      |> get("/api/statuses/public_timeline.json") +      |> json_response(403) + +      instance = +        Application.get_env(:pleroma, :instance) +        |> Keyword.put(:public, true) + +      Application.put_env(:pleroma, :instance, instance) +    end + +    test "returns 200 to unauthenticated request when the instance is public" do +      conn +      |> get("/api/statuses/public_timeline.json") +      |> json_response(200) +    end +  end + +  describe "GET /statuses/public_and_external_timeline.json" do +    test "returns 403 to unauthenticated request when the instance is not public" do +      instance = +        Application.get_env(:pleroma, :instance) +        |> Keyword.put(:public, false) + +      Application.put_env(:pleroma, :instance, instance) + +      conn +      |> get("/api/statuses/public_and_external_timeline.json") +      |> json_response(403) + +      instance = +        Application.get_env(:pleroma, :instance) +        |> Keyword.put(:public, true) + +      Application.put_env(:pleroma, :instance, instance) +    end + +    test "returns 200 to unauthenticated request when the instance is public" do +      conn +      |> get("/api/statuses/public_and_external_timeline.json") +      |> json_response(200) +    end    end    describe "GET /statuses/show/:id.json" do @@ -281,6 +331,56 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do      end    end +  describe "POST /api/qvitter/statuses/notifications/read" do +    setup [:valid_user] + +    test "without valid credentials", %{conn: conn} do +      conn = post(conn, "/api/qvitter/statuses/notifications/read", %{"latest_id" => 1_234_567}) +      assert json_response(conn, 403) == %{"error" => "Invalid credentials."} +    end + +    test "with credentials, without any params", %{conn: conn, user: current_user} do +      conn = +        conn +        |> with_credentials(current_user.nickname, "test") +        |> post("/api/qvitter/statuses/notifications/read") + +      assert json_response(conn, 400) == %{ +               "error" => "You need to specify latest_id", +               "request" => "/api/qvitter/statuses/notifications/read" +             } +    end + +    test "with credentials, with params", %{conn: conn, user: current_user} do +      other_user = insert(:user) + +      {:ok, _activity} = +        ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user}) + +      response_conn = +        conn +        |> with_credentials(current_user.nickname, "test") +        |> get("/api/qvitter/statuses/notifications.json") + +      [notification] = response = json_response(response_conn, 200) + +      assert length(response) == 1 + +      assert notification["is_seen"] == 0 + +      response_conn = +        conn +        |> with_credentials(current_user.nickname, "test") +        |> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]}) + +      [notification] = response = json_response(response_conn, 200) + +      assert length(response) == 1 + +      assert notification["is_seen"] == 1 +    end +  end +    describe "GET /statuses/user_timeline.json" do      setup [:valid_user] diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 6486540f8..8b9920bd9 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -48,7 +48,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do               "https://www.w3.org/ns/activitystreams#Public"             ) -    assert Enum.member?(get_in(activity.data, ["cc"]), "shp") +    assert Enum.member?(get_in(activity.data, ["to"]), "shp")      assert activity.local == true      assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} = | 
