From 8aa639a450c94fc3fb8ea812b334892324ffd51a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 21 Mar 2018 17:58:31 +0000 Subject: [PATCH 1/6] webfinger: support JSON output --- lib/pleroma/web/router.ex | 2 +- lib/pleroma/web/web_finger/web_finger.ex | 41 +++++++++++++++++-- .../web/web_finger/web_finger_controller.ex | 23 ++++++++--- test/web/web_finger/web_finger_test.exs | 4 +- 4 files changed, 57 insertions(+), 13 deletions(-) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 3e9a8ba7b..8835239c5 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -39,7 +39,7 @@ defmodule Pleroma.Web.Router do end pipeline :well_known do - plug :accepts, ["xml", "xrd+xml"] + plug :accepts, ["xml", "xrd+xml", "json", "jrd+json"] end pipeline :config do diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 019210124..378e544ba 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -17,22 +17,55 @@ defmodule Pleroma.Web.WebFinger do |> XmlBuilder.to_doc end - def webfinger(resource) do + def webfinger(resource, "JSON") do host = Pleroma.Web.Endpoint.host regex = ~r/(acct:)?(?\w+)@#{host}/ with %{"username" => username} <- Regex.named_captures(regex, resource) do user = User.get_by_nickname(username) - {:ok, represent_user(user)} + {:ok, represent_user(user, "JSON")} else _e -> 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 -> {:error, "Couldn't find user"} end end end - def represent_user(user) do + def webfinger(resource, "XML") do + host = Pleroma.Web.Endpoint.host + regex = ~r/(acct:)?(?\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, _private, public} = Salmon.keys_from_pem(user.info["keys"]) magic_key = Salmon.encode_key(public) diff --git a/lib/pleroma/web/web_finger/web_finger_controller.ex b/lib/pleroma/web/web_finger/web_finger_controller.ex index d4536fc46..eb54346c1 100644 --- a/lib/pleroma/web/web_finger/web_finger_controller.ex +++ b/lib/pleroma/web/web_finger/web_finger_controller.ex @@ -12,12 +12,23 @@ defmodule Pleroma.Web.WebFinger.WebFingerController do end def webfinger(conn, %{"resource" => resource}) do - with {:ok, response} <- WebFinger.webfinger(resource) do - conn - |> put_resp_content_type("application/xrd+xml") - |> send_resp(200, response) - else - _e -> send_resp(conn, 404, "Couldn't find user") + case get_format(conn) do + n when n in ["xml", "xrd+xml"] -> + with {:ok, response} <- WebFinger.webfinger(resource, "XML") do + conn + |> put_resp_content_type("application/xrd+xml") + |> send_resp(200, response) + else + _e -> send_resp(conn, 404, "Couldn't find user") + 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 diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs index ccca737f0..0be424c7a 100644 --- a/test/web/web_finger/web_finger_test.exs +++ b/test/web/web_finger/web_finger_test.exs @@ -15,14 +15,14 @@ defmodule Pleroma.Web.WebFingerTest do test "works for fqns" do 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) end test "works for ap_ids" do user = insert(:user) - {:ok, result} = WebFinger.webfinger(user.ap_id) + {:ok, result} = WebFinger.webfinger(user.ap_id, "XML") assert is_binary(result) end end From 1decd2ecb2d1c89ddb29067b2128558c84ce1f86 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 21 Mar 2018 18:06:41 +0000 Subject: [PATCH 2/6] webfinger: attempt to fall back if LRDD template cannot be found --- lib/pleroma/web/web_finger/web_finger.ex | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 378e544ba..de4165bb3 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -146,9 +146,14 @@ defmodule Pleroma.Web.WebFinger do URI.parse(account).host end - with {:ok, template} <- find_lrdd_template(domain), - address <- String.replace(template, "{uri}", URI.encode(account)), - response <- @httpoison.get(address, ["Accept": "application/xrd+xml"]), + case find_lrdd_template(domain) do + {:ok, template} -> + address = String.replace(template, "{uri}", URI.encode(account)) + _ -> + address = "http://#{domain}/.well-known/webfinger?resource=#{account}" + end + + with response <- @httpoison.get(address, ["Accept": "application/xrd+xml"]), {:ok, %{status_code: status_code, body: body}} when status_code in 200..299 <- response, doc when doc != :error<- XML.parse_document(body), {:ok, data} <- webfinger_from_xml(doc) do From 4d3af2af713d37363eed3ec81334b6c37c0407ed Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 21 Mar 2018 18:53:36 +0000 Subject: [PATCH 3/6] webfinger: implement json response parsing --- lib/pleroma/web/web_finger/web_finger.ex | 30 +++++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index de4165bb3..d8eb6f3e0 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -4,6 +4,7 @@ defmodule Pleroma.Web.WebFinger do alias Pleroma.{Repo, User, XmlBuilder} alias Pleroma.Web alias Pleroma.Web.{XML, Salmon, OStatus} + require Poison require Logger def host_meta do @@ -117,6 +118,19 @@ defmodule Pleroma.Web.WebFinger do {:ok, data} 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 xpath = "//Link[@rel='lrdd' and @type='application/xrd+xml']/@template" with doc when doc != :error <- XML.parse_document(body), @@ -150,14 +164,18 @@ defmodule Pleroma.Web.WebFinger do {:ok, template} -> address = String.replace(template, "{uri}", URI.encode(account)) _ -> - address = "http://#{domain}/.well-known/webfinger?resource=#{account}" + address = "http://#{domain}/.well-known/webfinger?resource=acct:#{account}" end - with response <- @httpoison.get(address, ["Accept": "application/xrd+xml"]), - {:ok, %{status_code: status_code, body: body}} when status_code in 200..299 <- response, - doc when doc != :error<- XML.parse_document(body), - {:ok, data} <- webfinger_from_xml(doc) do - {: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 e -> Logger.debug(fn -> "Couldn't finger #{account}" end) From ff7afc04654e4306f84f469634590a25831e997f Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 21 Mar 2018 19:23:09 +0000 Subject: [PATCH 4/6] tests: webfinger: test quering a JSON response for activitypub actor URI --- .../framasoft@framatube.org.json | 1 + test/support/httpoison_mock.ex | 57 +++++++++++-------- test/web/web_finger/web_finger_test.exs | 8 ++- 3 files changed, 40 insertions(+), 26 deletions(-) create mode 100644 test/fixtures/httpoison_mock/framasoft@framatube.org.json diff --git a/test/fixtures/httpoison_mock/framasoft@framatube.org.json b/test/fixtures/httpoison_mock/framasoft@framatube.org.json new file mode 100644 index 000000000..dcd5e88f5 --- /dev/null +++ b/test/fixtures/httpoison_mock/framasoft@framatube.org.json @@ -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"}]} \ No newline at end of file diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index a45eaf170..5d021a3b4 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -3,119 +3,126 @@ defmodule HTTPoisonMock do 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{ status_code: 500, body: File.read!("test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/spc_5381_xrd.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/atarifrosch_webfinger.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml") @@ -205,14 +212,14 @@ defmodule HTTPoisonMock do }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml") @@ -226,42 +233,42 @@ defmodule HTTPoisonMock do }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.webfigner") }} 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{ status_code: 200, body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml") diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs index 0be424c7a..ff60391fd 100644 --- a/test/web/web_finger/web_finger_test.exs +++ b/test/web/web_finger/web_finger_test.exs @@ -28,7 +28,7 @@ defmodule Pleroma.Web.WebFingerTest do end 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" {:ok, data} = WebFinger.finger(user) @@ -39,6 +39,12 @@ defmodule Pleroma.Web.WebFingerTest do assert data["salmon"] == "https://social.heldscal.la/main/salmon/user/29191" 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 user = "lain@squeet.me" From f9ab38a443be37fc49a4fb52dece8a1d44c44e13 Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 22 Mar 2018 12:37:24 +0100 Subject: [PATCH 5/6] Fix test. --- lib/pleroma/web/oauth/authorization.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/oauth/authorization.ex b/lib/pleroma/web/oauth/authorization.ex index 5a68bd593..1ba5be602 100644 --- a/lib/pleroma/web/oauth/authorization.ex +++ b/lib/pleroma/web/oauth/authorization.ex @@ -40,8 +40,8 @@ defmodule Pleroma.Web.OAuth.Authorization do if NaiveDateTime.diff(NaiveDateTime.utc_now, valid_until) < 0 do Repo.update(use_changeset(auth, %{used: true})) else - {:error, "Token expired"} + {:error, "token expired"} end end - def use_token(%Authorization{used: true}), do: {:error, "Already used"} + def use_token(%Authorization{used: true}), do: {:error, "already used"} end From 32ae9188430349e22721b81baec825b3cebfe8e5 Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 22 Mar 2018 12:44:32 +0100 Subject: [PATCH 6/6] Clear caches on test. --- test/support/conn_case.ex | 1 + test/support/data_case.ex | 1 + test/web/mastodon_api/status_view_test.exs | 5 +---- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 8d6969855..a83ef3b3a 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -28,6 +28,7 @@ defmodule Pleroma.Web.ConnCase do setup tags do + Cachex.clear(:user_cache) :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo) unless tags[:async] do Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()}) diff --git a/test/support/data_case.ex b/test/support/data_case.ex index 3f40c3670..8eff0fd94 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -26,6 +26,7 @@ defmodule Pleroma.DataCase do end setup tags do + Cachex.clear(:user_cache) :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo) unless tags[:async] do diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index 9e2bc3c18..a58f729a6 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -58,10 +58,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml") # a user with this ap id might be in the cache. recipient = "https://pleroma.soykaf.com/users/lain" - user = User.get_cached_by_ap_id(recipient) || insert(:user, %{ap_id: recipient}) - - # invalidate the cache - User.invalidate_cache(user) + user = insert(:user, %{ap_id: recipient}) {:ok, [activity]} = OStatus.handle_incoming(incoming)