mix format
Some checks are pending
ci/woodpecker/push/build-amd64 Pipeline is pending
ci/woodpecker/pr/build-amd64 Pipeline is pending
ci/woodpecker/pr/build-arm64 Pipeline is pending
ci/woodpecker/pr/docs Pipeline is pending
ci/woodpecker/pr/lint Pipeline is pending
ci/woodpecker/push/build-arm64 Pipeline is pending
ci/woodpecker/push/docs Pipeline is pending
ci/woodpecker/push/lint Pipeline is pending
ci/woodpecker/push/test Pipeline is pending
ci/woodpecker/pr/test Pipeline is pending

This commit is contained in:
Floatingghost 2024-08-20 11:05:17 +01:00
parent ccf1007883
commit 430b376ded
6 changed files with 78 additions and 50 deletions

View file

@ -144,14 +144,20 @@ def public_key_pem(e) do
@doc """ @doc """
Given a user, return the private key for that user in binary format. 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 def private_key(%User{} = user) do
key = case Repo.preload(user, :signing_key) do
private_key_pem %{signing_key: %__MODULE__{private_key: private_key_pem}} ->
|> :public_key.pem_decode() key =
|> hd() private_key_pem
|> :public_key.pem_entry_decode() |> :public_key.pem_decode()
|> hd()
|> :public_key.pem_entry_decode()
{:ok, key} {:ok, key}
_ ->
{:error, "key not found"}
end
end end
@spec get_or_fetch_by_key_id(String.t()) :: {:ok, __MODULE__} | {:error, String.t()} @spec get_or_fetch_by_key_id(String.t()) :: {:ok, __MODULE__} | {:error, String.t()}

View file

@ -259,7 +259,7 @@ test "works with URIs" do
|> Map.put(:multi_factor_authentication_settings, nil) |> Map.put(:multi_factor_authentication_settings, nil)
|> Map.put(:notification_settings, nil) |> Map.put(:notification_settings, nil)
assert_user_match(user, expected) assert_user_match(user, expected)
end end
test "excludes a blocked users from search result" do test "excludes a blocked users from search result" do

View file

