Merge branch 'bugfix/oauth-token-padding' into 'develop'
authorlambda <pleromagit@rogerbraun.net>
Fri, 15 Feb 2019 14:58:13 +0000 (14:58 +0000)
committerlambda <pleromagit@rogerbraun.net>
Fri, 15 Feb 2019 14:58:13 +0000 (14:58 +0000)
oauth: never use base64 padding when returning tokens to applications

See merge request pleroma/pleroma!825

43 files changed:
.credo.exs
config/config.exs
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/web/activity_pub/views/user_view.ex
lib/pleroma/web/media_proxy/media_proxy.ex
lib/pleroma/web/router.ex
priv/static/schemas/litepub-0.1.jsonld
test/formatter_test.exs
test/media_proxy_test.exs
test/notification_test.exs
test/object_test.exs
test/support/builders/user_builder.ex
test/tasks/relay_test.exs
test/tasks/user_test.exs
test/user_test.exs
test/web/activity_pub/activity_pub_controller_test.exs
test/web/activity_pub/activity_pub_test.exs
test/web/activity_pub/mrf/hellthread_policy_test.exs [new file with mode: 0644]
test/web/activity_pub/transmogrifier_test.exs
test/web/activity_pub/views/user_view_test.exs
test/web/admin_api/admin_api_controller_test.exs
test/web/common_api/common_api_utils_test.exs
test/web/federator_test.exs
test/web/mastodon_api/mastodon_api_controller_test.exs
test/web/mastodon_api/status_view_test.exs
test/web/oauth/authorization_test.exs
test/web/oauth/oauth_controller_test.exs
test/web/oauth/token_test.exs
test/web/ostatus/activity_representer_test.exs
test/web/ostatus/feed_representer_test.exs
test/web/ostatus/incoming_documents/delete_handling_test.exs
test/web/ostatus/ostatus_controller_test.exs
test/web/ostatus/ostatus_test.exs
test/web/salmon/salmon_test.exs
test/web/twitter_api/representers/activity_representer_test.exs
test/web/twitter_api/twitter_api_controller_test.exs
test/web/twitter_api/twitter_api_test.exs
test/web/twitter_api/views/notification_view_test.exs
test/web/websub/websub_controller_test.exs
test/web/websub/websub_test.exs

index 94e19c4b5b0710298bbab058f924004a25185d13..580cb270539657347a93c6853ab5c01565ef8ac6 100644 (file)
@@ -19,7 +19,7 @@
         #
         # You can give explicit globs or simply directories.
         # In the latter case `**/*.{ex,exs}` will be used.
-        included: ["lib/", "src/", "web/", "apps/"],
+        included: ["lib/", "src/", "web/", "apps/", "test/"],
         excluded: [~r"/_build/", ~r"/deps/"]
       },
       #
index 5db0ea9aa9a5397834fa53514c7b73fb71392724..e2a239a76baea09e3b986bd42d1fe7602adeb82b 100644 (file)
@@ -228,8 +228,8 @@ config :pleroma, :mrf_rejectnonpublic,
   allow_direct: false
 
 config :pleroma, :mrf_hellthread,
-  delist_threshold: 5,
-  reject_threshold: 10
+  delist_threshold: 10,
+  reject_threshold: 20
 
 config :pleroma, :mrf_simple,
   media_removal: [],
index 3232cb8421e50f7596c778b1482f0b92c70f2f36..29d2b3d896d20a64e78907df1e847889bbd17651 100644 (file)
@@ -731,7 +731,7 @@ defmodule Pleroma.User do
     # Strip the beginning @ off if there is a query
     query = String.trim_leading(query, "@")
 
-    if resolve, do: User.get_or_fetch_by_nickname(query)
+    if resolve, do: get_or_fetch(query)
 
     fts_results = do_search(fts_search_subquery(query), for_user)
 
index c46d8233e04aa77dfef3a4da5e0d49d66679454f..ab2872f56aadcc36e87da85c0ccc795b469e10dc 100644 (file)
@@ -818,8 +818,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     if object = Object.get_cached_by_ap_id(id) do
       {:ok, object}
     else
