diff options
Diffstat (limited to 'test/web/ostatus')
| -rw-r--r-- | test/web/ostatus/activity_representer_test.exs | 4 | ||||
| -rw-r--r-- | test/web/ostatus/feed_representer_test.exs | 4 | ||||
| -rw-r--r-- | test/web/ostatus/incoming_documents/delete_handling_test.exs | 11 | ||||
| -rw-r--r-- | test/web/ostatus/ostatus_controller_test.exs | 98 | ||||
| -rw-r--r-- | test/web/ostatus/ostatus_test.exs | 24 | 
5 files changed, 92 insertions, 49 deletions
diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs index 0869f2fd5..eebc5c040 100644 --- a/test/web/ostatus/activity_representer_test.exs +++ b/test/web/ostatus/activity_representer_test.exs @@ -6,7 +6,9 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do    use Pleroma.DataCase    alias Pleroma.Web.OStatus.ActivityRepresenter -  alias Pleroma.{User, Activity, Object} +  alias Pleroma.Activity +  alias Pleroma.User +  alias Pleroma.Object    alias Pleroma.Web.ActivityPub.ActivityPub    alias Pleroma.Web.OStatus diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs index 55717dec7..efd4e7217 100644 --- a/test/web/ostatus/feed_representer_test.exs +++ b/test/web/ostatus/feed_representer_test.exs @@ -6,7 +6,9 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do    use Pleroma.DataCase    import Pleroma.Factory    alias Pleroma.User -  alias Pleroma.Web.OStatus.{FeedRepresenter, UserRepresenter, ActivityRepresenter} +  alias Pleroma.Web.OStatus.ActivityRepresenter +  alias Pleroma.Web.OStatus.FeedRepresenter +  alias Pleroma.Web.OStatus.UserRepresenter    alias Pleroma.Web.OStatus    test "returns a feed of the last 20 items of the user" do diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs index c8fbff6cc..d295cc539 100644 --- a/test/web/ostatus/incoming_documents/delete_handling_test.exs +++ b/test/web/ostatus/incoming_documents/delete_handling_test.exs @@ -2,9 +2,18 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do    use Pleroma.DataCase    import Pleroma.Factory -  alias Pleroma.{Repo, Activity, Object} +  import Tesla.Mock + +  alias Pleroma.Repo +  alias Pleroma.Activity +  alias Pleroma.Object    alias Pleroma.Web.OStatus +  setup do +    mock(fn env -> apply(HttpRequestMock, :request, [env]) end) +    :ok +  end +    describe "deletions" do      test "it removes the mentioned activity" do        note = insert(:note_activity) diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index 995cc00d6..da9c72be8 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -5,7 +5,9 @@  defmodule Pleroma.Web.OStatus.OStatusControllerTest do    use Pleroma.Web.ConnCase    import Pleroma.Factory -  alias Pleroma.{User, Repo, Object} +  alias Pleroma.User +  alias Pleroma.Repo +  alias Pleroma.Object    alias Pleroma.Web.CommonAPI    alias Pleroma.Web.OStatus.ActivityRepresenter @@ -14,49 +16,51 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do      :ok    end -  test "decodes a salmon", %{conn: conn} do -    user = insert(:user) -    salmon = File.read!("test/fixtures/salmon.xml") +  describe "salmon_incoming" do +    test "decodes a salmon", %{conn: conn} do +      user = insert(:user) +      salmon = File.read!("test/fixtures/salmon.xml") -    conn = -      conn -      |> put_req_header("content-type", "application/atom+xml") -      |> post("/users/#{user.nickname}/salmon", salmon) +      conn = +        conn +        |> put_req_header("content-type", "application/atom+xml") +        |> post("/users/#{user.nickname}/salmon", salmon) -    assert response(conn, 200) -  end +      assert response(conn, 200) +    end -  test "decodes a salmon with a changed magic key", %{conn: conn} do -    user = insert(:user) -    salmon = File.read!("test/fixtures/salmon.xml") +    test "decodes a salmon with a changed magic key", %{conn: conn} do +      user = insert(:user) +      salmon = File.read!("test/fixtures/salmon.xml") -    conn = -      conn -      |> put_req_header("content-type", "application/atom+xml") -      |> post("/users/#{user.nickname}/salmon", salmon) +      conn = +        conn +        |> put_req_header("content-type", "application/atom+xml") +        |> post("/users/#{user.nickname}/salmon", salmon) -    assert response(conn, 200) +      assert response(conn, 200) -    # Set a wrong magic-key for a user so it has to refetch -    salmon_user = User.get_by_ap_id("http://gs.example.org:4040/index.php/user/1") -    # Wrong key -    info_cng = -      User.Info.remote_user_creation(salmon_user.info, %{ -        magic_key: -          "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB" -      }) +      # Set a wrong magic-key for a user so it has to refetch +      salmon_user = User.get_by_ap_id("http://gs.example.org:4040/index.php/user/1") +      # Wrong key +      info_cng = +        User.Info.remote_user_creation(salmon_user.info, %{ +          magic_key: +            "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB" +        }) -    salmon_user -    |> Ecto.Changeset.change() -    |> Ecto.Changeset.put_embed(:info, info_cng) -    |> Repo.update() +      salmon_user +      |> Ecto.Changeset.change() +      |> Ecto.Changeset.put_embed(:info, info_cng) +      |> Repo.update() -    conn = -      build_conn() -      |> put_req_header("content-type", "application/atom+xml") -      |> post("/users/#{user.nickname}/salmon", salmon) +      conn = +        build_conn() +        |> put_req_header("content-type", "application/atom+xml") +        |> post("/users/#{user.nickname}/salmon", salmon) -    assert response(conn, 200) +      assert response(conn, 200) +    end    end    test "gets a feed", %{conn: conn} do @@ -88,6 +92,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do      conn =        conn +      |> put_req_header("accept", "application/xml")        |> get(url)      expected = @@ -114,31 +119,34 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do      |> response(404)    end +  test "gets an activity in xml format", %{conn: conn} do +    note_activity = insert(:note_activity) +    [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"])) + +    conn +    |> put_req_header("accept", "application/xml") +    |> get("/activities/#{uuid}") +    |> response(200) +  end +    test "404s on deleted objects", %{conn: conn} do      note_activity = insert(:note_activity)      [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))      object = Object.get_by_ap_id(note_activity.data["object"]["id"])      conn +    |> put_req_header("accept", "application/xml")      |> get("/objects/#{uuid}")      |> response(200)      Object.delete(object)      conn +    |> put_req_header("accept", "application/xml")      |> get("/objects/#{uuid}")      |> response(404)    end -  test "gets an activity", %{conn: conn} do -    note_activity = insert(:note_activity) -    [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"])) - -    conn -    |> get("/activities/#{uuid}") -    |> response(200) -  end -    test "404s on private activities", %{conn: conn} do      note_activity = insert(:direct_note_activity)      [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"])) @@ -154,7 +162,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do      |> response(404)    end -  test "gets a notice", %{conn: conn} do +  test "gets a notice in xml format", %{conn: conn} do      note_activity = insert(:note_activity)      conn diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index 403cc7095..b4b19ab05 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -6,7 +6,11 @@ defmodule Pleroma.Web.OStatusTest do    use Pleroma.DataCase    alias Pleroma.Web.OStatus    alias Pleroma.Web.XML -  alias Pleroma.{Object, Repo, User, Activity} +  alias Pleroma.Object +  alias Pleroma.Repo +  alias Pleroma.User +  alias Pleroma.Activity +  alias Pleroma.Instances    import Pleroma.Factory    import ExUnit.CaptureLog @@ -311,6 +315,22 @@ defmodule Pleroma.Web.OStatusTest do      refute User.following?(follower, followed)    end +  test "it clears `unreachable` federation status of the sender" do +    incoming_reaction_xml = File.read!("test/fixtures/share-gs.xml") +    doc = XML.parse_document(incoming_reaction_xml) +    actor_uri = XML.string_from_xpath("//author/uri[1]", doc) +    reacted_to_author_uri = XML.string_from_xpath("//author/uri[2]", doc) + +    Instances.set_consistently_unreachable(actor_uri) +    Instances.set_consistently_unreachable(reacted_to_author_uri) +    refute Instances.reachable?(actor_uri) +    refute Instances.reachable?(reacted_to_author_uri) + +    {:ok, _} = OStatus.handle_incoming(incoming_reaction_xml) +    assert Instances.reachable?(actor_uri) +    refute Instances.reachable?(reacted_to_author_uri) +  end +    describe "new remote user creation" do      test "returns local users" do        local_user = insert(:user) @@ -514,6 +534,8 @@ defmodule Pleroma.Web.OStatusTest do          note_object.data          |> Map.put("type", "Article") +      Cachex.clear(:object_cache) +        cs = Object.change(note_object, %{data: note_data})        {:ok, _article_object} = Repo.update(cs)  | 
