From 83f75c3e93487ad95afd89bb26968dbf516e4289 Mon Sep 17 00:00:00 2001 From: Oneric Date: Sun, 21 Apr 2024 00:46:49 +0200 Subject: [PATCH] Accept all standard actor types --- .../object_validators/user_validator.ex | 4 +- test/fixtures/mastodon/service_actor.json | 117 ++++++++++++++++++ .../fixtures/peertube/actor-videochannel.json | 72 +++++++++++ .../object_validators/user_validator_test.exs | 38 ++++++ 4 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/mastodon/service_actor.json create mode 100644 test/fixtures/peertube/actor-videochannel.json create mode 100644 test/pleroma/web/activity_pub/object_validators/user_validator_test.exs diff --git a/lib/pleroma/web/activity_pub/object_validators/user_validator.ex b/lib/pleroma/web/activity_pub/object_validators/user_validator.ex index 90b5404f3..adb291a55 100644 --- a/lib/pleroma/web/activity_pub/object_validators/user_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/user_validator.ex @@ -16,11 +16,13 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UserValidator do alias Pleroma.Object.Containment alias Pleroma.Signature + require Pleroma.Constants + @impl true def validate(object, meta) def validate(%{"type" => type, "id" => _id} = data, meta) - when type in ["Person", "Organization", "Group", "Application"] do + when type in Pleroma.Constants.actor_types() do with :ok <- validate_pubkey(data), :ok <- validate_inbox(data), :ok <- contain_collection_origin(data) do diff --git a/test/fixtures/mastodon/service_actor.json b/test/fixtures/mastodon/service_actor.json new file mode 100644 index 000000000..2abd20b5e --- /dev/null +++ b/test/fixtures/mastodon/service_actor.json @@ -0,0 +1,117 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "toot": "http://joinmastodon.org/ns#", + "featured": { + "@id": "toot:featured", + "@type": "@id" + }, + "featuredTags": { + "@id": "toot:featuredTags", + "@type": "@id" + }, + "alsoKnownAs": { + "@id": "as:alsoKnownAs", + "@type": "@id" + }, + "movedTo": { + "@id": "as:movedTo", + "@type": "@id" + }, + "schema": "http://schema.org#", + "PropertyValue": "schema:PropertyValue", + "value": "schema:value", + "discoverable": "toot:discoverable", + "Device": "toot:Device", + "Ed25519Signature": "toot:Ed25519Signature", + "Ed25519Key": "toot:Ed25519Key", + "Curve25519Key": "toot:Curve25519Key", + "EncryptedMessage": "toot:EncryptedMessage", + "publicKeyBase64": "toot:publicKeyBase64", + "deviceId": "toot:deviceId", + "claim": { + "@type": "@id", + "@id": "toot:claim" + }, + "fingerprintKey": { + "@type": "@id", + "@id": "toot:fingerprintKey" + }, + "identityKey": { + "@type": "@id", + "@id": "toot:identityKey" + }, + "devices": { + "@type": "@id", + "@id": "toot:devices" + }, + "messageFranking": "toot:messageFranking", + "messageType": "toot:messageType", + "cipherText": "toot:cipherText", + "suspended": "toot:suspended", + "memorial": "toot:memorial", + "indexable": "toot:indexable", + "focalPoint": { + "@container": "@list", + "@id": "toot:focalPoint" + } + } + ], + "id": "https://mastodont.cat/users/fediverse", + "type": "Service", + "following": "https://mastodont.cat/users/fediverse/following", + "followers": "https://mastodont.cat/users/fediverse/followers", + "inbox": "https://mastodont.cat/users/fediverse/inbox", + "outbox": "https://mastodont.cat/users/fediverse/outbox", + "featured": "https://mastodont.cat/users/fediverse/collections/featured", + "featuredTags": "https://mastodont.cat/users/fediverse/collections/tags", + "preferredUsername": "fediverse", + "name": "fediverse's stats", + "summary": "

All fediverse alive servers stats. New refactored code!

Ask server info:

@fediverse server example.server

Ask software info:

@fediverse soft mastodon

