[#483] User.get_by_nickname/1: ensured case-insensitive matching for local FQN. Added tests.
This commit is contained in:
parent
b3574dccbb
commit
7bd49a3222
2 changed files with 20 additions and 1 deletions
|
@ -388,7 +388,7 @@ def get_cached_by_nickname(nickname) 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
|
||||
|
|
|
@ -278,6 +278,25 @@ test "gets an existing user, case insensitive" 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"
|
||||
|
|
Loading…
Reference in a new issue