-      Logger.info("Fetching #{id} via AP")
-
       with {:ok, data} <- fetch_and_contain_remote_object_from_id(id),
            nil <- Object.normalize(data),
            params <- %{
@@ -851,7 +849,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   end
 
   def fetch_and_contain_remote_object_from_id(id) do
-    Logger.info("Fetching #{id} via AP")
+    Logger.info("Fetching object #{id} via AP")
 
     with true <- String.starts_with?(id, "http"),
          {:ok, %{body: body, status: code}} when code in 200..299 <-
index 4c6e612b28357025f8b436c6ea3065e1bdce6bf7..8ab1dd4e51ea3bb6025497473962419ce54f2b14 100644 (file)
@@ -6,40 +6,80 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
   alias Pleroma.User
   @behaviour Pleroma.Web.ActivityPub.MRF
 
-  defp delist_message(message) do
+  defp delist_message(message, threshold) when threshold > 0 do
     follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address
 
-    message
-    |> Map.put("to", [follower_collection])
-    |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
+    follower_collection? = Enum.member?(message["to"] ++ message["cc"], follower_collection)
+
+    message =
+      case recipients = get_recipient_count(message) do
+        {:public, _}
+        when follower_collection? and recipients > threshold ->
+          message
+          |> Map.put("to", [follower_collection])
+          |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
+
+        {:public, _} when recipients > threshold ->
+          message
+          |> Map.put("to", [])
+          |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
+
+        _ ->
+          message
+      end
+
+    {:ok, message}
+  end
+
+  defp delist_message(message, _threshold), do: {:ok, message}
+
+  defp reject_message(message, threshold) when threshold > 0 do
+    with {_, recipients} <- get_recipient_count(message) do
+      if recipients > threshold do
+        {:reject, nil}
+      else
+        {:ok, message}
+      end
+    end
+  end
+
+  defp reject_message(message, _threshold), do: {:ok, message}
+
+  defp get_recipient_count(message) do
+    recipients = (message["to"] || []) ++ (message["cc"] || [])
+    follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address
+
+    if Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") do
+      recipients =
+        recipients
+        |> List.delete("https://www.w3.org/ns/activitystreams#Public")
+        |> List.delete(follower_collection)
+
+      {:public, length(recipients)}
+    else
+      recipients =
+        recipients
+        |> List.delete(follower_collection)
+
+      {:not_public, length(recipients)}
+    end
   end
 
   @impl true
   def filter(%{"type" => "Create"} = message) do
-    delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold])
-
     reject_threshold =
       Pleroma.Config.get(
         [:mrf_hellthread, :reject_threshold],
         Pleroma.Config.get([:mrf_hellthread, :threshold])
       )
 
-    recipients = (message["to"] || []) ++ (message["cc"] || [])
-
-    cond do
-      length(recipients) > reject_threshold and reject_threshold > 0 ->
-        {:reject, nil}
-
-      length(recipients) > delist_threshold and delist_threshold > 0 ->
-        if Enum.member?(message["to"], "https://www.w3.org/ns/activitystreams#Public") or
-             Enum.member?(message["cc"], "https://www.w3.org/ns/activitystreams#Public") do
-          {:ok, delist_message(message)}
-        else
-          {:ok, message}
-        end
+    delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold])
 
-      true ->
-        {:ok, message}
+    with {:ok, message} <- reject_message(message, reject_threshold),
+         {:ok, message} <- delist_message(message, delist_threshold) do
+      {:ok, message}
+    else
+      _e -> {:reject, nil}
     end
   end
 
index 98a2af8198dc1b25a11b315ec83d2819415c80a4..26b2dd575432b29b0868e8f295650af2e74367a3 100644 (file)
@@ -649,7 +649,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
     if object = Object.normalize(id), do: {:ok, object}, else: nil
   end
 
-  def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) do
+  def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) when is_binary(inReplyTo) do
     with false <- String.starts_with?(inReplyTo, "http"),
          {:ok, %{data: replied_to_object}} <- get_obj_helper(inReplyTo) do
       Map.put(object, "inReplyTo", replied_to_object["external_url"] || inReplyTo)
@@ -765,12 +765,18 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   def add_hashtags(object) do
     tags =
       (object["tag"] || [])
-      |> Enum.map(fn tag ->
-        %{
-          "href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}",
-          "name" => "##{tag}",
-          "type" => "Hashtag"
-        }
+      |> Enum.map(fn
+        # Expand internal representation tags into AS2 tags.
+        tag when is_binary(tag) ->
+          %{
+            "href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}",
+            "name" => "##{tag}",
+            "type" => "Hashtag"
+          }
+
+        # Do not process tags which are already AS2 tag objects.
+        tag when is_map(tag) ->
+          tag
       end)
 
     object
index 15e6c1f687c5ee755b7a2bc759e9cf90ff4235ff..c8e15498986d71a91a1c27cd6db6691d4bcc2b3d 100644 (file)
@@ -12,9 +12,26 @@ defmodule Pleroma.Web.ActivityPub.UserView do
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.ActivityPub.Transmogrifier
   alias Pleroma.Web.ActivityPub.Utils
+  alias Pleroma.Web.Router.Helpers
+  alias Pleroma.Web.Endpoint
 
   import Ecto.Query
 
+  def render("endpoints.json", %{user: %User{nickname: nil, local: true} = _user}) do
+    %{"sharedInbox" => Helpers.activity_pub_url(Endpoint, :inbox)}
+  end
+
+  def render("endpoints.json", %{user: %User{local: true} = _user}) do
+    %{
+      "oauthAuthorizationEndpoint" => Helpers.o_auth_url(Endpoint, :authorize),
+      "oauthRegistrationEndpoint" => Helpers.mastodon_api_url(Endpoint, :create_app),
+      "oauthTokenEndpoint" => Helpers.o_auth_url(Endpoint, :token_exchange),
+      "sharedInbox" => Helpers.activity_pub_url(Endpoint, :inbox)
+    }
+  end
+
+  def render("endpoints.json", _), do: %{}
+
   # the instance itself is not a Person, but instead an Application
   def render("user.json", %{user: %{nickname: nil} = user}) do
     {:ok, user} = WebFinger.ensure_keys_present(user)
@@ -22,6 +39,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do
     public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key)
     public_key = :public_key.pem_encode([public_key])
 
