From 589c0abb01659872aadce8303b5efa731fea284a Mon Sep 17 00:00:00 2001 From: miraikumiko Date: Wed, 18 Jun 2025 19:18:43 +0200 Subject: [PATCH 1/2] Update actor_controller_test.exs --- test/nulla_web/controllers/actor_controller_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/nulla_web/controllers/actor_controller_test.exs b/test/nulla_web/controllers/actor_controller_test.exs index 01cc610..db916a2 100644 --- a/test/nulla_web/controllers/actor_controller_test.exs +++ b/test/nulla_web/controllers/actor_controller_test.exs @@ -65,8 +65,8 @@ defmodule NullaWeb.ActorControllerTest do assert is_list(response["tag"]) assert is_list(response["attachment"]) assert is_map(response["endpoints"]) - assert is_map(response["icon"]) - assert is_map(response["image"]) + assert is_map(response["icon"]) or is_nil(response["icon"]) + assert is_map(response["image"]) or is_nil(response["image"]) assert is_binary(response["vcard:bday"]) or is_nil(response["vcard:bday"]) assert is_binary(response["vcard:Address"]) or is_nil(response["vcard:Address"]) end From 9d72fb293b19d1266ef08e52c10d22022fc2a812 Mon Sep 17 00:00:00 2001 From: miraikumiko Date: Wed, 18 Jun 2025 19:19:02 +0200 Subject: [PATCH 2/2] Add webfinger_controller_test.exs --- .../controllers/webfinger_controller_test.exs | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test/nulla_web/controllers/webfinger_controller_test.exs diff --git a/test/nulla_web/controllers/webfinger_controller_test.exs b/test/nulla_web/controllers/webfinger_controller_test.exs new file mode 100644 index 0000000..041ec5a --- /dev/null +++ b/test/nulla_web/controllers/webfinger_controller_test.exs @@ -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