Fetch the same data from json webfinger as from xml webfinger.
This commit is contained in:
parent
d1ee3edd3c
commit
e3a81fe58f
4 changed files with 31 additions and 3 deletions
|
@ -118,14 +118,23 @@ 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
|
defp webfinger_from_json(doc) do
|
||||||
data = Enum.reduce(doc["links"], %{"subject" => doc["subject"]}, fn (link, data) ->
|
data = Enum.reduce(doc["links"], %{"subject" => doc["subject"]}, fn (link, data) ->
|
||||||
case link["type"] do
|
case {link["type"], link["rel"]} do
|
||||||
"application/activity+json" ->
|
{"application/activity+json", "self"} ->
|
||||||
Map.put(data, "ap_id", link["href"])
|
Map.put(data, "ap_id", link["href"])
|
||||||
|
{_, "magic-public-key"} ->
|
||||||
|
"data:application/magic-public-key," <> magic_key = link["href"]
|
||||||
|
Map.put(data, "magic_key", magic_key)
|
||||||
|
{"application/atom+xml", "http://schemas.google.com/g/2010#updates-from"} ->
|
||||||
|
Map.put(data, "topic", link["href"])
|
||||||
|
{_, "salmon"} ->
|
||||||
|
Map.put(data, "salmon", link["href"])
|
||||||
|
{_, "http://ostatus.org/schema/1.0/subscribe"} ->
|
||||||
|
Map.put(data, "subscribe_address", link["template"])
|
||||||
_ ->
|
_ ->
|
||||||
Logger.debug("Unhandled type: #{inspect(link["type"])}")
|
Logger.debug("Unhandled type: #{inspect(link["type"])}")
|
||||||
|
data
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
{:ok, data}
|
{:ok, data}
|
||||||
|
|
1
test/fixtures/httpoison_mock/winterdienst_webfinger.json
vendored
Normal file
1
test/fixtures/httpoison_mock/winterdienst_webfinger.json
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"subject":"acct:winterdienst@gnusocial.de","aliases":["https:\/\/gnusocial.de\/user\/249296","https:\/\/gnusocial.de\/winterdienst","https:\/\/gnusocial.de\/index.php\/user\/249296","https:\/\/gnusocial.de\/index.php\/winterdienst"],"links":[{"rel":"http:\/\/webfinger.net\/rel\/profile-page","type":"text\/html","href":"https:\/\/gnusocial.de\/winterdienst"},{"rel":"http:\/\/gmpg.org\/xfn\/11","type":"text\/html","href":"https:\/\/gnusocial.de\/winterdienst"},{"rel":"describedby","type":"application\/rdf+xml","href":"https:\/\/gnusocial.de\/winterdienst\/foaf"},{"rel":"http:\/\/apinamespace.org\/atom","type":"application\/atomsvc+xml","href":"https:\/\/gnusocial.de\/api\/statusnet\/app\/service\/winterdienst.xml"},{"rel":"http:\/\/apinamespace.org\/twitter","href":"https:\/\/gnusocial.de\/api\/"},{"rel":"http:\/\/schemas.google.com\/g\/2010#updates-from","type":"application\/atom+xml","href":"https:\/\/gnusocial.de\/api\/statuses\/user_timeline\/249296.atom"},{"rel":"magic-public-key","href":"data:application\/magic-public-key,RSA.qfYaxztz7ZELrE4v5WpJrPM99SKI3iv9Y3Tw6nfLGk-4CRljNYqV8IYX2FXjeucC_DKhPNnlF6fXyASpcSmA_qupX9WC66eVhFhZ5OuyBOeLvJ1C4x7Hi7Di8MNBxY3VdQuQR0tTaS_YAZCwASKp7H6XEid3EJpGt0EQZoNzRd8=.AQAB"},{"rel":"salmon","href":"https:\/\/gnusocial.de\/main\/salmon\/user\/249296"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-replies","href":"https:\/\/gnusocial.de\/main\/salmon\/user\/249296"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-mention","href":"https:\/\/gnusocial.de\/main\/salmon\/user\/249296"},{"rel":"http:\/\/ostatus.org\/schema\/1.0\/subscribe","template":"https:\/\/gnusocial.de\/main\/ostatussub?profile={uri}"}]}
|
|
@ -9,6 +9,12 @@ def get("http://framatube.org/.well-known/webfinger?resource=acct:framasoft@fram
|
||||||
body: File.read!("test/fixtures/httpoison_mock/framasoft@framatube.org.json")
|
body: File.read!("test/fixtures/httpoison_mock/framasoft@framatube.org.json")
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
def get("http://gnusocial.de/.well-known/webfinger?resource=acct:winterdienst@gnusocial.de", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
|
||||||
|
{:ok, %Response{
|
||||||
|
status_code: 200,
|
||||||
|
body: File.read!("test/fixtures/httpoison_mock/winterdienst_webfinger.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
|
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{
|
||||||
|
|
|
@ -45,6 +45,18 @@ test "returns the ActivityPub actor URI for an ActivityPub user" do
|
||||||
{:ok, _data} = WebFinger.finger(user)
|
{:ok, _data} = WebFinger.finger(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "returns the correctly for json ostatus users" do
|
||||||
|
user = "winterdienst@gnusocial.de"
|
||||||
|
|
||||||
|
{:ok, data} = WebFinger.finger(user)
|
||||||
|
|
||||||
|
assert data["magic_key"] == "RSA.qfYaxztz7ZELrE4v5WpJrPM99SKI3iv9Y3Tw6nfLGk-4CRljNYqV8IYX2FXjeucC_DKhPNnlF6fXyASpcSmA_qupX9WC66eVhFhZ5OuyBOeLvJ1C4x7Hi7Di8MNBxY3VdQuQR0tTaS_YAZCwASKp7H6XEid3EJpGt0EQZoNzRd8=.AQAB"
|
||||||
|
assert data["topic"] == "https://gnusocial.de/api/statuses/user_timeline/249296.atom"
|
||||||
|
assert data["subject"] == "acct:winterdienst@gnusocial.de"
|
||||||
|
assert data["salmon"] == "https://gnusocial.de/main/salmon/user/249296"
|
||||||
|
assert data["subscribe_address"] == "https://gnusocial.de/main/ostatussub?profile={uri}"
|
||||||
|
end
|
||||||
|
|
||||||
test "it works for friendica" do
|
test "it works for friendica" do
|
||||||
user = "lain@squeet.me"
|
user = "lain@squeet.me"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue