mix format
This commit is contained in:
parent
35ef470d00
commit
05c935c396
@ -243,6 +243,7 @@ defmodule Pleroma.User.Info do
|
|||||||
|
|
||||||
def remote_user_creation(info, params) do
|
def remote_user_creation(info, params) do
|
||||||
params = Map.put(params, "fields", Enum.map(params["fields"], &truncate_field/1))
|
params = Map.put(params, "fields", Enum.map(params["fields"], &truncate_field/1))
|
||||||
|
|
||||||
info
|
info
|
||||||
|> cast(params, [
|
|> cast(params, [
|
||||||
:ap_enabled,
|
:ap_enabled,
|
||||||
@ -328,8 +329,12 @@ defmodule Pleroma.User.Info do
|
|||||||
defp valid_field?(_), do: false
|
defp valid_field?(_), do: false
|
||||||
|
|
||||||
defp truncate_field(%{"name" => name, "value" => value}) do
|
defp truncate_field(%{"name" => name, "value" => value}) do
|
||||||
{name, _chopped} = String.split_at(name, Pleroma.Config.get([:instance, :account_field_name_length], 255))
|
{name, _chopped} =
|
||||||
{value, _chopped} = String.split_at(value, Pleroma.Config.get([:instance, :account_field_value_length], 255))
|
String.split_at(name, Pleroma.Config.get([:instance, :account_field_name_length], 255))
|
||||||
|
|
||||||
|
{value, _chopped} =
|
||||||
|
String.split_at(value, Pleroma.Config.get([:instance, :account_field_value_length], 255))
|
||||||
|
|
||||||
%{"name" => name, "value" => value}
|
%{"name" => name, "value" => value}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1119,17 +1119,26 @@ defmodule Pleroma.UserTest do
|
|||||||
|
|
||||||
describe "insert or update a user from given data" do
|
describe "insert or update a user from given data" do
|
||||||
test "with normal data" do
|
test "with normal data" do
|
||||||
user = insert(:user, %{nickname: "nick@name.de"})
|
user = insert(:user, %{nickname: "nick@name.de"})
|
||||||
data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
|
data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
|
||||||
|
|
||||||
assert {:ok, %User{}} = User.insert_or_update_user(data)
|
assert {:ok, %User{}} = User.insert_or_update_user(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "with overly long fields" do
|
test "with overly long fields" do
|
||||||
current_max_length = Pleroma.Config.get([:instance, :account_field_value_length], 255)
|
current_max_length = Pleroma.Config.get([:instance, :account_field_value_length], 255)
|
||||||
user = insert(:user, nickname: "nickname@supergood.domain")
|
user = insert(:user, nickname: "nickname@supergood.domain")
|
||||||
data = %{ap_id: user.ap_id, info: %{ fields: [%{"name" => "myfield", "value" => String.duplicate("h", current_max_length + 1)}] }}
|
|
||||||
assert {:ok, %User{}} = User.insert_or_update_user(data)
|
data = %{
|
||||||
|
ap_id: user.ap_id,
|
||||||
|
info: %{
|
||||||
|
fields: [
|
||||||
|
%{"name" => "myfield", "value" => String.duplicate("h", current_max_length + 1)}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {:ok, %User{}} = User.insert_or_update_user(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user