Return webfinger for ap_ids.
This commit is contained in:
parent
6843755834
commit
e54e592d6c
@ -18,11 +18,15 @@ defmodule Pleroma.Web.WebFinger do
|
|||||||
def webfinger(resource) do
|
def webfinger(resource) do
|
||||||
host = Pleroma.Web.host
|
host = Pleroma.Web.host
|
||||||
regex = ~r/(acct:)?(?<username>\w+)@#{host}/
|
regex = ~r/(acct:)?(?<username>\w+)@#{host}/
|
||||||
case Regex.named_captures(regex, resource) do
|
with %{"username" => username} <- Regex.named_captures(regex, resource) do
|
||||||
%{"username" => username} ->
|
|
||||||
user = User.get_by_nickname(username)
|
user = User.get_by_nickname(username)
|
||||||
{:ok, represent_user(user)}
|
{:ok, represent_user(user)}
|
||||||
_ -> nil
|
else _e ->
|
||||||
|
with user when not is_nil(user) <- User.get_cached_by_ap_id(resource) do
|
||||||
|
{:ok, represent_user(user)}
|
||||||
|
else _e ->
|
||||||
|
{:error, "Couldn't find user"}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -11,6 +11,22 @@ defmodule Pleroma.Web.WebFingerTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "incoming webfinger request" do
|
||||||
|
test "works for fqns" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, result} = WebFinger.webfinger("#{user.nickname}@#{Pleroma.Web.host}")
|
||||||
|
assert is_binary(result)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "works for ap_ids" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, result} = WebFinger.webfinger(user.ap_id)
|
||||||
|
assert is_binary(result)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "fingering" do
|
describe "fingering" do
|
||||||
test "returns the info for a user" do
|
test "returns the info for a user" do
|
||||||
user = "shp@social.heldscal.la"
|
user = "shp@social.heldscal.la"
|
||||||
|
Loading…
Reference in New Issue
Block a user