+    endpoints = render("endpoints.json", %{user: user})
+
     %{
       "id" => user.ap_id,
       "type" => "Application",
@@ -37,9 +56,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
         "owner" => user.ap_id,
         "publicKeyPem" => public_key
       },
-      "endpoints" => %{
-        "sharedInbox" => "#{Pleroma.Web.Endpoint.url()}/inbox"
-      }
+      "endpoints" => endpoints
     }
     |> Map.merge(Utils.make_json_ld_header())
   end
@@ -50,6 +67,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do
     public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key)
     public_key = :public_key.pem_encode([public_key])
 
+    endpoints = render("endpoints.json", %{user: user})
+
     %{
       "id" => user.ap_id,
       "type" => "Person",
@@ -67,9 +86,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
         "owner" => user.ap_id,
         "publicKeyPem" => public_key
       },
-      "endpoints" => %{
-        "sharedInbox" => "#{Pleroma.Web.Endpoint.url()}/inbox"
-      },
+      "endpoints" => endpoints,
       "icon" => %{
         "type" => "Image",
         "url" => User.avatar_url(user)
@@ -88,7 +105,14 @@ defmodule Pleroma.Web.ActivityPub.UserView do
     query = from(user in query, select: [:ap_id])
     following = Repo.all(query)
 
-    collection(following, "#{user.ap_id}/following", page, !user.info.hide_follows)
+    total =
+      if !user.info.hide_follows do
+        length(following)
+      else
+        0
+      end
+
+    collection(following, "#{user.ap_id}/following", page, !user.info.hide_follows, total)
     |> Map.merge(Utils.make_json_ld_header())
   end
 
@@ -97,10 +121,17 @@ defmodule Pleroma.Web.ActivityPub.UserView do
     query = from(user in query, select: [:ap_id])
     following = Repo.all(query)
 
+    total =
+      if !user.info.hide_follows do
+        length(following)
+      else
+        0
+      end
+
     %{
       "id" => "#{user.ap_id}/following",
       "type" => "OrderedCollection",
-      "totalItems" => length(following),
+      "totalItems" => total,
       "first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_follows)
     }
     |> Map.merge(Utils.make_json_ld_header())
@@ -111,7 +142,14 @@ defmodule Pleroma.Web.ActivityPub.UserView do
     query = from(user in query, select: [:ap_id])
     followers = Repo.all(query)
 
-    collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_followers)
+    total =
+      if !user.info.hide_followers do
+        length(followers)
+      else
+        0
+      end
+
+    collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_followers, total)
     |> Map.merge(Utils.make_json_ld_header())
   end
 
@@ -120,19 +158,24 @@ defmodule Pleroma.Web.ActivityPub.UserView do
     query = from(user in query, select: [:ap_id])
     followers = Repo.all(query)
 
+    total =
+      if !user.info.hide_followers do
+        length(followers)
+      else
+        0
+      end
+
     %{
       "id" => "#{user.ap_id}/followers",
       "type" => "OrderedCollection",
-      "totalItems" => length(followers),
-      "first" => collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_followers)
+      "totalItems" => total,
+      "first" =>
+        collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_followers, total)
     }
     |> Map.merge(Utils.make_json_ld_header())
   end
 
   def render("outbox.json", %{user: user, max_id: max_qid}) do
-    # XXX: technically note_count is wrong for this, but it's better than nothing
-    info = User.user_info(user)
-
     params = %{
       "limit" => "10"
     }
@@ -160,7 +203,6 @@ defmodule Pleroma.Web.ActivityPub.UserView do
       "id" => "#{iri}?max_id=#{max_id}",
       "type" => "OrderedCollectionPage",
       "partOf" => iri,
-      "totalItems" => info.note_count,
       "orderedItems" => collection,
       "next" => "#{iri}?max_id=#{min_id}"
     }
@@ -169,7 +211,6 @@ defmodule Pleroma.Web.ActivityPub.UserView do
       %{
         "id" => iri,
         "type" => "OrderedCollection",
-        "totalItems" => info.note_count,
         "first" => page
       }
       |> Map.merge(Utils.make_json_ld_header())
@@ -207,7 +248,6 @@ defmodule Pleroma.Web.ActivityPub.UserView do
       "id" => "#{iri}?max_id=#{max_id}",
       "type" => "OrderedCollectionPage",
       "partOf" => iri,
-      "totalItems" => -1,
       "orderedItems" => collection,
       "next" => "#{iri}?max_id=#{min_id}"
     }
@@ -216,7 +256,6 @@ defmodule Pleroma.Web.ActivityPub.UserView do
       %{
         "id" => iri,
         "type" => "OrderedCollection",
-        "totalItems" => -1,
         "first" => page
       }
       |> Map.merge(Utils.make_json_ld_header())
index 1e9da728373d1638f0d38dcd58f9e0d266137de8..39a725a6941c86c61ae69d18657772ad7fb61c43 100644 (file)
@@ -19,11 +19,16 @@ defmodule Pleroma.Web.MediaProxy do
     else
       secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base]
 
+      # Must preserve `%2F` for compatibility with S3 (https://git.pleroma.social/pleroma/pleroma/issues/580)
+      replacement = get_replacement(url, ":2F:")
+
       # The URL is url-decoded and encoded again to ensure it is correctly encoded and not twice.
       base64 =
         url
