From 18370767c26cc02b8150333044d60d80494b7732 Mon Sep 17 00:00:00 2001 From: Floatingghost Date: Tue, 20 Aug 2024 11:05:17 +0100 Subject: [PATCH] mix format --- lib/pleroma/user/signing_key.ex | 20 ++++--- test/pleroma/user_search_test.exs | 2 +- .../activity_pub_controller_test.exs | 47 ++++++++------- .../web/activity_pub/publisher_test.exs | 57 ++++++++++++------- test/support/helpers.ex | 1 + test/support/matching_helpers.ex | 1 + 6 files changed, 78 insertions(+), 50 deletions(-) diff --git a/lib/pleroma/user/signing_key.ex b/lib/pleroma/user/signing_key.ex index 1fa574ae2..11786bbb0 100644 --- a/lib/pleroma/user/signing_key.ex +++ b/lib/pleroma/user/signing_key.ex @@ -144,14 +144,20 @@ defmodule Pleroma.User.SigningKey do @doc """ Given a user, return the private key for that user in binary format. """ - def private_key(%User{signing_key: %__MODULE__{private_key: private_key_pem}}) do - key = - private_key_pem - |> :public_key.pem_decode() - |> hd() - |> :public_key.pem_entry_decode() + def private_key(%User{} = user) do + case Repo.preload(user, :signing_key) do + %{signing_key: %__MODULE__{private_key: private_key_pem}} -> + key = + private_key_pem + |> :public_key.pem_decode() + |> hd() + |> :public_key.pem_entry_decode() - {:ok, key} + {:ok, key} + + _ -> + {:error, "key not found"} + end end @spec get_or_fetch_by_key_id(String.t()) :: {:ok, __MODULE__} | {:error, String.t()} diff --git a/test/pleroma/user_search_test.exs b/test/pleroma/user_search_test.exs index 5d018a301..b499629c8 100644 --- a/test/pleroma/user_search_test.exs +++ b/test/pleroma/user_search_test.exs @@ -259,7 +259,7 @@ defmodule Pleroma.UserSearchTest do |> Map.put(:multi_factor_authentication_settings, nil) |> Map.put(:notification_settings, nil) - assert_user_match(user, expected) + assert_user_match(user, expected) end test "excludes a blocked users from search result" do diff --git a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs index 120fb6d1b..183818159 100644 --- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs @@ -710,15 +710,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do headers: [{"content-type", "application/activity+json"}] } - %{ - method: :get, - url: ^key_id - } -> - %Tesla.Env{ - status: 200, - body: user, - headers: [{"content-type", "application/activity+json"}] - } + %{ + method: :get, + url: ^key_id + } -> + %Tesla.Env{ + status: 200, + body: user, + headers: [{"content-type", "application/activity+json"}] + } %{method: :get, url: "https://example.com/users/lain/collections/featured"} -> %Tesla.Env{ @@ -823,15 +823,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do headers: [{"content-type", "application/activity+json"}] } - %{ - method: :get, - url: ^key_id - } -> - %Tesla.Env{ - status: 200, - body: user, - headers: [{"content-type", "application/activity+json"}] - } + %{ + method: :get, + url: ^key_id + } -> + %Tesla.Env{ + status: 200, + body: user, + headers: [{"content-type", "application/activity+json"}] + } + %{method: :get, url: "https://example.com/users/lain/collections/featured"} -> %Tesla.Env{ status: 200, @@ -927,8 +928,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do end test "it accepts messages with to as string instead of array", %{conn: conn, data: data} do - user = insert(:user) - |> with_signing_key() + user = + insert(:user) + |> with_signing_key() data = data @@ -973,8 +975,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do end test "it accepts messages with bcc as string instead of array", %{conn: conn, data: data} do - user = insert(:user) - |> with_signing_key() + user = + insert(:user) + |> with_signing_key() data = data diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs index 726d85958..eeec59cfb 100644 --- a/test/pleroma/web/activity_pub/publisher_test.exs +++ b/test/pleroma/web/activity_pub/publisher_test.exs @@ -140,8 +140,9 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do {:ok, %Tesla.Env{status: 200, body: "port 80"}} end) - actor = insert(:user) - |> with_signing_key() + actor = + insert(:user) + |> with_signing_key() assert {:ok, %{body: "port 42"}} = Publisher.publish_one(%{ @@ -166,8 +167,10 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Instances, [:passthrough], [] do - actor = insert(:user) - |> with_signing_key() + actor = + insert(:user) + |> with_signing_key() + inbox = "http://200.site/users/nick1/inbox" assert {:ok, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) @@ -178,8 +181,10 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Instances, [:passthrough], [] do - actor = insert(:user) - |> with_signing_key() + actor = + insert(:user) + |> with_signing_key() + inbox = "http://200.site/users/nick1/inbox" assert {:ok, _} = @@ -198,8 +203,10 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Instances, [:passthrough], [] do - actor = insert(:user) - |> with_signing_key() + actor = + insert(:user) + |> with_signing_key() + inbox = "http://200.site/users/nick1/inbox" assert {:ok, _} = @@ -218,8 +225,10 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Instances, [:passthrough], [] do - actor = insert(:user) - |> with_signing_key() + actor = + insert(:user) + |> with_signing_key() + inbox = "http://404.site/users/nick1/inbox" assert {:error, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) @@ -231,8 +240,10 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Instances, [:passthrough], [] do - actor = insert(:user) - |> with_signing_key() + actor = + insert(:user) + |> with_signing_key() + inbox = "http://connrefused.site/users/nick1/inbox" assert capture_log(fn -> @@ -247,8 +258,10 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Instances, [:passthrough], [] do - actor = insert(:user) - |> with_signing_key() + actor = + insert(:user) + |> with_signing_key() + inbox = "http://200.site/users/nick1/inbox" assert {:ok, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) @@ -260,8 +273,10 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do Instances, [:passthrough], [] do - actor = insert(:user) - |> with_signing_key() + actor = + insert(:user) + |> with_signing_key() + inbox = "http://connrefused.site/users/nick1/inbox" assert capture_log(fn -> @@ -302,8 +317,9 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do ap_enabled: true }) - actor = insert(:user, follower_address: follower.ap_id) - |> with_signing_key() + actor = + insert(:user, follower_address: follower.ap_id) + |> with_signing_key() {:ok, follower, actor} = Pleroma.User.follow(follower, actor) {:ok, _another_follower, actor} = Pleroma.User.follow(another_follower, actor) @@ -374,8 +390,9 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do ap_enabled: true }) - actor = insert(:user, follower_address: follower.ap_id) - |> with_signing_key() + actor = + insert(:user, follower_address: follower.ap_id) + |> with_signing_key() {:ok, follower, actor} = Pleroma.User.follow(follower, actor) actor = refresh_record(actor) diff --git a/test/support/helpers.ex b/test/support/helpers.ex index 8d481b5f5..f0beae8ec 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -65,6 +65,7 @@ defmodule Pleroma.Tests.Helpers do clear_config: 1, clear_config: 2 ] + import Pleroma.Test.MatchingHelpers def time_travel(entity, seconds) do diff --git a/test/support/matching_helpers.ex b/test/support/matching_helpers.ex index 39963171f..c8411b907 100644 --- a/test/support/matching_helpers.ex +++ b/test/support/matching_helpers.ex @@ -1,5 +1,6 @@ defmodule Pleroma.Test.MatchingHelpers do import ExUnit.Assertions + @assoc_fields [ :signing_key ]