summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/test.exs1
-rw-r--r--docs/config.md2
-rw-r--r--lib/pleroma/instances/instance.ex25
-rw-r--r--lib/pleroma/mime.ex10
-rw-r--r--lib/pleroma/object.ex43
-rw-r--r--lib/pleroma/upload.ex4
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex15
-rw-r--r--lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex2
-rw-r--r--lib/pleroma/web/activity_pub/utils.ex2
-rw-r--r--lib/pleroma/web/federator/federator.ex4
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex17
-rw-r--r--lib/pleroma/web/salmon/salmon.ex30
-rw-r--r--lib/pleroma/web/websub/websub.ex14
-rw-r--r--test/support/conn_case.ex1
-rw-r--r--test/support/data_case.ex1
-rw-r--r--test/web/activity_pub/activity_pub_test.exs73
-rw-r--r--test/web/federator_test.exs37
-rw-r--r--test/web/instances/instances_test.exs23
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs5
-rw-r--r--test/web/ostatus/ostatus_test.exs2
-rw-r--r--test/web/twitter_api/twitter_api_test.exs15
21 files changed, 256 insertions, 70 deletions
diff --git a/config/test.exs b/config/test.exs
index 67ed4737f..412970d93 100644
--- a/config/test.exs
+++ b/config/test.exs
@@ -36,6 +36,7 @@ config :pbkdf2_elixir, rounds: 1
config :pleroma, :websub, Pleroma.Web.WebsubMock
config :pleroma, :ostatus, Pleroma.Web.OStatusMock
config :tesla, adapter: Tesla.Mock
+config :pleroma, :rich_media, enabled: false
config :web_push_encryption, :vapid_details,
subject: "mailto:administrator@example.com",
diff --git a/docs/config.md b/docs/config.md
index ed253e906..e042d216f 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -17,7 +17,7 @@ Note: `strip_exif` has been replaced by `Pleroma.Upload.Filter.Mogrify`.
## Pleroma.Upload.Filter.Mogrify
-* `args`: List of actions for the `mogrify` command like `"strip"` or `["strip", {"impode", "1"}]`.
+* `args`: List of actions for the `mogrify` command like `"strip"` or `["strip", "auto-orient", {"impode", "1"}]`.
## Pleroma.Upload.Filter.Dedupe
diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex
index a87590d8b..4a4ca26dd 100644
--- a/lib/pleroma/instances/instance.ex
+++ b/lib/pleroma/instances/instance.ex
@@ -26,7 +26,7 @@ defmodule Pleroma.Instances.Instance do
|> unique_constraint(:host)
end
- def filter_reachable([]), do: []
+ def filter_reachable([]), do: %{}
def filter_reachable(urls_or_hosts) when is_list(urls_or_hosts) do
hosts =
@@ -34,17 +34,28 @@ defmodule Pleroma.Instances.Instance do
|> Enum.map(&(&1 && host(&1)))
|> Enum.filter(&(to_string(&1) != ""))
- unreachable_hosts =
+ unreachable_since_by_host =
Repo.all(
from(i in Instance,
- where:
- i.host in ^hosts and
- i.unreachable_since <= ^Instances.reachability_datetime_threshold(),
- select: i.host
+ where: i.host in ^hosts,
+ select: {i.host, i.unreachable_since}
)
)
+ |> Map.new(& &1)
- Enum.filter(urls_or_hosts, &(&1 && host(&1) not in unreachable_hosts))
+ reachability_datetime_threshold = Instances.reachability_datetime_threshold()
+
+ for entry <- Enum.filter(urls_or_hosts, &is_binary/1) do
+ host = host(entry)
+ unreachable_since = unreachable_since_by_host[host]
+
+ if !unreachable_since ||
+ NaiveDateTime.compare(unreachable_since, reachability_datetime_threshold) == :gt do
+ {entry, unreachable_since}
+ end
+ end
+ |> Enum.filter(& &1)
+ |> Map.new(& &1)
end
def reachable?(url_or_host) when is_binary(url_or_host) do
diff --git a/lib/pleroma/mime.ex b/lib/pleroma/mime.ex
index 84fb536e0..36771533f 100644
--- a/lib/pleroma/mime.ex
+++ b/lib/pleroma/mime.ex
@@ -102,10 +102,18 @@ defmodule Pleroma.MIME do
"audio/ogg"
end
- defp check_mime_type(<<0x52, 0x49, 0x46, 0x46, _::binary>>) do
+ defp check_mime_type(<<"RIFF", _::binary-size(4), "WAVE", _::binary>>) do
"audio/wav"
end
+ defp check_mime_type(<<"RIFF", _::binary-size(4), "WEBP", _::binary>>) do
+ "image/webp"
+ end
+
+ defp check_mime_type(<<"RIFF", _::binary-size(4), "AVI.", _::binary>>) do
+ "video/avi"
+ end
+
defp check_mime_type(_) do
@default
end
diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex
index 1088bb5e4..7b46a3b05 100644
--- a/lib/pleroma/object.ex
+++ b/lib/pleroma/object.ex
@@ -42,24 +42,18 @@ defmodule Pleroma.Object do
# Legacy objects can be mutated by anybody
def authorize_mutation(%Object{}, %User{}), do: true
- if Mix.env() == :test do
- def get_cached_by_ap_id(ap_id) do
- get_by_ap_id(ap_id)
- end
- else
- def get_cached_by_ap_id(ap_id) do
- key = "object:#{ap_id}"
-
- Cachex.fetch!(:object_cache, key, fn _ ->
- object = get_by_ap_id(ap_id)
-
- if object do
- {:commit, object}
- else
- {:ignore, object}
- end
- end)
- end
+ def get_cached_by_ap_id(ap_id) do
+ key = "object:#{ap_id}"
+
+ Cachex.fetch!(:object_cache, key, fn _ ->
+ object = get_by_ap_id(ap_id)
+
+ if object do
+ {:commit, object}
+ else
+ {:ignore, object}
+ end
+ end)
end
def context_mapping(context) do
@@ -90,4 +84,17 @@ defmodule Pleroma.Object do
{:ok, object}
end
end
+
+ def set_cache(%Object{data: %{"id" => ap_id}} = object) do
+ Cachex.put(:object_cache, "object:#{ap_id}", object)
+ {:ok, object}
+ end
+
+ def update_and_set_cache(changeset) do
+ with {:ok, object} <- Repo.update(changeset) do
+ set_cache(object)
+ else
+ e -> e
+ end
+ end
end
diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex
index 0a19e737b..ce2a1b696 100644
--- a/lib/pleroma/upload.ex
+++ b/lib/pleroma/upload.ex
@@ -124,10 +124,10 @@ defmodule Pleroma.Upload do
:pleroma, Pleroma.Upload, [filters: [Pleroma.Upload.Filter.Mogrify]]
- :pleroma, Pleroma.Upload.Filter.Mogrify, args: "strip"
+ :pleroma, Pleroma.Upload.Filter.Mogrify, args: ["strip", "auto-orient"]
""")
- Pleroma.Config.put([Pleroma.Upload.Filter.Mogrify], args: "strip")
+ Pleroma.Config.put([Pleroma.Upload.Filter.Mogrify], args: ["strip", "auto-orient"])
Map.put(opts, :filters, opts.filters ++ [Pleroma.Upload.Filter.Mogrify])
else
opts
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 06e8c3f1c..4635e7fcd 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -744,7 +744,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
public = is_public?(activity)
- remote_inboxes =
+ reachable_inboxes_metadata =
(Pleroma.Web.Salmon.remote_users(activity) ++ remote_followers)
|> Enum.filter(fn user -> User.ap_enabled?(user) end)
|> Enum.map(fn %{info: %{source_data: data}} ->
@@ -757,17 +757,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
json = Jason.encode!(data)
- Enum.each(remote_inboxes, fn inbox ->
+ Enum.each(reachable_inboxes_metadata, fn {inbox, unreachable_since} ->
Federator.enqueue(:publish_single_ap, %{
inbox: inbox,
json: json,
actor: actor,
- id: activity.data["id"]
+ id: activity.data["id"],
+ unreachable_since: unreachable_since
})
end)
end
- def publish_one(%{inbox: inbox, json: json, actor: actor, id: id}) do
+ def publish_one(%{inbox: inbox, json: json, actor: actor, id: id} = params) do
Logger.info("Federating #{id} to #{inbox}")
host = URI.parse(inbox).host
@@ -791,11 +792,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
{"digest", digest}
]
) do
- Instances.set_reachable(inbox)
+ if !Map.has_key?(params, :unreachable_since) || params[:unreachable_since],
+ do: Instances.set_reachable(inbox)
+
result
else
{_post_result, response} ->
- Instances.set_unreachable(inbox)
+ unless params[:unreachable_since], do: Instances.set_unreachable(inbox)
{:error, response}
end
end
diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex
index dd0d6dd5f..4c6e612b2 100644
--- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex
+++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex
@@ -44,5 +44,5 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
end
@impl true
- def filter(message), do: {:ok_notcreate, message}
+ def filter(message), do: {:ok, message}
end
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index 3b0cdfe71..4a2cc6738 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -285,7 +285,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|> Map.put("#{property}_count", length(element))
|> Map.put("#{property}s", element),
changeset <- Changeset.change(object, data: new_data),
- {:ok, object} <- Repo.update(changeset),
+ {:ok, object} <- Object.update_and_set_cache(changeset),
_ <- update_object_in_activities(object) do
{:ok, object}
end
diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex
index 46f7a4973..bb7676cf0 100644
--- a/lib/pleroma/web/federator/federator.ex
+++ b/lib/pleroma/web/federator/federator.ex
@@ -124,8 +124,8 @@ defmodule Pleroma.Web.Federator do
end
end
- def handle(:publish_single_salmon, {user_or_url, feed, poster}) do
- Salmon.send_to_user(user_or_url, feed, poster)
+ def handle(:publish_single_salmon, params) do
+ Salmon.send_to_user(params)
end
def handle(:publish_single_ap, params) do
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index d5b7e68c7..d1b11d4f1 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -182,8 +182,19 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
end
def render("card.json", %{rich_media: rich_media, page_url: page_url}) do
- page_url = rich_media[:url] || page_url
- page_url_data = URI.parse(page_url)
+ page_url_data =
+ if rich_media[:url] != nil do
+ URI.merge(URI.parse(page_url), URI.parse(rich_media[:url]))
+ else
+ page_url
+ end
+
+ page_url = page_url_data |> to_string
+
+ image_url =
+ URI.merge(page_url_data, URI.parse(rich_media[:image]))
+ |> to_string
+
site_name = rich_media[:site_name] || page_url_data.host
%{
@@ -191,7 +202,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
provider_name: site_name,
provider_url: page_url_data.scheme <> "://" <> page_url_data.host,
url: page_url,
- image: rich_media[:image] |> MediaProxy.url(),
+ image: image_url |> MediaProxy.url(),
title: rich_media[:title],
description: rich_media[:description],
pleroma: %{
diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex
index 07ca42a5f..b1c2dc7fa 100644
--- a/lib/pleroma/web/salmon/salmon.ex
+++ b/lib/pleroma/web/salmon/salmon.ex
@@ -162,30 +162,31 @@ defmodule Pleroma.Web.Salmon do
|> Enum.filter(fn user -> user && !user.local end)
end
- # push an activity to remote accounts
- #
- def send_to_user(%{info: %{salmon: salmon}}, feed, poster),
- do: send_to_user(salmon, feed, poster)
+ @doc "Pushes an activity to remote account."
+ def send_to_user(%{recipient: %{info: %{salmon: salmon}}} = params),
+ do: send_to_user(Map.put(params, :recipient, salmon))
- def send_to_user(url, feed, poster) when is_binary(url) do
+ def send_to_user(%{recipient: url, feed: feed, poster: poster} = params) when is_binary(url) do
with {:ok, %{status: code}} when code in 200..299 <-
poster.(
url,
feed,
[{"Content-Type", "application/magic-envelope+xml"}]
) do
- Instances.set_reachable(url)
+ if !Map.has_key?(params, :unreachable_since) || params[:unreachable_since],
+ do: Instances.set_reachable(url)
+
Logger.debug(fn -> "Pushed to #{url}, code #{code}" end)
:ok
else
e ->
- Instances.set_unreachable(url)
+ unless params[:unreachable_since], do: Instances.set_reachable(url)
Logger.debug(fn -> "Pushing Salmon to #{url} failed, #{inspect(e)}" end)
:error
end
end
- def send_to_user(_, _, _), do: :noop
+ def send_to_user(_), do: :noop
@supported_activities [
"Create",
@@ -218,13 +219,20 @@ defmodule Pleroma.Web.Salmon do
remote_users = remote_users(activity)
salmon_urls = Enum.map(remote_users, & &1.info.salmon)
- reachable_salmon_urls = Instances.filter_reachable(salmon_urls)
+ reachable_urls_metadata = Instances.filter_reachable(salmon_urls)
+ reachable_urls = Map.keys(reachable_urls_metadata)
remote_users
- |> Enum.filter(&(&1.info.salmon in reachable_salmon_urls))
+ |> Enum.filter(&(&1.info.salmon in reachable_urls))
|> Enum.each(fn remote_user ->
Logger.debug(fn -> "Sending Salmon to #{remote_user.ap_id}" end)
- Pleroma.Web.Federator.enqueue(:publish_single_salmon, {remote_user, feed, poster})
+
+ Pleroma.Web.Federator.enqueue(:publish_single_salmon, %{
+ recipient: remote_user,
+ feed: feed,
+ poster: poster,
+ unreachable_since: reachable_urls_metadata[remote_user.info.salmon]
+ })
end)
end
end
diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex
index 8f7d53b03..90ba79962 100644
--- a/lib/pleroma/web/websub/websub.ex
+++ b/lib/pleroma/web/websub/websub.ex
@@ -70,7 +70,8 @@ defmodule Pleroma.Web.Websub do
subscriptions = Repo.all(query)
callbacks = Enum.map(subscriptions, & &1.callback)
- reachable_callbacks = Instances.filter_reachable(callbacks)
+ reachable_callbacks_metadata = Instances.filter_reachable(callbacks)
+ reachable_callbacks = Map.keys(reachable_callbacks_metadata)
subscriptions
|> Enum.filter(&(&1.callback in reachable_callbacks))
@@ -79,7 +80,8 @@ defmodule Pleroma.Web.Websub do
xml: response,
topic: topic,
callback: sub.callback,
- secret: sub.secret
+ secret: sub.secret,
+ unreachable_since: reachable_callbacks_metadata[sub.callback]
}
Pleroma.Web.Federator.enqueue(:publish_single_websub, data)
@@ -268,7 +270,7 @@ defmodule Pleroma.Web.Websub do
end)
end
- def publish_one(%{xml: xml, topic: topic, callback: callback, secret: secret}) do
+ def publish_one(%{xml: xml, topic: topic, callback: callback, secret: secret} = params) do
signature = sign(secret || "", xml)
Logger.info(fn -> "Pushing #{topic} to #{callback}" end)
@@ -281,12 +283,14 @@ defmodule Pleroma.Web.Websub do
{"X-Hub-Signature", "sha1=#{signature}"}
]
) do
- Instances.set_reachable(callback)
+ if !Map.has_key?(params, :unreachable_since) || params[:unreachable_since],
+ do: Instances.set_reachable(callback)
+
Logger.info(fn -> "Pushed to #{callback}, code #{code}" end)
{:ok, code}
else
{_post_result, response} ->
- Instances.set_unreachable(callback)
+ unless params[:unreachable_since], do: Instances.set_reachable(callback)
Logger.debug(fn -> "Couldn't push to #{callback}, #{inspect(response)}" end)
{:error, response}
end
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index c201d9a9b..ec5892ff5 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -33,6 +33,7 @@ defmodule Pleroma.Web.ConnCase do
setup tags do
Cachex.clear(:user_cache)
+ Cachex.clear(:object_cache)
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
unless tags[:async] do
diff --git a/test/support/data_case.ex b/test/support/data_case.ex
index 56d5896ad..df260bd3f 100644
--- a/test/support/data_case.ex
+++ b/test/support/data_case.ex
@@ -32,6 +32,7 @@ defmodule Pleroma.DataCase do
setup tags do
Cachex.clear(:user_cache)
+ Cachex.clear(:object_cache)
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
unless tags[:async] do
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 2ada4f2e5..a55961ac4 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -698,7 +698,57 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
describe "publish_one/1" do
- test_with_mock "it calls `Instances.set_unreachable` on target inbox on non-2xx HTTP response code",
+ test_with_mock "calls `Instances.set_reachable` on successful federation if `unreachable_since` is not specified",
+ Instances,
+ [:passthrough],
+ [] do
+ actor = insert(:user)
+ inbox = "http://200.site/users/nick1/inbox"
+
+ assert {:ok, _} = ActivityPub.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
+
+ assert called(Instances.set_reachable(inbox))
+ end
+
+ test_with_mock "calls `Instances.set_reachable` on successful federation if `unreachable_since` is set",
+ Instances,
+ [:passthrough],
+ [] do
+ actor = insert(:user)
+ inbox = "http://200.site/users/nick1/inbox"
+
+ assert {:ok, _} =
+ ActivityPub.publish_one(%{
+ inbox: inbox,
+ json: "{}",
+ actor: actor,
+ id: 1,
+ unreachable_since: NaiveDateTime.utc_now()
+ })
+
+ assert called(Instances.set_reachable(inbox))
+ end
+
+ test_with_mock "does NOT call `Instances.set_reachable` on successful federation if `unreachable_since` is nil",
+ Instances,
+ [:passthrough],
+ [] do
+ actor = insert(:user)
+ inbox = "http://200.site/users/nick1/inbox"
+
+ assert {:ok, _} =
+ ActivityPub.publish_one(%{
+ inbox: inbox,
+ json: "{}",
+ actor: actor,
+ id: 1,
+ unreachable_since: nil
+ })
+
+ refute called(Instances.set_reachable(inbox))
+ end
+
+ test_with_mock "calls `Instances.set_unreachable` on target inbox on non-2xx HTTP response code",
Instances,
[:passthrough],
[] do
@@ -724,7 +774,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert called(Instances.set_unreachable(inbox))
end
- test_with_mock "it does NOT call `Instances.set_unreachable` if target is reachable",
+ test_with_mock "does NOT call `Instances.set_unreachable` if target is reachable",
Instances,
[:passthrough],
[] do
@@ -735,6 +785,25 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
refute called(Instances.set_unreachable(inbox))
end
+
+ test_with_mock "does NOT call `Instances.set_unreachable` if target instance has non-nil `unreachable_since`",
+ Instances,
+ [:passthrough],
+ [] do
+ actor = insert(:user)
+ inbox = "http://connrefused.site/users/nick1/inbox"
+
+ assert {:error, _} =
+ ActivityPub.publish_one(%{
+ inbox: inbox,
+ json: "{}",
+ actor: actor,
+ id: 1,
+ unreachable_since: NaiveDateTime.utc_now()
+ })
+
+ refute called(Instances.set_unreachable(inbox))
+ end
end
def data_uri do
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index c6d10ef78..05f813291 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -95,15 +95,18 @@ defmodule Pleroma.Web.FederatorTest do
info: %{ap_enabled: true, source_data: %{"inbox" => inbox2}}
})
- Instances.set_unreachable(
- URI.parse(inbox2).host,
- Instances.reachability_datetime_threshold()
- )
+ dt = NaiveDateTime.utc_now()
+ Instances.set_unreachable(inbox1, dt)
+
+ Instances.set_consistently_unreachable(URI.parse(inbox2).host)
{:ok, _activity} =
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
- assert called(Federator.enqueue(:publish_single_ap, %{inbox: inbox1}))
+ assert called(
+ Federator.enqueue(:publish_single_ap, %{inbox: inbox1, unreachable_since: dt})
+ )
+
refute called(Federator.enqueue(:publish_single_ap, %{inbox: inbox2}))
end
@@ -128,11 +131,20 @@ defmodule Pleroma.Web.FederatorTest do
callback: "https://pleroma2.soykaf.com/cb"
})
+ dt = NaiveDateTime.utc_now()
+ Instances.set_unreachable(sub2.callback, dt)
+
Instances.set_consistently_unreachable(sub1.callback)
{:ok, _activity} = CommonAPI.post(user, %{"status" => "HI"})
- assert called(Federator.enqueue(:publish_single_websub, %{callback: sub2.callback}))
+ assert called(
+ Federator.enqueue(:publish_single_websub, %{
+ callback: sub2.callback,
+ unreachable_since: dt
+ })
+ )
+
refute called(Federator.enqueue(:publish_single_websub, %{callback: sub1.callback}))
end
@@ -158,13 +170,22 @@ defmodule Pleroma.Web.FederatorTest do
info: %{salmon: "https://domain2.com/salmon"}
})
+ dt = NaiveDateTime.utc_now()
+ Instances.set_unreachable(remote_user2.ap_id, dt)
+
Instances.set_consistently_unreachable("domain.com")
{:ok, _activity} =
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
- assert called(Federator.enqueue(:publish_single_salmon, {remote_user2, :_, :_}))
- refute called(Federator.enqueue(:publish_single_websub, {remote_user1, :_, :_}))
+ assert called(
+ Federator.enqueue(:publish_single_salmon, %{
+ recipient: remote_user2,
+ unreachable_since: dt
+ })
+ )
+
+ refute called(Federator.enqueue(:publish_single_websub, %{recipient: remote_user1}))
end
end
diff --git a/test/web/instances/instances_test.exs b/test/web/instances/instances_test.exs
index adb8560a7..2530c09fe 100644
--- a/test/web/instances/instances_test.exs
+++ b/test/web/instances/instances_test.exs
@@ -47,7 +47,7 @@ defmodule Pleroma.InstancesTest do
end
describe "filter_reachable/1" do
- test "keeps only reachable elements of supplied list" do
+ setup do
host = "consistently-unreachable.name"
url1 = "http://eventually-unreachable.com/path"
url2 = "http://domain.com/path"
@@ -55,7 +55,26 @@ defmodule Pleroma.InstancesTest do
Instances.set_consistently_unreachable(host)
Instances.set_unreachable(url1)
- assert [url1, url2] == Instances.filter_reachable([host, url1, url2])
+ result = Instances.filter_reachable([host, url1, url2, nil])
+ %{result: result, url1: url1, url2: url2}
+ end
+
+ test "returns a map with keys containing 'not marked consistently unreachable' elements of supplied list",
+ %{result: result, url1: url1, url2: url2} do
+ assert is_map(result)
+ assert Enum.sort([url1, url2]) == result |> Map.keys() |> Enum.sort()
+ end
+
+ test "returns a map with `unreachable_since` values for keys",
+ %{result: result, url1: url1, url2: url2} do
+ assert is_map(result)
+ assert %NaiveDateTime{} = result[url1]
+ assert is_nil(result[url2])
+ end
+
+ test "returns an empty map for empty list or list containing no hosts / url" do
+ assert %{} == Instances.filter_reachable([])
+ assert %{} == Instances.filter_reachable([nil])
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 141d300c7..8528d4f64 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -137,6 +137,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
test "posting a status with OGP link preview", %{conn: conn} do
+ Pleroma.Config.put([:rich_media, :enabled], true)
user = insert(:user)
conn =
@@ -148,6 +149,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
assert Repo.get(Activity, id)
+ Pleroma.Config.put([:rich_media, :enabled], false)
end
test "posting a direct status", %{conn: conn} do
@@ -1667,6 +1669,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
test "Status rich-media Card", %{conn: conn, user: user} do
+ Pleroma.Config.put([:rich_media, :enabled], true)
{:ok, activity} = CommonAPI.post(user, %{"status" => "http://example.com/ogp"})
response =
@@ -1691,6 +1694,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
}
}
}
+
+ Pleroma.Config.put([:rich_media, :enabled], false)
end
end
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 0c63dd84d..dbe5de2e2 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -530,6 +530,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)
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index f94e2b873..48ddbcf50 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -200,12 +200,27 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
test "it favorites a status, returns the updated activity" do
user = insert(:user)
+ other_user = insert(:user)
note_activity = insert(:note_activity)
{:ok, status} = TwitterAPI.fav(user, note_activity.id)
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
+ assert ActivityView.render("activity.json", %{activity: updated_activity})["fave_num"] == 1
+
+ object = Object.normalize(note_activity.data["object"])
+
+ assert object.data["like_count"] == 1
assert status == updated_activity
+
+ {:ok, _status} = TwitterAPI.fav(other_user, note_activity.id)
+
+ object = Object.normalize(note_activity.data["object"])
+
+ assert object.data["like_count"] == 2
+
+ updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
+ assert ActivityView.render("activity.json", %{activity: updated_activity})["fave_num"] == 2
end
test "it unfavorites a status, returns the updated activity" do