Add research page with MCP write tools, longer hold for repeat offenders and svn/hg decoys
Build and deploy / build (push) Successful in 1m50s
Build and deploy / deploy (push) Successful in 21s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TomandClaude Opus 5.5 committed 2026-11-17 18:27:35 +01:00
1 parent a25072e6fb
commit e88dc415f9
48 files changed
+1983 -57

No files matched your search

+66 -2
View File
@@ -99,6 +99,58 @@ public sealed class TrapRunnerTests
_sink.Received(1).Publish(Arg.Is<TrapEvent>(e => e.RemoteIp.Equals(IPAddress.Parse("192.168.1.20"))));
}
[Fact]
public async Task Holds_ips_with_an_earlier_timeout_longer_and_marks_the_strategy()
{
AllowAcquire();
var lookup = Substitute.For<IRepeatOffenderLookup>();
lookup.HasTimedOutSinceAsync(Arg.Any<IPAddress>(), Arg.Any<DateTime>(), Arg.Any<CancellationToken>()).Returns(true);
using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(500));
var outcome = await CreateRunner(TimeSpan.FromMilliseconds(100), repeatOffenders: lookup, repeatWindowDays: 7, repeatHoldDuration: TimeSpan.FromMinutes(1))
.RunAsync(Context(), Open, cts.Token);
outcome.ShouldBe(TrapOutcome.ClientAborted);
await lookup.Received(1).HasTimedOutSinceAsync(
IPAddress.Parse("203.0.113.9"),
Arg.Is<DateTime>(since => Math.Abs((DateTime.UtcNow.AddDays(-7) - since).TotalSeconds) < 30),
Arg.Any<CancellationToken>());
_sink.Received(1).Publish(Arg.Is<TrapEvent>(e => e.Strategy.EndsWith(" repeat")));
}
[Fact]
public async Task Keeps_the_normal_limit_for_new_ips()
{
AllowAcquire();
var lookup = Substitute.For<IRepeatOffenderLookup>();
lookup.HasTimedOutSinceAsync(Arg.Any<IPAddress>(), Arg.Any<DateTime>(), Arg.Any<CancellationToken>()).Returns(false);
var outcome = await CreateRunner(TimeSpan.FromMilliseconds(100), repeatOffenders: lookup, repeatWindowDays: 7)
.RunAsync(Context(), Open, CancellationToken.None);
outcome.ShouldBe(TrapOutcome.Timeout);
_sink.Received(1).Publish(Arg.Is<TrapEvent>(e => !e.Strategy.EndsWith(" repeat")));
}
[Theory]
[InlineData(0, "00:00:00.100")]
[InlineData(7, "00:00:00.050")]
public async Task Does_not_ask_when_the_feature_is_off_or_would_not_extend_the_hold(int windowDays, string repeatHold)
{
AllowAcquire();
var lookup = Substitute.For<IRepeatOffenderLookup>();
await CreateRunner(TimeSpan.FromMilliseconds(100), repeatOffenders: lookup, repeatWindowDays: windowDays, repeatHoldDuration: TimeSpan.Parse(repeatHold))
.RunAsync(Context(), Open, CancellationToken.None);
await lookup.DidNotReceiveWithAnyArgs().HasTimedOutSinceAsync(default!, default, default);
}
private sealed class NullRepeatLookup : IRepeatOffenderLookup
{
public ValueTask<bool> HasTimedOutSinceAsync(IPAddress address, DateTime since, CancellationToken ct) => ValueTask.FromResult(false);
}
private IDisposable AllowAcquire()
{
var lease = Substitute.For<IDisposable>();
@@ -113,7 +165,12 @@ public sealed class TrapRunnerTests
private ValueTask<ITrapChannel> Open(ITarpitStrategy strategy, CancellationToken ct) => ValueTask.FromResult<ITrapChannel>(_channel);
private TrapRunner CreateRunner(TimeSpan maxHoldDuration, bool ignorePrivateNetworks = true)
private TrapRunner CreateRunner(
TimeSpan maxHoldDuration,
bool ignorePrivateNetworks = true,
IRepeatOffenderLookup? repeatOffenders = null,
int repeatWindowDays = 0,
TimeSpan? repeatHoldDuration = null)
{
var dripOptions = TestOptions.Monitor(new DripOptions { MinDelay = TimeSpan.FromMilliseconds(5), MaxDelay = TimeSpan.FromMilliseconds(20) });
var random = new SeededRandomSource(7);
@@ -122,7 +179,14 @@ public sealed class TrapRunnerTests
_governor,
new ConfiguredStrategySelector([drip], dripOptions, random),
_sink,
TestOptions.Monitor(new FlypaperOptions { MaxHoldDuration = maxHoldDuration, IgnorePrivateNetworks = ignorePrivateNetworks }),
repeatOffenders ?? new NullRepeatLookup(),
TestOptions.Monitor(new FlypaperOptions
{
MaxHoldDuration = maxHoldDuration,
IgnorePrivateNetworks = ignorePrivateNetworks,
RepeatWindowDays = repeatWindowDays,
RepeatHoldDuration = repeatHoldDuration ?? TimeSpan.FromHours(24)
}),
TimeProvider.System,
NullLogger<TrapRunner>.Instance);
}