41 lines
1.8 KiB
C#
41 lines
1.8 KiB
C#
using PrivaPub.Federation.Actors;
|
|||
|
|
|
||
|
|
using System.Text.Json;
|
||
|
|
|
||
|
|
namespace PrivaPub.Tests.Federation
|
||
|
|
{
|
||
|
|
public class ActorProfileTests
|
||
|
|
{
|
||
|
|
[Fact]
|
||
|
|
public void Reads_a_mastodon_profile_with_its_header_fields_emoji_and_lock()
|
||
|
|
{
|
||
|
|
using var json = JsonDocument.Parse("""
|
||
|
|
{
|
||
|
|
"id": "https://m.example/users/ann", "type": "Person", "preferredUsername": "ann", "name": "Ann :sparkle:",
|
||
|
|
"inbox": "https://m.example/users/ann/inbox", "manuallyApprovesFollowers": true, "indexable": true, "memorial": false,
|
||
|
|
"published": "2023-04-01T00:00:00Z", "movedTo": "https://n.example/users/ann",
|
||
|
|
"icon": { "type": "Image", "url": "https://m.example/a.png", "summary": "a cat" },
|
||
|
|
"image": { "type": "Image", "url": "https://m.example/h.png", "name": "mountains" },
|
||
|
|
"tag": [{ "type": "Emoji", "name": ":sparkle:", "icon": { "type": "Image", "url": "https://m.example/emoji/sparkle.png" } }],
|
||
|
|
"attachment": [
|
||
|
|
{ "type": "PropertyValue", "name": "Site", "value": "<a href=\"https://ann.example\" rel=\"me\">ann.example</a><script>x</script>" },
|
||
|
|
{ "type": "PropertyValue", "name": "Pronouns", "value": "she/her" }
|
||
|
|
]
|
||
|
|
}
|
||
|
|
""");
|
||
|
|
|
||
|
|
var actor = ActorDocument.Parse(json.RootElement);
|
||
|
|
|
||
|
|
Assert.True(actor.Locked);
|
||
|
|
Assert.True(actor.Indexable);
|
||
|
|
Assert.Equal("https://m.example/h.png", actor.Header);
|
||
|
|
Assert.Equal("a cat", actor.IconDescription);
|
||
|
|
Assert.Equal("mountains", actor.HeaderDescription);
|
||
|
|
Assert.Equal("https://n.example/users/ann", actor.MovedTo);
|
||
|
|
Assert.Equal(new DateTime(2023, 4, 1, 0, 0, 0, DateTimeKind.Utc), actor.Published);
|
||
|
|
Assert.Equal("sparkle", Assert.Single(actor.Emojis).Shortcode);
|
||
|
|
Assert.Equal(new[] { "Site", "Pronouns" }, actor.Fields.Keys);
|
||
|
|
Assert.DoesNotContain("<script>", actor.Fields["Site"]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|