Merge pull request 'fix flaky test filter_controller_test.exs:200' (#239) from ilja...
authorfloatingghost <hannah@coffee-and-dreams.uk>
Tue, 1 Nov 2022 14:42:43 +0000 (14:42 +0000)
committerfloatingghost <hannah@coffee-and-dreams.uk>
Tue, 1 Nov 2022 14:42:43 +0000 (14:42 +0000)
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/239

CHANGELOG.md
config/description.exs
lib/pleroma/web/auth/ldap_authenticator.ex
restarter/lib/pleroma.ex
restarter/mix.exs
test/pleroma/config/transfer_task_test.exs
test/pleroma/conversation/participation_test.exs
test/pleroma/web/o_auth/ldap_authorization_test.exs
test/pleroma/web/plugs/rate_limiter_test.exs

index b3e4f371f64905699186560f17023625ad26f292..34c09cd6523c11d735cb24e1eddb21b4d76aafd8 100644 (file)
@@ -14,6 +14,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - Follows no longer override domain blocks, a domain block is final
 - Deletes are now the lowest priority to publish and will be handled after creates
 
+## Fixed
+- Registrations via ldap are now compatible with the latest OTP24
+
 ## 2022.10
 
 ### Added
index a17897b98a08f0cbd70159ee781b498e5008b6f6..1ff0a582bd6438524d0c773925c7f98f605c76cd 100644 (file)
@@ -1389,6 +1389,12 @@ config :pleroma, :config_description, [
             label: "Render misskey markdown",
             type: :boolean,
             description: "Whether to render Misskey-flavoured markdown"
+          },
+          %{
+            key: :stopGifs,
+            label: "Stop Gifs",
+            type: :boolean,
+            description: "Whether to pause animated images until they're hovered on"
           }
         ]
       },
index f77e8d20342648c012926639435b1e1b793dab8b..ccf4b41041b3f1c021a8fdd3747f3d761bf54f4b 100644 (file)
@@ -102,7 +102,7 @@ defmodule Pleroma.Web.Auth.LDAPAuthenticator do
            {:scope, :eldap.wholeSubtree()},
            {:timeout, @search_timeout}
          ]) do
