From 72d2557e11265f13eedc8f4ad11640abdd6d7158 Mon Sep 17 00:00:00 2001
From: kPherox <admin@mail.kr-kp.com>
Date: Fri, 15 Nov 2019 18:51:55 +0900
Subject: [PATCH 1/2] Add fieldsLimit to metadata of nodeinfo

---
 lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
index 486b9f6a4..abcf46034 100644
--- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
+++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
@@ -120,6 +120,12 @@ def raw_nodeinfo do
           banner: Config.get([:instance, :banner_upload_limit]),
           background: Config.get([:instance, :background_upload_limit])
         },
+        fieldsLimits: %{
+          maxFields: Config.get([:instance, :max_account_fields]),
+          maxRemoteFields: Config.get([:instance, :max_remote_account_fields]),
+          nameLength: Config.get([:instance, :account_field_name_length]),
+          valueLength: Config.get([:instance, :account_field_value_length])
+        },
         accountActivationRequired: Config.get([:instance, :account_activation_required], false),
         invitesEnabled: Config.get([:instance, :invites_enabled], false),
         mailerEnabled: Config.get([Pleroma.Emails.Mailer, :enabled], false),

From c9a06b14abd19b2cf15b1ecb9b16d74b815e74e5 Mon Sep 17 00:00:00 2001
From: kPherox <admin@mail.kr-kp.com>
Date: Fri, 15 Nov 2019 23:55:28 +0900
Subject: [PATCH 2/2] Add test

---
 test/web/node_info_test.exs | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs
index 6cc876602..9a574a38d 100644
--- a/test/web/node_info_test.exs
+++ b/test/web/node_info_test.exs
@@ -61,6 +61,33 @@ test "returns software.repository field in nodeinfo 2.1", %{conn: conn} do
     assert Pleroma.Application.repository() == result["software"]["repository"]
   end
 
+  test "returns fieldsLimits field", %{conn: conn} do
+    max_account_fields = Pleroma.Config.get([:instance, :max_account_fields])
+    max_remote_account_fields = Pleroma.Config.get([:instance, :max_remote_account_fields])
+    account_field_name_length = Pleroma.Config.get([:instance, :account_field_name_length])
+    account_field_value_length = Pleroma.Config.get([:instance, :account_field_value_length])
+
+    Pleroma.Config.put([:instance, :max_account_fields], 10)
+    Pleroma.Config.put([:instance, :max_remote_account_fields], 15)
+    Pleroma.Config.put([:instance, :account_field_name_length], 255)
+    Pleroma.Config.put([:instance, :account_field_value_length], 2048)
+
+    response =
+      conn
+      |> get("/nodeinfo/2.1.json")
+      |> json_response(:ok)
+
+    assert response["metadata"]["fieldsLimits"]["maxFields"] == 10
+    assert response["metadata"]["fieldsLimits"]["maxRemoteFields"] == 15
+    assert response["metadata"]["fieldsLimits"]["nameLength"] == 255
+    assert response["metadata"]["fieldsLimits"]["valueLength"] == 2048
+
+    Pleroma.Config.put([:instance, :max_account_fields], max_account_fields)
+    Pleroma.Config.put([:instance, :max_remote_account_fields], max_remote_account_fields)
+    Pleroma.Config.put([:instance, :account_field_name_length], account_field_name_length)
+    Pleroma.Config.put([:instance, :account_field_value_length], account_field_value_length)
+  end
+
   test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do
     option = Pleroma.Config.get([:instance, :safe_dm_mentions])
     Pleroma.Config.put([:instance, :safe_dm_mentions], true)