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>
This commit is contained in:
1 parent
35aba56255
commit
7c11bf211e
15 files changed
+249
-5
No files matched your search
@@ -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()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user