mix format
This commit is contained in:
parent
5acceec133
commit
18370767c2
6 changed files with 78 additions and 50 deletions
|
@ -144,7 +144,9 @@ defmodule Pleroma.User.SigningKey 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
|
||||||
|
case Repo.preload(user, :signing_key) do
|
||||||
|
%{signing_key: %__MODULE__{private_key: private_key_pem}} ->
|
||||||
key =
|
key =
|
||||||
private_key_pem
|
private_key_pem
|
||||||
|> :public_key.pem_decode()
|
|> :public_key.pem_decode()
|
||||||
|
@ -152,6 +154,10 @@ defmodule Pleroma.User.SigningKey do
|
||||||
|> :public_key.pem_entry_decode()
|
|> :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()}
|
||||||
|
|
|
@ -832,6 +832,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||||
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,7 +928,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||||
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 =
|
||||||
|
insert(:user)
|
||||||
|> with_signing_key()
|
|> with_signing_key()
|
||||||
|
|
||||||
data =
|
data =
|
||||||
|
@ -973,7 +975,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||||
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 =
|
||||||
|
insert(:user)
|
||||||
|> with_signing_key()
|
|> with_signing_key()
|
||||||
|
|
||||||
data =
|
data =
|
||||||
|
|
|
@ -140,7 +140,8 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||||
{:ok, %Tesla.Env{status: 200, body: "port 80"}}
|
{:ok, %Tesla.Env{status: 200, body: "port 80"}}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
actor = insert(:user)
|
actor =
|
||||||
|
insert(:user)
|
||||||
|> with_signing_key()
|
|> with_signing_key()
|
||||||
|
|
||||||
assert {:ok, %{body: "port 42"}} =
|
assert {:ok, %{body: "port 42"}} =
|
||||||
|
@ -166,8 +167,10 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||||
Instances,
|
Instances,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
actor = insert(:user)
|
actor =
|
||||||
|
insert(:user)
|
||||||
|> with_signing_key()
|
|> 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 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||||
Instances,
|
Instances,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
actor = insert(:user)
|
actor =
|
||||||
|
insert(:user)
|
||||||
|> with_signing_key()
|
|> 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 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||||
Instances,
|
Instances,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
actor = insert(:user)
|
actor =
|
||||||
|
insert(:user)
|
||||||
|> with_signing_key()
|
|> 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 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||||
Instances,
|
Instances,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
actor = insert(:user)
|
actor =
|
||||||
|
insert(:user)
|
||||||
|> with_signing_key()
|
|> 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 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||||
Instances,
|
Instances,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
actor = insert(:user)
|
actor =
|
||||||
|
insert(:user)
|
||||||
|> with_signing_key()
|
|> 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 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||||
Instances,
|
Instances,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
actor = insert(:user)
|
actor =
|
||||||
|
insert(:user)
|
||||||
|> with_signing_key()
|
|> 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 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||||
Instances,
|
Instances,
|
||||||
[:passthrough],
|
[:passthrough],
|
||||||
[] do
|
[] do
|
||||||
actor = insert(:user)
|
actor =
|
||||||
|
insert(:user)
|
||||||
|> with_signing_key()
|
|> 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,7 +317,8 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||||
ap_enabled: true
|
ap_enabled: true
|
||||||
})
|
})
|
||||||
|
|
||||||
actor = insert(:user, follower_address: follower.ap_id)
|
actor =
|
||||||
|
insert(:user, follower_address: follower.ap_id)
|
||||||
|> with_signing_key()
|
|> with_signing_key()
|
||||||
|
|
||||||
{:ok, follower, actor} = Pleroma.User.follow(follower, actor)
|
{:ok, follower, actor} = Pleroma.User.follow(follower, actor)
|
||||||
|
@ -374,7 +390,8 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||||
ap_enabled: true
|
ap_enabled: true
|
||||||
})
|
})
|
||||||
|
|
||||||
actor = insert(:user, follower_address: follower.ap_id)
|
actor =
|
||||||
|
insert(:user, follower_address: follower.ap_id)
|
||||||
|> with_signing_key()
|
|> with_signing_key()
|
||||||
|
|
||||||
{:ok, follower, actor} = Pleroma.User.follow(follower, actor)
|
{:ok, follower, actor} = Pleroma.User.follow(follower, actor)
|
||||||
|
|
|
@ -65,6 +65,7 @@ defmodule Pleroma.Tests.Helpers 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
|
||||||
|
|
|
@ -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
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue