From 302b40c1720afc629caeb876aa38c2a89fcac70d Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 26 Nov 2026 21:24:04 +0100 Subject: [PATCH] Put signposts back into the trap into the fake files .env, JSON, YAML, SQL and Git config carry URLs marked with the serving catch, so a later request shows where the address came from. MCP exposes the marker. Switch: Flypaper__Drip__Signposts. Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 10 +++ docs/configuration.md | 1 + docs/mcp.md | 2 +- src/Flypaper.Core/Strategies/DripOptions.cs | 2 + src/Flypaper.Core/Strategies/FileContent.cs | 41 +++++---- .../Strategies/FileDripStrategy.cs | 3 +- src/Flypaper.Core/Strategies/SignpostLinks.cs | 28 ++++++ src/Flypaper.Storage/Queries/CatchQueries.cs | 11 ++- src/Flypaper.Storage/Queries/CatchRecords.cs | 6 +- src/Flypaper.Web/Mcp/FlypaperTools.cs | 18 +++- src/Flypaper.Web/Mcp/McpResults.cs | 3 +- test/Flypaper.Tests/Core/FileContentTests.cs | 2 +- test/Flypaper.Tests/Core/SignpostTests.cs | 87 +++++++++++++++++++ test/Flypaper.Tests/Mcp/FlypaperToolsTests.cs | 12 +++ 14 files changed, 199 insertions(+), 27 deletions(-) create mode 100644 src/Flypaper.Core/Strategies/SignpostLinks.cs create mode 100644 test/Flypaper.Tests/Core/SignpostTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 19bb6fd..bb0612e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,16 @@ All notable changes to Flypaper are documented in this file. The format follows ## [Unreleased] +### Added + +- Signposts in fake files: `.env` (`BACKUP_URL`, `ADMIN_URL`, `CONFIG_URL`), JSON and YAML (`backup_url`, + `api_base`), SQL dumps (comment naming the previous dump) and the Git config (remote URL) point back into the + trap. They sit in the first, undelayed chunk and carry the marker of the serving catch, so a later request + shows which catch the address came from, even from another IP. Switch: `Flypaper__Drip__Signposts` + (default `true`), no dashboard setting. No database change. +- MCP: every catch has a `marker`, and `list_catches` accepts `marker` to find the catch that handed out a + signpost. + ## [0.8.0] - 2026-11-22 ### Added diff --git a/docs/configuration.md b/docs/configuration.md index ef4cd2f..7967dbf 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -25,6 +25,7 @@ All optional. Read at startup; list entries need an index (`__0`, `__1`, ...). | `Flypaper__Drip__HeadStartSize` | Bytes sent immediately before dripping starts (`0` = off) | `1024` | | `Flypaper__Drip__LinkSpacing` | Link labyrinth: bytes of text between two links in the HTML page (`0` = off, plain `html-drip`) | `160` | | `Flypaper__Drip__BaitPaths` | Comma-separated decoy paths listed in `robots.txt` (max. 8, empty = off); requests to them get `robots-bait` and are held for at least 24 h | `/backup-2024/,/admin-old/,/internal/db-export/,/old-site/` | +| `Flypaper__Drip__Signposts` | Fake `.env`, JSON, YAML, SQL and Git files carry signpost URLs back into the trap (on the requested host, relative if the host is unusable); each URL holds the marker of the catch that served it (first 12 hex characters of its session id) | `true` | | `Flypaper__Drip__Lure` | First visit of an unknown IP to `/` or `/favicon.ico` gets an instant WordPress-looking page or icon (`lure-page`, `lure-icon`) and is not held; every later request is trapped as usual | `true` | | `Flypaper__Drip__MatchPath` | Pick content by request path (`/.env`, `*.json`, `*.xml`, `*.yml`, `*.sql`, `/.git/…`, `/SDK/…`, `/ISAPI/…`, `wp-login.php`) | `true` | | `TZ` | Time zone for the dashboard | UTC | diff --git a/docs/mcp.md b/docs/mcp.md index d8e9793..990ebc4 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -63,7 +63,7 @@ seconds. A *period* is a number with `m`, `h`, `d` or `w` (e.g. `1h`, `24h`, `7d |---|---|---| | `list_active` | – | Bots held in the trap right now with origin, URL, user agent, strategy, time held and bytes sent (memory only) | | `get_stats` | `period` (default `24h`) | Catches, rejected connections, unique IPs, total and average hold time, traps active now, longest catch | -| `list_catches` | `since`, `until` (ISO 8601), `country` (ISO code), `provider` (`AS4134` or part of the name), `ip`, `target_contains`, `limit` (default 50, max 500) | Events, newest first, including rejected ones | +| `list_catches` | `since`, `until` (ISO 8601), `country` (ISO code), `provider` (`AS4134` or part of the name), `ip`, `target_contains`, `limit` (default 50, max 500), `marker` (12 hex characters from a signpost URL) | Events, newest first, including rejected ones; each carries its `marker` | | `top` | `dimension` (`ips`, `countries`, `providers`, `targets`, `user_agents`), `period` (default `24h`), `limit` (default 10) | Most frequent values by number of catches, with total hold time | | `longest_catches` | `period` (default `7d`), `limit` (default 10) | Catches that held a bot the longest | | `lookup_ip` | `ip` | Origin, provider, totals, first and last seen, and its events (newest first, at most 500); local data only | diff --git a/src/Flypaper.Core/Strategies/DripOptions.cs b/src/Flypaper.Core/Strategies/DripOptions.cs index a450563..ffc747a 100644 --- a/src/Flypaper.Core/Strategies/DripOptions.cs +++ b/src/Flypaper.Core/Strategies/DripOptions.cs @@ -18,6 +18,8 @@ public sealed class DripOptions public int LinkSpacing { get; set; } = 160; + public bool Signposts { get; set; } = true; + public bool Lure { get; set; } = true; public string BaitPaths { get; set; } = Strategies.BaitPaths.Default; diff --git a/src/Flypaper.Core/Strategies/FileContent.cs b/src/Flypaper.Core/Strategies/FileContent.cs index 69ace17..d728020 100644 --- a/src/Flypaper.Core/Strategies/FileContent.cs +++ b/src/Flypaper.Core/Strategies/FileContent.cs @@ -7,20 +7,20 @@ public sealed record FileProfile( string Name, string MediaType, Func Matches, - Func> Generate); + Func> Generate); public static class FileContent { public static readonly IReadOnlyList Profiles = [ new("git-drip", "text/plain; charset=utf-8", IsGit, GitConfig), - new("svn-drip", "text/plain; charset=utf-8", path => IsInside(path, "/.svn"), Svn), - new("hg-drip", "text/plain; charset=utf-8", path => IsInside(path, "/.hg"), Mercurial), - new("wordpress-drip", "text/html; charset=UTF-8", path => LastSegment(path) == "wp-login.php", WordPressLogin), - new("hikvision-drip", "application/xml", path => path.StartsWith("/sdk/", StringComparison.Ordinal) || path.StartsWith("/isapi/", StringComparison.Ordinal), Hikvision), + new("svn-drip", "text/plain; charset=utf-8", path => IsInside(path, "/.svn"), (random, _) => Svn(random)), + new("hg-drip", "text/plain; charset=utf-8", path => IsInside(path, "/.hg"), (random, _) => Mercurial(random)), + new("wordpress-drip", "text/html; charset=UTF-8", path => LastSegment(path) == "wp-login.php", (random, _) => WordPressLogin(random)), + new("hikvision-drip", "application/xml", path => path.StartsWith("/sdk/", StringComparison.Ordinal) || path.StartsWith("/isapi/", StringComparison.Ordinal), (random, _) => Hikvision(random)), new("env-drip", "text/plain; charset=utf-8", path => IsEnv(LastSegment(path)), Env), new("json-drip", "application/json", path => path.EndsWith(".json", StringComparison.Ordinal), Json), - new("xml-drip", "application/xml", path => path.EndsWith(".xml", StringComparison.Ordinal), Xml), + new("xml-drip", "application/xml", path => path.EndsWith(".xml", StringComparison.Ordinal), (random, _) => Xml(random)), new("yaml-drip", "text/plain; charset=utf-8", path => path.EndsWith(".yml", StringComparison.Ordinal) || path.EndsWith(".yaml", StringComparison.Ordinal), Yaml), new("sql-drip", "text/plain; charset=utf-8", path => path.EndsWith(".sql", StringComparison.Ordinal), Sql) ]; @@ -46,10 +46,13 @@ public static class FileContent private static bool IsEnv(string name) => name.StartsWith(".env", StringComparison.Ordinal) || name.EndsWith(".env", StringComparison.Ordinal) || name == "env"; - private static IEnumerable Env(IRandomSource random) + private static IEnumerable Env(IRandomSource random, SignpostLinks? links) { - yield return $"APP_NAME=Portal\nAPP_ENV=production\nAPP_DEBUG=false\nAPP_URL=https://example.com\nAPP_KEY=base64:{Hex(random, 32)}\n\n" - + $"DB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=app\nDB_USERNAME=app\nDB_PASSWORD={Hex(random, 16)}\n\n"; + var appUrl = links is { BaseUrl.Length: > 0 } ? links.BaseUrl : "https://example.com"; + var signposts = links is null ? "" : $"BACKUP_URL={links.Backup}\nADMIN_URL={links.Admin}\nCONFIG_URL={links.Settings}\n\n"; + yield return $"APP_NAME=Portal\nAPP_ENV=production\nAPP_DEBUG=false\nAPP_URL={appUrl}\nAPP_KEY=base64:{Hex(random, 32)}\n\n" + + $"DB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=app\nDB_USERNAME=app\nDB_PASSWORD={Hex(random, 16)}\n\n" + + signposts; while (true) { @@ -117,9 +120,10 @@ public static class FileContent } } - private static IEnumerable Json(IRandomSource random) + private static IEnumerable Json(IRandomSource random, SignpostLinks? links) { - yield return "{\n \"name\": \"portal\",\n \"version\": \"1.4.2\",\n \"private\": true,\n \"entries\": [\n"; + var signposts = links is null ? "" : $" \"backup_url\": \"{links.Backup}\",\n \"api_base\": \"{links.Settings}\",\n"; + yield return "{\n \"name\": \"portal\",\n \"version\": \"1.4.2\",\n \"private\": true,\n" + signposts + " \"entries\": [\n"; var id = 1; while (true) @@ -139,9 +143,10 @@ public static class FileContent } } - private static IEnumerable Yaml(IRandomSource random) + private static IEnumerable Yaml(IRandomSource random, SignpostLinks? links) { - yield return "version: \"3.8\"\nservices:\n"; + var signposts = links is null ? "" : $"x-backup:\n backup_url: {links.Backup}\n api_base: {links.Settings}\n"; + yield return "version: \"3.8\"\n" + signposts + "services:\n"; while (true) { @@ -149,9 +154,10 @@ public static class FileContent } } - private static IEnumerable Sql(IRandomSource random) + private static IEnumerable Sql(IRandomSource random, SignpostLinks? links) { - yield return "-- MySQL dump 10.13 Distrib 8.0.36, for Linux (x86_64)\n--\n-- Host: localhost Database: app\n-- ------------------------------------------------------\n\n" + var signpost = links is null ? "" : $"-- Previous full dump: {links.Backup}\n"; + yield return "-- MySQL dump 10.13 Distrib 8.0.36, for Linux (x86_64)\n--\n-- Host: localhost Database: app\n" + signpost + "-- ------------------------------------------------------\n\n" + "DROP TABLE IF EXISTS `users`;\nCREATE TABLE `users` (\n `id` int NOT NULL AUTO_INCREMENT,\n `name` varchar(64) NOT NULL,\n `token` varchar(64) NOT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n\n" + "LOCK TABLES `users` WRITE;\n"; @@ -162,10 +168,11 @@ public static class FileContent } } - private static IEnumerable GitConfig(IRandomSource random) + private static IEnumerable GitConfig(IRandomSource random, SignpostLinks? links) { + var remote = links?.Repository ?? "https://example.com/portal.git"; yield return "[core]\n\trepositoryformatversion = 0\n\tfilemode = true\n\tbare = false\n\tlogallrefupdates = true\n" - + "[remote \"origin\"]\n\turl = https://example.com/portal.git\n\tfetch = +refs/heads/*:refs/remotes/origin/*\n"; + + $"[remote \"origin\"]\n\turl = {remote}\n\tfetch = +refs/heads/*:refs/remotes/origin/*\n"; while (true) { diff --git a/src/Flypaper.Core/Strategies/FileDripStrategy.cs b/src/Flypaper.Core/Strategies/FileDripStrategy.cs index cacaebd..6eb662c 100644 --- a/src/Flypaper.Core/Strategies/FileDripStrategy.cs +++ b/src/Flypaper.Core/Strategies/FileDripStrategy.cs @@ -13,5 +13,6 @@ public sealed class FileDripStrategy( public override string MediaType => profile.MediaType; - protected override IEnumerable Content(IRandomSource random, ITrapChannel channel, DripOptions options) => profile.Generate(random); + protected override IEnumerable Content(IRandomSource random, ITrapChannel channel, DripOptions options) => + profile.Generate(random, options.Signposts ? SignpostLinks.For(channel) : null); } diff --git a/src/Flypaper.Core/Strategies/SignpostLinks.cs b/src/Flypaper.Core/Strategies/SignpostLinks.cs new file mode 100644 index 0000000..25546d9 --- /dev/null +++ b/src/Flypaper.Core/Strategies/SignpostLinks.cs @@ -0,0 +1,28 @@ +using System.Text.RegularExpressions; +using Flypaper.Core.Abstractions; + +namespace Flypaper.Core.Strategies; + +public sealed partial record SignpostLinks(string BaseUrl, string Marker) +{ + public const int MarkerLength = 12; + + public string Backup => $"{BaseUrl}/backup/db-{Marker}.sql"; + + public string Admin => $"{BaseUrl}/admin-{Marker}/"; + + public string Settings => $"{BaseUrl}/storage/settings-{Marker}.json"; + + public string Repository => $"{BaseUrl}/git-{Marker}/portal.git"; + + public static string MarkerOf(Guid sessionId) => sessionId.ToString("N")[..MarkerLength]; + + public static SignpostLinks For(ITrapChannel channel) + { + var baseUrl = channel.Host is { } host && HostPattern().IsMatch(host) ? $"http://{host}" : ""; + return new SignpostLinks(baseUrl, MarkerOf(channel.Session.Id)); + } + + [GeneratedRegex(@"^[A-Za-z0-9.-]{1,253}\z")] + private static partial Regex HostPattern(); +} diff --git a/src/Flypaper.Storage/Queries/CatchQueries.cs b/src/Flypaper.Storage/Queries/CatchQueries.cs index 9549a0c..ca0ef9b 100644 --- a/src/Flypaper.Storage/Queries/CatchQueries.cs +++ b/src/Flypaper.Storage/Queries/CatchQueries.cs @@ -1,5 +1,6 @@ using System.Globalization; using Flypaper.Core.Models; +using Flypaper.Core.Strategies; using Flypaper.Storage.Entities; using Microsoft.EntityFrameworkCore; @@ -61,6 +62,13 @@ public sealed class CatchQueries(IDbContextFactory dbContextF events = events.Where(e => e.Target != null && e.Target.ToLower().Contains(text)); } + if (!string.IsNullOrWhiteSpace(filter.Marker)) + { + var marker = filter.Marker.Trim(); + var prefix = $"{marker[..8]}-{marker[8..]}%"; + events = events.Where(e => EF.Functions.Like(e.SessionId.ToString(), prefix)); + } + var rows = await events.OrderByDescending(e => e.StartedAt).ThenByDescending(e => e.Id).Take(Clamp(filter.Limit)).ToListAsync(ct); return rows.Select(ToRecord).ToList(); } @@ -176,7 +184,8 @@ public sealed class CatchQueries(IDbContextFactory dbContextF e.Asn, e.Provider, e.Target, - e.ClientInfo); + e.ClientInfo, + SignpostLinks.MarkerOf(e.SessionId)); private sealed class TopRow { diff --git a/src/Flypaper.Storage/Queries/CatchRecords.cs b/src/Flypaper.Storage/Queries/CatchRecords.cs index d4c7fa5..df1d113 100644 --- a/src/Flypaper.Storage/Queries/CatchRecords.cs +++ b/src/Flypaper.Storage/Queries/CatchRecords.cs @@ -17,7 +17,8 @@ public sealed record CatchRecord( long? Asn, string? Provider, string? Target, - string? UserAgent); + string? UserAgent, + string Marker); public sealed record CatchFilter( DateTime? Since = null, @@ -26,7 +27,8 @@ public sealed record CatchFilter( string? Provider = null, string? Ip = null, string? TargetContains = null, - int Limit = 50); + int Limit = 50, + string? Marker = null); public sealed record CatchStats( int Catches, diff --git a/src/Flypaper.Web/Mcp/FlypaperTools.cs b/src/Flypaper.Web/Mcp/FlypaperTools.cs index 72da3e6..b42f38e 100644 --- a/src/Flypaper.Web/Mcp/FlypaperTools.cs +++ b/src/Flypaper.Web/Mcp/FlypaperTools.cs @@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations; using System.Globalization; using System.Net; using Flypaper.Core.Abstractions; +using Flypaper.Core.Strategies; using Flypaper.Storage.Queries; using Flypaper.Web.Components.Shared; using ModelContextProtocol; @@ -61,7 +62,7 @@ public sealed class FlypaperTools(CatchQueries queries, IConnectionGovernor gove } [McpServerTool(Name = "list_catches", Title = "List catches", ReadOnly = true, Destructive = false, Idempotent = true, OpenWorld = false, UseStructuredContent = true)] - [Description("Trap events, newest first, optionally filtered. Includes rejected connections (outcome Rejected).")] + [Description("Trap events, newest first, optionally filtered. Includes rejected connections (outcome Rejected). Fake files contain signpost URLs carrying the marker of the catch that served them: use marker to find that catch, and target_contains with the same value to find who followed them.")] public async Task ListCatches( [Description("Only events that started at or after this ISO 8601 time, e.g. 2026-11-15T08:00:00Z.")] string? since = null, [Description("Only events that started before this ISO 8601 time.")] string? until = null, @@ -70,6 +71,7 @@ public sealed class FlypaperTools(CatchQueries queries, IConnectionGovernor gove [Description("Exact client IP address.")] string? ip = null, [Description("Case-insensitive text the request (method, host and path) must contain, e.g. .env.")] string? target_contains = null, [Description("Maximum number of events, 1 to 500.")] int limit = 50, + [Description("12 hex characters taken from a signpost URL, e.g. 7f3a9c21b4e8: only the catch that handed out this signpost.")] string? marker = null, CancellationToken ct = default) { var filter = new CatchFilter( @@ -79,7 +81,8 @@ public sealed class FlypaperTools(CatchQueries queries, IConnectionGovernor gove provider, ip is null ? null : ParseIp(ip), target_contains, - limit); + limit, + marker is null ? null : ParseMarker(marker)); var catches = (await queries.ListAsync(filter, ct)).Select(ToItem).ToList(); return new CatchListResult(catches.Count, catches); } @@ -182,6 +185,14 @@ public sealed class FlypaperTools(CatchQueries queries, IConnectionGovernor gove : throw new McpException($"{name} must be an ISO 8601 time, e.g. 2026-11-15T08:00:00Z."); } + private static string ParseMarker(string value) + { + var marker = value.Trim().ToLowerInvariant(); + return marker.Length == SignpostLinks.MarkerLength && marker.All(char.IsAsciiHexDigit) + ? marker + : throw new McpException($"marker must be {SignpostLinks.MarkerLength} hex characters, e.g. 7f3a9c21b4e8."); + } + private static string ParseIp(string value) => IPAddress.TryParse(value.Trim(), out var address) ? (address.IsIPv4MappedToIPv6 ? address.MapToIPv4() : address).ToString() @@ -206,5 +217,6 @@ public sealed class FlypaperTools(CatchQueries queries, IConnectionGovernor gove Asn(record.Asn), record.Provider, record.Target, - record.UserAgent); + record.UserAgent, + record.Marker); } diff --git a/src/Flypaper.Web/Mcp/McpResults.cs b/src/Flypaper.Web/Mcp/McpResults.cs index 21d55e8..c01085a 100644 --- a/src/Flypaper.Web/Mcp/McpResults.cs +++ b/src/Flypaper.Web/Mcp/McpResults.cs @@ -15,7 +15,8 @@ public sealed record CatchItem( string? Asn, string? Provider, string? Target, - string? UserAgent); + string? UserAgent, + string Marker); public sealed record StatsResult( string Period, diff --git a/test/Flypaper.Tests/Core/FileContentTests.cs b/test/Flypaper.Tests/Core/FileContentTests.cs index 6cb5108..34280dd 100644 --- a/test/Flypaper.Tests/Core/FileContentTests.cs +++ b/test/Flypaper.Tests/Core/FileContentTests.cs @@ -68,7 +68,7 @@ public sealed class FileContentTests { var profile = FileContent.Match(path).ShouldNotBeNull(); - var text = string.Concat(profile.Generate(new SeededRandomSource(5)).Take(200)); + var text = string.Concat(profile.Generate(new SeededRandomSource(5), null).Take(200)); text.ShouldStartWith(start); text.Length.ShouldBeGreaterThan(1000); diff --git a/test/Flypaper.Tests/Core/SignpostTests.cs b/test/Flypaper.Tests/Core/SignpostTests.cs new file mode 100644 index 0000000..d9dcb11 --- /dev/null +++ b/test/Flypaper.Tests/Core/SignpostTests.cs @@ -0,0 +1,87 @@ +using System.Text; +using System.Text.Json; +using Flypaper.Core.Strategies; +using Flypaper.Tests.Fakes; +using Shouldly; + +namespace Flypaper.Tests.Core; + +public sealed class SignpostTests +{ + [Theory] + [InlineData("env-drip", "BACKUP_URL=http://trap.example/backup/db-{m}.sql")] + [InlineData("env-drip", "ADMIN_URL=http://trap.example/admin-{m}/")] + [InlineData("env-drip", "CONFIG_URL=http://trap.example/storage/settings-{m}.json")] + [InlineData("json-drip", "\"backup_url\": \"http://trap.example/backup/db-{m}.sql\"")] + [InlineData("yaml-drip", "backup_url: http://trap.example/backup/db-{m}.sql")] + [InlineData("sql-drip", "-- Previous full dump: http://trap.example/backup/db-{m}.sql")] + [InlineData("git-drip", "url = http://trap.example/git-{m}/portal.git")] + public async Task Signposts_arrive_with_the_undelayed_head_and_carry_the_session_marker(string strategy, string expected) + { + var (head, channel) = await HeadAsync(strategy, "trap.example"); + + head.ShouldContain(expected.Replace("{m}", SignpostLinks.MarkerOf(channel.Session.Id))); + } + + [Theory] + [InlineData(null)] + [InlineData("[::1]")] + [InlineData("_")] + [InlineData("bad host\n")] + public async Task Unusable_hosts_give_relative_signposts(string? host) + { + var (head, channel) = await HeadAsync("env-drip", host); + + head.ShouldContain($"BACKUP_URL=/backup/db-{SignpostLinks.MarkerOf(channel.Session.Id)}.sql"); + head.ShouldContain("APP_URL=https://example.com"); + } + + [Theory] + [InlineData("env-drip")] + [InlineData("json-drip")] + [InlineData("yaml-drip")] + [InlineData("sql-drip")] + [InlineData("git-drip")] + public async Task Switch_removes_the_signposts(string strategy) + { + var (head, channel) = await HeadAsync(strategy, "trap.example", signposts: false); + + head.ShouldNotContain(SignpostLinks.MarkerOf(channel.Session.Id)); + head.ShouldNotContain("trap.example"); + } + + [Fact] + public void Json_with_signposts_stays_well_formed() + { + var profile = FileContent.Profiles.First(p => p.Name == "json-drip"); + var links = new SignpostLinks("http://trap.example", "7f3a9c21b4e8"); + var text = string.Concat(profile.Generate(new SeededRandomSource(5), links).Take(5)).TrimEnd().TrimEnd(',') + "]}"; + + using var document = JsonDocument.Parse(text); + + document.RootElement.GetProperty("api_base").GetString().ShouldBe("http://trap.example/storage/settings-7f3a9c21b4e8.json"); + } + + [Theory] + [InlineData("/backup/db-7f3a9c21b4e8.sql", "sql-drip")] + [InlineData("/storage/settings-7f3a9c21b4e8.json", "json-drip")] + public void Followed_signposts_lead_to_the_next_fake_file(string path, string strategy) => + FileContent.Match(path).ShouldNotBeNull().Name.ShouldBe(strategy); + + private static async Task<(string Head, FakeTrapChannel Channel)> HeadAsync(string strategy, string? host, bool signposts = true) + { + var options = TestOptions.Monitor(new DripOptions + { + Signposts = signposts, + MinDelay = TimeSpan.FromSeconds(30), + MaxDelay = TimeSpan.FromSeconds(30) + }); + var drip = new FileDripStrategy(FileContent.Profiles.First(p => p.Name == strategy), options, new SeededRandomSource(3), TimeProvider.System); + var channel = new FakeTrapChannel { Host = host }; + using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)); + + await Should.ThrowAsync(() => drip.RunAsync(channel, cts.Token)); + + return (Encoding.UTF8.GetString(channel.Writes.First()), channel); + } +} diff --git a/test/Flypaper.Tests/Mcp/FlypaperToolsTests.cs b/test/Flypaper.Tests/Mcp/FlypaperToolsTests.cs index ad6972b..fa3da45 100644 --- a/test/Flypaper.Tests/Mcp/FlypaperToolsTests.cs +++ b/test/Flypaper.Tests/Mcp/FlypaperToolsTests.cs @@ -49,6 +49,18 @@ public sealed class FlypaperToolsTests : IDisposable [Fact] public void List_active_is_empty_without_traps() => _tools.ListActive().Count.ShouldBe(0); + [Fact] + public async Task List_catches_finds_the_catch_behind_a_signpost_marker() + { + var origin = (await _tools.ListCatches()).Catches[2]; + + var found = await _tools.ListCatches(marker: origin.Marker.ToUpperInvariant()); + + origin.Marker.Length.ShouldBe(12); + found.Catches.ShouldHaveSingleItem().Id.ShouldBe(origin.Id); + await Should.ThrowAsync(() => _tools.ListCatches(marker: "not-a-marker")); + } + [Fact] public async Task Get_stats_summarizes_the_period() {