", + "url": "https://mastodont.cat/@fediverse", + "manuallyApprovesFollowers": false, + "discoverable": true, + "indexable": false, + "published": "2020-05-13T00:00:00Z", + "memorial": false, + "devices": "https://mastodont.cat/users/fediverse/collections/devices", + "publicKey": { + "id": "https://mastodont.cat/users/fediverse#main-key", + "owner": "https://mastodont.cat/users/fediverse", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu2X8LqAR/6j95UUTG02T\nWG+PmNRWnfOl+zjDts3OctyJK7at5AwA+T0be1faHpf+oLREl/dkWXc8VQY2UJzY\n8QTuXXnIkwHAeA7WADB6kPvQhVpfGPgKD0dpAgBz9WHFquMSXcnuyt7q1CDn5wId\nRoUtkCAcg1rOX+lIAoeic5hT0O0sXLJdtaSCTZmGqkF2Cf+/16q8XhRevMRh73vP\nX2PefCr63Iy/Zh5rnVhPluQMyQ6FGxXgd5dEKJRa2kxrhIsrm0TzMX892Ev45AwI\ndppYQOQ+nLOgMYrpFNYdOmizJsn635l18K1r/tyDDAegPp6Kfa8v+BaZdOmNTFKr\n/wIDAQAB\n-----END PUBLIC KEY-----\n" + }, + "tag": [], + "attachment": [ + { + "type": "PropertyValue", + "name": "code", + "value": "https://codeberg.org/spla/stats" + }, + { + "type": "PropertyValue", + "name": "my user-agent", + "value": ""fediverse's stats (fediverse@mastodont.cat)"" + }, + { + "type": "PropertyValue", + "name": "coded by", + "value": "@spla" + } + ], + "endpoints": { + "sharedInbox": "https://mastodont.cat/inbox" + }, + "icon": { + "type": "Image", + "mediaType": "image/png", + "url": "https://mastodont.cat/system/accounts/avatars/000/149/323/original/33201dbeb139a24a.png" + }, + "image": { + "type": "Image", + "mediaType": "image/jpeg", + "url": "https://mastodont.cat/system/accounts/headers/000/149/323/original/75c861d59e5a8860.jpeg" + } +} diff --git a/test/fixtures/peertube/actor-videochannel.json b/test/fixtures/peertube/actor-videochannel.json new file mode 100644 index 000000000..3d0ee5980 --- /dev/null +++ b/test/fixtures/peertube/actor-videochannel.json @@ -0,0 +1,72 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "RsaSignature2017": "https://w3id.org/security#RsaSignature2017" + }, + { + "pt": "https://joinpeertube.org/ns#", + "sc": "http://schema.org/", + "playlists": { + "@id": "pt:playlists", + "@type": "@id" + }, + "support": { + "@type": "sc:Text", + "@id": "pt:support" + }, + "icons": "as:icon" + } + ], + "type": "Group", + "id": "https://spectra.video/video-channels/fediforum_demos", + "following": "https://spectra.video/video-channels/fediforum_demos/following", + "followers": "https://spectra.video/video-channels/fediforum_demos/followers", + "playlists": "https://spectra.video/video-channels/fediforum_demos/playlists", + "inbox": "https://spectra.video/video-channels/fediforum_demos/inbox", + "outbox": "https://spectra.video/video-channels/fediforum_demos/outbox", + "preferredUsername": "fediforum_demos", + "url": "https://spectra.video/video-channels/fediforum_demos", + "name": "FediForum Demos", + "endpoints": { + "sharedInbox": "https://spectra.video/inbox" + }, + "publicKey": { + "id": "https://spectra.video/video-channels/fediforum_demos#main-key", + "owner": "https://spectra.video/video-channels/fediforum_demos", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxFVESAz0Z28zhXVJafzg\nKXVWS6yuZdQ4vOuA+k//ioSpNls53pI9vwQyixNa+QLdnXxm51dy//Py49wZbzAV\n2nC2FEnzcCM/EZvA4gzy7wekcjnGIz3equbdLOj3IAJJTSwCvZpW2f0poAa1CUmQ\nDRV5p3t3bjtUX5B9RnhiuDitN8qCzEeEbD9SHoyMDIACl8wXer8eyi5v98CMTHwh\nJYUJZJmS7/SSlJO2aqThEBaAYCUzVxlcXOecF1N1RWjjtwqi9xXxmlJ+teivYyST\nYfCeLmY/zZPY7OjoBxoVcVa/Yj3Wg6Nt+A5co9NATpsXmud7GWx4CvQ00uH/fa7e\nvQIDAQAB\n-----END PUBLIC KEY-----\n" + }, + "published": "2024-03-26T19:34:06.073Z", + "icon": [ + { + "type": "Image", + "mediaType": "image/png", + "height": 48, + "width": 48, + "url": "https://spectra.video/lazy-static/avatars/b13e5038-0169-420e-a6bc-4f5e0666fae6.png" + }, + { + "type": "Image", + "mediaType": "image/png", + "height": 120, + "width": 120, + "url": "https://spectra.video/lazy-static/avatars/559b141a-96ec-4161-8889-1111b71abca0.png" + } + ], + "image": { + "type": "Image", + "mediaType": "image/png", + "height": 317, + "width": 1920, + "url": "https://spectra.video/lazy-static/banners/bbe18e2c-79ef-4640-9193-cdd743c964dd.png" + }, + "summary": "Demos from the the FediForum Unconference. For the sake of simplicity, demos are [broken out into playlists](https://spectra.video/c/fediforum_demos/video-playlists) representing each FediForum Event.", + "support": "Check out our site: https://fediforum.org/\nFollow us on Mastodon: https://mastodon.social/@fediforum", + "attributedTo": [ + { + "type": "Person", + "id": "https://spectra.video/accounts/fediforum" + } + ] +} diff --git a/test/pleroma/web/activity_pub/object_validators/user_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/user_validator_test.exs new file mode 100644 index 000000000..f96911a81 --- /dev/null +++ b/test/pleroma/web/activity_pub/object_validators/user_validator_test.exs @@ -0,0 +1,38 @@ +# Akkoma: Magically expressive social media +# Copyright © 2024 Akkoma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.ObjectValidators.UserValidatorTest do + use Pleroma.DataCase, async: true + + alias Pleroma.Web.ActivityPub.ObjectValidators.UserValidator + + # all standard actor types are listed here: + # https://www.w3.org/TR/activitystreams-vocabulary/#actor-types + describe "accepts standard type" do + test "Application" do + validates_file!("test/fixtures/mastodon/application_actor.json") + end + + test "Group" do + validates_file!("test/fixtures/peertube/actor-videochannel.json") + end + + test "Organization" do + validates_file!("test/fixtures/tesla_mock/wedistribute-user.json") + end + + test "Person" do + validates_file!("test/fixtures/bridgy/actor.json") + end + + test "Service" do + validates_file!("test/fixtures/mastodon/service_actor.json") + end + end + + defp validates_file!(path) do + user_data = Jason.decode!(File.read!(path)) + {:ok, _validated_data, _meta} = UserValidator.validate(user_data, []) + end +end