Better tests
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
e454d0d470
commit
4eb51567c3
|
@ -522,19 +522,6 @@ defmodule Eventos.Actors do
|
|||
|
||||
alias Eventos.Actors.Member
|
||||
|
||||
@doc """
|
||||
Returns the list of members.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> list_members()
|
||||
[%Member{}, ...]
|
||||
|
||||
"""
|
||||
def list_members do
|
||||
Repo.all(Member)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single member.
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ defmodule EventosWeb.ActivityPubController do
|
|||
conn
|
||||
|> put_resp_header("content-type", "application/activity+json")
|
||||
|> json(ActorView.render("actor.json", %{actor: actor}))
|
||||
else
|
||||
nil -> {:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -25,9 +27,7 @@ defmodule EventosWeb.ActivityPubController do
|
|||
|> json(ObjectView.render("event.json", %{event: event}))
|
||||
else
|
||||
false ->
|
||||
conn
|
||||
|> put_status(404)
|
||||
|> json("Not found")
|
||||
{:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -86,19 +86,35 @@ defmodule EventosWeb.ActivityPubController do
|
|||
json(conn, "ok")
|
||||
end
|
||||
|
||||
# only accept relayed Creates
|
||||
def inbox(conn, %{"type" => "Create"} = params) do
|
||||
Logger.info(
|
||||
"Signature missing or not from author, relayed Create message, fetching object from source"
|
||||
)
|
||||
|
||||
ActivityPub.fetch_object_from_url(params["object"]["id"])
|
||||
|
||||
json(conn, "ok")
|
||||
end
|
||||
|
||||
def inbox(conn, params) do
|
||||
headers = Enum.into(conn.req_headers, %{})
|
||||
|
||||
if String.contains?(headers["signature"] || "", params["actor"]) do
|
||||
Logger.info("Signature error")
|
||||
Logger.info("Could not validate #{params["actor"]}")
|
||||
if String.contains?(headers["signature"], params["actor"]) do
|
||||
Logger.info(
|
||||
"Signature validation error for: #{params["actor"]}, make sure you are forwarding the HTTP Host header!"
|
||||
)
|
||||
|
||||
Logger.info(inspect(conn.req_headers))
|
||||
else
|
||||
Logger.info("Signature not from author, relayed message, fetching from source")
|
||||
ActivityPub.fetch_event_from_url(params["object"]["id"])
|
||||
end
|
||||
|
||||
json(conn, "ok")
|
||||
json(conn, "error")
|
||||
end
|
||||
|
||||
def errors(conn, {:error, :not_found}) do
|
||||
conn
|
||||
|> put_status(404)
|
||||
|> json("Not found")
|
||||
end
|
||||
|
||||
def errors(conn, _e) do
|
||||
|
|
|
@ -140,6 +140,24 @@ defmodule Eventos.EventsTest do
|
|||
event1 = insert(:event, organizer_actor: actor)
|
||||
assert {:ok, [event_found], 2} = Events.get_events_for_actor(actor, 1, 1)
|
||||
end
|
||||
|
||||
test "get_event_by_url/1 with valid url", %{actor: actor, event: event} do
|
||||
assert event = Events.get_event_by_url(event.url)
|
||||
end
|
||||
|
||||
test "get_event_by_url/1 with bad url", %{actor: actor, event: event} do
|
||||
refute event == Events.get_event_by_url("not valid")
|
||||
end
|
||||
|
||||
test "get_event_by_url!/1 with valid url", %{actor: actor, event: event} do
|
||||
assert event = Events.get_event_by_url!(event.url)
|
||||
end
|
||||
|
||||
test "get_event_by_url!/1 with bad url", %{actor: actor, event: event} do
|
||||
assert_raise Ecto.NoResultsError, fn ->
|
||||
Events.get_event_by_url!("not valid")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "categories" do
|
||||
|
|
Loading…
Reference in New Issue