[#1560] Added tests for non-federating instance bahaviour to ActivityPubControllerTest.
authorIvan Tashkinov <ivantashkinov@gmail.com>
Mon, 2 Mar 2020 18:43:18 +0000 (21:43 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Mon, 2 Mar 2020 18:43:18 +0000 (21:43 +0300)
docs/API/differences_in_mastoapi_responses.md
docs/clients.md
test/plugs/oauth_plug_test.exs
test/web/activity_pub/activity_pub_controller_test.exs

index 06de90f717becb989802e96cc6aaefc69efd75d8..476a4a2bf804945be6d4119b4191ca67e732b675 100644 (file)
@@ -180,7 +180,7 @@ Post here request with grant_type=refresh_token to obtain new access token. Retu
 ## Account Registration
 `POST /api/v1/accounts`
 
 ## Account Registration
 `POST /api/v1/accounts`
 
-Has theses additionnal parameters (which are the same as in Pleroma-API):
+Has theses additional parameters (which are the same as in Pleroma-API):
     * `fullname`: optional
     * `bio`: optional
     * `captcha_solution`: optional, contains provider-specific captcha solution,
     * `fullname`: optional
     * `bio`: optional
     * `captcha_solution`: optional, contains provider-specific captcha solution,
index 8ac9ad3de9a2b4a3231c93bd1826d00cdab9dc45..1eae0f0c6333357add19add1bc0cf2e12ec9b120 100644 (file)
@@ -1,5 +1,5 @@
 # Pleroma Clients
 # Pleroma Clients
-Note: Additionnal clients may be working but theses are officially supporting Pleroma.
+Note: Additional clients may be working but theses are officially supporting Pleroma.
 Feel free to contact us to be added to this list!
 
 ## Desktop
 Feel free to contact us to be added to this list!
 
 ## Desktop
index dea11cdb0e1254d19dd18b7c26279dd10d55fd77..0eef27c1f94e054dcae1f3c06a419b30f0397bfc 100644 (file)
@@ -38,7 +38,7 @@ defmodule Pleroma.Plugs.OAuthPlugTest do
     assert conn.assigns[:user] == opts[:user]
   end
 
     assert conn.assigns[:user] == opts[:user]
   end
 
-  test "with valid token(downcase) in url parameters, it assings the user", opts do
+  test "with valid token(downcase) in url parameters, it assigns the user", opts do
     conn =
       :get
       |> build_conn("/?access_token=#{opts[:token]}")
     conn =
       :get
       |> build_conn("/?access_token=#{opts[:token]}")
index ba2ce1dd9157e5ea3ac854398a11208968969a1a..af0417406f3826dacaffe99cff456c507c6aa615 100644 (file)
@@ -25,9 +25,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
     :ok
   end
 
     :ok
   end
 
-  clear_config_all([:instance, :federating],
-    do: Pleroma.Config.put([:instance, :federating], true)
-  )
+  clear_config_all([:instance, :federating]) do
+    Pleroma.Config.put([:instance, :federating], true)
+  end
 
   describe "/relay" do
     clear_config([:instance, :allow_relay])
 
   describe "/relay" do
     clear_config([:instance, :allow_relay])
@@ -1008,7 +1008,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
     end
   end
 
     end
   end
 
-  describe "Additionnal ActivityPub C2S endpoints" do
+  describe "Additional ActivityPub C2S endpoints" do
     test "/api/ap/whoami", %{conn: conn} do
       user = insert(:user)
 
     test "/api/ap/whoami", %{conn: conn} do
       user = insert(:user)
 
@@ -1047,4 +1047,87 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
       assert object["actor"] == user.ap_id
     end
   end
       assert object["actor"] == user.ap_id
     end
   end
+
+  describe "when instance is not federating," do
+    clear_config([:instance, :federating]) do
+      Pleroma.Config.put([:instance, :federating], false)
+    end
+
+    test "returns 404 for GET routes", %{conn: conn} do
+      user = insert(:user)
+      conn = put_req_header(conn, "accept", "application/json")
+
+      get_uris = [
+        "/users/#{user.nickname}",
+        "/users/#{user.nickname}/outbox",
+        "/users/#{user.nickname}/inbox?page=true",
+        "/users/#{user.nickname}/followers",
+        "/users/#{user.nickname}/following",
+        "/internal/fetch",
+        "/relay",
+        "/relay/following",
+        "/relay/followers",
+        "/api/ap/whoami"
+      ]
+
+      for get_uri <- get_uris do
+        conn
+        |> get(get_uri)
+        |> json_response(404)
+
+        conn
+        |> assign(:user, user)
+        |> get(get_uri)
+        |> json_response(404)
+      end
+    end
+
+    test "returns 404 for activity-related POST routes", %{conn: conn} do
+      user = insert(:user)
+
+      conn =
+        conn
+        |> assign(:valid_signature, true)
+        |> put_req_header("content-type", "application/activity+json")
+
+      post_activity_data =
+        "test/fixtures/mastodon-post-activity.json"
+        |> File.read!()
+        |> Poison.decode!()
+
+      post_activity_uris = [
+        "/inbox",
+        "/relay/inbox",
+        "/users/#{user.nickname}/inbox",
+        "/users/#{user.nickname}/outbox"
+      ]
+
+      for post_activity_uri <- post_activity_uris do
+        conn
+        |> post(post_activity_uri, post_activity_data)
+        |> json_response(404)
+
+        conn
+        |> assign(:user, user)
+        |> post(post_activity_uri, post_activity_data)
+        |> json_response(404)
+      end
+    end
+
+    test "returns 404 for media upload attempt", %{conn: conn} do
+      user = insert(:user)
+      desc = "Description of the image"
+
+      image = %Plug.Upload{
+        content_type: "image/jpg",
+        path: Path.absname("test/fixtures/image.jpg"),
+        filename: "an_image.jpg"
+      }
+
+      conn
+      |> assign(:user, user)
+      |> post("/api/ap/upload_media", %{"file" => image, "description" => desc})
+      |> json_response(404)
+    end
+  end
 end
 end