[#483] User.get_by_nickname/1: ensured case-insensitive matching for local FQN. Added...
authorIvan Tashkinov <ivantashkinov@gmail.com>
Sat, 29 Dec 2018 09:26:23 +0000 (12:26 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Sat, 29 Dec 2018 09:26:23 +0000 (12:26 +0300)
lib/pleroma/user.ex
test/user_test.exs

index d4a6b13fb51676bc789f4dc02f0150944d7a5234..1f6d4cc5ed0a0c7ef6b4a55d38d63b55f0b8cf77 100644 (file)
@@ -388,7 +388,7 @@ defmodule Pleroma.User do
 
   def get_by_nickname(nickname) do
     Repo.get_by(User, nickname: nickname) ||
-      if String.ends_with?(nickname, "@" <> Pleroma.Web.Endpoint.host()) do
+      if Regex.match?(~r(@#{Pleroma.Web.Endpoint.host()})i, nickname) do
         [local_nickname, _] = String.split(nickname, "@")
         Repo.get_by(User, nickname: local_nickname)
       end
index 6a081c5c559cc10d5dea545c0e06ec581556c6c3..8225453abffc92cc44de69695a83d9f05ce422a5 100644 (file)
@@ -278,6 +278,25 @@ defmodule Pleroma.UserTest do
       assert user == fetched_user
     end
 
+
+    test "gets an existing user by fully qualified nickname" do
+      user = insert(:user)
+
+      fetched_user =
+        User.get_or_fetch_by_nickname(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
+
+      assert user == fetched_user
+    end
+
+    test "gets an existing user by fully qualified nickname, case insensitive" do
+      user = insert(:user, nickname: "nick")
+      casing_altered_fqn = String.upcase(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
+
+      fetched_user = User.get_or_fetch_by_nickname(casing_altered_fqn)
+
+      assert user == fetched_user
+    end
+
     test "fetches an external user via ostatus if no user exists" do
       fetched_user = User.get_or_fetch_by_nickname("shp@social.heldscal.la")
       assert fetched_user.nickname == "shp@social.heldscal.la"