test fixes

This commit is contained in:
Alex S 2019-05-01 16:09:53 +07:00
parent bdfa3a6fa8
commit f11e7037c2
8 changed files with 27 additions and 27 deletions

View file

@ -126,7 +126,7 @@ def run(["new", nickname, email | rest]) do
proceed? = assume_yes? or Mix.shell().yes?("Continue?") proceed? = assume_yes? or Mix.shell().yes?("Continue?")
unless not proceed? do if proceed? do
Common.start_pleroma() Common.start_pleroma()
params = %{ params = %{

View file

@ -513,7 +513,7 @@ def get_cached_by_nickname(nickname) do
case user_result do case user_result do
{:ok, user} -> {:commit, user} {:ok, user} -> {:commit, user}
{:error, error} -> {:ignore, error} {:error, _error} -> {:ignore, nil}
end end
end) end)
end end
@ -563,7 +563,7 @@ def get_or_fetch_by_nickname(nickname) do
{:ok, user} {:ok, user}
else else
e -> {:error, e} _e -> {:error, "not found " <> nickname}
end end
end end
end end
@ -1210,11 +1210,11 @@ def fetch_by_ap_id(ap_id) do
case ap_try do case ap_try do
{:ok, user} -> {:ok, user} ->
user {:ok, user}
_ -> _ ->
case OStatus.make_user(ap_id) do case OStatus.make_user(ap_id) do
{:ok, user} -> user {:ok, user} -> {:ok, user}
_ -> {:error, "Could not fetch by AP id"} _ -> {:error, "Could not fetch by AP id"}
end end
end end
@ -1229,15 +1229,15 @@ def get_or_fetch_by_ap_id(ap_id) do
# Whether to fetch initial posts for the user (if it's a new user & the fetching is enabled) # Whether to fetch initial posts for the user (if it's a new user & the fetching is enabled)
should_fetch_initial = is_nil(user) and Pleroma.Config.get([:fetch_initial_posts, :enabled]) should_fetch_initial = is_nil(user) and Pleroma.Config.get([:fetch_initial_posts, :enabled])
resp = fetch_by_ap_id(ap_id)
if should_fetch_initial do if should_fetch_initial do
with {:ok, %User{} = user} = fetch_by_ap_id(ap_id) do with {:ok, %User{} = user} = resp do
{:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user]) {:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user])
end end
{:ok, user}
else
_ -> {:error, "Could not fetch by AP id"}
end end
resp
end end
end end

View file

@ -155,7 +155,7 @@ def outbox(conn, %{"nickname" => nickname} = params) do
def inbox(%{assigns: %{valid_signature: true}} = conn, %{"nickname" => nickname} = params) do def inbox(%{assigns: %{valid_signature: true}} = conn, %{"nickname" => nickname} = params) do
with %User{} = recipient <- User.get_cached_by_nickname(nickname), with %User{} = recipient <- User.get_cached_by_nickname(nickname),
%User{} = actor <- User.get_or_fetch_by_ap_id(params["actor"]), {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(params["actor"]),
true <- Utils.recipient_in_message(recipient, actor, params), true <- Utils.recipient_in_message(recipient, actor, params),
params <- Utils.maybe_splice_recipient(recipient.ap_id, params) do params <- Utils.maybe_splice_recipient(recipient.ap_id, params) do
Federator.incoming_ap_doc(params) Federator.incoming_ap_doc(params)

View file

@ -126,7 +126,7 @@ def fix_implicit_addressing(%{"to" => to, "cc" => cc} = object, followers_collec
def fix_implicit_addressing(object, _), do: object def fix_implicit_addressing(object, _), do: object
def fix_addressing(object) do def fix_addressing(object) do
%User{} = user = User.get_or_fetch_by_ap_id(object["actor"]) {:ok, %User{} = user} = User.get_or_fetch_by_ap_id(object["actor"])
followers_collection = User.ap_followers(user) followers_collection = User.ap_followers(user)
object object

View file

@ -1653,7 +1653,7 @@ def suggestions(%{assigns: %{user: user}} = conn, _) do
x, x,
"id", "id",
case User.get_or_fetch(x["acct"]) do case User.get_or_fetch(x["acct"]) do
{:ok, %User{} = %{id: id}} -> id {:ok, %User{id: id}} -> id
_ -> 0 _ -> 0
end end
) )

View file

@ -147,7 +147,7 @@ test "gives a replacement for user links, using local nicknames in user links te
end end
test "gives a replacement for user links when the user is using Osada" do test "gives a replacement for user links when the user is using Osada" do
mike = User.get_or_fetch("mike@osada.macgirvin.com") {:ok, mike} = User.get_or_fetch("mike@osada.macgirvin.com")
text = "@mike@osada.macgirvin.com test" text = "@mike@osada.macgirvin.com test"

