diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/web/activity_pub/activity_pub_test.exs | 45 | ||||
| -rw-r--r-- | test/web/metadata/rel_me_test.exs | 18 | ||||
| -rw-r--r-- | test/web/oauth/oauth_controller_test.exs | 90 | 
3 files changed, 116 insertions, 37 deletions
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 17fec05b1..79116824e 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -341,6 +341,51 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do      assert Enum.member?(activities, activity_one)    end +  test "doesn't return transitive interactions concerning blocked users" do +    blocker = insert(:user) +    blockee = insert(:user) +    friend = insert(:user) + +    {:ok, blocker} = User.block(blocker, blockee) + +    {:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey!"}) + +    {:ok, activity_two} = CommonAPI.post(friend, %{"status" => "hey! @#{blockee.nickname}"}) + +    {:ok, activity_three} = CommonAPI.post(blockee, %{"status" => "hey! @#{friend.nickname}"}) + +    {:ok, activity_four} = CommonAPI.post(blockee, %{"status" => "hey! @#{blocker.nickname}"}) + +    activities = ActivityPub.fetch_activities([], %{"blocking_user" => blocker}) + +    assert Enum.member?(activities, activity_one) +    refute Enum.member?(activities, activity_two) +    refute Enum.member?(activities, activity_three) +    refute Enum.member?(activities, activity_four) +  end + +  test "doesn't return announce activities concerning blocked users" do +    blocker = insert(:user) +    blockee = insert(:user) +    friend = insert(:user) + +    {:ok, blocker} = User.block(blocker, blockee) + +    {:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey!"}) + +    {:ok, activity_two} = CommonAPI.post(blockee, %{"status" => "hey! @#{friend.nickname}"}) + +    {:ok, activity_three, _} = CommonAPI.repeat(activity_two.id, friend) + +    activities = +      ActivityPub.fetch_activities([], %{"blocking_user" => blocker}) +      |> Enum.map(fn act -> act.id end) + +    assert Enum.member?(activities, activity_one.id) +    refute Enum.member?(activities, activity_two.id) +    refute Enum.member?(activities, activity_three.id) +  end +    test "doesn't return muted activities" do      activity_one = insert(:note_activity)      activity_two = insert(:note_activity) diff --git a/test/web/metadata/rel_me_test.exs b/test/web/metadata/rel_me_test.exs new file mode 100644 index 000000000..f66bf7834 --- /dev/null +++ b/test/web/metadata/rel_me_test.exs @@ -0,0 +1,18 @@ +defmodule Pleroma.Web.Metadata.Providers.RelMeTest do +  use Pleroma.DataCase +  import Pleroma.Factory +  alias Pleroma.Web.Metadata.Providers.RelMe + +  test "it renders all links with rel='me' from user bio" do +    bio = +      ~s(<a href="https://some-link.com">https://some-link.com</a> <a rel="me" href="https://another-link.com">https://another-link.com</a> +    <link href="http://some.com"> <link rel="me" href="http://some3.com>") + +    user = insert(:user, %{bio: bio}) + +    assert RelMe.build_tags(%{user: user}) == [ +             {:link, [rel: "me", href: "http://some3.com>"], []}, +             {:link, [rel: "me", href: "https://another-link.com"], []} +           ] +  end +end diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs index ac7843f9b..fb505fab3 100644 --- a/test/web/oauth/oauth_controller_test.exs +++ b/test/web/oauth/oauth_controller_test.exs @@ -68,10 +68,12 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do            "/oauth/prepare_request",            %{              "provider" => "twitter", -            "scope" => "read follow", -            "client_id" => app.client_id, -            "redirect_uri" => app.redirect_uris, -            "state" => "a_state" +            "authorization" => %{ +              "scope" => "read follow", +              "client_id" => app.client_id, +              "redirect_uri" => app.redirect_uris, +              "state" => "a_state" +            }            }          ) @@ -104,7 +106,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do        }        with_mock Pleroma.Web.Auth.Authenticator, -        get_registration: fn _, _ -> {:ok, registration} end do +        get_registration: fn _ -> {:ok, registration} end do          conn =            get(              conn, @@ -134,7 +136,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do        }        with_mock Pleroma.Web.Auth.Authenticator, -        get_registration: fn _, _ -> {:ok, registration} end do +        get_registration: fn _ -> {:ok, registration} end do          conn =            get(              conn, @@ -193,12 +195,14 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do            conn,            "/oauth/registration_details",            %{ -            "scopes" => app.scopes, -            "client_id" => app.client_id, -            "redirect_uri" => app.redirect_uris, -            "state" => "a_state", -            "nickname" => nil, -            "email" => "john@doe.com" +            "authorization" => %{ +              "scopes" => app.scopes, +              "client_id" => app.client_id, +              "redirect_uri" => app.redirect_uris, +              "state" => "a_state", +              "nickname" => nil, +              "email" => "john@doe.com" +            }            }          ) @@ -221,12 +225,14 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do            "/oauth/register",            %{              "op" => "register", -            "scopes" => app.scopes, -            "client_id" => app.client_id, -            "redirect_uri" => app.redirect_uris, -            "state" => "a_state", -            "nickname" => "availablenick", -            "email" => "available@email.com" +            "authorization" => %{ +              "scopes" => app.scopes, +              "client_id" => app.client_id, +              "redirect_uri" => app.redirect_uris, +              "state" => "a_state", +              "nickname" => "availablenick", +              "email" => "available@email.com" +            }            }          ) @@ -244,17 +250,23 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do        params = %{          "op" => "register", -        "scopes" => app.scopes, -        "client_id" => app.client_id, -        "redirect_uri" => app.redirect_uris, -        "state" => "a_state", -        "nickname" => "availablenickname", -        "email" => "available@email.com" +        "authorization" => %{ +          "scopes" => app.scopes, +          "client_id" => app.client_id, +          "redirect_uri" => app.redirect_uris, +          "state" => "a_state", +          "nickname" => "availablenickname", +          "email" => "available@email.com" +        }        }        for {bad_param, bad_param_value} <-              [{"nickname", another_user.nickname}, {"email", another_user.email}] do -        bad_params = Map.put(params, bad_param, bad_param_value) +        bad_registration_attrs = %{ +          "authorization" => Map.put(params["authorization"], bad_param, bad_param_value) +        } + +        bad_params = Map.merge(params, bad_registration_attrs)          conn =            conn @@ -281,12 +293,14 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do            "/oauth/register",            %{              "op" => "connect", -            "scopes" => app.scopes, -            "client_id" => app.client_id, -            "redirect_uri" => app.redirect_uris, -            "state" => "a_state", -            "auth_name" => user.nickname, -            "password" => "testpassword" +            "authorization" => %{ +              "scopes" => app.scopes, +              "client_id" => app.client_id, +              "redirect_uri" => app.redirect_uris, +              "state" => "a_state", +              "name" => user.nickname, +              "password" => "testpassword" +            }            }          ) @@ -304,12 +318,14 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do        params = %{          "op" => "connect", -        "scopes" => app.scopes, -        "client_id" => app.client_id, -        "redirect_uri" => app.redirect_uris, -        "state" => "a_state", -        "auth_name" => user.nickname, -        "password" => "wrong password" +        "authorization" => %{ +          "scopes" => app.scopes, +          "client_id" => app.client_id, +          "redirect_uri" => app.redirect_uris, +          "state" => "a_state", +          "name" => user.nickname, +          "password" => "wrong password" +        }        }        conn =  | 
