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

+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"}""" },