Show the bots held in the trap right now
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

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>
This commit is contained in:
TomandClaude Sonnet 5.5 committed 2026-11-22 01:59:07 +01:00
1 parent 35aba56255
commit 7c11bf211e
15 files changed
+249 -5

No files matched your search

@@ -0,0 +1,40 @@
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);
}
@@ -179,6 +179,7 @@ public sealed class TrapRunnerTests
_governor,
new ConfiguredStrategySelector([drip], dripOptions, random),
_sink,
new ActiveTrapRegistry(TimeProvider.System),
repeatOffenders ?? new NullRepeatLookup(),
TestOptions.Monitor(new FlypaperOptions
{
+30 -1
View File
@@ -1,4 +1,5 @@
using Flypaper.Core.Abstractions;
using Flypaper.Core.Runtime;
using Flypaper.Storage.Queries;
using Flypaper.Tests.Fakes;
using Flypaper.Web.Mcp;
@@ -12,14 +13,42 @@ public sealed class FlypaperToolsTests : IDisposable
{
private readonly McpTestData _data = new();
private readonly FlypaperTools _tools;
private readonly ActiveTrapRegistry _active = new(new FixedTimeProvider(McpTestData.Now));
private readonly IIpEnricher _enricher = Substitute.For<IIpEnricher>();
public FlypaperToolsTests()
{
var governor = Substitute.For<IConnectionGovernor>();
governor.ActiveConnections.Returns(2);
_tools = new FlypaperTools(new CatchQueries(_data.Factory), governor, new FixedTimeProvider(McpTestData.Now));
_tools = new FlypaperTools(new CatchQueries(_data.Factory), governor, _active, _enricher, new FixedTimeProvider(McpTestData.Now));
}
[Fact]
public void List_active_shows_running_traps_with_origin_and_bytes()
{
var address = System.Net.IPAddress.Parse("203.0.113.7");
_enricher.Lookup(address).Returns(new Flypaper.Core.Models.IpOrigin("DE", "Germany", "Berlin", 3320, "Telekom"));
var context = new Flypaper.Core.Models.TrapContext(
new Flypaper.Core.Models.TrapSession(Guid.NewGuid(), Flypaper.Core.Models.TrapProtocol.Http, address, McpTestData.Now.AddMinutes(-5)),
"GET /.env",
"curl/8.7.1");
_active.Begin(context, "env-drip").Attach(() => 2048);
var result = _tools.ListActive();
var trap = result.Traps.ShouldHaveSingleItem();
result.Count.ShouldBe(1);
trap.Ip.ShouldBe("203.0.113.7");
trap.CountryCode.ShouldBe("DE");
trap.Asn.ShouldBe("AS3320");
trap.Target.ShouldBe("GET /.env");
trap.BytesSent.ShouldBe(2048);
trap.DurationSeconds.ShouldBe(0);
}
[Fact]
public void List_active_is_empty_without_traps() => _tools.ListActive().Count.ShouldBe(0);
[Fact]
public async Task Get_stats_summarizes_the_period()
{
+2 -1
View File
@@ -24,7 +24,7 @@ public sealed class McpEndpointTests : IDisposable
}
private static readonly string[] ReadTools =
["get_stats", "list_catches", "longest_catches", "lookup_ip", "top", "list_explanation_rules", "list_unexplained", "test_explanation_rule"];
["get_stats", "list_active", "list_catches", "longest_catches", "lookup_ip", "top", "list_explanation_rules", "list_unexplained", "test_explanation_rule"];
[Fact]
public async Task Rejects_requests_without_token()
@@ -80,6 +80,7 @@ public sealed class McpEndpointTests : IDisposable
{
{ "get_stats", """{"period":"all"}""" },
{ "get_stats", """{"period":"24h"}""" },
{ "list_active", """{}""" },
{ "list_catches", """{}""" },
{ "list_catches", """{"country":"CN","limit":1}""" },
{ "top", """{"dimension":"ips","period":"all"}""" },