-      {:ok, {:eldap_search_result, [{:eldap_entry, _, attributes}], _}} ->
+      {:ok, {:eldap_search_result, [{:eldap_entry, _, attributes}], _, _}} ->
         params = %{
           name: name,
           nickname: name,
index 149a569ce42b016910c9780814aa24999d640176..a7186cec48b87b743ed6281ac3dc0a54651464b7 100644 (file)
@@ -61,6 +61,12 @@ defmodule Restarter.Pleroma do
     {:noreply, @init_state}
   end
 
+  # Don't actually restart during tests.
+  # We just check if the correct call has been done.
+  # If we actually restart, we get errors during the tests like
+  #     (RuntimeError) could not lookup Ecto repo Pleroma.Repo because it was not started or
+  #      it does not exist
+  # See tests in Pleroma.Config.TransferTaskTest
   def handle_cast({:restart, :test, _}, state) do
     Logger.debug("pleroma manually restarted")
     {:noreply, Map.put(state, :need_reboot, false)}
@@ -74,6 +80,12 @@ defmodule Restarter.Pleroma do
 
   def handle_cast({:after_boot, _}, %{after_boot: true} = state), do: {:noreply, state}
 
+  # Don't actually restart during tests.
+  # We just check if the correct call has been done.
+  # If we actually restart, we get errors during the tests like
+  #     (RuntimeError) could not lookup Ecto repo Pleroma.Repo because it was not started or
+  #      it does not exist
+  # See tests in Pleroma.Config.TransferTaskTest
   def handle_cast({:after_boot, :test}, state) do
     Logger.debug("pleroma restarted after boot")
     state = %{state | after_boot: true, rebooted: true}
index b0908aecec046065277c0afb0189f03c8198c6ba..9f26f5f64917c9868aa45870370b726b3102efbf 100644 (file)
@@ -13,7 +13,8 @@ defmodule Restarter.MixProject do
 
   def application do
     [
-      mod: {Restarter, []}
+      mod: {Restarter, []},
+      extra_applications: [:logger]
     ]
   end
 
index 30cb92fa7e746f56963535527193b95a2101c553..988214eb158ddced9f7a7bbd62208c74706dbfbd 100644 (file)
@@ -119,44 +119,87 @@ defmodule Pleroma.Config.TransferTaskTest do
 
   describe "pleroma restart" do
     setup do
-      on_exit(fn -> Restarter.Pleroma.refresh() end)
+      on_exit(fn ->
+        Restarter.Pleroma.refresh()
+
+        # Restarter.Pleroma.refresh/0 is an asynchronous call.
+        # A GenServer will first finish the previous call before starting a new one.
+        # Here we do a synchronous call.
+        # That way we are sure that the previous call has finished before we continue.
+        # See https://stackoverflow.com/questions/51361856/how-to-use-task-await-with-genserver
+        Restarter.Pleroma.rebooted?()
+      end)
     end
 
-    @tag :erratic
     test "don't restart if no reboot time settings were changed" do
       clear_config(:emoji)
       insert(:config, key: :emoji, value: [groups: [a: 1, b: 2]])
 
       refute String.contains?(
-               capture_log(fn -> TransferTask.start_link([]) end),
+               capture_log(fn ->
+                 TransferTask.start_link([])
+
+                 # TransferTask.start_link/1 is an asynchronous call.
+                 # A GenServer will first finish the previous call before starting a new one.
+                 # Here we do a synchronous call.
+                 # That way we are sure that the previous call has finished before we continue.
+                 Restarter.Pleroma.rebooted?()
+               end),
                "pleroma restarted"
              )
     end
 
-    @tag :erratic
     test "on reboot time key" do
-      clear_config([:pleroma, :rate_limit])
-      insert(:config, key: {:pleroma, :rate_limit}, value: [enabled: false])
-      assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
+      clear_config(:rate_limit)
+      insert(:config, key: :rate_limit, value: [enabled: false])
+
+      # Note that we don't actually restart Pleroma.
+      # See module Restarter.Pleroma
+      assert capture_log(fn ->
+               TransferTask.start_link([])
+
+               # TransferTask.start_link/1 is an asynchronous call.
+               # A GenServer will first finish the previous call before starting a new one.
+               # Here we do a synchronous call.
+               # That way we are sure that the previous call has finished before we continue.
+               Restarter.Pleroma.rebooted?()
+             end) =~ "pleroma restarted"
     end
 
-    @tag :erratic
     test "on reboot time subkey" do
       clear_config(Pleroma.Captcha)
       insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
-      assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"
+
+      # Note that we don't actually restart Pleroma.
+      # See module Restarter.Pleroma
+      assert capture_log(fn ->
+               TransferTask.start_link([])
+
+               # TransferTask.start_link/1 is an asynchronous call.
+               # A GenServer will first finish the previous call before starting a new one.
+               # Here we do a synchronous call.
+               # That way we are sure that the previous call has finished before we continue.
+               Restarter.Pleroma.rebooted?()
+             end) =~ "pleroma restarted"
     end
 
-    @tag :erratic
     test "don't restart pleroma on reboot time key and subkey if there is false flag" do
-      clear_config([:pleroma, :rate_limit])
+      clear_config(:rate_limit)
       clear_config(Pleroma.Captcha)
 
-      insert(:config, key: {:pleroma, :rate_limit}, value: [enabled: false])
+      insert(:config, key: :rate_limit, value: [enabled: false])
       insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
 
       refute String.contains?(
-               capture_log(fn -> TransferTask.load_and_update_env([], false) end),
+               capture_log(fn ->
+                 TransferTask.load_and_update_env([], false)
+
+                 # TransferTask.start_link/1 is an asynchronous call.
+                 # A GenServer will first finish the previous call before starting a new one.
+                 # Here we do a synchronous call.
+                 # That way we are sure that the previous call has finished before we continue.
+                 Restarter.Pleroma.rebooted?()
+               end),
                "pleroma restarted"
              )
     end
index a25e17c957f1206b8b510cc75e67184d0b14535d..2bf57f5395502fb5be4e91b6b240e504c34067f2 100644 (file)
@@ -122,11 +122,11 @@ defmodule Pleroma.Conversation.ParticipationTest do
   end
 
   test "it marks a participation as read" do
-    participation = insert(:participation, %{read: false})
+    participation = insert(:participation, %{updated_at: ~N[2017-07-17 17:09:58], read: false})
     {:ok, updated_participation} = Participation.mark_as_read(participation)
 
     assert updated_participation.read
-    assert updated_participation.updated_at == participation.updated_at
+    assert :gt = NaiveDateTime.compare(updated_participation.updated_at, participation.updated_at)
   end
 
   test "it marks a participation as unread" do
index 61b9ce6b76d7350155666ec04fa5052a6ae05750..c8a1d65ab5f0614c6174186df96a662b589aa597 100644 (file)
@@ -71,7 +71,7 @@ defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do
          equalityMatch: fn _type, _value -> :ok end,
          wholeSubtree: fn -> :ok end,
          search: fn _connection, _options ->
-           {:ok, {:eldap_search_result, [{:eldap_entry, '', []}], []}}
+           {:ok, {:eldap_search_result, [{:eldap_entry, '', []}], [], []}}
          end,
          close: fn _connection ->
            send(self(), :close_connection)
index b7cfde1f788d47035452a119f62a82565267b1f3..83a47ea308f6011edc5e172cdad6861eaff2a568 100644 (file)
@@ -48,38 +48,42 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
     refute RateLimiter.disabled?(build_conn())
   end
 
-  @tag :erratic
   test "it restricts based on config values" do
     limiter_name = :test_plug_opts
     scale = 80
     limit = 5
 
-    clear_config([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+    clear_config([Pleroma.Web.Endpoint, :http, :ip], {127, 0, 0, 1})
     clear_config([:rate_limit, limiter_name], {scale, limit})
 
     plug_opts = RateLimiter.init(name: limiter_name)
     conn = build_conn(:get, "/")
 
-    for i <- 1..5 do
-      conn = RateLimiter.call(conn, plug_opts)
-      assert {^i, _} = RateLimiter.inspect_bucket(conn, limiter_name, plug_opts)
-      Process.sleep(10)
+    for _ <- 1..5 do
+      conn_limited = RateLimiter.call(conn, plug_opts)
+
+      refute conn_limited.status == Conn.Status.code(:too_many_requests)
+      refute conn_limited.resp_body
+      refute conn_limited.halted
     end
 
-    conn = RateLimiter.call(conn, plug_opts)
-    assert %{"error" => "Throttled"} = ConnTest.json_response(conn, :too_many_requests)
-    assert conn.halted
+    conn_limited = RateLimiter.call(conn, plug_opts)
+    assert %{"error" => "Throttled"} = ConnTest.json_response(conn_limited, :too_many_requests)
+    assert conn_limited.halted
 
-    Process.sleep(50)
+    expire_ttl(conn, limiter_name)
 
-    conn = build_conn(:get, "/")
+    for _ <- 1..5 do
+      conn_limited = RateLimiter.call(conn, plug_opts)
 
-    conn = RateLimiter.call(conn, plug_opts)
-    assert {1, 4} = RateLimiter.inspect_bucket(conn, limiter_name, plug_opts)
+      refute conn_limited.status == Conn.Status.code(:too_many_requests)
+      refute conn_limited.resp_body
+      refute conn_limited.halted
+    end
 
-    refute conn.status == Conn.Status.code(:too_many_requests)
-    refute conn.resp_body
-    refute conn.halted
+    conn_limited = RateLimiter.call(conn, plug_opts)
+    assert %{"error" => "Throttled"} = ConnTest.json_response(conn_limited, :too_many_requests)
+    assert conn_limited.halted
   end
 
   describe "options" do
@@ -263,4 +267,12 @@ defmodule Pleroma.Web.Plugs.RateLimiterTest do
 
     refute {:err, :not_found} == RateLimiter.inspect_bucket(conn, limiter_name, opts)
   end
+
+  def expire_ttl(%{remote_ip: remote_ip} = _conn, bucket_name_root) do
+    bucket_name = "anon:#{bucket_name_root}" |> String.to_atom()
+    key_name = "ip::#{remote_ip |> Tuple.to_list() |> Enum.join(".")}"
+
+    {:ok, bucket_value} = Cachex.get(bucket_name, key_name)
+    Cachex.put(bucket_name, key_name, bucket_value, ttl: -1)
+  end
 end