+        |> String.replace("%2F", replacement)
         |> URI.decode()
         |> URI.encode()
+        |> String.replace(replacement, "%2F")
         |> Base.url_encode64(@base64_opts)
 
       sig = :crypto.hmac(:sha, secret, base64)
@@ -60,4 +65,12 @@ defmodule Pleroma.Web.MediaProxy do
     |> Enum.filter(fn value -> value end)
     |> Path.join()
   end
+
+  defp get_replacement(url, replacement) do
+    if String.contains?(url, replacement) do
+      get_replacement(url, replacement <> replacement)
+    else
+      replacement
+    end
+  end
 end
index 5b5627ce84cb20a8a1796de752439e7dd0eb677d..d66a1c2a136b2d60eec02d900e747a5d90b99790 100644 (file)
@@ -468,8 +468,8 @@ defmodule Pleroma.Web.Router do
 
   scope "/", Pleroma.Web.ActivityPub do
     pipe_through(:activitypub)
-    post("/users/:nickname/inbox", ActivityPubController, :inbox)
     post("/inbox", ActivityPubController, :inbox)
+    post("/users/:nickname/inbox", ActivityPubController, :inbox)
   end
 
   scope "/.well-known", Pleroma.Web do
index 15645646a3dbe04cad7af2099e04e4562db17e39..f36b231c5b070c8654aa766f40f98ff40b416736 100644 (file)
             "value": "schema:value",
             "sensitive": "as:sensitive",
             "litepub": "http://litepub.social/ns#",
-            "directMessage": "litepub:directMessage"
+            "directMessage": "litepub:directMessage",
+            "oauthRegistrationEndpoint": {
+                "@id": "litepub:oauthRegistrationEndpoint",
+                "@type": "@id"
+            }
         }
     ]
 }
index 2e717194bb38f1302640f48e5761ba54b58b938f..f14077d25559d4f295e8a83bd1089479ea844679 100644 (file)
@@ -197,7 +197,7 @@ defmodule Pleroma.FormatterTest do
 
       {subs, text} = Formatter.add_user_links({[], text}, mentions)
 
-      assert length(subs) == 0
+      assert Enum.empty?(subs)
       Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
 
       expected_text = "@a hi"
index 05d927422ee7777cff95b2f7ebd6b59c8c3e4314..ddbadfbf542198443b653171d38f6d07d2284869 100644 (file)
@@ -140,6 +140,15 @@ defmodule Pleroma.MediaProxyTest do
 
       assert String.starts_with?(encoded, Pleroma.Config.get([:media_proxy, :base_url]))
     end
+
+    # https://git.pleroma.social/pleroma/pleroma/issues/580
+    test "encoding S3 links (must preserve `%2F`)" do
+      url =
+        "https://s3.amazonaws.com/example/test.png?X-Amz-Credential=your-access-key-id%2F20130721%2Fus-east-1%2Fs3%2Faws4_request"
+
+      encoded = url(url)
+      assert decode_result(encoded) == url
+    end
   end
 
   describe "when disabled" do
index 94fb0ab154ae81a10583041a549f247091632cc7..755874a3da9ee9846c265821bca0cf3e63513c9c 100644 (file)
@@ -6,7 +6,8 @@ defmodule Pleroma.NotificationTest do
   use Pleroma.DataCase
   alias Pleroma.Web.TwitterAPI.TwitterAPI
   alias Pleroma.Web.CommonAPI
-  alias Pleroma.{User, Notification}
+  alias Pleroma.User
+  alias Pleroma.Notification
   alias Pleroma.Web.ActivityPub.Transmogrifier
   import Pleroma.Factory
 
