diff options
| author | Maksim Pechnikov <parallel588@gmail.com> | 2020-06-12 14:49:54 +0300 | 
|---|---|---|
| committer | Maksim Pechnikov <parallel588@gmail.com> | 2020-06-12 14:49:54 +0300 | 
| commit | f9dcf15ecb684b4b802d731a216448c76913d462 (patch) | |
| tree | 6947ad2cae0b79cd1ff2e123f35b93aa3e2758d3 /test/web | |
| parent | 5474b5c988d3ab8869217b72d3702fb9396adadf (diff) | |
| download | pleroma-f9dcf15ecb684b4b802d731a216448c76913d462.tar.gz pleroma-f9dcf15ecb684b4b802d731a216448c76913d462.zip  | |
added admin api for MediaProxy cache invalidation
Diffstat (limited to 'test/web')
| -rw-r--r-- | test/web/admin_api/controllers/media_proxy_cache_controller_test.exs | 66 | 
1 files changed, 66 insertions, 0 deletions
diff --git a/test/web/admin_api/controllers/media_proxy_cache_controller_test.exs b/test/web/admin_api/controllers/media_proxy_cache_controller_test.exs new file mode 100644 index 000000000..1b1d6bc36 --- /dev/null +++ b/test/web/admin_api/controllers/media_proxy_cache_controller_test.exs @@ -0,0 +1,66 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do +  use Pleroma.Web.ConnCase + +  import Pleroma.Factory + +  setup do +    admin = insert(:user, is_admin: true) +    token = insert(:oauth_admin_token, user: admin) + +    conn = +      build_conn() +      |> assign(:user, admin) +      |> assign(:token, token) + +    {:ok, %{admin: admin, token: token, conn: conn}} +  end + +  describe "GET /api/pleroma/admin/media_proxy_caches" do +    test "shows banned MediaProxy URLs", %{conn: conn} do +      response = +        conn +        |> get("/api/pleroma/admin/media_proxy_caches") +        |> json_response_and_validate_schema(200) + +      assert response["urls"] == [] +    end +  end + +  describe "DELETE /api/pleroma/admin/media_proxy_caches/delete" do +    test "deleted MediaProxy URLs from banned", %{conn: conn} do +      response = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/pleroma/admin/media_proxy_caches/delete", %{ +          urls: ["http://example.com/media/a688346.jpg", "http://example.com/media/fb1f4d.jpg"] +        }) +        |> json_response_and_validate_schema(200) + +      assert response["urls"] == [ +               "http://example.com/media/a688346.jpg", +               "http://example.com/media/fb1f4d.jpg" +             ] +    end +  end + +  describe "PURGE /api/pleroma/admin/media_proxy_caches/purge" do +    test "perform invalidates cache of MediaProxy", %{conn: conn} do +      response = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/pleroma/admin/media_proxy_caches/purge", %{ +          urls: ["http://example.com/media/a688346.jpg", "http://example.com/media/fb1f4d.jpg"] +        }) +        |> json_response_and_validate_schema(200) + +      assert response["urls"] == [ +               "http://example.com/media/a688346.jpg", +               "http://example.com/media/fb1f4d.jpg" +             ] +    end +  end +end  | 
