A few more tests

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2018-11-28 10:49:16 +01:00
parent 3ddd5ee485
commit c9f58ea899
3 changed files with 15 additions and 3 deletions

View file

@ -6,6 +6,7 @@ defmodule Mobilizon.Service.WebFinger do
""" """
alias Mobilizon.Actors alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.XmlBuilder alias Mobilizon.Service.XmlBuilder
require Jason require Jason
require Logger require Logger
@ -32,12 +33,12 @@ defmodule Mobilizon.Service.WebFinger do
host = MobilizonWeb.Endpoint.host() host = MobilizonWeb.Endpoint.host()
regex = ~r/(acct:)?(?<name>\w+)@#{host}/ regex = ~r/(acct:)?(?<name>\w+)@#{host}/
with %{"name" => name} <- Regex.named_captures(regex, resource) do with %{"name" => name} <- Regex.named_captures(regex, resource),
actor = Actors.get_local_actor_by_name(name) %Actor{} = actor <- Actors.get_local_actor_by_name(name) do
{:ok, represent_actor(actor, "JSON")} {:ok, represent_actor(actor, "JSON")}
else else
_e -> _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")} {:ok, represent_actor(actor, "JSON")}
else else
_e -> _e ->

View file

@ -36,4 +36,10 @@ defmodule MobilizonWeb.NodeInfoControllerTest do
"version" => "2.0" "version" => "2.0"
} }
end 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 end

View file

@ -21,6 +21,11 @@ defmodule MobilizonWeb.WebFingerTest do
assert json_response(conn, 200) == WebFinger.represent_actor(actor) assert json_response(conn, 200) == WebFinger.represent_actor(actor)
end 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 test "GET /.well-known/webfinger with no query", %{conn: conn} do
conn = get(conn, "/.well-known/webfinger") conn = get(conn, "/.well-known/webfinger")
assert response(conn, 400) == "No query provided" assert response(conn, 400) == "No query provided"