From a2c181f7feb4bbf54540afaa4a06d9ed8eb5b3ec Mon Sep 17 00:00:00 2001 From: Julien Lavergne Date: Fri, 24 May 2019 09:18:19 +0200 Subject: [PATCH] Update NodeInfo support to 2.1 (#79) --- config/config.exs | 3 ++- .../controllers/node_info_controller.ex | 15 ++++++++------- .../controllers/nodeinfo_controller_test.exs | 14 +++++++++----- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/config/config.exs b/config/config.exs index c83cac04..8d65f58c 100644 --- a/config/config.exs +++ b/config/config.exs @@ -13,7 +13,8 @@ config :mobilizon, :instance, name: System.get_env("MOBILIZON_INSTANCE_NAME") || "Localhost", description: System.get_env("MOBILIZON_INSTANCE_DESCRIPTION") || "This is a Mobilizon instance", version: "1.0.0-dev", - registrations_open: System.get_env("MOBILIZON_INSTANCE_REGISTRATIONS_OPEN") || false + registrations_open: System.get_env("MOBILIZON_INSTANCE_REGISTRATIONS_OPEN") || false, + repository: Mix.Project.config()[:source_url] config :mime, :types, %{ "application/activity+json" => ["activity-json"], diff --git a/lib/mobilizon_web/controllers/node_info_controller.ex b/lib/mobilizon_web/controllers/node_info_controller.ex index c20b8292..b044d0e3 100644 --- a/lib/mobilizon_web/controllers/node_info_controller.ex +++ b/lib/mobilizon_web/controllers/node_info_controller.ex @@ -14,8 +14,8 @@ defmodule MobilizonWeb.NodeInfoController do response = %{ links: [ %{ - rel: "http://nodeinfo.diaspora.software/ns/schema/2.0", - href: MobilizonWeb.Router.Helpers.node_info_url(MobilizonWeb.Endpoint, :nodeinfo, "2.0") + rel: "http://nodeinfo.diaspora.software/ns/schema/2.1", + href: MobilizonWeb.Router.Helpers.node_info_url(MobilizonWeb.Endpoint, :nodeinfo, "2.1") } ] } @@ -23,13 +23,14 @@ defmodule MobilizonWeb.NodeInfoController 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 response = %{ - version: "2.0", + version: "2.1", software: %{ name: "mobilizon", - version: Keyword.get(@instance, :version) + version: Keyword.get(@instance, :version), + repository: Keyword.get(@instance, :repository) }, protocols: ["activitypub"], services: %{ @@ -52,7 +53,7 @@ defmodule MobilizonWeb.NodeInfoController 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/mobilizon_web/controllers/nodeinfo_controller_test.exs b/test/mobilizon_web/controllers/nodeinfo_controller_test.exs index 1aad43c1..832a9578 100644 --- a/test/mobilizon_web/controllers/nodeinfo_controller_test.exs +++ b/test/mobilizon_web/controllers/nodeinfo_controller_test.exs @@ -13,16 +13,16 @@ defmodule MobilizonWeb.NodeInfoControllerTest do MobilizonWeb.Router.Helpers.node_info_url( MobilizonWeb.Endpoint, :nodeinfo, - "2.0" + "2.1" ), - "rel" => "http://nodeinfo.diaspora.software/ns/schema/2.0" + "rel" => "http://nodeinfo.diaspora.software/ns/schema/2.1" } ] } end test "Get node info", %{conn: conn} do - conn = get(conn, node_info_path(conn, :nodeinfo, "2.0")) + conn = get(conn, node_info_path(conn, :nodeinfo, "2.1")) resp = json_response(conn, 200) @@ -31,9 +31,13 @@ defmodule MobilizonWeb.NodeInfoControllerTest do "openRegistrations" => Keyword.get(@instance, :registrations_open), "protocols" => ["activitypub"], "services" => %{"inbound" => [], "outbound" => []}, - "software" => %{"name" => "mobilizon", "version" => Keyword.get(@instance, :version)}, + "software" => %{ + "name" => "mobilizon", + "version" => Keyword.get(@instance, :version), + "repository" => Keyword.get(@instance, :repository) + }, "usage" => %{"localComments" => 0, "localPosts" => 0, "users" => %{"total" => 0}}, - "version" => "2.0" + "version" => "2.1" } end