From adf31d596e77ef71e2ffe80d9dc41988f6c1cfb5 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Thu, 15 Aug 2019 12:07:51 +0300 Subject: [PATCH] Add tests for downloading from fallback url --- .../emoji/test_pack_nonshared/nonshared.zip | Bin 0 -> 256 bytes .../emoji/test_pack_nonshared/pack.json | 4 +- test/web/emoji_api_controller_test.exs | 40 +++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 test/instance_static/emoji/test_pack_nonshared/nonshared.zip diff --git a/test/instance_static/emoji/test_pack_nonshared/nonshared.zip b/test/instance_static/emoji/test_pack_nonshared/nonshared.zip new file mode 100644 index 0000000000000000000000000000000000000000..148446c642ea24b494bc3e25ccd772faaf2f2a13 GIT binary patch literal 256 zcmWIWW@Zs#U|`^2I2p(9A0OT*8Uf_R12HFq3`0^*VqUghL0)=j2qy#cF4@r7Q$So= z!Og(P@`9Ox0ZhE+`B41)>7++V2?-CrektH&y2Pt+hC@XnZuhYzjGD_PDeO;RYuj`( zUAMu8(_j4f1g>LGSdR&<=@xdWn#IJs;|^bzfkATSK6P%elQ2Vo rHzSiAGcLzT0G$W{OBz8ml2chBPDOKOfHx}}NFgH-`UC0NAPxfnZrnv? literal 0 HcmV?d00001 diff --git a/test/instance_static/emoji/test_pack_nonshared/pack.json b/test/instance_static/emoji/test_pack_nonshared/pack.json index b49b1efe7..b96781f81 100644 --- a/test/instance_static/emoji/test_pack_nonshared/pack.json +++ b/test/instance_static/emoji/test_pack_nonshared/pack.json @@ -4,8 +4,8 @@ "homepage": "https://pleroma.social", "description": "Test description", - "fallblack-src": "https://example.com", - "fallback-src-sha256": "65CDCCBCA9388A68023519F997367783BE69ED42864398CAC568E56F65CE0E75", + "fallback-src": "https://nonshared-pack", + "fallback-src-sha256": "74409E2674DAA06C072729C6C8426C4CB3B7E0B85ED77792DB7A436E11D76DAF", "share-files": false }, diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs index bf56c1516..aa30e3058 100644 --- a/test/web/emoji_api_controller_test.exs +++ b/test/web/emoji_api_controller_test.exs @@ -42,9 +42,10 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do assert Enum.find(arch, fn {n, _} -> n == 'blank.png' end) end - test "downloading a shared pack from another instance via download_from, deleting it" do + test "downloading shared & unshared packs from another instance via download_from, deleting them" do on_exit(fn -> File.rm_rf!("test/instance_static/emoji/test_pack2") + File.rm_rf!("test/instance_static/emoji/test_pack_nonshared2") end) mock(fn @@ -69,6 +70,12 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do |> get(emoji_api_path(conn, :download_shared, "test_pack")) |> response(200) |> text() + + %{ + method: :get, + url: "https://nonshared-pack" + } -> + text(File.read!("test/instance_static/emoji/test_pack_nonshared/nonshared.zip")) end) admin = insert(:user, info: %{is_admin: true}) @@ -101,5 +108,36 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do |> response(200) == "ok" refute File.exists?("test/instance_static/emoji/test_pack2") + + # non-shared, downloaded from the fallback URL + + conn = build_conn() + + assert conn + |> put_req_header("content-type", "application/json") + |> assign(:user, admin) + |> post( + emoji_api_path( + conn, + :download_from + ), + %{ + instance_address: "https://example.com", + pack_name: "test_pack_nonshared", + as: "test_pack_nonshared2" + } + |> Jason.encode!() + ) + |> text_response(200) == "ok" + + assert File.exists?("test/instance_static/emoji/test_pack_nonshared2/pack.json") + assert File.exists?("test/instance_static/emoji/test_pack_nonshared2/blank.png") + + assert conn + |> assign(:user, admin) + |> delete(emoji_api_path(conn, :delete, "test_pack_nonshared2")) + |> response(200) == "ok" + + refute File.exists?("test/instance_static/emoji/test_pack_nonshared2") end end