From f9dfe64ba485220bf9956f7ffd78756acf79b9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Mon, 14 Nov 2022 14:28:58 +0100 Subject: [PATCH 1/3] Privacy policy API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- config/config.exs | 3 +- config/description.exs | 6 +++ .../api_spec/operations/instance_operation.ex | 23 ++++++++++ .../controllers/instance_controller.ex | 19 ++++++++ .../web/mastodon_api/views/instance_view.ex | 6 +-- lib/pleroma/web/router.ex | 1 + .../controllers/instance_controller_test.exs | 45 +++++++++++++++++++ 7 files changed, 99 insertions(+), 4 deletions(-) diff --git a/config/config.exs b/config/config.exs index 2b6e1dade8..81d11e802d 100644 --- a/config/config.exs +++ b/config/config.exs @@ -250,7 +250,8 @@ birthday_required: false, birthday_min_age: 0, max_media_attachments: 1_000, - migration_cooldown_period: 30 + migration_cooldown_period: 30, + privacy_policy: "/instance/about/privacy.html" config :pleroma, :welcome, direct_message: [ diff --git a/config/description.exs b/config/description.exs index 2aecc78e7c..3724194349 100644 --- a/config/description.exs +++ b/config/description.exs @@ -1035,6 +1035,12 @@ description: "Number of days for which users won't be able to migrate account again after successful migration.", suggestions: [30] + }, + %{ + key: :privacy_policy, + type: :string, + description: "Privacy policy content file.", + suggestions: ["/instance/about/privacy.html"] } ] }, diff --git a/lib/pleroma/web/api_spec/operations/instance_operation.ex b/lib/pleroma/web/api_spec/operations/instance_operation.ex index 85a1cc7c6b..1d84282ffb 100644 --- a/lib/pleroma/web/api_spec/operations/instance_operation.ex +++ b/lib/pleroma/web/api_spec/operations/instance_operation.ex @@ -5,6 +5,7 @@ defmodule Pleroma.Web.ApiSpec.InstanceOperation do alias OpenApiSpex.Operation alias OpenApiSpex.Schema + alias Pleroma.Web.ApiSpec.Schemas.ApiError def open_api_operation(action) do operation = String.to_existing_atom("#{action}_operation") @@ -57,6 +58,18 @@ def rules_operation do } end + def privacy_policy_operation do + %Operation{ + tags: ["Instance"], + summary: "Retrieve instance privacy policy", + operationId: "InstanceController.privacy_policy", + responses: %{ + 200 => Operation.response("Privacy policy", "application/json", privacy_policy()), + 404 => Operation.response("Not Found", "application/json", ApiError) + } + } + end + defp instance do %Schema{ type: :object, @@ -425,4 +438,14 @@ defp array_of_rules do } } end + + defp privacy_policy do + %Schema{ + type: :object, + properties: %{ + updated_at: %Schema{type: :string, format: :"date-time"}, + content: %Schema{type: :string} + } + } + end end diff --git a/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex b/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex index 10293c990e..caa621446d 100644 --- a/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex @@ -9,6 +9,8 @@ defmodule Pleroma.Web.MastodonAPI.InstanceController do plug(:skip_auth when action in [:show, :peers]) + action_fallback(Pleroma.Web.MastodonAPI.FallbackController) + defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.InstanceOperation @doc "GET /api/v1/instance" @@ -30,4 +32,21 @@ def peers(conn, _params) do def rules(conn, _params) do render(conn, "rules.json") end + + @doc "GET /api/v1/instance/privacy_policy" + def privacy_policy(conn, _params) do + with path when is_binary(path) <- Pleroma.Config.get([:instance, :privacy_policy]), + path <- Pleroma.Web.Plugs.InstanceStatic.file_path(path), + true <- File.exists?(path), + {:ok, content} <- File.read(path), + {:ok, %{mtime: updated_at}} <- File.stat(path), + updated_at <- Timex.to_datetime(updated_at, "Etc/UTC") do + json(conn, %{ + updated_at: updated_at, + content: content + }) + else + _ -> {:error, :not_found} + end + end end diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex index 3f8d82231e..9bd5506bef 100644 --- a/lib/pleroma/web/mastodon_api/views/instance_view.ex +++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex @@ -172,7 +172,7 @@ def federation do |> Map.put(:enabled, Config.get([:instance, :federating])) end - def fields_limits do + defp fields_limits do %{ max_fields: Config.get([:instance, :max_account_fields]), max_remote_fields: Config.get([:instance, :max_remote_account_fields]), @@ -181,7 +181,7 @@ def fields_limits do } end - def configuration do + defp configuration do %{ statuses: %{ max_characters: Config.get([:instance, :limit]), @@ -200,7 +200,7 @@ def configuration do } end - def configuration2 do + defp configuration2 do configuration() |> Map.merge(%{ urls: %{streaming: Pleroma.Web.Endpoint.websocket_url()}, diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index ba6642d4b0..b863edf451 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -661,6 +661,7 @@ defmodule Pleroma.Web.Router do get("/instance", InstanceController, :show) get("/instance/peers", InstanceController, :peers) get("/instance/rules", InstanceController, :rules) + get("/instance/privacy_policy", InstanceController, :privacy_policy) get("/statuses", StatusController, :index) get("/statuses/:id", StatusController, :show) diff --git a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs index 6abd021fee..3d8b72a0d6 100644 --- a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs @@ -10,6 +10,8 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do alias Pleroma.User import Pleroma.Factory + @dir "test/instance_static_test" + test "get instance information", %{conn: conn} do clear_config([:auth, :oauth_consumer_strategies], []) @@ -154,4 +156,47 @@ test "get instance information v2", %{conn: conn} do assert get(conn, "/api/v2/instance") |> json_response_and_validate_schema(200) end + + describe "instance privacy policy" do + setup do + File.mkdir_p!(@dir) + clear_config([:instance, :static_dir], @dir) + + on_exit(fn -> + File.rm_rf(@dir) + end) + end + + test "get instance privacy policy", %{conn: conn} do + clear_config([:instance, :privacy_policy], "/instance/privacy.html") + + content = "

Privacy policy

What information do we collect?

" + + File.mkdir!(@dir <> "/instance/") + File.write!(@dir <> "/instance/privacy.html", content) + + conn = get(conn, "/api/v1/instance/privacy_policy") + + assert %{ + "content" => ^content, + "updated_at" => _ + } = json_response_and_validate_schema(conn, 200) + end + + test "returns 404 if privacy policy not specified", %{conn: conn} do + clear_config([:instance, :privacy_policy], nil) + + conn = get(conn, "/api/v1/instance/privacy_policy") + + assert json_response_and_validate_schema(conn, 404) + end + + test "returns 404 if privacy policy file does not exist", %{conn: conn} do + clear_config([:instance, :privacy_policy], "/instance/i_do_not_exist.html") + + conn = get(conn, "/api/v1/instance/privacy_policy") + + assert json_response_and_validate_schema(conn, 404) + end + end end From 9126ba769522f32ab4f88a7a6870b9ee7be51e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Mon, 14 Nov 2022 16:21:26 +0100 Subject: [PATCH 2/3] Add domain_blocks and extended_description endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- config/config.exs | 3 +- config/description.exs | 6 +++ lib/pleroma/upload.ex | 2 +- .../api_spec/operations/instance_operation.ex | 47 ++++++++++++++++++- .../controllers/instance_controller.ex | 21 ++++++++- .../web/mastodon_api/views/instance_view.ex | 33 +++++++++++++ lib/pleroma/web/router.ex | 2 + lib/pleroma/webhook.ex | 3 +- lib/pleroma/webhook/notify.ex | 2 +- .../controllers/instance_controller_test.exs | 27 +++++++++++ 10 files changed, 137 insertions(+), 9 deletions(-) diff --git a/config/config.exs b/config/config.exs index 81d11e802d..3f4a0f020c 100644 --- a/config/config.exs +++ b/config/config.exs @@ -251,7 +251,8 @@ birthday_min_age: 0, max_media_attachments: 1_000, migration_cooldown_period: 30, - privacy_policy: "/instance/about/privacy.html" + privacy_policy: "/instance/about/privacy.html", + extended_description: "/instance/about/index.html" config :pleroma, :welcome, direct_message: [ diff --git a/config/description.exs b/config/description.exs index 3724194349..83ec65c72a 100644 --- a/config/description.exs +++ b/config/description.exs @@ -1041,6 +1041,12 @@ type: :string, description: "Privacy policy content file.", suggestions: ["/instance/about/privacy.html"] + }, + %{ + key: :extended_description, + type: :string, + description: "Extended description content file.", + suggestions: ["/instance/about/index.html"] } ] }, diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 4aee9326f3..d36e5de445 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -174,7 +174,7 @@ defp prepare_upload(%Plug.Upload{} = file, opts) do defp prepare_upload(%{img: "data:image/" <> image_data}, opts) do parsed = Regex.named_captures(~r/(?jpeg|png|gif);base64,(?.*)/, image_data) data = Base.decode64!(parsed["data"], ignore: :whitespace) - hash = Base.encode16(:crypto.hash(:sha256, data), lower: true) + hash = Base.encode16(:crypto.hash(:sha256, data), case: :lower) with :ok <- check_binary_size(data, opts.size_limit), tmp_path <- tempfile_for_image(data), diff --git a/lib/pleroma/web/api_spec/operations/instance_operation.ex b/lib/pleroma/web/api_spec/operations/instance_operation.ex index 1d84282ffb..30950198ff 100644 --- a/lib/pleroma/web/api_spec/operations/instance_operation.ex +++ b/lib/pleroma/web/api_spec/operations/instance_operation.ex @@ -58,13 +58,41 @@ def rules_operation do } end + def domain_blocks_operation do + %Operation{ + tags: ["Instance"], + summary: "Retrieve instance domain blocks", + operationId: "InstanceController.domain_blocks", + responses: %{ + 200 => + Operation.response( + "Array of domain blocks", + "application/json", + array_of_domain_blocks() + ) + } + } + end + def privacy_policy_operation do %Operation{ tags: ["Instance"], summary: "Retrieve instance privacy policy", operationId: "InstanceController.privacy_policy", responses: %{ - 200 => Operation.response("Privacy policy", "application/json", privacy_policy()), + 200 => Operation.response("Privacy policy", "application/json", html_content()), + 404 => Operation.response("Not Found", "application/json", ApiError) + } + } + end + + def extended_description_operation do + %Operation{ + tags: ["Instance"], + summary: "Retrieve extended instance description", + operationId: "InstanceController.extended_description", + responses: %{ + 200 => Operation.response("Extended description", "application/json", html_content()), 404 => Operation.response("Not Found", "application/json", ApiError) } } @@ -439,7 +467,22 @@ defp array_of_rules do } end - defp privacy_policy do + defp array_of_domain_blocks do + %Schema{ + type: :array, + items: %Schema{ + type: :object, + properties: %{ + domain: %Schema{type: :string}, + digest: %Schema{type: :string}, + severity: %Schema{type: :string}, + comment: %Schema{type: :string} + } + } + } + end + + defp html_content do %Schema{ type: :object, properties: %{ diff --git a/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex b/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex index caa621446d..172d8395e9 100644 --- a/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex @@ -33,10 +33,23 @@ def rules(conn, _params) do render(conn, "rules.json") end + @doc "GET /api/v1/instance/domain_blocks" + def domain_blocks(conn, _params) do + render(conn, "domain_blocks.json") + end + @doc "GET /api/v1/instance/privacy_policy" def privacy_policy(conn, _params) do - with path when is_binary(path) <- Pleroma.Config.get([:instance, :privacy_policy]), - path <- Pleroma.Web.Plugs.InstanceStatic.file_path(path), + render_file(conn, Pleroma.Config.get([:instance, :privacy_policy])) + end + + @doc "GET /api/v1/instance/extended_description" + def extended_description(conn, _params) do + render_file(conn, Pleroma.Config.get([:instance, :extended_description])) + end + + defp render_file(conn, path) when is_binary(path) do + with path <- Pleroma.Web.Plugs.InstanceStatic.file_path(path), true <- File.exists?(path), {:ok, content} <- File.read(path), {:ok, %{mtime: updated_at}} <- File.stat(path), @@ -49,4 +62,8 @@ def privacy_policy(conn, _params) do _ -> {:error, :not_found} end end + + defp render_file(_, _) do + {:error, :not_found} + end end diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex index 9bd5506bef..a2b136a422 100644 --- a/lib/pleroma/web/mastodon_api/views/instance_view.ex +++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex @@ -12,6 +12,11 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do @mastodon_api_level "2.7.2" + @block_severities %{ + federated_timeline_removal: "silence", + reject: "suspend" + } + def render("show.json", _) do instance = Config.get(:instance) @@ -100,6 +105,34 @@ def render("rule.json", %{rule: rule}) do } end + def render("domain_blocks.json", _) do + if Config.get([:mrf, :transparency]) do + exclusions = Config.get([:mrf, :transparency_exclusions]) |> MRF.instance_list_from_tuples() + + domain_blocks = + Config.get(:mrf_simple) + |> Enum.map(fn {rule, instances} -> + MRF.normalize_instance_list(instances) + |> Enum.reject(fn {host, _} -> + host in exclusions or not Map.has_key?(@block_severities, rule) + end) + |> Enum.map(fn {host, reason} -> + %{ + domain: host, + digest: :crypto.hash(:sha256, host) |> Base.encode16(case: :lower), + severity: Map.get(@block_severities, rule), + comment: reason + } + end) + end) + |> List.flatten() + + domain_blocks + else + [] + end + end + def features do [ "pleroma_api", diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index b863edf451..9691fbc62c 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -661,7 +661,9 @@ defmodule Pleroma.Web.Router do get("/instance", InstanceController, :show) get("/instance/peers", InstanceController, :peers) get("/instance/rules", InstanceController, :rules) + get("/instance/domain_blocks", InstanceController, :domain_blocks) get("/instance/privacy_policy", InstanceController, :privacy_policy) + get("/instance/extended_description", InstanceController, :extended_description) get("/statuses", StatusController, :index) get("/statuses/:id", StatusController, :show) diff --git a/lib/pleroma/webhook.ex b/lib/pleroma/webhook.ex index 6cf47fd687..5579b24118 100644 --- a/lib/pleroma/webhook.ex +++ b/lib/pleroma/webhook.ex @@ -94,7 +94,6 @@ defp put_secret(changeset) do end defp generate_secret do - Base.encode16(:crypto.strong_rand_bytes(20)) - |> String.downcase() + Base.encode16(:crypto.strong_rand_bytes(20), case: :lower) end end diff --git a/lib/pleroma/webhook/notify.ex b/lib/pleroma/webhook/notify.ex index ec84b89ef5..e805dee8f7 100644 --- a/lib/pleroma/webhook/notify.ex +++ b/lib/pleroma/webhook/notify.ex @@ -67,6 +67,6 @@ defp deliver(%Webhook{url: url, secret: secret}, object, type) do end defp signature(body, secret) do - :crypto.mac(:hmac, :sha256, secret, body) |> Base.encode16() + :crypto.mac(:hmac, :sha256, secret, body) |> Base.encode16(case: :lower) end end diff --git a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs index 3d8b72a0d6..370862394e 100644 --- a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs @@ -157,6 +157,33 @@ test "get instance information v2", %{conn: conn} do |> json_response_and_validate_schema(200) end + describe "instance domain blocks" do + setup do + clear_config([:mrf_simple, :reject], [{"fediverse.pl", "uses Soapbox"}]) + end + + test "get instance domain blocks", %{conn: conn} do + conn = get(conn, "/api/v1/instance/domain_blocks") + + assert [ + %{ + "comment" => "uses Soapbox", + "digest" => "55e3f44aefe7eb022d3b1daaf7396cabf7f181bf6093c8ea841e30c9fc7d8226", + "domain" => "fediverse.pl", + "severity" => "suspend" + } + ] == json_response_and_validate_schema(conn, 200) + end + + test "returns empty array if mrf transparency is disabled", %{conn: conn} do + clear_config([:mrf, :transparency], false) + + conn = get(conn, "/api/v1/instance/domain_blocks") + + assert [] == json_response_and_validate_schema(conn, 200) + end + end + describe "instance privacy policy" do setup do File.mkdir_p!(@dir) From 1175127549af9fbebe8978af46a73eead2ed95f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Mon, 14 Nov 2022 19:41:40 +0100 Subject: [PATCH 3/3] Only keep domain_blocks for now MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- config/config.exs | 4 +- config/description.exs | 12 ----- .../api_spec/operations/instance_operation.ex | 35 --------------- .../controllers/instance_controller.ex | 31 ------------- lib/pleroma/web/router.ex | 2 - .../controllers/instance_controller_test.exs | 45 ------------------- 6 files changed, 1 insertion(+), 128 deletions(-) diff --git a/config/config.exs b/config/config.exs index 3f4a0f020c..2b6e1dade8 100644 --- a/config/config.exs +++ b/config/config.exs @@ -250,9 +250,7 @@ birthday_required: false, birthday_min_age: 0, max_media_attachments: 1_000, - migration_cooldown_period: 30, - privacy_policy: "/instance/about/privacy.html", - extended_description: "/instance/about/index.html" + migration_cooldown_period: 30 config :pleroma, :welcome, direct_message: [ diff --git a/config/description.exs b/config/description.exs index 83ec65c72a..2aecc78e7c 100644 --- a/config/description.exs +++ b/config/description.exs @@ -1035,18 +1035,6 @@ description: "Number of days for which users won't be able to migrate account again after successful migration.", suggestions: [30] - }, - %{ - key: :privacy_policy, - type: :string, - description: "Privacy policy content file.", - suggestions: ["/instance/about/privacy.html"] - }, - %{ - key: :extended_description, - type: :string, - description: "Extended description content file.", - suggestions: ["/instance/about/index.html"] } ] }, diff --git a/lib/pleroma/web/api_spec/operations/instance_operation.ex b/lib/pleroma/web/api_spec/operations/instance_operation.ex index 30950198ff..b26c5a7adc 100644 --- a/lib/pleroma/web/api_spec/operations/instance_operation.ex +++ b/lib/pleroma/web/api_spec/operations/instance_operation.ex @@ -5,7 +5,6 @@ defmodule Pleroma.Web.ApiSpec.InstanceOperation do alias OpenApiSpex.Operation alias OpenApiSpex.Schema - alias Pleroma.Web.ApiSpec.Schemas.ApiError def open_api_operation(action) do operation = String.to_existing_atom("#{action}_operation") @@ -74,30 +73,6 @@ def domain_blocks_operation do } end - def privacy_policy_operation do - %Operation{ - tags: ["Instance"], - summary: "Retrieve instance privacy policy", - operationId: "InstanceController.privacy_policy", - responses: %{ - 200 => Operation.response("Privacy policy", "application/json", html_content()), - 404 => Operation.response("Not Found", "application/json", ApiError) - } - } - end - - def extended_description_operation do - %Operation{ - tags: ["Instance"], - summary: "Retrieve extended instance description", - operationId: "InstanceController.extended_description", - responses: %{ - 200 => Operation.response("Extended description", "application/json", html_content()), - 404 => Operation.response("Not Found", "application/json", ApiError) - } - } - end - defp instance do %Schema{ type: :object, @@ -481,14 +456,4 @@ defp array_of_domain_blocks do } } end - - defp html_content do - %Schema{ - type: :object, - properties: %{ - updated_at: %Schema{type: :string, format: :"date-time"}, - content: %Schema{type: :string} - } - } - end end diff --git a/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex b/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex index 172d8395e9..1e1e350c7a 100644 --- a/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/instance_controller.ex @@ -9,8 +9,6 @@ defmodule Pleroma.Web.MastodonAPI.InstanceController do plug(:skip_auth when action in [:show, :peers]) - action_fallback(Pleroma.Web.MastodonAPI.FallbackController) - defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.InstanceOperation @doc "GET /api/v1/instance" @@ -37,33 +35,4 @@ def rules(conn, _params) do def domain_blocks(conn, _params) do render(conn, "domain_blocks.json") end - - @doc "GET /api/v1/instance/privacy_policy" - def privacy_policy(conn, _params) do - render_file(conn, Pleroma.Config.get([:instance, :privacy_policy])) - end - - @doc "GET /api/v1/instance/extended_description" - def extended_description(conn, _params) do - render_file(conn, Pleroma.Config.get([:instance, :extended_description])) - end - - defp render_file(conn, path) when is_binary(path) do - with path <- Pleroma.Web.Plugs.InstanceStatic.file_path(path), - true <- File.exists?(path), - {:ok, content} <- File.read(path), - {:ok, %{mtime: updated_at}} <- File.stat(path), - updated_at <- Timex.to_datetime(updated_at, "Etc/UTC") do - json(conn, %{ - updated_at: updated_at, - content: content - }) - else - _ -> {:error, :not_found} - end - end - - defp render_file(_, _) do - {:error, :not_found} - end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 9691fbc62c..a07ba912f8 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -662,8 +662,6 @@ defmodule Pleroma.Web.Router do get("/instance/peers", InstanceController, :peers) get("/instance/rules", InstanceController, :rules) get("/instance/domain_blocks", InstanceController, :domain_blocks) - get("/instance/privacy_policy", InstanceController, :privacy_policy) - get("/instance/extended_description", InstanceController, :extended_description) get("/statuses", StatusController, :index) get("/statuses/:id", StatusController, :show) diff --git a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs index 370862394e..0697820c3d 100644 --- a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs @@ -10,8 +10,6 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do alias Pleroma.User import Pleroma.Factory - @dir "test/instance_static_test" - test "get instance information", %{conn: conn} do clear_config([:auth, :oauth_consumer_strategies], []) @@ -183,47 +181,4 @@ test "returns empty array if mrf transparency is disabled", %{conn: conn} do assert [] == json_response_and_validate_schema(conn, 200) end end - - describe "instance privacy policy" do - setup do - File.mkdir_p!(@dir) - clear_config([:instance, :static_dir], @dir) - - on_exit(fn -> - File.rm_rf(@dir) - end) - end - - test "get instance privacy policy", %{conn: conn} do - clear_config([:instance, :privacy_policy], "/instance/privacy.html") - - content = "

Privacy policy

What information do we collect?

" - - File.mkdir!(@dir <> "/instance/") - File.write!(@dir <> "/instance/privacy.html", content) - - conn = get(conn, "/api/v1/instance/privacy_policy") - - assert %{ - "content" => ^content, - "updated_at" => _ - } = json_response_and_validate_schema(conn, 200) - end - - test "returns 404 if privacy policy not specified", %{conn: conn} do - clear_config([:instance, :privacy_policy], nil) - - conn = get(conn, "/api/v1/instance/privacy_policy") - - assert json_response_and_validate_schema(conn, 404) - end - - test "returns 404 if privacy policy file does not exist", %{conn: conn} do - clear_config([:instance, :privacy_policy], "/instance/i_do_not_exist.html") - - conn = get(conn, "/api/v1/instance/privacy_policy") - - assert json_response_and_validate_schema(conn, 404) - end - end end