T1: tests stop sharing state they don't own
- JobQueue takes an optional scope, so a test's worker leases and reaps only its own jobs. - The dead-host delivery test runs alone (Exclusive), on its own jobs, and cleans up the breaker rows it trips; the breaker has tests of its own on unique hosts. - Index and migration tests run alone: they drop indexes and rewrite every post. - DomainBlocks.Load replaces reflection and a database-wide block in tests. - Harness.Outgoing sees only deliveries queued since the harness started: Peer ports are reused within a run, which made the circle test flaky. - Two pure-logic tests leave Mongo-gated classes, so CI runs them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ELjqpznMFMNrJoJUj6K5p2
This commit is contained in:
1 parent
7c6fe80f1b
commit
00b2685cf4
14 files changed
+285
-106
No files matched your search
@@ -0,0 +1,37 @@
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
using PrivaPub.Federation.Moderation;
|
||||
using PrivaPub.Models.Federation;
|
||||
|
||||
namespace PrivaPub.Tests.Federation
|
||||
{
|
||||
public class DomainBlocksTests
|
||||
{
|
||||
[Fact]
|
||||
public void A_block_covers_subdomains_but_not_lookalikes()
|
||||
{
|
||||
var blocks = new DomainBlocks(NullLogger<DomainBlocks>.Instance);
|
||||
blocks.Load(new[] { new DomainBlock { Domain = "evil.example", Severity = DomainBlockSeverity.Silence } });
|
||||
|
||||
Assert.NotNull(blocks.Find("evil.example"));
|
||||
Assert.NotNull(blocks.Find("A.Evil.Example."));
|
||||
Assert.Null(blocks.Find("notevil.example"));
|
||||
Assert.False(blocks.IsSuspended("evil.example"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_suspension_is_found_from_any_subdomain()
|
||||
{
|
||||
var blocks = new DomainBlocks(NullLogger<DomainBlocks>.Instance);
|
||||
blocks.Load(new[]
|
||||
{
|
||||
new DomainBlock { Domain = " Spam.Example. ", Severity = DomainBlockSeverity.Suspend },
|
||||
new DomainBlock { Domain = "", Severity = DomainBlockSeverity.Suspend }
|
||||
});
|
||||
|
||||
Assert.True(blocks.IsSuspended("deep.inside.spam.example"));
|
||||
Assert.False(blocks.IsSuspended("example"));
|
||||
Assert.Null(blocks.Find(default));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,38 +269,14 @@ namespace PrivaPub.Tests.Federation
|
||||
var token = TestContext.Current.CancellationToken;
|
||||
var alice = await LocalAvatar("alice");
|
||||
var bob = new RemoteActor(_peer, "bob", _peer.B);
|
||||
await DB.Default.SaveAsync(new DomainBlock { Domain = "localhost", Severity = DomainBlockSeverity.Suspend }, token);
|
||||
try
|
||||
{
|
||||
await _blocks.Reload(token);
|
||||
var before = _peer.Requests.Count;
|
||||
_blocks.Load(new[] { new DomainBlock { Domain = "localhost", Severity = DomainBlockSeverity.Suspend } });
|
||||
var before = _peer.Requests.Count;
|
||||
|
||||
var result = await Deliver(bob, $"/peasants/{alice.UserName}/mouth", DirectCreate(bob, alice.Uri));
|
||||
var result = await Deliver(bob, $"/peasants/{alice.UserName}/mouth", DirectCreate(bob, alice.Uri));
|
||||
|
||||
Assert.Equal(202, result.StatusCode);
|
||||
Assert.Equal(before, _peer.Requests.Count);
|
||||
Assert.False(await DB.Default.Find<Post>().Match(p => p.ActorURI == bob.Id).ExecuteAnyAsync(token));
|
||||
}
|
||||
finally
|
||||
{
|
||||
await DB.Default.DeleteAsync<DomainBlock>(b => b.Domain == "localhost");
|
||||
await _blocks.Reload(token);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_block_covers_subdomains_but_not_lookalikes()
|
||||
{
|
||||
var blocks = new DomainBlocks(NullLogger<DomainBlocks>.Instance);
|
||||
typeof(DomainBlocks).GetField("_blocks", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)!
|
||||
.SetValue(blocks, new Dictionary<string, DomainBlock> { ["evil.example"] = new() { Domain = "evil.example", Severity = DomainBlockSeverity.Silence } });
|
||||
typeof(DomainBlocks).GetField("_loadedAt", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)!
|
||||
.SetValue(blocks, DateTime.UtcNow);
|
||||
|
||||
Assert.NotNull(blocks.Find("evil.example"));
|
||||
Assert.NotNull(blocks.Find("A.Evil.Example."));
|
||||
Assert.Null(blocks.Find("notevil.example"));
|
||||
Assert.False(blocks.IsSuspended("evil.example"));
|
||||
Assert.Equal(202, result.StatusCode);
|
||||
Assert.Equal(before, _peer.Requests.Count);
|
||||
Assert.False(await DB.Default.Find<Post>().Match(p => p.ActorURI == bob.Id).ExecuteAnyAsync(token));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using PrivaPub.Federation.Objects;
|
||||
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace PrivaPub.Tests.Federation
|
||||
{
|
||||
public class ObjectRecordsTests
|
||||
{
|
||||
[Fact]
|
||||
public void An_object_larger_than_the_cap_keeps_only_its_hash()
|
||||
{
|
||||
var big = new JsonObject { ["content"] = new string('x', ObjectRecords.MaxRawBytes + 1) };
|
||||
|
||||
var (text, hash, bytes, truncated) = ObjectRecords.Capture(big);
|
||||
|
||||
Assert.Null(text);
|
||||
Assert.True(truncated);
|
||||
Assert.True(bytes > ObjectRecords.MaxRawBytes);
|
||||
Assert.Equal(64, hash.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_small_object_is_kept_whole_with_its_hash()
|
||||
{
|
||||
var small = new JsonObject { ["type"] = "Note", ["content"] = "hi" };
|
||||
|
||||
var (text, hash, bytes, truncated) = ObjectRecords.Capture(small);
|
||||
|
||||
Assert.Equal(small.ToJsonString(), text);
|
||||
Assert.False(truncated);
|
||||
Assert.Equal(text.Length, bytes);
|
||||
Assert.Equal(64, hash.Length);
|
||||
Assert.Equal(default, ObjectRecords.Capture(default));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,18 +68,5 @@ namespace PrivaPub.Tests.Federation
|
||||
Assert.Equal("<p>hi again</p>", JsonNode.Parse(Assert.Single(record.Revisions).Raw)!["content"]!.GetValue<string>());
|
||||
Assert.True(await DB.Default.Find<Job>().Match(j => j.Kind == JobKind.DescribeInstance && j.Payload == record.Host).ExecuteAnyAsync(token));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_object_larger_than_the_cap_keeps_only_its_hash()
|
||||
{
|
||||
var big = new JsonObject { ["content"] = new string('x', ObjectRecords.MaxRawBytes + 1) };
|
||||
|
||||
var (text, hash, bytes, truncated) = ObjectRecords.Capture(big);
|
||||
|
||||
Assert.Null(text);
|
||||
Assert.True(truncated);
|
||||
Assert.True(bytes > ObjectRecords.MaxRawBytes);
|
||||
Assert.Equal(64, hash.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user