feat(nodeinfo): extract and save NodeInfo information from instances to display it on instances list
We also try to detect the application actor if it's not given by NodeInfo metadata (FEP-2677) (guessing for Mobilizon, PeerTube & Mastodon). Closes #1392 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -8,6 +8,10 @@ defmodule Mobilizon.Federation.NodeInfoTest do
|
||||
@instance_domain "event-federation.eu"
|
||||
@nodeinfo_fixture_path "test/fixtures/nodeinfo/wp-event-federation.json"
|
||||
@nodeinfo_regular_fixture_path "test/fixtures/nodeinfo/regular.json"
|
||||
@nodeinfo_both_versions_fixture_path "test/fixtures/nodeinfo/both_versions.json"
|
||||
@nodeinfo_older_versions_fixture_path "test/fixtures/nodeinfo/older_versions.json"
|
||||
@nodeinfo_data_fixture_path "test/fixtures/nodeinfo/data.json"
|
||||
@nodeinfo_wp_data_fixture_path "test/fixtures/nodeinfo/wp-data.json"
|
||||
|
||||
describe "getting application actor" do
|
||||
test "from wordpress event federation" do
|
||||
@@ -57,4 +61,128 @@ defmodule Mobilizon.Federation.NodeInfoTest do
|
||||
assert nil == NodeInfo.application_actor(@instance_domain)
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting informations" do
|
||||
test "with both 2.0 and 2.1 endpoints" do
|
||||
nodeinfo_end_point_data =
|
||||
@nodeinfo_both_versions_fixture_path |> File.read!() |> Jason.decode!()
|
||||
|
||||
nodeinfo_data = @nodeinfo_data_fixture_path |> File.read!() |> Jason.decode!()
|
||||
|
||||
WebfingerClientMock
|
||||
|> expect(:call, fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://mobilizon.fr/.well-known/nodeinfo"
|
||||
},
|
||||
_opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: nodeinfo_end_point_data}}
|
||||
end)
|
||||
|
||||
WebfingerClientMock
|
||||
|> expect(:call, fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://mobilizon.fr/.well-known/nodeinfo/2.1"
|
||||
},
|
||||
_opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: nodeinfo_data}}
|
||||
end)
|
||||
|
||||
assert {:ok, data} = NodeInfo.nodeinfo("mobilizon.fr")
|
||||
assert data["version"] == "2.1"
|
||||
assert data["software"]["name"] == "Mobilizon"
|
||||
# Added in 2.1
|
||||
refute is_nil(data["software"]["repository"])
|
||||
end
|
||||
|
||||
test "with only 2.0 endpoint" do
|
||||
nodeinfo_end_point_data = @nodeinfo_regular_fixture_path |> File.read!() |> Jason.decode!()
|
||||
nodeinfo_wp_data = @nodeinfo_wp_data_fixture_path |> File.read!() |> Jason.decode!()
|
||||
|
||||
WebfingerClientMock
|
||||
|> expect(:call, fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://event-federation.eu/.well-known/nodeinfo"
|
||||
},
|
||||
_opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: nodeinfo_end_point_data}}
|
||||
end)
|
||||
|
||||
WebfingerClientMock
|
||||
|> expect(:call, fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://event-federation.eu/wp-json/activitypub/1.0/nodeinfo"
|
||||
},
|
||||
_opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: nodeinfo_wp_data}}
|
||||
end)
|
||||
|
||||
assert {:ok, data} = NodeInfo.nodeinfo("event-federation.eu")
|
||||
assert data["version"] == "2.0"
|
||||
assert data["software"]["name"] == "wordpress"
|
||||
# Added in 2.1
|
||||
assert is_nil(data["software"]["repository"])
|
||||
end
|
||||
|
||||
test "with no valid endpoint" do
|
||||
nodeinfo_end_point_data =
|
||||
@nodeinfo_older_versions_fixture_path |> File.read!() |> Jason.decode!()
|
||||
|
||||
WebfingerClientMock
|
||||
|> expect(:call, fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://somewhere.tld/.well-known/nodeinfo"
|
||||
},
|
||||
_opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: nodeinfo_end_point_data}}
|
||||
end)
|
||||
|
||||
assert {:error, :no_node_info_endpoint_found} = NodeInfo.nodeinfo("somewhere.tld")
|
||||
end
|
||||
|
||||
test "with no answer from well-known endpoint" do
|
||||
WebfingerClientMock
|
||||
|> expect(:call, fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://somewhere.tld/.well-known/nodeinfo"
|
||||
},
|
||||
_opts ->
|
||||
{:ok, %Tesla.Env{status: 404}}
|
||||
end)
|
||||
|
||||
assert {:error, :node_info_meta_http_error} = NodeInfo.nodeinfo("somewhere.tld")
|
||||
end
|
||||
|
||||
test "with no answer from version endpoint" do
|
||||
nodeinfo_end_point_data =
|
||||
@nodeinfo_both_versions_fixture_path |> File.read!() |> Jason.decode!()
|
||||
|
||||
WebfingerClientMock
|
||||
|> expect(:call, fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://mobilizon.fr/.well-known/nodeinfo"
|
||||
},
|
||||
_opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: nodeinfo_end_point_data}}
|
||||
end)
|
||||
|
||||
WebfingerClientMock
|
||||
|> expect(:call, fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://mobilizon.fr/.well-known/nodeinfo/2.1"
|
||||
},
|
||||
_opts ->
|
||||
{:ok, %Tesla.Env{status: 404}}
|
||||
end)
|
||||
|
||||
assert {:error, :node_info_endpoint_http_error} = NodeInfo.nodeinfo("mobilizon.fr")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
12
test/fixtures/nodeinfo/both_versions.json
vendored
Normal file
12
test/fixtures/nodeinfo/both_versions.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"links": [
|
||||
{
|
||||
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
|
||||
"href": "https://mobilizon.fr/.well-known/nodeinfo/2.0"
|
||||
},
|
||||
{
|
||||
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.1",
|
||||
"href": "https://mobilizon.fr/.well-known/nodeinfo/2.1"
|
||||
}
|
||||
]
|
||||
}
|
||||
29
test/fixtures/nodeinfo/data.json
vendored
Normal file
29
test/fixtures/nodeinfo/data.json
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"version": "2.1",
|
||||
"protocols": [
|
||||
"activitypub"
|
||||
],
|
||||
"metadata": {
|
||||
"nodeDescription": "Mobilizon.fr est l'instance Mobilizon de Framasoft.",
|
||||
"nodeName": "Mobilizon"
|
||||
},
|
||||
"usage": {
|
||||
"users": {
|
||||
"total": 9204
|
||||
},
|
||||
"localComments": 3253,
|
||||
"localPosts": 7545
|
||||
},
|
||||
"services": {
|
||||
"outbound": [
|
||||
"atom1.0"
|
||||
],
|
||||
"inbound": []
|
||||
},
|
||||
"software": {
|
||||
"name": "Mobilizon",
|
||||
"version": "4.0.2",
|
||||
"repository": "https://framagit.org/framasoft/mobilizon"
|
||||
},
|
||||
"openRegistrations": true
|
||||
}
|
||||
8
test/fixtures/nodeinfo/older_versions.json
vendored
Normal file
8
test/fixtures/nodeinfo/older_versions.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"links": [
|
||||
{
|
||||
"rel": "http://nodeinfo.diaspora.software/ns/schema/1.1",
|
||||
"href": "https://mobilizon.fr/.well-known/nodeinfo/1.1"
|
||||
}
|
||||
]
|
||||
}
|
||||
4
test/fixtures/nodeinfo/regular.json
vendored
4
test/fixtures/nodeinfo/regular.json
vendored
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"links": [
|
||||
{
|
||||
"rel": "http:\/\/nodeinfo.diaspora.software\/ns\/schema\/2.0",
|
||||
"href": "https:\/\/event-federation.eu\/wp-json\/activitypub\/1.0\/nodeinfo"
|
||||
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
|
||||
"href": "https://event-federation.eu/wp-json/activitypub/1.0/nodeinfo"
|
||||
}
|
||||
]
|
||||
}
|
||||
24
test/fixtures/nodeinfo/wp-data.json
vendored
Normal file
24
test/fixtures/nodeinfo/wp-data.json
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "2.0",
|
||||
"software": {
|
||||
"name": "wordpress",
|
||||
"version": "6.4.2"
|
||||
},
|
||||
"usage": {
|
||||
"users": {
|
||||
"total": 1,
|
||||
"activeMonth": 1,
|
||||
"activeHalfyear": 1
|
||||
},
|
||||
"localPosts": 3,
|
||||
"localComments": 3
|
||||
},
|
||||
"openRegistrations": false,
|
||||
"protocols": [
|
||||
"activitypub"
|
||||
],
|
||||
"services": {
|
||||
"inbound": [],
|
||||
"outbound": []
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"links": [
|
||||
{
|
||||
"rel": "http:\/\/nodeinfo.diaspora.software\/ns\/schema\/2.0",
|
||||
"href": "https:\/\/event-federation.eu\/wp-json\/activitypub\/1.0\/nodeinfo"
|
||||
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
|
||||
"href": "https://event-federation.eu/wp-json/activitypub/1.0/nodeinfo"
|
||||
},
|
||||
{
|
||||
"rel": "https://www.w3.org/ns/activitystreams#Application",
|
||||
|
||||
Reference in New Issue
Block a user