Add webfinger_controller_test.exs

This commit is contained in:
Mirai Kumiko 2025-06-18 19:19:02 +02:00
parent 589c0abb01
commit 9d72fb293b
Signed by: miraikumiko
GPG key ID: 3F178B1B5E0CB278

View file

@ -0,0 +1,82 @@
defmodule NullaWeb.WebfingerControllerTest do
use NullaWeb.ConnCase
alias Nulla.Models.Actor
setup do
Actor.create_actor(%{
domain: "localhost",
ap_id: "http://localhost/users/test",
type: "Person",
following: "http://localhost/users/test/following",
followers: "http://localhost/users/test/followers",
inbox: "http://localhost/users/test/inbox",
outbox: "http://localhost/users/test/outbox",
featured: "http://localhost/users/test/collections/featured",
featuredTags: "http://localhost/users/test/collections/tags",
preferredUsername: "test",
name: "Test",
summary: "Test User",
url: "http://localhost/@test",
manuallyApprovesFollowers: false,
discoverable: true,
indexable: true,
published: DateTime.utc_now(),
memorial: false,
publicKey:
Jason.OrderedObject.new(
id: "http://localhost/users/test#main-key",
owner: "http://localhost/users/test",
publicKeyPem: "PUBLIC KEY"
),
endpoints: Jason.OrderedObject.new(sharedInbox: "http://localhost/inbox")
})
:ok
end
describe "GET /.well-known/webfinger" do
test "returns 400 without parameters", %{conn: conn} do
conn =
conn
|> get(~p"/.well-known/webfinger")
assert conn.status == 400
end
test "returns 400 without :acct", %{conn: conn} do
conn =
conn
|> get(~p"/.well-known/webfinger?resource=test@localhost")
assert conn.status == 400
end
test "returns 400 without domain", %{conn: conn} do
conn =
conn
|> get(~p"/.well-known/webfinger?resource=acct:test")
assert conn.status == 400
end
test "returns 404 with invalid domain", %{conn: conn} do
conn =
conn
|> get(~p"/.well-known/webfinger?resource=acct:test@example")
assert conn.status == 404
end
test "returns Webfinger", %{conn: conn} do
conn =
conn
|> get(~p"/.well-known/webfinger?resource=acct:test@localhost")
assert response = json_response(conn, 200)
assert is_binary(response["subject"])
assert is_list(response["aliases"])
assert is_list(response["links"])
end
end
end