S1 and S2 of the roadmap. RemoteActorService: - FetchObject accepts a document only when its id is the address it was served from; a same-origin document naming another address is asked for at that address once (how GoToSocial serves its key URIs), anything else is dropped; - GetActorByKeyId accepts a key only when the actor lists it, its owner is the actor and it lives on the actor's origin, whether the keyId points at the actor or at a key document; - a refetch for a key or an actor happens at most once per five minutes, so a bad signature cannot make us hammer a host; - the cache row is written by one atomic upsert on ActorURI; - every fetch is signed by the instance actor, never by the persona that happened to receive the activity. The inbox refuses an activity whose id is not on its actor's origin, and an Undo of someone else's activity; a Create's object, an Update and a Delete must be on the actor's origin too, and a cross-origin object is refetched from its own origin before it is trusted. Tests: a fake peer on two origins serves forged actors, foreign-owned keys, cross-origin key documents, aliases and a GoToSocial-style key address (integration, PRIVAPUB_TEST_MONGOD=1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012CzABvBkbcFqoHdmi8b9WB
41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using MongoDB.Bson;
|
|
using MongoDB.Bson.Serialization;
|
|
using MongoDB.Bson.Serialization.Serializers;
|
|
using MongoDB.Driver;
|
|
using MongoDB.Entities;
|
|
|
|
[assembly: AssemblyFixture(typeof(PrivaPub.Tests.Support.MongoFixture))]
|
|
|
|
namespace PrivaPub.Tests.Support
|
|
{
|
|
public sealed class MongoFixture : IAsyncLifetime
|
|
{
|
|
public const string Skip = "set PRIVAPUB_TEST_MONGOD=1 (and optionally PRIVAPUB_TEST_MONGO) to run the tests that need a mongod";
|
|
|
|
public static bool Enabled => Environment.GetEnvironmentVariable("PRIVAPUB_TEST_MONGOD") == "1";
|
|
|
|
public string Database { get; } = $"PrivaPubTests_{Guid.NewGuid():N}";
|
|
|
|
public async ValueTask InitializeAsync()
|
|
{
|
|
if (!Enabled)
|
|
return;
|
|
try
|
|
{
|
|
BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard));
|
|
}
|
|
catch (BsonSerializationException)
|
|
{
|
|
}
|
|
var connection = Environment.GetEnvironmentVariable("PRIVAPUB_TEST_MONGO") ?? "mongodb://127.0.0.1:27017";
|
|
await DB.InitAsync(Database, MongoClientSettings.FromConnectionString(connection));
|
|
}
|
|
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
if (Enabled)
|
|
await DB.Default.Database().Client.DropDatabaseAsync(Database);
|
|
}
|
|
}
|
|
}
|