From c9f58ea8995a32c9a1f7268f7ddc699532e61a7c Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 28 Nov 2018 10:49:16 +0100 Subject: [PATCH] A few more tests Signed-off-by: Thomas Citharel --- lib/service/web_finger/web_finger.ex | 7 ++++--- .../mobilizon_web/controllers/nodeinfo_controller_test.exs | 6 ++++++ .../controllers/webfinger_controller_test.exs | 5 +++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/service/web_finger/web_finger.ex b/lib/service/web_finger/web_finger.ex index 36d62014b..fdd561bf1 100644 --- a/lib/service/web_finger/web_finger.ex +++ b/lib/service/web_finger/web_finger.ex @@ -6,6 +6,7 @@ defmodule Mobilizon.Service.WebFinger do """ alias Mobilizon.Actors + alias Mobilizon.Actors.Actor alias Mobilizon.Service.XmlBuilder require Jason require Logger @@ -32,12 +33,12 @@ defmodule Mobilizon.Service.WebFinger do host = MobilizonWeb.Endpoint.host() regex = ~r/(acct:)?(?\w+)@#{host}/ - with %{"name" => name} <- Regex.named_captures(regex, resource) do - actor = Actors.get_local_actor_by_name(name) + with %{"name" => name} <- Regex.named_captures(regex, resource), + %Actor{} = actor <- Actors.get_local_actor_by_name(name) do {:ok, represent_actor(actor, "JSON")} else _e -> - with actor when not is_nil(actor) <- Actors.get_actor_by_url!(resource) do + with %Actor{} = actor when not is_nil(actor) <- Actors.get_actor_by_url(resource) do {:ok, represent_actor(actor, "JSON")} else _e -> diff --git a/test/mobilizon_web/controllers/nodeinfo_controller_test.exs b/test/mobilizon_web/controllers/nodeinfo_controller_test.exs index b929cc2e0..1aad43c15 100644 --- a/test/mobilizon_web/controllers/nodeinfo_controller_test.exs +++ b/test/mobilizon_web/controllers/nodeinfo_controller_test.exs @@ -36,4 +36,10 @@ defmodule MobilizonWeb.NodeInfoControllerTest do "version" => "2.0" } end + + test "Get node info with non supported version (1.0)", %{conn: conn} do + conn = get(conn, node_info_path(conn, :nodeinfo, "1.0")) + + assert json_response(conn, 404) == %{"error" => "Nodeinfo schema version not handled"} + end end diff --git a/test/mobilizon_web/controllers/webfinger_controller_test.exs b/test/mobilizon_web/controllers/webfinger_controller_test.exs index da2096112..de9b2643b 100644 --- a/test/mobilizon_web/controllers/webfinger_controller_test.exs +++ b/test/mobilizon_web/controllers/webfinger_controller_test.exs @@ -21,6 +21,11 @@ defmodule MobilizonWeb.WebFingerTest do assert json_response(conn, 200) == WebFinger.represent_actor(actor) end + test "GET /.well-known/webfinger with non existent actor", %{conn: conn} do + conn = get(conn, "/.well-known/webfinger?resource=acct:notme@localhost:4001") + assert response(conn, 404) == "Couldn't find user" + end + test "GET /.well-known/webfinger with no query", %{conn: conn} do conn = get(conn, "/.well-known/webfinger") assert response(conn, 400) == "No query provided"