diff options
Diffstat (limited to 'test/web')
| -rw-r--r-- | test/web/mastodon_api/mastodon_api_controller_test.exs | 2 | ||||
| -rw-r--r-- | test/web/twitter_api/twitter_api_controller_test.exs | 67 | ||||
| -rw-r--r-- | test/web/twitter_api/twitter_api_test.exs | 3 | 
3 files changed, 66 insertions, 6 deletions
| diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 098acb59f..b5839cff1 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -804,7 +804,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do        }        media = -        TwitterAPI.upload(file, "json") +        TwitterAPI.upload(file, user, "json")          |> Poison.decode!()        {:ok, image_post} = diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 478763de7..c07dc6912 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -1254,15 +1254,74 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do      end    end -  describe "POST /api/media/metadata/create" do -    test "it updates `data[name]` of referenced Object with provided value", %{conn: conn} do +  describe "POST /api/media/upload" do +    setup context do +      Pleroma.DataCase.ensure_local_uploader(context) +    end + +    test "it performs the upload and sets `data[actor]` with AP id of uploader user", %{ +      conn: conn +    } do        user = insert(:user) + +      upload_filename = "test/fixtures/image_tmp.jpg" +      File.cp!("test/fixtures/image.jpg", upload_filename) + +      file = %Plug.Upload{ +        content_type: "image/jpg", +        path: Path.absname(upload_filename), +        filename: "image.jpg" +      } + +      response = +        conn +        |> assign(:user, user) +        |> put_req_header("content-type", "application/octet-stream") +        |> post("/api/media/upload", %{ +          "media" => file +        }) +        |> json_response(:ok) + +      assert response["media_id"] +      object = Repo.get(Object, response["media_id"]) +      assert object +      assert object.data["actor"] == User.ap_id(user) +    end +  end + +  describe "POST /api/media/metadata/create" do +    setup do        object = insert(:note) -      description = "Informative description of the image. Initial: #{object.data["name"]}}" +      user = User.get_by_ap_id(object.data["actor"]) +      %{object: object, user: user} +    end + +    test "it returns :forbidden status on attempt to modify someone else's upload", %{ +      conn: conn, +      object: object +    } do +      initial_description = object.data["name"] +      another_user = insert(:user) + +      conn +      |> assign(:user, another_user) +      |> post("/api/media/metadata/create", %{"media_id" => object.id}) +      |> json_response(:forbidden) + +      object = Repo.get(Object, object.id) +      assert object.data["name"] == initial_description +    end + +    test "it updates `data[name]` of referenced Object with provided value", %{ +      conn: conn, +      object: object, +      user: user +    } do +      description = "Informative description of the image. Initial value: #{object.data["name"]}}"        conn        |> assign(:user, user) -      |> post("/api/media/metadata/create.json", %{ +      |> post("/api/media/metadata/create", %{          "media_id" => object.id,          "alt_text" => %{"text" => description}        }) diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 28230699f..e34fbbabd 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -182,13 +182,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do    end    test "upload a file" do +    user = insert(:user)      file = %Plug.Upload{        content_type: "image/jpg",        path: Path.absname("test/fixtures/image.jpg"),        filename: "an_image.jpg"      } -    response = TwitterAPI.upload(file) +    response = TwitterAPI.upload(file, user)      assert is_binary(response)    end | 
