Merge branch 'bugfix/mrf-antifollowbot-nil-bio' into 'develop'

MRF: anti followbot: gracefully handle nil display names

See merge request pleroma/pleroma!909
This commit is contained in:
rinpatch 2019-03-07 16:42:05 +00:00
commit 2a9191a53e
2 changed files with 24 additions and 3 deletions

View File

@ -23,15 +23,21 @@ defp score_displayname("fedibot"), do: 1.0
defp score_displayname(_), do: 0.0 defp score_displayname(_), do: 0.0
defp determine_if_followbot(%User{nickname: nickname, name: displayname}) do defp determine_if_followbot(%User{nickname: nickname, name: displayname}) do
# nickname will always be a binary string because it's generated by Pleroma.
nick_score = nick_score =
nickname nickname
|> String.downcase() |> String.downcase()
|> score_nickname() |> score_nickname()
# displayname will either be a binary string or nil, if a displayname isn't set.
name_score = name_score =
displayname if is_binary(displayname) do
|> String.downcase() displayname
|> score_displayname() |> String.downcase()
|> score_displayname()
else
0.0
end
nick_score + name_score nick_score + name_score
end end

View File

@ -54,4 +54,19 @@ test "it allows non-followbots" do
{:ok, _} = AntiFollowbotPolicy.filter(message) {:ok, _} = AntiFollowbotPolicy.filter(message)
end end
test "it gracefully handles nil display names" do
actor = insert(:user, %{name: nil})
target = insert(:user)
message = %{
"@context" => "https://www.w3.org/ns/activitystreams",
"type" => "Follow",
"actor" => actor.ap_id,
"object" => target.ap_id,
"id" => "https://example.com/activities/1234"
}
{:ok, _} = AntiFollowbotPolicy.filter(message)
end
end end