2018-12-27 10:24:04 +00:00
|
|
|
# Portions of this file are derived from Pleroma:
|
|
|
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/web_finger/web_finger_test.exs
|
|
|
|
|
2020-01-22 21:40:40 +00:00
|
|
|
defmodule Mobilizon.Federation.WebFingerTest do
|
2020-01-22 01:14:42 +00:00
|
|
|
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
2018-10-11 15:37:39 +00:00
|
|
|
use Mobilizon.DataCase
|
2020-01-22 01:14:42 +00:00
|
|
|
|
2018-10-11 15:37:39 +00:00
|
|
|
import Mobilizon.Factory
|
2018-05-17 09:32:23 +00:00
|
|
|
|
2020-01-22 21:40:40 +00:00
|
|
|
alias Mobilizon.Federation.WebFinger
|
2018-11-13 11:23:37 +00:00
|
|
|
|
2020-01-28 18:18:33 +00:00
|
|
|
alias Mobilizon.Web.Endpoint
|
|
|
|
|
2018-11-13 11:23:37 +00:00
|
|
|
@mastodon_account "tcit@social.tcit.fr"
|
|
|
|
@mastodon_account_username "tcit"
|
|
|
|
@pleroma_account "lain@pleroma.soykaf.com"
|
|
|
|
@pleroma_account_username "lain"
|
|
|
|
@peertube_account "framasoft@framatube.org"
|
|
|
|
@peertube_account_username "framasoft"
|
|
|
|
@friendica_account "lain@squeet.me"
|
|
|
|
@friendica_account_username "lain"
|
|
|
|
|
2018-05-17 09:32:23 +00:00
|
|
|
describe "host meta" do
|
|
|
|
test "returns a link to the xml lrdd" do
|
|
|
|
host_info = WebFinger.host_meta()
|
|
|
|
|
2020-01-28 18:18:33 +00:00
|
|
|
assert String.contains?(host_info, Endpoint.url())
|
2018-05-17 09:32:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "incoming webfinger request" do
|
|
|
|
test "works for fqns" do
|
2018-06-14 15:25:55 +00:00
|
|
|
actor = insert(:actor)
|
2018-05-17 09:32:23 +00:00
|
|
|
|
|
|
|
{:ok, result} =
|
2020-01-26 20:53:04 +00:00
|
|
|
WebFinger.webfinger(
|
2020-01-28 18:18:33 +00:00
|
|
|
"#{actor.preferred_username}@#{Endpoint.host()}",
|
2020-01-26 20:53:04 +00:00
|
|
|
"JSON"
|
|
|
|
)
|
2018-07-27 08:45:35 +00:00
|
|
|
|
2018-05-17 09:32:23 +00:00
|
|
|
assert is_map(result)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "works for urls" do
|
2018-06-14 15:25:55 +00:00
|
|
|
actor = insert(:actor)
|
2018-05-17 09:32:23 +00:00
|
|
|
|
2018-06-14 15:25:55 +00:00
|
|
|
{:ok, result} = WebFinger.webfinger(actor.url, "JSON")
|
2018-05-17 09:32:23 +00:00
|
|
|
assert is_map(result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "fingering" do
|
2018-06-14 15:25:55 +00:00
|
|
|
test "a mastodon actor" do
|
2018-11-13 11:23:37 +00:00
|
|
|
use_cassette "webfinger/mastodon" do
|
|
|
|
res = %{
|
|
|
|
"subject" => "acct:" <> @mastodon_account,
|
|
|
|
"url" => "https://social.tcit.fr/users/#{@mastodon_account_username}"
|
|
|
|
}
|
2018-05-17 09:32:23 +00:00
|
|
|
|
2018-11-13 11:23:37 +00:00
|
|
|
assert {:ok, res} == WebFinger.finger(@mastodon_account)
|
|
|
|
end
|
2018-05-17 09:32:23 +00:00
|
|
|
end
|
|
|
|
|
2018-06-14 15:25:55 +00:00
|
|
|
test "a pleroma actor" do
|
2018-11-13 11:23:37 +00:00
|
|
|
use_cassette "webfinger/pleroma" do
|
|
|
|
res = %{
|
|
|
|
"subject" => "acct:" <> @pleroma_account,
|
|
|
|
"url" => "https://pleroma.soykaf.com/users/#{@pleroma_account_username}"
|
|
|
|
}
|
2018-05-17 09:32:23 +00:00
|
|
|
|
2018-11-13 11:23:37 +00:00
|
|
|
assert {:ok, res} == WebFinger.finger(@pleroma_account)
|
|
|
|
end
|
2018-05-17 09:32:23 +00:00
|
|
|
end
|
|
|
|
|
2018-06-14 15:25:55 +00:00
|
|
|
test "a peertube actor" do
|
2018-11-13 11:23:37 +00:00
|
|
|
use_cassette "webfinger/peertube" do
|
|
|
|
res = %{
|
|
|
|
"subject" => "acct:" <> @peertube_account,
|
|
|
|
"url" => "https://framatube.org/accounts/#{@peertube_account_username}"
|
|
|
|
}
|
2018-05-17 09:32:23 +00:00
|
|
|
|
2018-11-13 11:23:37 +00:00
|
|
|
assert {:ok, res} == WebFinger.finger(@peertube_account)
|
|
|
|
end
|
2018-05-17 09:32:23 +00:00
|
|
|
end
|
|
|
|
|
2018-06-14 15:25:55 +00:00
|
|
|
test "a friendica actor" do
|
2018-11-13 11:23:37 +00:00
|
|
|
use_cassette "webfinger/friendica" do
|
|
|
|
res = %{
|
|
|
|
"subject" => "acct:" <> @friendica_account,
|
|
|
|
"url" => "https://squeet.me/profile/#{@friendica_account_username}"
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, res} == WebFinger.finger(@friendica_account)
|
|
|
|
end
|
2018-05-17 09:32:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|