From c05928dbdabfafc536512341e8d64b240b097f62 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 03:55:10 -0300 Subject: [PATCH 1/8] use nodeinfo 2.1, add repository field that is the only change from nodeinfo 2.0 to 2.1 also this makes the nodeinfo tests use 2.1.json instead of 2.0.json --- lib/pleroma/application.ex | 2 ++ lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 15 ++++++++------- test/web/node_info_test.exs | 8 ++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 40bff08c7..8b50bcf8c 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -8,9 +8,11 @@ defmodule Pleroma.Application do @name "Pleroma" @version Mix.Project.config()[:version] + @repository "https://git.pleroma.social/pleroma/pleroma" def name, do: @name def version, do: @version def named_version(), do: @name <> " " <> @version + def repository, do: @repository def user_agent() do info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>" diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 11b97164d..de7256dda 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -17,8 +17,8 @@ def schemas(conn, _params) do response = %{ links: [ %{ - rel: "http://nodeinfo.diaspora.software/ns/schema/2.0", - href: Web.base_url() <> "/nodeinfo/2.0.json" + rel: "http://nodeinfo.diaspora.software/ns/schema/2.1", + href: Web.base_url() <> "/nodeinfo/2.1.json" } ] } @@ -26,8 +26,8 @@ def schemas(conn, _params) do json(conn, response) end - # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json - def nodeinfo(conn, %{"version" => "2.0"}) do + # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json + def nodeinfo(conn, %{"version" => "2.1"}) do instance = Application.get_env(:pleroma, :instance) media_proxy = Application.get_env(:pleroma, :media_proxy) suggestions = Application.get_env(:pleroma, :suggestions) @@ -99,10 +99,11 @@ def nodeinfo(conn, %{"version" => "2.0"}) do |> Enum.filter(& &1) response = %{ - version: "2.0", + version: "2.1", software: %{ name: Pleroma.Application.name(), - version: Pleroma.Application.version() + version: Pleroma.Application.version(), + repository: Pleroma.Application.repository(), }, protocols: ["ostatus", "activitypub"], services: %{ @@ -146,7 +147,7 @@ def nodeinfo(conn, %{"version" => "2.0"}) do conn |> put_resp_header( "content-type", - "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8" + "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.1#; charset=utf-8" ) |> json(response) end diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs index 5981c70a7..360ee0baf 100644 --- a/test/web/node_info_test.exs +++ b/test/web/node_info_test.exs @@ -12,7 +12,7 @@ test "nodeinfo shows staff accounts", %{conn: conn} do conn = conn - |> get("/nodeinfo/2.0.json") + |> get("/nodeinfo/2.1.json") assert result = json_response(conn, 200) @@ -22,7 +22,7 @@ test "nodeinfo shows staff accounts", %{conn: conn} do test "nodeinfo shows restricted nicknames", %{conn: conn} do conn = conn - |> get("/nodeinfo/2.0.json") + |> get("/nodeinfo/2.1.json") assert result = json_response(conn, 200) @@ -42,7 +42,7 @@ test "returns 404 when federation is disabled", %{conn: conn} do |> json_response(404) conn - |> get("/nodeinfo/2.0.json") + |> get("/nodeinfo/2.1.json") |> json_response(404) instance = @@ -58,7 +58,7 @@ test "returns 200 when federation is enabled", %{conn: conn} do |> json_response(200) conn - |> get("/nodeinfo/2.0.json") + |> get("/nodeinfo/2.1.json") |> json_response(200) end end From b0c4c082c4d166f3f49ffce69bb86639c1a34790 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 04:02:40 -0300 Subject: [PATCH 2/8] mix format pass --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index de7256dda..f5974fbb9 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -103,7 +103,7 @@ def nodeinfo(conn, %{"version" => "2.1"}) do software: %{ name: Pleroma.Application.name(), version: Pleroma.Application.version(), - repository: Pleroma.Application.repository(), + repository: Pleroma.Application.repository() }, protocols: ["ostatus", "activitypub"], services: %{ From cd6db6abe4df010905649816735d925c0538da34 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 14:11:23 -0300 Subject: [PATCH 3/8] use Mix.Project.Config for some Application functions --- lib/pleroma/application.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 8b50bcf8c..d67e2cdc8 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -6,9 +6,9 @@ defmodule Pleroma.Application do use Application import Supervisor.Spec - @name "Pleroma" + @name Mix.Project.config()[:name] @version Mix.Project.config()[:version] - @repository "https://git.pleroma.social/pleroma/pleroma" + @repository Mix.Project.config()[:source_url] def name, do: @name def version, do: @version def named_version(), do: @name <> " " <> @version From b17ce875cf3ae73423f737e46b7103116f45e7d0 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 14:23:40 -0300 Subject: [PATCH 4/8] keep compatibility with nodeinfo 2.0 splits actual nodeinfo generation into raw_nodeinfo, the 2.0 handler gives the same result, while the 2.1 handler inserts the software.repository field. requested by @href --- .../web/nodeinfo/nodeinfo_controller.ex | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index f5974fbb9..72b5d97ac 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -16,6 +16,10 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do def schemas(conn, _params) do response = %{ links: [ + %{ + rel: "http://nodeinfo.diaspora.software/ns/schema/2.0", + href: Web.base_url() <> "/nodeinfo/2.0.json" + }, %{ rel: "http://nodeinfo.diaspora.software/ns/schema/2.1", href: Web.base_url() <> "/nodeinfo/2.1.json" @@ -26,8 +30,9 @@ def schemas(conn, _params) do json(conn, response) end - # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json - def nodeinfo(conn, %{"version" => "2.1"}) do + # returns a nodeinfo 2.0 map, since 2.1 just adds a repository field + # under software. + def raw_nodeinfo() do instance = Application.get_env(:pleroma, :instance) media_proxy = Application.get_env(:pleroma, :media_proxy) suggestions = Application.get_env(:pleroma, :suggestions) @@ -98,12 +103,11 @@ def nodeinfo(conn, %{"version" => "2.1"}) do ] |> Enum.filter(& &1) - response = %{ - version: "2.1", + %{ + version: "2.0", software: %{ name: Pleroma.Application.name(), version: Pleroma.Application.version(), - repository: Pleroma.Application.repository() }, protocols: ["ostatus", "activitypub"], services: %{ @@ -143,6 +147,28 @@ def nodeinfo(conn, %{"version" => "2.1"}) do restrictedNicknames: Pleroma.Config.get([Pleroma.User, :restricted_nicknames]) } } + end + + # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json + # and https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json + def nodeinfo(conn, %{"version" => "2.0"}) do + conn + |> put_resp_header( + "content-type", + "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8" + ) + |> json(raw_nodeinfo()) + end + + def nodeinfo(conn, %{"version" => "2.1"}) do + raw_response = raw_nodeinfo() + + updated_software = + raw_response + |> Map.get(:software) + |> Map.put(:repository, Pleroma.Application.repository()) + + response = raw_response |> Map.put(:software, updated_software) conn |> put_resp_header( From e8c7be38fcf416eb8676c5e586c56c15b4f88986 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 14:33:14 -0300 Subject: [PATCH 5/8] add tests for nodeinfo 2.0 compat and 2.1's new field --- test/web/node_info_test.exs | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs index 360ee0baf..763549bd1 100644 --- a/test/web/node_info_test.exs +++ b/test/web/node_info_test.exs @@ -61,4 +61,49 @@ test "returns 200 when federation is enabled", %{conn: conn} do |> get("/nodeinfo/2.1.json") |> json_response(200) end + + test "returns 404 when federation is disabled (nodeinfo 2.0)", %{conn: conn} do + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:federating, false) + + Application.put_env(:pleroma, :instance, instance) + + conn + |> get("/.well-known/nodeinfo") + |> json_response(404) + + conn + |> get("/nodeinfo/2.0.json") + |> json_response(404) + + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:federating, true) + + Application.put_env(:pleroma, :instance, instance) + end + + test "returns 200 when federation is enabled (nodeinfo 2.0)", %{conn: conn} do + conn + |> get("/.well-known/nodeinfo") + |> json_response(200) + + conn + |> get("/nodeinfo/2.0.json") + |> json_response(200) + end + + test "returns software.repository field in nodeinfo 2.1", %{conn: conn} do + conn + |> get("/.well-known/nodeinfo") + |> json_response(200) + + conn = + conn + |> get("/nodeinfo/2.1.json") + + assert result = json_response(conn, 200) + assert Pleroma.Application.repository() == result["software"]["repository"] + end end From 23b1c64a19ab13b152ba46e1a744cbf2efafce57 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 14:35:08 -0300 Subject: [PATCH 6/8] downcase software name in nodeinfo --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 72b5d97ac..b1db58d0b 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -106,7 +106,7 @@ def raw_nodeinfo() do %{ version: "2.0", software: %{ - name: Pleroma.Application.name(), + name: Pleroma.Application.name() |> String.downcase, version: Pleroma.Application.version(), }, protocols: ["ostatus", "activitypub"], From 1cdcee89daec2f0538c6ab69cd9259d6486a7f6f Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 14:40:43 -0300 Subject: [PATCH 7/8] mix format pass --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index b1db58d0b..a1a395c8f 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -106,8 +106,8 @@ def raw_nodeinfo() do %{ version: "2.0", software: %{ - name: Pleroma.Application.name() |> String.downcase, - version: Pleroma.Application.version(), + name: Pleroma.Application.name() |> String.downcase(), + version: Pleroma.Application.version() }, protocols: ["ostatus", "activitypub"], services: %{ From 9cac8729afa7219d8b87e2851b855cab7a1c04b3 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 16:03:23 -0300 Subject: [PATCH 8/8] update nodeinfo version when requesting 2.1 --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index a1a395c8f..21694a5ee 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -168,7 +168,10 @@ def nodeinfo(conn, %{"version" => "2.1"}) do |> Map.get(:software) |> Map.put(:repository, Pleroma.Application.repository()) - response = raw_response |> Map.put(:software, updated_software) + response = + raw_response + |> Map.put(:software, updated_software) + |> Map.put(:version, "2.1") conn |> put_resp_header(