Add Flypaper solution skeleton with HTTP tarpit, SQLite event log and tests
This commit is contained in:
1 parent
20314268c6
commit
f9161f48e7
55 files changed
+1331
No files matched your search
@@ -0,0 +1,43 @@
|
||||
using Flypaper.Core;
|
||||
using Flypaper.Core.Strategies;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Shouldly;
|
||||
|
||||
namespace Flypaper.Tests;
|
||||
|
||||
public sealed class DripStrategyTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Drips_single_bytes_until_cancelled()
|
||||
{
|
||||
var strategy = CreateStrategy(TimeSpan.FromMilliseconds(20));
|
||||
var channel = new FakeTrapChannel();
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(300));
|
||||
|
||||
await Should.ThrowAsync<OperationCanceledException>(() => strategy.RunAsync(channel, cts.Token));
|
||||
|
||||
channel.Writes.Count.ShouldBeInRange(3, 20);
|
||||
channel.Writes.ShouldAllBe(write => write.Length == 1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Writes_first_byte_immediately()
|
||||
{
|
||||
var strategy = CreateStrategy(TimeSpan.FromMinutes(1));
|
||||
var channel = new FakeTrapChannel();
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100));
|
||||
|
||||
await Should.ThrowAsync<OperationCanceledException>(() => strategy.RunAsync(channel, cts.Token));
|
||||
|
||||
channel.Writes.Count.ShouldBe(1);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(TrapProtocol.Http, true)]
|
||||
[InlineData(TrapProtocol.Ssh, false)]
|
||||
public void Supports_only_http(TrapProtocol protocol, bool expected) =>
|
||||
CreateStrategy(TimeSpan.FromSeconds(1)).Supports(protocol).ShouldBe(expected);
|
||||
|
||||
private static DripStrategy CreateStrategy(TimeSpan interval) =>
|
||||
new(Options.Create(new DripOptions { Interval = interval }), TimeProvider.System);
|
||||
}
|
||||
Reference in new issue
Block a user