aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaelwenn <contact+git.pleroma.social@hacktivis.me>2019-07-23 18:39:01 +0000
committerHaelwenn <contact+git.pleroma.social@hacktivis.me>2019-07-23 18:39:01 +0000
commit638f772356afdb92a722ae54059604dbbab94d58 (patch)
tree2615bdb374a4df01794cb0378e6f9a4b1e232a58
parenta042a7ac6d65dca3e19e6c4ddd65d2010e94aeba (diff)
parente7c64f106eb578f802d000ecd8dacbc00a357b66 (diff)
downloadpleroma-638f772356afdb92a722ae54059604dbbab94d58.tar.gz
Merge branch 'bugfix/http-signatures-misskey' into 'develop'
signature: properly deduce the actor from misskey key IDs See merge request pleroma/pleroma!1476
-rw-r--r--lib/pleroma/signature.ex15
-rw-r--r--test/signature_test.exs21
2 files changed, 27 insertions, 9 deletions
diff --git a/lib/pleroma/signature.ex b/lib/pleroma/signature.ex
index 2a0823ecf..0bf49fd7c 100644
--- a/lib/pleroma/signature.ex
+++ b/lib/pleroma/signature.ex
@@ -10,9 +10,18 @@ defmodule Pleroma.Signature do
alias Pleroma.Web.ActivityPub.ActivityPub
def key_id_to_actor_id(key_id) do
- URI.parse(key_id)
- |> Map.put(:fragment, nil)
- |> URI.to_string()
+ uri =
+ URI.parse(key_id)
+ |> Map.put(:fragment, nil)
+
+ uri =
+ if String.ends_with?(uri.path, "/publickey") do
+ Map.put(uri, :path, String.replace(uri.path, "/publickey", ""))
+ else
+ uri
+ end
+
+ URI.to_string(uri)
end
def fetch_public_key(conn) do
diff --git a/test/signature_test.exs b/test/signature_test.exs
index 7400cae9a..26337eaf9 100644
--- a/test/signature_test.exs
+++ b/test/signature_test.exs
@@ -48,16 +48,14 @@ defmodule Pleroma.SignatureTest do
test "it returns error when not found user" do
assert capture_log(fn ->
- assert Signature.fetch_public_key(make_fake_conn("test-ap_id")) ==
- {:error, :error}
+ assert Signature.fetch_public_key(make_fake_conn("test-ap_id")) == {:error, :error}
end) =~ "[error] Could not decode user"
end
test "it returns error if public key is empty" do
user = insert(:user, %{info: %{source_data: %{"publicKey" => %{}}}})
- assert Signature.fetch_public_key(make_fake_conn(user.ap_id)) ==
- {:error, :error}
+ assert Signature.fetch_public_key(make_fake_conn(user.ap_id)) == {:error, :error}
end
end
@@ -65,8 +63,7 @@ defmodule Pleroma.SignatureTest do
test "it returns key" do
ap_id = "https://mastodon.social/users/lambadalambda"
- assert Signature.refetch_public_key(make_fake_conn(ap_id)) ==
- {:ok, @rsa_public_key}
+ assert Signature.refetch_public_key(make_fake_conn(ap_id)) == {:ok, @rsa_public_key}
end
test "it returns error when not found user" do
@@ -105,4 +102,16 @@ defmodule Pleroma.SignatureTest do
) == {:error, []}
end
end
+
+ describe "key_id_to_actor_id/1" do
+ test "it properly deduces the actor id for misskey" do
+ assert Signature.key_id_to_actor_id("https://example.com/users/1234/publickey") ==
+ "https://example.com/users/1234"
+ end
+
+ test "it properly deduces the actor id for mastodon and pleroma" do
+ assert Signature.key_id_to_actor_id("https://example.com/users/1234#main-key") ==
+ "https://example.com/users/1234"
+ end
+ end
end