Reserve a few user names
authorlain <lain@soykaf.club>
Tue, 25 Dec 2018 19:09:27 +0000 (20:09 +0100)
committerlain <lain@soykaf.club>
Tue, 25 Dec 2018 19:10:45 +0000 (20:10 +0100)
These are all names that are used for domain.com/:route routes or projected to be.

config/config.exs
lib/pleroma/user.ex
test/user_test.exs

index 4b8762761a971658b7dd27561728b0aec78cf332..980c215c818a12a6109d197ff48f525d28cf06e4 100644 (file)
@@ -220,6 +220,35 @@ config :cors_plug,
   credentials: true,
   headers: ["Authorization", "Content-Type", "Idempotency-Key"]
 
+config :pleroma, Pleroma.User,
+  restricted_nicknames: [
+    "main",
+    "users",
+    "settings",
+    "objects",
+    "activities",
+    "web",
+    "registration",
+    "friend-requests",
+    "pleroma",
+    "api",
+    "tag",
+    "notice",
+    "status",
+    "user-search",
+    "ostatus_subscribe",
+    "oauth",
+    "push",
+    "relay",
+    "inbox",
+    ".well-known",
+    "nodeinfo",
+    "auth",
+    "proxy",
+    "dev",
+    "internal"
+  ]
+
 # Import environment specific config. This must remain at the bottom
 # of this file so it overrides the configuration defined above.
 import_config "#{Mix.env()}.exs"
index 1f930479d7aa718b948e8f5eed931b6d7db1cc3f..33f5e43fc4134ce5df3b20096ae50834f8d49d90 100644 (file)
@@ -197,6 +197,7 @@ defmodule Pleroma.User do
       |> validate_confirmation(:password)
       |> unique_constraint(:email)
       |> unique_constraint(:nickname)
+      |> validate_exclusion(:nickname, Pleroma.Config.get([Pleroma.User, :restricted_nicknames]))
       |> validate_format(:nickname, local_nickname_regex())
       |> validate_format(:email, @email_regex)
       |> validate_length(:bio, max: 1000)
index aab6473cf6ecf2752ab71153f9e4a770271d56df..8c7e1594b33d0c73fd245fc2f2f37e33b4322927 100644 (file)
@@ -153,6 +153,20 @@ defmodule Pleroma.UserTest do
       end)
     end
 
+    test "it restricts certain nicknames" do
+      [restricted_name | _] = Pleroma.Config.get([Pleroma.User, :restricted_nicknames])
+
+      assert is_bitstring(restricted_name)
+
+      params =
+        @full_user_data
+        |> Map.put(:nickname, restricted_name)
+
+      changeset = User.register_changeset(%User{}, params)
+
+      refute changeset.valid?
+    end
+
     test "it sets the password_hash, ap_id and following fields" do
       changeset = User.register_changeset(%User{}, @full_user_data)