Merge branch 'develop' into kaniini/pleroma-feature/activitypub-endpoints
This commit is contained in:
commit
b72a25f5b1
|
@ -40,8 +40,8 @@ def use_token(%Authorization{used: false, valid_until: valid_until} = auth) do
|
||||||
if NaiveDateTime.diff(NaiveDateTime.utc_now, valid_until) < 0 do
|
if NaiveDateTime.diff(NaiveDateTime.utc_now, valid_until) < 0 do
|
||||||
Repo.update(use_changeset(auth, %{used: true}))
|
Repo.update(use_changeset(auth, %{used: true}))
|
||||||
else
|
else
|
||||||
{:error, "Token expired"}
|
{:error, "token expired"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def use_token(%Authorization{used: true}), do: {:error, "Already used"}
|
def use_token(%Authorization{used: true}), do: {:error, "already used"}
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,7 +39,7 @@ def user_fetcher(username) do
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :well_known do
|
pipeline :well_known do
|
||||||
plug :accepts, ["xml", "xrd+xml"]
|
plug :accepts, ["xml", "xrd+xml", "json", "jrd+json"]
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :config do
|
pipeline :config do
|
||||||
|
|
|
@ -4,6 +4,7 @@ defmodule Pleroma.Web.WebFinger do
|
||||||
alias Pleroma.{Repo, User, XmlBuilder}
|
alias Pleroma.{Repo, User, XmlBuilder}
|
||||||
alias Pleroma.Web
|
alias Pleroma.Web
|
||||||
alias Pleroma.Web.{XML, Salmon, OStatus}
|
alias Pleroma.Web.{XML, Salmon, OStatus}
|
||||||
|
require Poison
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
def host_meta do
|
def host_meta do
|
||||||
|
@ -17,22 +18,55 @@ def host_meta do
|
||||||
|> XmlBuilder.to_doc
|
|> XmlBuilder.to_doc
|
||||||
end
|
end
|
||||||
|
|
||||||
def webfinger(resource) do
|
def webfinger(resource, "JSON") do
|
||||||
host = Pleroma.Web.Endpoint.host
|
host = Pleroma.Web.Endpoint.host
|
||||||
regex = ~r/(acct:)?(?<username>\w+)@#{host}/
|
regex = ~r/(acct:)?(?<username>\w+)@#{host}/
|
||||||
with %{"username" => username} <- Regex.named_captures(regex, resource) do
|
with %{"username" => username} <- Regex.named_captures(regex, resource) do
|
||||||
user = User.get_by_nickname(username)
|
user = User.get_by_nickname(username)
|
||||||
{:ok, represent_user(user)}
|
{:ok, represent_user(user, "JSON")}
|
||||||
else _e ->
|
else _e ->
|
||||||
with user when not is_nil(user) <- User.get_cached_by_ap_id(resource) do
|
with user when not is_nil(user) <- User.get_cached_by_ap_id(resource) do
|
||||||
{:ok, represent_user(user)}
|
{:ok, represent_user(user, "JSON")}
|
||||||
else _e ->
|
else _e ->
|
||||||
{:error, "Couldn't find user"}
|
{:error, "Couldn't find user"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def represent_user(user) do
|
def webfinger(resource, "XML") do
|
||||||
|
host = Pleroma.Web.Endpoint.host
|
||||||
|
regex = ~r/(acct:)?(?<username>\w+)@#{host}/
|
||||||
|
with %{"username" => username} <- Regex.named_captures(regex, resource) do
|
||||||
|
user = User.get_by_nickname(username)
|
||||||
|
{:ok, represent_user(user, "XML")}
|
||||||
|
else _e ->
|
||||||
|
with user when not is_nil(user) <- User.get_cached_by_ap_id(resource) do
|
||||||
|
{:ok, represent_user(user, "XML")}
|
||||||
|
else _e ->
|
||||||
|
{:error, "Couldn't find user"}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def represent_user(user, "JSON") do
|
||||||
|
{:ok, user} = ensure_keys_present(user)
|
||||||
|
{:ok, _private, public} = Salmon.keys_from_pem(user.info["keys"])
|
||||||
|
magic_key = Salmon.encode_key(public)
|
||||||
|
%{
|
||||||
|
"subject" => "acct:#{user.nickname}@#{Pleroma.Web.Endpoint.host}",
|
||||||
|
"aliases" => [user.ap_id],
|
||||||
|
"links" => [
|
||||||
|
%{"rel" => "http://schemas.google.com/g/2010#updates-from", "type" => "application/atom+xml", "href" => OStatus.feed_path(user)},
|
||||||
|
%{"rel" => "http://webfinger.net/rel/profile-page", "type" => "text/html", "href" => user.ap_id},
|
||||||
|
%{"rel" => "salmon", "href" => OStatus.salmon_path(user)},
|
||||||
|
%{"rel" => "magic-public-key", "href" => "data:application/magic-public-key,#{magic_key}"},
|
||||||
|
%{"rel" => "self", "type" => "application/activity+json", "href" => user.ap_id},
|
||||||
|
%{"rel" => "http://ostatus.org/schema/1.0/subscribe", "template" => OStatus.remote_follow_path()}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def represent_user(user, "XML") do
|
||||||
{:ok, user} = ensure_keys_present(user)
|
{:ok, user} = ensure_keys_present(user)
|
||||||
{:ok, _private, public} = Salmon.keys_from_pem(user.info["keys"])
|
{:ok, _private, public} = Salmon.keys_from_pem(user.info["keys"])
|
||||||
magic_key = Salmon.encode_key(public)
|
magic_key = Salmon.encode_key(public)
|
||||||
|
@ -84,6 +118,19 @@ defp webfinger_from_xml(doc) do
|
||||||
{:ok, data}
|
{:ok, data}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: maybe fill in other details from JRD webfinger response
|
||||||
|
defp webfinger_from_json(doc) do
|
||||||
|
data = Enum.reduce(doc["links"], %{"subject" => doc["subject"]}, fn (link, data) ->
|
||||||
|
case link["type"] do
|
||||||
|
"application/activity+json" ->
|
||||||
|
Map.put(data, "ap_id", link["href"])
|
||||||
|
_ ->
|
||||||
|
Logger.debug("Unhandled type: #{inspect(link["type"])}")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
{:ok, data}
|
||||||
|
end
|
||||||
|
|
||||||
def get_template_from_xml(body) do
|
def get_template_from_xml(body) do
|
||||||
xpath = "//Link[@rel='lrdd' and @type='application/xrd+xml']/@template"
|
xpath = "//Link[@rel='lrdd' and @type='application/xrd+xml']/@template"
|
||||||
with doc when doc != :error <- XML.parse_document(body),
|
with doc when doc != :error <- XML.parse_document(body),
|
||||||
|
@ -113,13 +160,22 @@ def finger(account) do
|
||||||
URI.parse(account).host
|
URI.parse(account).host
|
||||||
end
|
end
|
||||||
|
|
||||||
with {:ok, template} <- find_lrdd_template(domain),
|
case find_lrdd_template(domain) do
|
||||||
address <- String.replace(template, "{uri}", URI.encode(account)),
|
{:ok, template} ->
|
||||||
response <- @httpoison.get(address, ["Accept": "application/xrd+xml"]),
|
address = String.replace(template, "{uri}", URI.encode(account))
|
||||||
{:ok, %{status_code: status_code, body: body}} when status_code in 200..299 <- response,
|
_ ->
|
||||||
doc when doc != :error<- XML.parse_document(body),
|
address = "http://#{domain}/.well-known/webfinger?resource=acct:#{account}"
|
||||||
{:ok, data} <- webfinger_from_xml(doc) do
|
end
|
||||||
{:ok, data}
|
|
||||||
|
with response <- @httpoison.get(address, ["Accept": "application/xrd+xml,application/jrd+json"], follow_redirect: true),
|
||||||
|
{:ok, %{status_code: status_code, body: body}} when status_code in 200..299 <- response do
|
||||||
|
doc = XML.parse_document(body)
|
||||||
|
if doc != :error do
|
||||||
|
webfinger_from_xml(doc)
|
||||||
|
else
|
||||||
|
{:ok, doc} = Poison.decode(body)
|
||||||
|
webfinger_from_json(doc)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
e ->
|
e ->
|
||||||
Logger.debug(fn -> "Couldn't finger #{account}" end)
|
Logger.debug(fn -> "Couldn't finger #{account}" end)
|
||||||
|
|
|
@ -12,12 +12,23 @@ def host_meta(conn, _params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def webfinger(conn, %{"resource" => resource}) do
|
def webfinger(conn, %{"resource" => resource}) do
|
||||||
with {:ok, response} <- WebFinger.webfinger(resource) do
|
case get_format(conn) do
|
||||||
|
n when n in ["xml", "xrd+xml"] ->
|
||||||
|
with {:ok, response} <- WebFinger.webfinger(resource, "XML") do
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("application/xrd+xml")
|
|> put_resp_content_type("application/xrd+xml")
|
||||||
|> send_resp(200, response)
|
|> send_resp(200, response)
|
||||||
else
|
else
|
||||||
_e -> send_resp(conn, 404, "Couldn't find user")
|
_e -> send_resp(conn, 404, "Couldn't find user")
|
||||||
end
|
end
|
||||||
|
n when n in ["json", "jrd+json"] ->
|
||||||
|
with {:ok, response} <- WebFinger.webfinger(resource, "JSON") do
|
||||||
|
json(conn, response)
|
||||||
|
else
|
||||||
|
_e -> send_resp(conn, 404, "Couldn't find user")
|
||||||
|
end
|
||||||
|
_ ->
|
||||||
|
send_resp(conn, 404, "Unsupported format")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{"subject":"acct:framasoft@framatube.org","aliases":["https://framatube.org/accounts/framasoft"],"links":[{"rel":"self","type":"application/activity+json","href":"https://framatube.org/accounts/framasoft"}]}
|
|
@ -28,6 +28,7 @@ defmodule Pleroma.Web.ConnCase do
|
||||||
|
|
||||||
|
|
||||||
setup tags do
|
setup tags do
|
||||||
|
Cachex.clear(:user_cache)
|
||||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
|
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
|
||||||
unless tags[:async] do
|
unless tags[:async] do
|
||||||
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
|
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
|
||||||
|
|
|
@ -26,6 +26,7 @@ defmodule Pleroma.DataCase do
|
||||||
end
|
end
|
||||||
|
|
||||||
setup tags do
|
setup tags do
|
||||||
|
Cachex.clear(:user_cache)
|
||||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
|
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
|
||||||
|
|
||||||
unless tags[:async] do
|
unless tags[:async] do
|
||||||
|
|
|
@ -3,119 +3,126 @@ defmodule HTTPoisonMock do
|
||||||
|
|
||||||
def get(url, body \\ [], headers \\ [])
|
def get(url, body \\ [], headers \\ [])
|
||||||
|
|
||||||
def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "nonexistant@social.heldscal.la"]]) do
|
def get("http://framatube.org/.well-known/webfinger?resource=acct:framasoft@framatube.org", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
|
{:ok, %Response{
|
||||||
|
status_code: 200,
|
||||||
|
body: File.read!("test/fixtures/httpoison_mock/framasoft@framatube.org.json")
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
|
def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "nonexistant@social.heldscal.la"], follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 500,
|
status_code: 500,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml")
|
body: File.read!("test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la", [Accept: "application/xrd+xml"], []) do
|
def get("https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
|
body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "shp@social.heldscal.la"]]) do
|
def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "shp@social.heldscal.la"], follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
|
body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://social.heldscal.la/user/23211"]]) do
|
def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://social.heldscal.la/user/23211"], follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
|
body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211", [Accept: "application/xrd+xml"], []) do
|
def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
|
body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://social.heldscal.la/user/29191"]]) do
|
def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://social.heldscal.la/user/29191"], follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
|
body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191", [Accept: "application/xrd+xml"], []) do
|
def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
|
body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://mastodon.social/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://mastodon.social/users/lambadalambda"]]) do
|
def get("https://mastodon.social/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://mastodon.social/users/lambadalambda"], follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml")
|
body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda", [Accept: "application/xrd+xml"], []) do
|
def get("https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml")
|
body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://shitposter.club/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://shitposter.club/user/1"]]) do
|
def get("https://shitposter.club/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://shitposter.club/user/1"], follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
|
body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1", [Accept: "application/xrd+xml"], []) do
|
def get("https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
|
body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381", [Accept: "application/xrd+xml"], []) do
|
def get("https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/spc_5381_xrd.xml")
|
body: File.read!("test/fixtures/httpoison_mock/spc_5381_xrd.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("http://gs.example.org/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "http://gs.example.org:4040/index.php/user/1"], follow_redirect: true]) do
|
def get("http://gs.example.org/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "http://gs.example.org:4040/index.php/user/1"], follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml")
|
body: File.read!("test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1", [Accept: "application/xrd+xml"], []) do
|
def get("http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml")
|
body: File.read!("test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=https://social.stopwatchingus-heidelberg.de/user/18330", [Accept: "application/xrd+xml"], []) do
|
def get("https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=https://social.stopwatchingus-heidelberg.de/user/18330", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/atarifrosch_webfinger.xml")
|
body: File.read!("test/fixtures/httpoison_mock/atarifrosch_webfinger.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://pleroma.soykaf.com/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://pleroma.soykaf.com/users/lain"]]) do
|
def get("https://pleroma.soykaf.com/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://pleroma.soykaf.com/users/lain"], follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
|
body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain", [Accept: "application/xrd+xml"], []) do
|
def get("https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
|
body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
|
||||||
|
@ -205,14 +212,14 @@ def post("https://social.heldscal.la/main/push/hub", {:form, data}, ["Content-ty
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://pawoo.net/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://pawoo.net/users/pekorino"]]) do
|
def get("https://pawoo.net/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://pawoo.net/users/pekorino"], follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
|
body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://pawoo.net/.well-known/webfinger?resource=https://pawoo.net/users/pekorino", [Accept: "application/xrd+xml"], []) do
|
def get("https://pawoo.net/.well-known/webfinger?resource=https://pawoo.net/users/pekorino", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
|
body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
|
||||||
|
@ -226,42 +233,42 @@ def get("https://pawoo.net/users/pekorino.atom", _, _) do
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://mamot.fr/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://mamot.fr/users/Skruyb"]]) do
|
def get("https://mamot.fr/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://mamot.fr/users/Skruyb"], follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
|
body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://mamot.fr/.well-known/webfinger?resource=https://mamot.fr/users/Skruyb", [Accept: "application/xrd+xml"], []) do
|
def get("https://mamot.fr/.well-known/webfinger?resource=https://mamot.fr/users/Skruyb", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
|
body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://social.sakamoto.gq/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://social.sakamoto.gq/users/eal"]]) do
|
def get("https://social.sakamoto.gq/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://social.sakamoto.gq/users/eal"], follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
|
body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal", [Accept: "application/xrd+xml"], []) do
|
def get("https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
|
body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/shp", [Accept: "application/xrd+xml"], []) do
|
def get("https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/shp", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.webfigner")
|
body: File.read!("test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.webfigner")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get("https://squeet.me/xrd/?uri=lain@squeet.me", [Accept: "application/xrd+xml"], []) do
|
def get("https://squeet.me/xrd/?uri=lain@squeet.me", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
{:ok, %Response{
|
{:ok, %Response{
|
||||||
status_code: 200,
|
status_code: 200,
|
||||||
body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml")
|
body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml")
|
||||||
|
|
|
@ -58,10 +58,7 @@ test "contains mentions" do
|
||||||
incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
|
incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
|
||||||
# a user with this ap id might be in the cache.
|
# a user with this ap id might be in the cache.
|
||||||
recipient = "https://pleroma.soykaf.com/users/lain"
|
recipient = "https://pleroma.soykaf.com/users/lain"
|
||||||
user = User.get_cached_by_ap_id(recipient) || insert(:user, %{ap_id: recipient})
|
user = insert(:user, %{ap_id: recipient})
|
||||||
|
|
||||||
# invalidate the cache
|
|
||||||
User.invalidate_cache(user)
|
|
||||||
|
|
||||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||||
|
|
||||||
|
|
|
@ -15,20 +15,20 @@ test "returns a link to the xml lrdd" do
|
||||||
test "works for fqns" do
|
test "works for fqns" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
{:ok, result} = WebFinger.webfinger("#{user.nickname}@#{Pleroma.Web.Endpoint.host}")
|
{:ok, result} = WebFinger.webfinger("#{user.nickname}@#{Pleroma.Web.Endpoint.host}", "XML")
|
||||||
assert is_binary(result)
|
assert is_binary(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "works for ap_ids" do
|
test "works for ap_ids" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
{:ok, result} = WebFinger.webfinger(user.ap_id)
|
{:ok, result} = WebFinger.webfinger(user.ap_id, "XML")
|
||||||
assert is_binary(result)
|
assert is_binary(result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "fingering" do
|
describe "fingering" do
|
||||||
test "returns the info for a user" do
|
test "returns the info for an OStatus user" do
|
||||||
user = "shp@social.heldscal.la"
|
user = "shp@social.heldscal.la"
|
||||||
|
|
||||||
{:ok, data} = WebFinger.finger(user)
|
{:ok, data} = WebFinger.finger(user)
|
||||||
|
@ -39,6 +39,12 @@ test "returns the info for a user" do
|
||||||
assert data["salmon"] == "https://social.heldscal.la/main/salmon/user/29191"
|
assert data["salmon"] == "https://social.heldscal.la/main/salmon/user/29191"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "returns the ActivityPub actor URI for an ActivityPub user" do
|
||||||
|
user = "framasoft@framatube.org"
|
||||||
|
|
||||||
|
{:ok, _data} = WebFinger.finger(user)
|
||||||
|
end
|
||||||
|
|
||||||
test "it works for friendica" do
|
test "it works for friendica" do
|
||||||
user = "lain@squeet.me"
|
user = "lain@squeet.me"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue