logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: 222312900e6d847e0d4823fb62b6eb3675a0180f
parent 57d0379b89bd323dacf4959b03c55519de173ec0
Author: lain <lain@soykaf.club>
Date:   Wed,  2 Dec 2020 12:18:43 +0100

User: Don't allow local users in remote changesets

Diffstat:

Mlib/pleroma/user.ex13+++++++++++++
Mtest/pleroma/user_test.exs7+++++++
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex @@ -472,7 +472,20 @@ defmodule Pleroma.User do |> validate_format(:nickname, @email_regex) |> validate_length(:bio, max: bio_limit) |> validate_length(:name, max: name_limit) + |> validate_inclusion(:local, [true]) |> validate_fields(true) + |> validate_non_local() + end + + defp validate_non_local(cng) do + local? = get_field(cng, :local) + + if local? do + cng + |> add_error(:local, "User is local, can't update with this changeset.") + else + cng + end end def update_changeset(struct, params \\ %{}) do diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs @@ -895,6 +895,13 @@ defmodule Pleroma.UserTest do refute cs.valid? end) end + + test "it is invalid given a local user" do + user = insert(:user) + cs = User.remote_user_changeset(user, %{name: "tom from myspace"}) + + refute cs.valid? + end end describe "followers and friends" do