cherry-pick security from upstream
[akkoma] / test / pleroma / web / plugs / cache_test.exs
index 105b170f00e5704243cdfa494f32d5fe1f699506..4e729cafbbadcb408a8f62a093f68aca312a4461 100644 (file)
@@ -1,12 +1,13 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Plugs.CacheTest do
-  use ExUnit.Case, async: true
+  # Relies on Cachex, has to stay synchronous
+  use Pleroma.DataCase
   use Plug.Test
 
-  alias Pleroma.Plugs.Cache
+  alias Pleroma.Web.Plugs.Cache
 
   @miss_resp {200,
               [
@@ -24,11 +25,6 @@ defmodule Pleroma.Web.Plugs.CacheTest do
 
   @ttl 5
 
-  setup do
-    Cachex.clear(:web_resp_cache)
-    :ok
-  end
-
   test "caches a response" do
     assert @miss_resp ==
              conn(:get, "/")
@@ -183,4 +179,22 @@ defmodule Pleroma.Web.Plugs.CacheTest do
              |> send_resp(:im_a_teapot, "🥤")
              |> sent_resp()
   end
+
+  test "ignores if skip_cache is assigned" do
+    assert @miss_resp ==
+             conn(:get, "/")
+             |> assign(:skip_cache, true)
+             |> Cache.call(%{query_params: false, ttl: nil})
+             |> put_resp_content_type("cofe/hot")
+             |> send_resp(:ok, "cofe")
+             |> sent_resp()
+
+    assert @miss_resp ==
+             conn(:get, "/")
+             |> assign(:skip_cache, true)
+             |> Cache.call(%{query_params: false, ttl: nil})
+             |> put_resp_content_type("cofe/hot")
+             |> send_resp(:ok, "cofe")
+             |> sent_resp()
+  end
 end