View file

@ -362,7 +362,7 @@ test "it creates confirmed user if :confirmed option is given" do
describe "get_or_fetch/1" do describe "get_or_fetch/1" do
test "gets an existing user by nickname" do test "gets an existing user by nickname" do
user = insert(:user) user = insert(:user)
fetched_user = User.get_or_fetch(user.nickname) {:ok, fetched_user} = User.get_or_fetch(user.nickname)
assert user == fetched_user assert user == fetched_user
end end
@ -379,7 +379,7 @@ test "gets an existing user by ap_id" do
info: %{} info: %{}
) )
fetched_user = User.get_or_fetch(ap_id) {:ok, fetched_user} = User.get_or_fetch(ap_id)
freshed_user = refresh_record(user) freshed_user = refresh_record(user)
assert freshed_user == fetched_user assert freshed_user == fetched_user
end end
@ -388,14 +388,14 @@ test "gets an existing user by ap_id" do
describe "fetching a user from nickname or trying to build one" do describe "fetching a user from nickname or trying to build one" do
test "gets an existing user" do test "gets an existing user" do
user = insert(:user) user = insert(:user)
fetched_user = User.get_or_fetch_by_nickname(user.nickname) {:ok, fetched_user} = User.get_or_fetch_by_nickname(user.nickname)
assert user == fetched_user assert user == fetched_user
end end
test "gets an existing user, case insensitive" do test "gets an existing user, case insensitive" do
user = insert(:user, nickname: "nick") user = insert(:user, nickname: "nick")
fetched_user = User.get_or_fetch_by_nickname("NICK") {:ok, fetched_user} = User.get_or_fetch_by_nickname("NICK")
assert user == fetched_user assert user == fetched_user
end end
@ -403,7 +403,7 @@ test "gets an existing user, case insensitive" do
test "gets an existing user by fully qualified nickname" do test "gets an existing user by fully qualified nickname" do
user = insert(:user) user = insert(:user)
fetched_user = {:ok, fetched_user} =
User.get_or_fetch_by_nickname(user.nickname <> "@" <> Pleroma.Web.Endpoint.host()) User.get_or_fetch_by_nickname(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
assert user == fetched_user assert user == fetched_user
@ -413,24 +413,24 @@ test "gets an existing user by fully qualified nickname, case insensitive" do
user = insert(:user, nickname: "nick") user = insert(:user, nickname: "nick")
casing_altered_fqn = String.upcase(user.nickname <> "@" <> Pleroma.Web.Endpoint.host()) casing_altered_fqn = String.upcase(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
fetched_user = User.get_or_fetch_by_nickname(casing_altered_fqn) {:ok, fetched_user} = User.get_or_fetch_by_nickname(casing_altered_fqn)
assert user == fetched_user assert user == fetched_user
end end
test "fetches an external user via ostatus if no user exists" do test "fetches an external user via ostatus if no user exists" do
fetched_user = User.get_or_fetch_by_nickname("shp@social.heldscal.la") {:ok, fetched_user} = User.get_or_fetch_by_nickname("shp@social.heldscal.la")
assert fetched_user.nickname == "shp@social.heldscal.la" assert fetched_user.nickname == "shp@social.heldscal.la"
end end
test "returns nil if no user could be fetched" do test "returns nil if no user could be fetched" do
fetched_user = User.get_or_fetch_by_nickname("nonexistant@social.heldscal.la") {:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant@social.heldscal.la")
assert fetched_user == nil assert fetched_user == "not found nonexistant@social.heldscal.la"
end end
test "returns nil for nonexistant local user" do test "returns nil for nonexistant local user" do
fetched_user = User.get_or_fetch_by_nickname("nonexistant") {:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant")
assert fetched_user == nil assert fetched_user == "not found nonexistant"
end end
test "updates an existing user, if stale" do test "updates an existing user, if stale" do
@ -448,7 +448,7 @@ test "updates an existing user, if stale" do
assert orig_user.last_refreshed_at == a_week_ago assert orig_user.last_refreshed_at == a_week_ago
user = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin") {:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
assert user.info.source_data["endpoints"] assert user.info.source_data["endpoints"]
refute user.last_refreshed_at == orig_user.last_refreshed_at refute user.last_refreshed_at == orig_user.last_refreshed_at

View file

@ -219,7 +219,7 @@ test "it rejects incoming follow requests from blocked users when deny_follow_bl
Pleroma.Config.put([:user, :deny_follow_blocked], true) Pleroma.Config.put([:user, :deny_follow_blocked], true)
user = insert(:user) user = insert(:user)
target = User.get_or_fetch("http://mastodon.example.org/users/admin") {:ok, target} = User.get_or_fetch("http://mastodon.example.org/users/admin")
{:ok, user} = User.block(user, target) {:ok, user} = User.block(user, target)