Files
Flypaper/test/Flypaper.Tests/Core/ActiveTrapRegistryTests.cs
TomandClaude Sonnet 5.5 7c11bf211e
Build and deploy / build (push) Successful in 1m36s
Release / image (push) Successful in 1m59s
Build and deploy / deploy (push) Successful in 31s
Release / release (push) Successful in 7s
Show the bots held in the trap right now
Dashboard table "Gerade in der Falle" and MCP tool list_active, backed by an
in-memory registry of running traps. Changelog prepared for 0.8.0.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 01:59:07 +01:00

41 lines
1.4 KiB
C#

using System.Net;
using Flypaper.Core.Models;
using Flypaper.Core.Runtime;
using Flypaper.Tests.Fakes;
using Shouldly;
namespace Flypaper.Tests.Core;
public sealed class ActiveTrapRegistryTests
{
private static readonly DateTimeOffset Start = new(2026, 11, 22, 10, 0, 0, TimeSpan.Zero);
[Fact]
public void Lists_running_traps_with_bytes_and_forgets_finished_ones()
{
var registry = new ActiveTrapRegistry(new FixedTimeProvider(Start));
var first = Context("203.0.113.1", "GET /.env");
var second = Context("203.0.113.2", "GET /");
var handle = registry.Begin(first, "env-drip");
registry.Begin(second, "maze-drip");
var bytes = 0L;
handle.Attach(() => bytes);
bytes = 4096;
var snapshot = registry.Snapshot();
snapshot.Select(t => t.Ip.ToString()).ShouldBe(["203.0.113.1", "203.0.113.2"], ignoreOrder: true);
snapshot.Single(t => t.Ip.ToString() == "203.0.113.1").BytesSent.ShouldBe(4096);
snapshot.Single(t => t.Ip.ToString() == "203.0.113.2").BytesSent.ShouldBe(0);
snapshot.ShouldAllBe(t => t.StartedAt == Start);
handle.Dispose();
registry.Snapshot().Select(t => t.Ip.ToString()).ShouldBe(["203.0.113.2"]);
}
private static TrapContext Context(string ip, string target) =>
new(new TrapSession(Guid.NewGuid(), TrapProtocol.Http, IPAddress.Parse(ip), Start), target);
}