@@ -299,7 +300,7 @@ defmodule Pleroma.NotificationTest do
 
       {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
 
       {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
 
@@ -307,7 +308,7 @@ defmodule Pleroma.NotificationTest do
 
       {:ok, _} = CommonAPI.delete(activity.id, user)
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
     end
 
     test "liking an activity results in 1 notification, then 0 if the activity is unliked" do
@@ -316,7 +317,7 @@ defmodule Pleroma.NotificationTest do
 
       {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
 
       {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
 
@@ -324,7 +325,7 @@ defmodule Pleroma.NotificationTest do
 
       {:ok, _, _, _} = CommonAPI.unfavorite(activity.id, other_user)
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
     end
 
     test "repeating an activity results in 1 notification, then 0 if the activity is deleted" do
@@ -333,7 +334,7 @@ defmodule Pleroma.NotificationTest do
 
       {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
 
       {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
 
@@ -341,7 +342,7 @@ defmodule Pleroma.NotificationTest do
 
       {:ok, _} = CommonAPI.delete(activity.id, user)
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
     end
 
     test "repeating an activity results in 1 notification, then 0 if the activity is unrepeated" do
@@ -350,7 +351,7 @@ defmodule Pleroma.NotificationTest do
 
       {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
 
       {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
 
@@ -358,7 +359,7 @@ defmodule Pleroma.NotificationTest do
 
       {:ok, _, _} = CommonAPI.unrepeat(activity.id, other_user)
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
     end
 
     test "liking an activity which is already deleted does not generate a notification" do
@@ -367,15 +368,15 @@ defmodule Pleroma.NotificationTest do
 
       {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
 
       {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
 
       {:error, _} = CommonAPI.favorite(activity.id, other_user)
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
     end
 
     test "repeating an activity which is already deleted does not generate a notification" do
@@ -384,15 +385,15 @@ defmodule Pleroma.NotificationTest do
 
       {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
 
       {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
 
       {:error, _} = CommonAPI.repeat(activity.id, other_user)
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
     end
 
     test "replying to a deleted post without tagging does not generate a notification" do
@@ -408,7 +409,7 @@ defmodule Pleroma.NotificationTest do
           "in_reply_to_status_id" => activity.id
         })
 
-      assert length(Notification.for_user(user)) == 0
+      assert Enum.empty?(Notification.for_user(user))
     end
   end
 end
index 72194975d7b25405bae21fedb1c7d9e93d0dedda..a820a34ee87db85676218dd0b8589f5470ebcc89 100644 (file)
@@ -5,7 +5,8 @@
 defmodule Pleroma.ObjectTest do
   use Pleroma.DataCase
   import Pleroma.Factory
-  alias Pleroma.{Repo, Object}
+  alias Pleroma.Repo
+  alias Pleroma.Object
 
   test "returns an object by it's AP id" do
     object = insert(:note)
index 7a1ca79b50540347a0cdef9eba7c7be720c7d6bb..611a5be18f7364bb32d29551e84b5572cfb05f77 100644 (file)
@@ -1,5 +1,6 @@
 defmodule Pleroma.Builders.UserBuilder do
-  alias Pleroma.{User, Repo}
+  alias Pleroma.User
+  alias Pleroma.Repo
 
   def build(data \\ %{}) do
     user = %User{
index 96fac4811e6a889ecb05ebf72df790be840e9f88..64ff07753af295814a6fd5f7dcb29e923022ff3d 100644 (file)
@@ -4,7 +4,9 @@
 
 defmodule Mix.Tasks.Pleroma.RelayTest do
   alias Pleroma.Activity
-  alias Pleroma.Web.ActivityPub.{ActivityPub, Relay, Utils}
+  alias Pleroma.Web.ActivityPub.ActivityPub
+  alias Pleroma.Web.ActivityPub.Utils
+  alias Pleroma.Web.ActivityPub.Relay
   alias Pleroma.User
   use Pleroma.DataCase
 
index 44271898c1de0d9f77609fa6787acd048f63e623..7b814d171dad113cd0677d4f6547a34117f0d771 100644 (file)
@@ -151,7 +151,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
       assert message =~ "Successfully unsubscribed"
 
       user = User.get_by_nickname(user.nickname)
-      assert length(user.following) == 0
+      assert Enum.empty?(user.following)
       assert user.info.deactivated
     end
 
index a282274cebf323c8aafec97c636534d612f73d6e..a99b79a0de773e73d369e766197234fe368d353a 100644 (file)
@@ -4,7 +4,9 @@
 
 defmodule Pleroma.UserTest do
   alias Pleroma.Builders.UserBuilder
-  alias Pleroma.{User, Repo, Activity}
+  alias Pleroma.Activity
+  alias Pleroma.Repo
+  alias Pleroma.User
   alias Pleroma.Web.CommonAPI
   use Pleroma.DataCase
 
@@ -876,6 +878,16 @@ defmodule Pleroma.UserTest do
         assert [] == User.search(query)
       end)
     end
+
+    test "works with URIs" do
+      results = User.search("http://mastodon.example.org/users/admin", true)
+      result = results |> List.first()
+
+      user = User.get_by_ap_id("http://mastodon.example.org/users/admin")
+
+      assert length(results) == 1
+      assert user == result |> Map.put(:search_rank, nil)
+    end
   end
 
   test "auth_active?/1 works correctly" do
index 570bee6b3dd57f56b3db4d8efa252d35e13a4925..398bedf7793f378b6a4e48a6e2adec5917497582 100644 (file)
@@ -5,8 +5,13 @@
 defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
   use Pleroma.Web.ConnCase
   import Pleroma.Factory
-  alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
-  alias Pleroma.{Object, Repo, Activity, User, Instances}
+  alias Pleroma.Web.ActivityPub.UserView
+  alias Pleroma.Web.ActivityPub.ObjectView
+  alias Pleroma.Object
+  alias Pleroma.Repo
+  alias Pleroma.Activity
+  alias Pleroma.User
+  alias Pleroma.Instances
 
   setup_all do
     Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -397,7 +402,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
         |> json_response(200)
 
       assert result["first"]["orderedItems"] == []
-      assert result["totalItems"] == 1
+      assert result["totalItems"] == 0
     end
 
     test "it works for more than 10 users", %{conn: conn} do
@@ -452,7 +457,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
         |> json_response(200)
 
       assert result["first"]["orderedItems"] == []
-      assert result["totalItems"] == 1
+      assert result["totalItems"] == 0
     end
 
     test "it works for more than 10 users", %{conn: conn} do
index a55961ac4bdba0587eac52df8dd402f0963539b9..a6f8b822ac1124b64cb47558941a917b9518c758 100644 (file)
@@ -7,7 +7,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.ActivityPub.Utils
   alias Pleroma.Web.CommonAPI
-  alias Pleroma.{Activity, Object, User, Instances}
+  alias Pleroma.Activity
+  alias Pleroma.Object
+  alias Pleroma.User
+  alias Pleroma.Instances
   alias Pleroma.Builders.ActivityBuilder
 
   import Pleroma.Factory
diff --git a/test/web/activity_pub/mrf/hellthread_policy_test.exs b/test/web/activity_pub/mrf/hellthread_policy_test.exs
new file mode 100644 (file)
index 0000000..ebf9997
--- /dev/null
@@ -0,0 +1,50 @@
+# Pleroma: A lightweight social networking server
+# Copyright Â© 2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
+  use Pleroma.DataCase
+  import Pleroma.Factory
+
+  import Pleroma.Web.ActivityPub.MRF.HellthreadPolicy
+
+  describe "hellthread filter tests" do
+    setup do
+      user = insert(:user)
+
+      message = %{
+        "actor" => user.ap_id,
+        "cc" => [user.follower_address],
+        "type" => "Create",
+        "to" => [
+          "https://www.w3.org/ns/activitystreams#Public",
+          "https://instace.tld/users/user1",
+          "https://instace.tld/users/user2",
+          "https://instace.tld/users/user3"
+        ]
+      }
+
+      [user: user, message: message]
+    end
+
+    test "reject test", %{message: message} do
+      Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
+
+      {:reject, nil} = filter(message)
+    end
+
+    test "delist test", %{user: user, message: message} do
+      Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
+
+      {:ok, message} = filter(message)
+      assert user.follower_address in message["to"]
+      assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
+    end
+
+    test "excludes follower collection and public URI from threshold count", %{message: message} do
+      Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
+
+      {:ok, _} = filter(message)
+    end
+  end
+end
index e5e3c8d33ddee2afd9b39ffd25bdd290b8e870bf..86c66deff6af1a5b0fd60c9bbfcb55a69dd3a3c1 100644 (file)
@@ -1128,4 +1128,58 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
         )
     end
   end
+
+  describe "reserialization" do
+    test "successfully reserializes a message with inReplyTo == nil" do
+      user = insert(:user)
+
+      message = %{
+        "@context" => "https://www.w3.org/ns/activitystreams",
+        "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+        "cc" => [],
+        "type" => "Create",
+        "object" => %{
+          "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+          "cc" => [],
+          "type" => "Note",
+          "content" => "Hi",
+          "inReplyTo" => nil,
+          "attributedTo" => user.ap_id
+        },
+        "actor" => user.ap_id
+      }
+
+      {:ok, activity} = Transmogrifier.handle_incoming(message)
+
+      {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
+    end
+
+    test "successfully reserializes a message with AS2 objects in IR" do
+      user = insert(:user)
+
+      message = %{
+        "@context" => "https://www.w3.org/ns/activitystreams",
+        "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+        "cc" => [],
+        "type" => "Create",
+        "object" => %{
+          "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+          "cc" => [],
+          "type" => "Note",
+          "content" => "Hi",
+          "inReplyTo" => nil,
+          "attributedTo" => user.ap_id,
+          "tag" => [
+            %{"name" => "#2hu", "href" => "http://example.com/2hu", "type" => "Hashtag"},
+            %{"name" => "Bob", "href" => "http://example.com/bob", "type" => "Mention"}
+          ]
+        },
+        "actor" => user.ap_id
+      }
+
+      {:ok, activity} = Transmogrifier.handle_incoming(message)
+
+      {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
+    end
+  end
 end
index 7fc870e962753840ef6dca0fa70bd627491c00c6..0bc1d4728f2296f29b5c52cae442beef1b139fa0 100644 (file)
@@ -15,4 +15,43 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
 
     assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
   end
+
+  describe "endpoints" do
+    test "local users have a usable endpoints structure" do
+      user = insert(:user)
+      {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
+
+      result = UserView.render("user.json", %{user: user})
+
+      assert result["id"] == user.ap_id
+
+      %{
+        "sharedInbox" => _,
+        "oauthAuthorizationEndpoint" => _,
+        "oauthRegistrationEndpoint" => _,
+        "oauthTokenEndpoint" => _
+      } = result["endpoints"]
+    end
+
+    test "remote users have an empty endpoints structure" do
+      user = insert(:user, local: false)
+      {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
+
+      result = UserView.render("user.json", %{user: user})
+
+      assert result["id"] == user.ap_id
+      assert result["endpoints"] == %{}
+    end
+
+    test "instance users do not expose oAuth endpoints" do
+      user = insert(:user, nickname: nil, local: true)
+      {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
+
+      result = UserView.render("user.json", %{user: user})
+
+      refute result["endpoints"]["oauthAuthorizationEndpoint"]
+      refute result["endpoints"]["oauthRegistrationEndpoint"]
+      refute result["endpoints"]["oauthTokenEndpoint"]
+    end
+  end
 end
index 42450a7b65d84396beac10cdaafee0d1d84d4204..a27c26f9563f6d7acf449bb23652af555ae45506 100644 (file)
@@ -5,7 +5,8 @@
 defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
   use Pleroma.Web.ConnCase
 
-  alias Pleroma.{Repo, User}
+  alias Pleroma.Repo
+  alias Pleroma.User
   import Pleroma.Factory
 
   describe "/api/pleroma/admin/user" do
index 754bc72557e8a9e630797ebf78f1c5d9fe175dc7..faed6b6855ee4b79d55473b608e227d59c13a6d1 100644 (file)
@@ -5,7 +5,7 @@
 defmodule Pleroma.Web.CommonAPI.UtilsTest do
   alias Pleroma.Web.CommonAPI.Utils
   alias Pleroma.Web.Endpoint
-  alias Pleroma.Builders.{UserBuilder}
+  alias Pleroma.Builders.UserBuilder
   use Pleroma.DataCase
 
   test "it adds attachment links to a given text and attachment set" do
index 05f813291bc5f3644789dab5aa472face3496659..9f8d71454aed3475ae3994bcbbab1306e0eda82b 100644 (file)
@@ -3,7 +3,8 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.FederatorTest do
-  alias Pleroma.Web.{CommonAPI, Federator}
+  alias Pleroma.Web.CommonAPI
+  alias Pleroma.Web.Federator
   alias Pleroma.Instances
   use Pleroma.DataCase
   import Pleroma.Factory
index 1a60ad8e6c50b7eb76dbed4b188c92fc6f9fb203..26c9c25a619b7e2fe2d7cb16d06f9d3e82c499e5 100644 (file)
@@ -6,8 +6,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
   use Pleroma.Web.ConnCase
 
   alias Pleroma.Web.TwitterAPI.TwitterAPI
-  alias Pleroma.{Repo, User, Object, Activity, Notification}
-  alias Pleroma.Web.{OStatus, CommonAPI}
+  alias Pleroma.Repo
+  alias Pleroma.User
+  alias Pleroma.Object
+  alias Pleroma.Activity
+  alias Pleroma.Notification
+  alias Pleroma.Web.OStatus
+  alias Pleroma.Web.CommonAPI
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.MastodonAPI.FilterView
   alias Ecto.Changeset
@@ -31,7 +36,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
       |> assign(:user, user)
       |> get("/api/v1/timelines/home")
 
-    assert length(json_response(conn, 200)) == 0
+    assert Enum.empty?(json_response(conn, 200))
 
     {:ok, user} = User.follow(user, following)
 
index 2106253f2390efd4c435daf3d63908deefd880b2..0dc9c538cb5b255cfa624e315feabda0c2a1db42 100644 (file)
@@ -5,7 +5,8 @@
 defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
   use Pleroma.DataCase
 
-  alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
+  alias Pleroma.Web.MastodonAPI.AccountView
+  alias Pleroma.Web.MastodonAPI.StatusView
   alias Pleroma.User
   alias Pleroma.Web.OStatus
   alias Pleroma.Web.CommonAPI
index 3b1ddada81e70fcce978833e8782d4b8da472aae..81618e9350c2d2c4cacabd3a3514a373fe8ca2c4 100644 (file)
@@ -4,7 +4,8 @@
 
 defmodule Pleroma.Web.OAuth.AuthorizationTest do
   use Pleroma.DataCase
-  alias Pleroma.Web.OAuth.{Authorization, App}
+  alias Pleroma.Web.OAuth.Authorization
+  alias Pleroma.Web.OAuth.App
   import Pleroma.Factory
 
   test "create an authorization token for a valid app" do
index e0d3cb55f916d0ccafc777457251028db12e90bf..2315f9a34b6186e19da2a5a4650936827b9f7612 100644 (file)
@@ -7,7 +7,8 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
   import Pleroma.Factory
 
   alias Pleroma.Repo
-  alias Pleroma.Web.OAuth.{Authorization, Token}
+  alias Pleroma.Web.OAuth.Authorization
+  alias Pleroma.Web.OAuth.Token
 
   test "redirects with oauth authorization" do
     user = insert(:user)
index 9a241d61a04d20806df97538430a0046042d65e7..4dab4a30807d7a1ab80895a7d5c429f47c0b05a9 100644 (file)
@@ -4,7 +4,9 @@
 
 defmodule Pleroma.Web.OAuth.TokenTest do
   use Pleroma.DataCase
-  alias Pleroma.Web.OAuth.{App, Token, Authorization}
+  alias Pleroma.Web.OAuth.App
+  alias Pleroma.Web.OAuth.Authorization
+  alias Pleroma.Web.OAuth.Token
   alias Pleroma.Repo
 
   import Pleroma.Factory
index 0869f2fd509734abe149211a6b6e6e957155fc12..eebc5c040057036de50385267ac64e93f59dafde 100644 (file)
@@ -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
 
index 55717dec7b8a1341e657b98d904fbc00fda4b016..efd4e7217ed1cb7e394fedf6b0a7625a76581ca6 100644 (file)
@@ -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
index d97cd79f4df10773e071bb6635887378ccc9c636..d295cc539f9d194a29ab66965c107a83e2943919 100644 (file)
@@ -4,7 +4,9 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
   import Pleroma.Factory
   import Tesla.Mock
 
-  alias Pleroma.{Repo, Activity, Object}
+  alias Pleroma.Repo
+  alias Pleroma.Activity
+  alias Pleroma.Object
   alias Pleroma.Web.OStatus
 
   setup do
index 3145ca9a1ab7a010f3364f84e67f717962ed91e8..da9c72be82b54b5cf49f059cdd4a00ad390cc36e 100644 (file)
@@ -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
 
index dbe5de2e21e132a89c74642415c69fa79a37011d..b4b19ab05351167166f31598b30317b13ca94986 100644 (file)
@@ -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, Instances}
+  alias Pleroma.Object
+  alias Pleroma.Repo
+  alias Pleroma.User
+  alias Pleroma.Activity
+  alias Pleroma.Instances
   import Pleroma.Factory
   import ExUnit.CaptureLog
 
index c539a28b263e8ba159daba0652ce62ed7767f2a2..9e583ba40229e6cfb5247c93c8925670f47e2726 100644 (file)
@@ -5,7 +5,9 @@
 defmodule Pleroma.Web.Salmon.SalmonTest do
   use Pleroma.DataCase
   alias Pleroma.Web.Salmon
-  alias Pleroma.{Repo, Activity, User}
+  alias Pleroma.Activity
+  alias Pleroma.Repo
+  alias Pleroma.User
   import Pleroma.Factory
 
   @magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
index ea5813733d6575c382f864176567e50b6d35f67c..365c7f6599310ea2ead8b2847086222f8d680427 100644 (file)
@@ -4,8 +4,11 @@
 
 defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
   use Pleroma.DataCase
-  alias Pleroma.{User, Activity, Object}
-  alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, ObjectRepresenter}
+  alias Pleroma.User
+  alias Pleroma.Activity
+  alias Pleroma.Object
+  alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
+  alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.TwitterAPI.UserView
   import Pleroma.Factory
index 855ae1526ba9d0edfabafe73724667536f9ad0e3..acb03b146fee5993f4f24c281902fda4c68ed1a4 100644 (file)
@@ -5,8 +5,13 @@
 defmodule Pleroma.Web.TwitterAPI.ControllerTest do
   use Pleroma.Web.ConnCase
   alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
-  alias Pleroma.Builders.{ActivityBuilder, UserBuilder}
-  alias Pleroma.{Repo, Activity, User, Object, Notification}
+  alias Pleroma.Builders.ActivityBuilder
+  alias Pleroma.Builders.UserBuilder
+  alias Pleroma.Repo
+  alias Pleroma.Activity
+  alias Pleroma.User
+  alias Pleroma.Object
+  alias Pleroma.Notification
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.TwitterAPI.UserView
   alias Pleroma.Web.TwitterAPI.NotificationView
index 48ddbcf506ecd76ef79b1853df6ea95c08b784a8..aa2a4d6508e633dbf0107d5bcd1ebd08f85a6285 100644 (file)
@@ -4,8 +4,13 @@
 
 defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
   use Pleroma.DataCase
-  alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
-  alias Pleroma.{Activity, User, Object, Repo, UserInviteToken}
+  alias Pleroma.Web.TwitterAPI.TwitterAPI
+  alias Pleroma.Web.TwitterAPI.UserView
+  alias Pleroma.Activity
+  alias Pleroma.User
+  alias Pleroma.Object
+  alias Pleroma.Repo
+  alias Pleroma.UserInviteToken
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.TwitterAPI.ActivityView
 
index 8367fc6c7616047d6095e29653523ba0a3044f9a..3a67f72926c3e53296129f6ea0d93ada2e4ca2ae 100644 (file)
@@ -5,7 +5,8 @@
 defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
   use Pleroma.DataCase
 
-  alias Pleroma.{User, Notification}
+  alias Pleroma.User
+  alias Pleroma.Notification
   alias Pleroma.Web.TwitterAPI.TwitterAPI
   alias Pleroma.Web.TwitterAPI.NotificationView
   alias Pleroma.Web.TwitterAPI.UserView
index 6492df2a0b5c0167fbf3229c41c16e9e02bdebb3..87b01d89b5cba80b5a381eb0067ef41bf7272095 100644 (file)
@@ -6,7 +6,8 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
   use Pleroma.Web.ConnCase
   import Pleroma.Factory
   alias Pleroma.Web.Websub.WebsubClientSubscription
-  alias Pleroma.{Repo, Activity}
+  alias Pleroma.Activity
+  alias Pleroma.Repo
   alias Pleroma.Web.Websub
 
   test "websub subscription request", %{conn: conn} do
@@ -80,7 +81,7 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
 
       assert response(conn, 500) == "Error"
 
-      assert length(Repo.all(Activity)) == 0
+      assert Enum.empty?(Repo.all(Activity))
     end
   end
 end
index 9751d161db225e1393de260d786e013d4d2e8d9a..9a9b9df02c0692a0f00d19c9877ade7d41c2123c 100644 (file)
@@ -5,7 +5,8 @@
 defmodule Pleroma.Web.WebsubTest do
   use Pleroma.DataCase
   alias Pleroma.Web.Websub
-  alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription}
+  alias Pleroma.Web.Websub.WebsubServerSubscription
+  alias Pleroma.Web.Websub.WebsubClientSubscription
   import Pleroma.Factory
   alias Pleroma.Web.Router.Helpers
   import Tesla.Mock