@ -710,15 +710,15 @@ test "accepts Add/Remove activities", %{conn: conn} do
headers: [{"content-type", "application/activity+json"}] headers: [{"content-type", "application/activity+json"}]
} }
%{ %{
method: :get, method: :get,
url: ^key_id url: ^key_id
} -> } ->
%Tesla.Env{ %Tesla.Env{
status: 200, status: 200,
body: user, body: user,
headers: [{"content-type", "application/activity+json"}] headers: [{"content-type", "application/activity+json"}]
} }
%{method: :get, url: "https://example.com/users/lain/collections/featured"} -> %{method: :get, url: "https://example.com/users/lain/collections/featured"} ->
%Tesla.Env{ %Tesla.Env{
@ -823,15 +823,16 @@ test "mastodon pin/unpin", %{conn: conn} do
headers: [{"content-type", "application/activity+json"}] headers: [{"content-type", "application/activity+json"}]
} }
%{ %{
method: :get, method: :get,
url: ^key_id url: ^key_id
} -> } ->
%Tesla.Env{ %Tesla.Env{
status: 200, status: 200,
body: user, body: user,
headers: [{"content-type", "application/activity+json"}] headers: [{"content-type", "application/activity+json"}]
} }
%{method: :get, url: "https://example.com/users/lain/collections/featured"} -> %{method: :get, url: "https://example.com/users/lain/collections/featured"} ->
%Tesla.Env{ %Tesla.Env{
status: 200, status: 200,
@ -927,8 +928,9 @@ test "it inserts an incoming activity into the database", %{conn: conn, data: da
end end
test "it accepts messages with to as string instead of array", %{conn: conn, data: data} do test "it accepts messages with to as string instead of array", %{conn: conn, data: data} do
user = insert(:user) user =
|> with_signing_key() insert(:user)
|> with_signing_key()
data = data =
data data
@ -973,8 +975,9 @@ test "it accepts messages with cc as string instead of array", %{conn: conn, dat
end end
test "it accepts messages with bcc as string instead of array", %{conn: conn, data: data} do test "it accepts messages with bcc as string instead of array", %{conn: conn, data: data} do
user = insert(:user) user =
|> with_signing_key() insert(:user)
|> with_signing_key()
data = data =
data data

View file

@ -140,8 +140,9 @@ test "publish to url with with different ports" do
{:ok, %Tesla.Env{status: 200, body: "port 80"}} {:ok, %Tesla.Env{status: 200, body: "port 80"}}
end) end)
actor = insert(:user) actor =
|> with_signing_key() insert(:user)
|> with_signing_key()
assert {:ok, %{body: "port 42"}} = assert {:ok, %{body: "port 42"}} =
Publisher.publish_one(%{ Publisher.publish_one(%{
@ -166,8 +167,10 @@ test "publish to url with with different ports" do
Instances, Instances,
[:passthrough], [:passthrough],
[] do [] do
actor = insert(:user) actor =
|> with_signing_key() insert(:user)
|> with_signing_key()
inbox = "http://200.site/users/nick1/inbox" inbox = "http://200.site/users/nick1/inbox"
assert {:ok, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) assert {:ok, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
@ -178,8 +181,10 @@ test "publish to url with with different ports" do
Instances, Instances,
[:passthrough], [:passthrough],
[] do [] do
actor = insert(:user) actor =
|> with_signing_key() insert(:user)
|> with_signing_key()
inbox = "http://200.site/users/nick1/inbox" inbox = "http://200.site/users/nick1/inbox"
assert {:ok, _} = assert {:ok, _} =
@ -198,8 +203,10 @@ test "publish to url with with different ports" do
Instances, Instances,
[:passthrough], [:passthrough],
[] do [] do
actor = insert(:user) actor =
|> with_signing_key() insert(:user)
|> with_signing_key()
inbox = "http://200.site/users/nick1/inbox" inbox = "http://200.site/users/nick1/inbox"
assert {:ok, _} = assert {:ok, _} =
@ -218,8 +225,10 @@ test "publish to url with with different ports" do
Instances, Instances,
[:passthrough], [:passthrough],
[] do [] do
actor = insert(:user) actor =
|> with_signing_key() insert(:user)
|> with_signing_key()
inbox = "http://404.site/users/nick1/inbox" inbox = "http://404.site/users/nick1/inbox"
assert {:error, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) assert {:error, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
@ -231,8 +240,10 @@ test "publish to url with with different ports" do
Instances, Instances,
[:passthrough], [:passthrough],
[] do [] do
actor = insert(:user) actor =
|> with_signing_key() insert(:user)
|> with_signing_key()
inbox = "http://connrefused.site/users/nick1/inbox" inbox = "http://connrefused.site/users/nick1/inbox"
assert capture_log(fn -> assert capture_log(fn ->
@ -247,8 +258,10 @@ test "publish to url with with different ports" do
Instances, Instances,
[:passthrough], [:passthrough],
[] do [] do
actor = insert(:user) actor =
|> with_signing_key() insert(:user)
|> with_signing_key()
inbox = "http://200.site/users/nick1/inbox" inbox = "http://200.site/users/nick1/inbox"
assert {:ok, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1}) assert {:ok, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
@ -260,8 +273,10 @@ test "publish to url with with different ports" do
Instances, Instances,
[:passthrough], [:passthrough],
[] do [] do
actor = insert(:user) actor =
|> with_signing_key() insert(:user)
|> with_signing_key()
inbox = "http://connrefused.site/users/nick1/inbox" inbox = "http://connrefused.site/users/nick1/inbox"
assert capture_log(fn -> assert capture_log(fn ->
@ -302,8 +317,9 @@ test "publish to url with with different ports" do
ap_enabled: true ap_enabled: true
}) })
actor = insert(:user, follower_address: follower.ap_id) actor =
|> with_signing_key() insert(:user, follower_address: follower.ap_id)
|> with_signing_key()
{:ok, follower, actor} = Pleroma.User.follow(follower, actor) {:ok, follower, actor} = Pleroma.User.follow(follower, actor)
{:ok, _another_follower, actor} = Pleroma.User.follow(another_follower, actor) {:ok, _another_follower, actor} = Pleroma.User.follow(another_follower, actor)
@ -374,8 +390,9 @@ test "publish to url with with different ports" do
ap_enabled: true ap_enabled: true
}) })
actor = insert(:user, follower_address: follower.ap_id) actor =
|> with_signing_key() insert(:user, follower_address: follower.ap_id)
|> with_signing_key()
{:ok, follower, actor} = Pleroma.User.follow(follower, actor) {:ok, follower, actor} = Pleroma.User.follow(follower, actor)
actor = refresh_record(actor) actor = refresh_record(actor)

View file

@ -65,6 +65,7 @@ defmacro __using__(_opts) do
clear_config: 1, clear_config: 1,
clear_config: 2 clear_config: 2
] ]
import Pleroma.Test.MatchingHelpers import Pleroma.Test.MatchingHelpers
def time_travel(entity, seconds) do def time_travel(entity, seconds) do

View file

@ -1,5 +1,6 @@
defmodule Pleroma.Test.MatchingHelpers do defmodule Pleroma.Test.MatchingHelpers do
import ExUnit.Assertions import ExUnit.Assertions
@assoc_fields [ @assoc_fields [
:signing_key :signing_key
] ]