diff options
| author | Roman Chvanikov <chvanikoff@pm.me> | 2019-07-20 16:41:58 +0300 | 
|---|---|---|
| committer | Roman Chvanikov <chvanikoff@pm.me> | 2019-07-20 16:41:58 +0300 | 
| commit | 8292331b35f088a19a4d14eff69b74a6d1ed4746 (patch) | |
| tree | 3a4f85b315f299b59c36cbdb3f8830a4923c11da /test | |
| parent | ae4fc58589ac48a0853719e6f83b2559b6de44fb (diff) | |
| parent | fe548f322e834c7c81678a460c54c71f1198021c (diff) | |
| download | pleroma-8292331b35f088a19a4d14eff69b74a6d1ed4746.tar.gz pleroma-8292331b35f088a19a4d14eff69b74a6d1ed4746.zip  | |
Merge branch 'develop' into feature/digest-email
Diffstat (limited to 'test')
| -rw-r--r-- | test/plugs/authentication_plug_test.exs | 12 | ||||
| -rw-r--r-- | test/signature_test.exs | 13 | ||||
| -rw-r--r-- | test/upload_test.exs | 16 | ||||
| -rw-r--r-- | test/web/mastodon_api/search_controller_test.exs | 34 | ||||
| -rw-r--r-- | test/web/ostatus/ostatus_controller_test.exs | 39 | 
5 files changed, 75 insertions, 39 deletions
diff --git a/test/plugs/authentication_plug_test.exs b/test/plugs/authentication_plug_test.exs index b55e746f8..7ca045616 100644 --- a/test/plugs/authentication_plug_test.exs +++ b/test/plugs/authentication_plug_test.exs @@ -8,6 +8,9 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do    alias Pleroma.Plugs.AuthenticationPlug    alias Pleroma.User +  import ExUnit.CaptureLog +  import Mock +    setup %{conn: conn} do      user = %User{        id: 1, @@ -68,15 +71,18 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do        hash =          "$6$9psBWV8gxkGOZWBz$PmfCycChoxeJ3GgGzwvhlgacb9mUoZ.KUXNCssekER4SJ7bOK53uXrHNb2e4i8yPFgSKyzaW9CcmrDXWIEMtD1" -      assert AuthenticationPlug.checkpw("password", hash) -      refute AuthenticationPlug.checkpw("password1", hash) +      with_mock :crypt, crypt: fn _password, password_hash -> password_hash end do +        assert AuthenticationPlug.checkpw("password", hash) +      end      end      test "it returns false when hash invalid" do        hash =          "psBWV8gxkGOZWBz$PmfCycChoxeJ3GgGzwvhlgacb9mUoZ.KUXNCssekER4SJ7bOK53uXrHNb2e4i8yPFgSKyzaW9CcmrDXWIEMtD1" -      refute Pleroma.Plugs.AuthenticationPlug.checkpw("password", hash) +      assert capture_log(fn -> +               refute Pleroma.Plugs.AuthenticationPlug.checkpw("password", hash) +             end) =~ "[error] Password hash not recognized"      end    end  end diff --git a/test/signature_test.exs b/test/signature_test.exs index 840987cd6..7400cae9a 100644 --- a/test/signature_test.exs +++ b/test/signature_test.exs @@ -5,6 +5,7 @@  defmodule Pleroma.SignatureTest do    use Pleroma.DataCase +  import ExUnit.CaptureLog    import Pleroma.Factory    import Tesla.Mock @@ -46,8 +47,10 @@ defmodule Pleroma.SignatureTest do      end      test "it returns error when not found user" do -      assert Signature.fetch_public_key(make_fake_conn("test-ap_id")) == -               {:error, :error} +      assert capture_log(fn -> +               assert Signature.fetch_public_key(make_fake_conn("test-ap_id")) == +                        {:error, :error} +             end) =~ "[error] Could not decode user"      end      test "it returns error if public key is empty" do @@ -67,8 +70,10 @@ defmodule Pleroma.SignatureTest do      end      test "it returns error when not found user" do -      assert Signature.refetch_public_key(make_fake_conn("test-ap_id")) == -               {:error, {:error, :ok}} +      assert capture_log(fn -> +               assert Signature.refetch_public_key(make_fake_conn("test-ap_id")) == +                        {:error, {:error, :ok}} +             end) =~ "[error] Could not decode user"      end    end diff --git a/test/upload_test.exs b/test/upload_test.exs index f7b1893ad..32c6977d1 100644 --- a/test/upload_test.exs +++ b/test/upload_test.exs @@ -5,6 +5,8 @@  defmodule Pleroma.UploadTest do    use Pleroma.DataCase +  import ExUnit.CaptureLog +    alias Pleroma.Upload    alias Pleroma.Uploaders.Uploader @@ -77,8 +79,12 @@ defmodule Pleroma.UploadTest do      test "it returns error" do        File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg") -      assert Upload.store(@upload_file) == {:error, "Errors"} -      Task.await(Agent.get(TestUploaderError, fn task_pid -> task_pid end)) + +      assert capture_log(fn -> +               assert Upload.store(@upload_file) == {:error, "Errors"} +               Task.await(Agent.get(TestUploaderError, fn task_pid -> task_pid end)) +             end) =~ +               "[error] Elixir.Pleroma.Upload store (using Pleroma.UploadTest.TestUploaderError) failed: \"Errors\""      end    end @@ -89,7 +95,11 @@ defmodule Pleroma.UploadTest do      test "it returns error" do        File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg") -      assert Upload.store(@upload_file) == {:error, "Uploader callback timeout"} + +      assert capture_log(fn -> +               assert Upload.store(@upload_file) == {:error, "Uploader callback timeout"} +             end) =~ +               "[error] Elixir.Pleroma.Upload store (using Pleroma.UploadTest.TestUploader) failed: \"Uploader callback timeout\""      end    end diff --git a/test/web/mastodon_api/search_controller_test.exs b/test/web/mastodon_api/search_controller_test.exs index 9f50c09f4..043b96c14 100644 --- a/test/web/mastodon_api/search_controller_test.exs +++ b/test/web/mastodon_api/search_controller_test.exs @@ -24,12 +24,16 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do          {Pleroma.User, [], [search: fn _q, _o -> raise "Oops" end]},          {Pleroma.Activity, [], [search: fn _u, _q, _o -> raise "Oops" end]}        ] do -        conn = get(conn, "/api/v2/search", %{"q" => "2hu"}) - -        assert results = json_response(conn, 200) - -        assert results["accounts"] == [] -        assert results["statuses"] == [] +        capture_log(fn -> +          results = +            conn +            |> get("/api/v2/search", %{"q" => "2hu"}) +            |> json_response(200) + +          assert results["accounts"] == [] +          assert results["statuses"] == [] +        end) =~ +          "[error] Elixir.Pleroma.Web.MastodonAPI.SearchController search error: %RuntimeError{message: \"Oops\"}"        end      end @@ -99,14 +103,16 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do          {Pleroma.User, [], [search: fn _q, _o -> raise "Oops" end]},          {Pleroma.Activity, [], [search: fn _u, _q, _o -> raise "Oops" end]}        ] do -        conn = -          conn -          |> get("/api/v1/search", %{"q" => "2hu"}) - -        assert results = json_response(conn, 200) - -        assert results["accounts"] == [] -        assert results["statuses"] == [] +        capture_log(fn -> +          results = +            conn +            |> get("/api/v1/search", %{"q" => "2hu"}) +            |> json_response(200) + +          assert results["accounts"] == [] +          assert results["statuses"] == [] +        end) =~ +          "[error] Elixir.Pleroma.Web.MastodonAPI.SearchController search error: %RuntimeError{message: \"Oops\"}"        end      end diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index 3dd8c6491..bb7648bdd 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -4,7 +4,10 @@  defmodule Pleroma.Web.OStatus.OStatusControllerTest do    use Pleroma.Web.ConnCase + +  import ExUnit.CaptureLog    import Pleroma.Factory +    alias Pleroma.Object    alias Pleroma.User    alias Pleroma.Web.CommonAPI @@ -27,24 +30,28 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest 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) +      assert capture_log(fn -> +               conn = +                 conn +                 |> put_req_header("content-type", "application/atom+xml") +                 |> post("/users/#{user.nickname}/salmon", salmon) -      assert response(conn, 200) +               assert response(conn, 200) +             end) =~ "[error]"      end      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) +      assert capture_log(fn -> +               conn = +                 conn +                 |> put_req_header("content-type", "application/atom+xml") +                 |> post("/users/#{user.nickname}/salmon", salmon) -      assert response(conn, 200) +               assert response(conn, 200) +             end) =~ "[error]"        # Set a wrong magic-key for a user so it has to refetch        salmon_user = User.get_cached_by_ap_id("http://gs.example.org:4040/index.php/user/1") @@ -61,12 +68,14 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do        |> Ecto.Changeset.put_embed(:info, info_cng)        |> User.update_and_set_cache() -      conn = -        build_conn() -        |> put_req_header("content-type", "application/atom+xml") -        |> post("/users/#{user.nickname}/salmon", salmon) +      assert capture_log(fn -> +               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) =~ "[error]"      end    end  | 
