using PrivaPub.Federation.Actors; using System.Security.Cryptography; using System.Text.Json; using System.Text.Json.Nodes; namespace PrivaPub.Tests.Federation { public class ActorFeaturesTests { [Fact] public void A_rich_actor_reports_the_extensions_it_uses() { using var rsa = RSA.Create(4096); var actor = new JsonObject { ["id"] = "https://social.example/users/a", ["type"] = "Person", ["featured"] = "https://social.example/users/a/featured", ["alsoKnownAs"] = new JsonArray("https://old.example/users/a"), ["endpoints"] = new JsonObject { ["sharedInbox"] = "https://social.example/inbox" }, ["assertionMethod"] = new JsonArray(), ["attachment"] = new JsonArray(new JsonObject { ["type"] = "PropertyValue", ["name"] = "x", ["value"] = "y" }), ["manuallyApprovesFollowers"] = true, ["discoverable"] = false, ["indexable"] = true, ["isCat"] = true, ["_misskey_summary"] = "hi", ["publicKey"] = new JsonObject { ["id"] = "https://social.example/users/a#main-key", ["publicKeyPem"] = rsa.ExportSubjectPublicKeyInfoPem() } }; var features = ActorFeatures.Detect(JsonDocument.Parse(actor.ToJsonString()).RootElement); Assert.Equal(new[] { "featured", "also-known-as", "shared-inbox", "fep-521a-assertion-method", "property-value", "misskey", "is-cat", "indexable", "undiscoverable", "locked", "key:rsa-4096" }, features); } [Fact] public void A_bare_actor_reports_nothing_and_junk_is_survived() { Assert.Empty(ActorFeatures.Detect(JsonDocument.Parse("{\"id\":\"https://a.example/u\",\"type\":\"Person\"}").RootElement)); Assert.Equal(new[] { "public-key-array" }, ActorFeatures.Detect(JsonDocument.Parse("{\"publicKey\":[{\"publicKeyPem\":\"not a key\"}]}").RootElement)); Assert.Empty(ActorFeatures.Detect(JsonDocument.Parse("[1,2]").RootElement)); } } }