Add data management, randomized HTML drip and public README
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3671019e60
commit
f5d8ca7484
46 files changed
+1601
-172
No files matched your search
@@ -47,7 +47,7 @@ public sealed class TrapRunnerTests
|
||||
outcome.ShouldBe(TrapOutcome.Timeout);
|
||||
lease.Received(1).Dispose();
|
||||
_sink.Received(1).Publish(Arg.Is<TrapEvent>(e =>
|
||||
e.Outcome == TrapOutcome.Timeout && e.BytesSent == _channel.Writes.Count && e.BytesSent > 0));
|
||||
e.Outcome == TrapOutcome.Timeout && e.BytesSent == _channel.Writes.Sum(w => w.Length) && e.BytesSent > 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -59,7 +59,44 @@ public sealed class TrapRunnerTests
|
||||
var outcome = await CreateRunner(TimeSpan.FromMinutes(1)).RunAsync(Context(), Open, cts.Token);
|
||||
|
||||
outcome.ShouldBe(TrapOutcome.ClientAborted);
|
||||
_sink.Received(1).Publish(Arg.Is<TrapEvent>(e => e.Outcome == TrapOutcome.ClientAborted && e.Strategy == "drip"));
|
||||
_sink.Received(1).Publish(Arg.Is<TrapEvent>(e => e.Outcome == TrapOutcome.ClientAborted && e.Strategy == "html-drip"));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("192.168.1.20")]
|
||||
[InlineData("172.19.0.1")]
|
||||
[InlineData("127.0.0.1")]
|
||||
public async Task Traps_but_does_not_store_private_ips_by_default(string ip)
|
||||
{
|
||||
AllowAcquire();
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100));
|
||||
|
||||
var outcome = await CreateRunner(TimeSpan.FromMinutes(1)).RunAsync(Context(ip), Open, cts.Token);
|
||||
|
||||
outcome.ShouldBe(TrapOutcome.ClientAborted);
|
||||
_channel.Writes.ShouldNotBeEmpty();
|
||||
_sink.DidNotReceiveWithAnyArgs().Publish(default!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Does_not_store_rejected_private_ips_by_default()
|
||||
{
|
||||
_governor.TryAcquire(Arg.Any<TrapSession>(), out Arg.Any<IDisposable?>()).Returns(false);
|
||||
|
||||
await CreateRunner(TimeSpan.FromSeconds(1)).RunAsync(Context("10.0.0.5"), Open, CancellationToken.None);
|
||||
|
||||
_sink.DidNotReceiveWithAnyArgs().Publish(default!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Stores_private_ips_when_option_is_off()
|
||||
{
|
||||
AllowAcquire();
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100));
|
||||
|
||||
await CreateRunner(TimeSpan.FromMinutes(1), ignorePrivateNetworks: false).RunAsync(Context("192.168.1.20"), Open, cts.Token);
|
||||
|
||||
_sink.Received(1).Publish(Arg.Is<TrapEvent>(e => e.RemoteIp.Equals(IPAddress.Parse("192.168.1.20"))));
|
||||
}
|
||||
|
||||
private IDisposable AllowAcquire()
|
||||
@@ -76,18 +113,21 @@ public sealed class TrapRunnerTests
|
||||
|
||||
private ValueTask<ITrapChannel> Open(CancellationToken ct) => ValueTask.FromResult<ITrapChannel>(_channel);
|
||||
|
||||
private TrapRunner CreateRunner(TimeSpan maxHoldDuration)
|
||||
private TrapRunner CreateRunner(TimeSpan maxHoldDuration, bool ignorePrivateNetworks = true)
|
||||
{
|
||||
var drip = new DripStrategy(TestOptions.Monitor(new DripOptions { Interval = TimeSpan.FromMilliseconds(20) }), TimeProvider.System);
|
||||
var drip = new HtmlDripStrategy(
|
||||
TestOptions.Monitor(new DripOptions { MinDelay = TimeSpan.FromMilliseconds(5), MaxDelay = TimeSpan.FromMilliseconds(20) }),
|
||||
new SeededRandomSource(7),
|
||||
TimeProvider.System);
|
||||
return new TrapRunner(
|
||||
_governor,
|
||||
[drip],
|
||||
new ProtocolStrategySelector([drip]),
|
||||
_sink,
|
||||
TestOptions.Monitor(new FlypaperOptions { MaxHoldDuration = maxHoldDuration }),
|
||||
TestOptions.Monitor(new FlypaperOptions { MaxHoldDuration = maxHoldDuration, IgnorePrivateNetworks = ignorePrivateNetworks }),
|
||||
TimeProvider.System,
|
||||
NullLogger<TrapRunner>.Instance);
|
||||
}
|
||||
|
||||
private static TrapContext Context() =>
|
||||
new(new TrapSession(Guid.NewGuid(), TrapProtocol.Http, IPAddress.Parse("203.0.113.9"), DateTimeOffset.UtcNow), "GET /.env");
|
||||
private static TrapContext Context(string ip = "203.0.113.9") =>
|
||||
new(new TrapSession(Guid.NewGuid(), TrapProtocol.Http, IPAddress.Parse(ip), DateTimeOffset.UtcNow), "GET /.env");
|
||||
}
|
||||
Reference in new issue
Block a user