Improve group refreshment and fixed date signature generation
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -120,7 +120,6 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do
|
||||
|
||||
describe "/@:preferred_username/inbox" do
|
||||
test "it inserts an incoming event into the database", %{conn: conn} do
|
||||
# use_cassette "activity_pub_controller/mastodon-post-activity_actor_call" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!()
|
||||
|
||||
%Actor{url: remote_actor_url} =
|
||||
@@ -151,6 +150,9 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do
|
||||
^local_actor_url ->
|
||||
{:ok, %Tesla.Env{status: 200, body: local_actor_data}}
|
||||
|
||||
"https://framapiaf.org/users/tcit" ->
|
||||
{:ok, %Tesla.Env{status: 404, body: ""}}
|
||||
|
||||
"https://framapiaf.org/users/admin/statuses/99512778738411822" ->
|
||||
{:ok, %Tesla.Env{status: 404, body: ""}}
|
||||
end
|
||||
@@ -168,7 +170,6 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do
|
||||
ActivityPub.fetch_object_from_url(data["object"]["id"])
|
||||
|
||||
assert comment.actor.id == remote_actor.id
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
|
||||
defmodule Mobilizon.Web.Plugs.MappedSignatureToIdentityTest do
|
||||
use Mobilizon.Web.ConnCase
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
import Mox
|
||||
|
||||
alias Mobilizon.Service.HTTP.ActivityPub.Mock
|
||||
alias Mobilizon.Web.Plugs.MappedSignatureToIdentity
|
||||
|
||||
defp set_signature(conn, key_id) do
|
||||
@@ -15,47 +16,100 @@ defmodule Mobilizon.Web.Plugs.MappedSignatureToIdentityTest do
|
||||
|> assign(:valid_signature, true)
|
||||
end
|
||||
|
||||
test "it successfully maps a valid identity with a valid signature" do
|
||||
use_cassette "activity_pub/signature/valid" do
|
||||
conn =
|
||||
build_conn(:get, "/doesntmattter")
|
||||
|> set_signature("https://framapiaf.org/users/admin")
|
||||
|> MappedSignatureToIdentity.call(%{})
|
||||
defp framapiaf_admin do
|
||||
"test/fixtures/signature/framapiaf_admin.json"
|
||||
|> File.read!()
|
||||
|> Jason.decode!()
|
||||
end
|
||||
|
||||
refute is_nil(conn.assigns.actor)
|
||||
end
|
||||
defp nyu_rye do
|
||||
"test/fixtures/signature/nyu_rye.json"
|
||||
|> File.read!()
|
||||
|> Jason.decode!()
|
||||
end
|
||||
|
||||
test "it successfully maps a valid identity with a valid signature" do
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: "https://framapiaf.org/users/admin"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: framapiaf_admin()}}
|
||||
end)
|
||||
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: "/doesntmattter"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: ""}}
|
||||
end)
|
||||
|
||||
conn =
|
||||
build_conn(:get, "/doesntmattter")
|
||||
|> set_signature("https://framapiaf.org/users/admin")
|
||||
|> MappedSignatureToIdentity.call(%{})
|
||||
|
||||
refute is_nil(conn.assigns.actor)
|
||||
end
|
||||
|
||||
test "it successfully maps a valid identity with a valid signature with payload" do
|
||||
use_cassette "activity_pub/signature/valid_payload" do
|
||||
conn =
|
||||
build_conn(:post, "/doesntmattter", %{"actor" => "https://framapiaf.org/users/admin"})
|
||||
|> set_signature("https://framapiaf.org/users/admin")
|
||||
|> MappedSignatureToIdentity.call(%{})
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: "https://framapiaf.org/users/admin"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: framapiaf_admin()}}
|
||||
end)
|
||||
|
||||
refute is_nil(conn.assigns.actor)
|
||||
end
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :post, url: "/doesntmattter"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: ""}}
|
||||
end)
|
||||
|
||||
conn =
|
||||
build_conn(:post, "/doesntmattter", %{"actor" => "https://framapiaf.org/users/admin"})
|
||||
|> set_signature("https://framapiaf.org/users/admin")
|
||||
|> MappedSignatureToIdentity.call(%{})
|
||||
|
||||
refute is_nil(conn.assigns.actor)
|
||||
end
|
||||
|
||||
test "it considers a mapped identity to be invalid when it mismatches a payload" do
|
||||
use_cassette "activity_pub/signature/invalid_payload" do
|
||||
conn =
|
||||
build_conn(:post, "/doesntmattter", %{"actor" => "https://framapiaf.org/users/admin"})
|
||||
|> set_signature("https://niu.moe/users/rye")
|
||||
|> MappedSignatureToIdentity.call(%{})
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: "https://niu.moe/users/rye"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: nyu_rye()}}
|
||||
end)
|
||||
|
||||
assert %{valid_signature: false} == conn.assigns
|
||||
end
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :post, url: "/doesntmattter"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: ""}}
|
||||
end)
|
||||
|
||||
conn =
|
||||
build_conn(:post, "/doesntmattter", %{"actor" => "https://framapiaf.org/users/admin"})
|
||||
|> set_signature("https://niu.moe/users/rye")
|
||||
|> MappedSignatureToIdentity.call(%{})
|
||||
|
||||
assert %{valid_signature: false} == conn.assigns
|
||||
end
|
||||
|
||||
@tag skip: "Available again when lib/web/plugs/mapped_signature_to_identity.ex#62 is fixed"
|
||||
test "it considers a mapped identity to be invalid when the identity cannot be found" do
|
||||
use_cassette "activity_pub/signature/invalid_not_found" do
|
||||
conn =
|
||||
build_conn(:post, "/doesntmattter", %{"actor" => "https://framapiaf.org/users/admin"})
|
||||
|> set_signature("https://mastodon.social/users/gargron")
|
||||
|> MappedSignatureToIdentity.call(%{})
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: "https://mastodon.social/users/gargron"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 404, body: ""}}
|
||||
end)
|
||||
|
||||
assert %{valid_signature: false} == conn.assigns
|
||||
end
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :post, url: "/doesntmattter"}, _opts ->
|
||||
{:ok, %Tesla.Env{status: 200, body: ""}}
|
||||
end)
|
||||
|
||||
conn =
|
||||
build_conn(:post, "/doesntmattter", %{"actor" => "https://framapiaf.org/users/admin"})
|
||||
|> set_signature("https://mastodon.social/users/gargron")
|
||||
|> MappedSignatureToIdentity.call(%{})
|
||||
|
||||
assert %{valid_signature: false} == conn.assigns
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user