From 13468bbdf9e4b92f9159f6610e8e7bc19425d288 Mon Sep 17 00:00:00 2001 From: Tom Date: Mon, 16 Nov 2026 23:00:26 +0100 Subject: [PATCH] Pick tarpit content by request path Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 4 + docs/configuration.md | 2 + src/Flypaper.Core/FlypaperCoreExtensions.cs | 10 ++ src/Flypaper.Core/Models/TrapContext.cs | 2 +- .../Runtime/ConfiguredStrategySelector.cs | 6 + .../Settings/HoldMethodSettings.cs | 3 + .../Settings/RuntimeSettingsParser.cs | 1 + src/Flypaper.Core/Settings/SettingKeys.cs | 3 +- src/Flypaper.Core/Strategies/DripOptions.cs | 2 + src/Flypaper.Core/Strategies/FileContent.cs | 142 ++++++++++++++++++ .../Strategies/FileDripStrategy.cs | 17 +++ .../Middleware/FlypaperMiddleware.cs | 3 +- .../Pages/Settings/HoldMethodModel.cs | 2 + .../Pages/Settings/HoldMethodSection.razor | 10 ++ test/Flypaper.Tests/Core/FileContentTests.cs | 92 ++++++++++++ .../Core/HoldMethodParserTests.cs | 3 +- test/Flypaper.Tests/Http/ContentTypeTests.cs | 11 +- .../Storage/SettingsOverrideTests.cs | 3 +- 18 files changed, 307 insertions(+), 9 deletions(-) create mode 100644 src/Flypaper.Core/Strategies/FileContent.cs create mode 100644 src/Flypaper.Core/Strategies/FileDripStrategy.cs create mode 100644 test/Flypaper.Tests/Core/FileContentTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 121be2f..2fa8a93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ All notable changes to Flypaper are documented in this file. The format follows ### Added +- Content matches the requested path: `.env`, `*.json`, `*.xml` (sitemaps), `*.yml`, `*.sql`, + `/.git/…` and `robots.txt` get an endless, matching file with the right `Content-Type` + instead of an HTML page (strategy names `env-drip`, `json-drip`, …). Switchable on the + settings page (`Flypaper__Drip__MatchPath`). - Head start: the first bytes of the page (at least `HeadStartSize`, default 1024) are sent immediately after the `200` headers, with a `Server` header, so scanners see a real response before the drip begins. Adjustable on the settings page; the stored strategy name gets a diff --git a/docs/configuration.md b/docs/configuration.md index 3fd4b56..46abc86 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -24,6 +24,7 @@ All optional. Read at startup; list entries need an index (`__0`, `__1`, ...). | `Flypaper__Drip__MinDelay` / `MaxDelay` | Pause between chunks | `00:00:00.05` / `00:00:01` | | `Flypaper__Drip__MinChunkSize` / `MaxChunkSize` | Bytes per chunk | `1` / `64` | | `Flypaper__Drip__HeadStartSize` | Bytes sent immediately before dripping starts (`0` = off) | `1024` | +| `Flypaper__Drip__MatchPath` | Pick content by request path (`/.env`, `*.json`, `*.xml`, `*.yml`, `*.sql`, `/.git/…`, `robots.txt`) | `true` | | `TZ` | Time zone for the dashboard | UTC | The defaults of the runtime settings below can also be set this way, e.g. @@ -40,6 +41,7 @@ general reset button removes all saved values; the hold method section has its o | Hold method: pause between chunks, min and max (10 ms to 30 s) | 50 ms / 1000 ms | | Hold method: chunk size, min and max (1 to 4096 bytes) | 1 / 64 bytes | | Hold method: head start, sent without delay before the drip (0 to 65536 bytes) | 1024 bytes | +| Hold method: content matching the request path (e.g. `/.env`, `/config.json`) | on | | Hold method: maximum hold time per catch | `01:00:00` | | Maximum connections overall | `1000` | | Maximum connections per IP | `10` | diff --git a/src/Flypaper.Core/FlypaperCoreExtensions.cs b/src/Flypaper.Core/FlypaperCoreExtensions.cs index 12fda55..ac033f8 100644 --- a/src/Flypaper.Core/FlypaperCoreExtensions.cs +++ b/src/Flypaper.Core/FlypaperCoreExtensions.cs @@ -5,6 +5,7 @@ using Flypaper.Core.Strategies; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Options; namespace Flypaper.Core; @@ -20,6 +21,15 @@ public static class FlypaperCoreExtensions services.TryAddSingleton(); services.TryAddEnumerable(ServiceDescriptor.Singleton()); services.TryAddEnumerable(ServiceDescriptor.Singleton()); + foreach (var profile in FileContent.Profiles) + { + services.AddSingleton(provider => new FileDripStrategy( + profile, + provider.GetRequiredService>(), + provider.GetRequiredService(), + provider.GetRequiredService())); + } + services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); diff --git a/src/Flypaper.Core/Models/TrapContext.cs b/src/Flypaper.Core/Models/TrapContext.cs index 7324083..edb1915 100644 --- a/src/Flypaper.Core/Models/TrapContext.cs +++ b/src/Flypaper.Core/Models/TrapContext.cs @@ -1,3 +1,3 @@ namespace Flypaper.Core.Models; -public sealed record TrapContext(TrapSession Session, string? Target = null, string? ClientInfo = null); +public sealed record TrapContext(TrapSession Session, string? Target = null, string? ClientInfo = null, string? Path = null); diff --git a/src/Flypaper.Core/Runtime/ConfiguredStrategySelector.cs b/src/Flypaper.Core/Runtime/ConfiguredStrategySelector.cs index 5821d7e..c1d8bf9 100644 --- a/src/Flypaper.Core/Runtime/ConfiguredStrategySelector.cs +++ b/src/Flypaper.Core/Runtime/ConfiguredStrategySelector.cs @@ -13,6 +13,12 @@ public sealed class ConfiguredStrategySelector( public ITarpitStrategy? Select(TrapContext context) { var candidates = strategies.Where(strategy => strategy.Supports(context.Session.Protocol)).ToList(); + if (options.CurrentValue.MatchPath && FileContent.Match(context.Path) is { } profile + && candidates.FirstOrDefault(strategy => strategy.Name == profile.Name) is { } fileStrategy) + { + return fileStrategy; + } + string[] wanted = options.CurrentValue.Content switch { DripContent.Text => [TextDripStrategy.StrategyName], diff --git a/src/Flypaper.Core/Settings/HoldMethodSettings.cs b/src/Flypaper.Core/Settings/HoldMethodSettings.cs index f6dcc7b..36e08a3 100644 --- a/src/Flypaper.Core/Settings/HoldMethodSettings.cs +++ b/src/Flypaper.Core/Settings/HoldMethodSettings.cs @@ -10,6 +10,7 @@ public sealed record HoldMethodSettings( int MinChunkSize, int MaxChunkSize, int HeadStartSize, + bool MatchPath, TimeSpan MaxHoldDuration) { public double BytesPerSecond => AverageBytesPerSecond(MinDelay, MaxDelay, MinChunkSize, MaxChunkSize); @@ -22,6 +23,7 @@ public sealed record HoldMethodSettings( [SettingKeys.DripMinChunkSize] = MinChunkSize.ToString(CultureInfo.InvariantCulture), [SettingKeys.DripMaxChunkSize] = MaxChunkSize.ToString(CultureInfo.InvariantCulture), [SettingKeys.DripHeadStartSize] = HeadStartSize.ToString(CultureInfo.InvariantCulture), + [SettingKeys.DripMatchPath] = MatchPath ? "true" : "false", [SettingKeys.MaxHoldDuration] = MaxHoldDuration.ToString("c", CultureInfo.InvariantCulture) }; @@ -39,6 +41,7 @@ public sealed record HoldMethodInput( string? MinChunkSize, string? MaxChunkSize, string? HeadStartSize, + bool MatchPath, string? MaxHoldDuration); public sealed record HoldMethodParseResult(HoldMethodSettings? Settings, IReadOnlyDictionary Errors); diff --git a/src/Flypaper.Core/Settings/RuntimeSettingsParser.cs b/src/Flypaper.Core/Settings/RuntimeSettingsParser.cs index 7c4a67e..85eae90 100644 --- a/src/Flypaper.Core/Settings/RuntimeSettingsParser.cs +++ b/src/Flypaper.Core/Settings/RuntimeSettingsParser.cs @@ -84,6 +84,7 @@ public static class RuntimeSettingsParser minChunk!.Value, maxChunk!.Value, headStart!.Value, + input.MatchPath, hold!.Value), errors); } diff --git a/src/Flypaper.Core/Settings/SettingKeys.cs b/src/Flypaper.Core/Settings/SettingKeys.cs index d07bb83..0be7ea7 100644 --- a/src/Flypaper.Core/Settings/SettingKeys.cs +++ b/src/Flypaper.Core/Settings/SettingKeys.cs @@ -13,12 +13,13 @@ public static class SettingKeys public const string DripMinChunkSize = "Flypaper:Drip:MinChunkSize"; public const string DripMaxChunkSize = "Flypaper:Drip:MaxChunkSize"; public const string DripHeadStartSize = "Flypaper:Drip:HeadStartSize"; + public const string DripMatchPath = "Flypaper:Drip:MatchPath"; public static readonly IReadOnlyList General = [MaxConnections, MaxConnectionsPerIp, IgnorePrivateNetworks, RetentionDays]; public static readonly IReadOnlyList HoldMethod = - [DripContent, DripMinDelay, DripMaxDelay, DripMinChunkSize, DripMaxChunkSize, DripHeadStartSize, MaxHoldDuration]; + [DripContent, DripMinDelay, DripMaxDelay, DripMinChunkSize, DripMaxChunkSize, DripHeadStartSize, DripMatchPath, MaxHoldDuration]; public static readonly IReadOnlySet All = new HashSet(General.Concat(HoldMethod), StringComparer.OrdinalIgnoreCase); diff --git a/src/Flypaper.Core/Strategies/DripOptions.cs b/src/Flypaper.Core/Strategies/DripOptions.cs index 70b8ea6..dd89bd8 100644 --- a/src/Flypaper.Core/Strategies/DripOptions.cs +++ b/src/Flypaper.Core/Strategies/DripOptions.cs @@ -15,4 +15,6 @@ public sealed class DripOptions public int MaxChunkSize { get; set; } = 64; public int HeadStartSize { get; set; } = 1024; + + public bool MatchPath { get; set; } = true; } diff --git a/src/Flypaper.Core/Strategies/FileContent.cs b/src/Flypaper.Core/Strategies/FileContent.cs new file mode 100644 index 0000000..7b56517 --- /dev/null +++ b/src/Flypaper.Core/Strategies/FileContent.cs @@ -0,0 +1,142 @@ +using System.Globalization; +using Flypaper.Core.Abstractions; + +namespace Flypaper.Core.Strategies; + +public sealed record FileProfile( + string Name, + string MediaType, + Func Matches, + Func> Generate); + +public static class FileContent +{ + private static readonly string[] Sections = ["docs", "blog", "wiki", "support", "products", "archive", "news", "help", "files"]; + + public static readonly IReadOnlyList Profiles = + [ + new("git-drip", "text/plain; charset=utf-8", path => path.Contains("/.git/", StringComparison.Ordinal), GitConfig), + new("robots-drip", "text/plain; charset=utf-8", path => LastSegment(path) == "robots.txt", Robots), + 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("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) + ]; + + public static FileProfile? Match(string? path) + { + if (string.IsNullOrEmpty(path)) + { + return null; + } + + var normalized = path.ToLowerInvariant(); + return Profiles.FirstOrDefault(profile => profile.Matches(normalized)); + } + + private static string LastSegment(string path) => path[(path.LastIndexOf('/') + 1)..]; + + private static bool IsEnv(string name) => + name.StartsWith(".env", StringComparison.Ordinal) || name.EndsWith(".env", StringComparison.Ordinal) || name == "env"; + + private static IEnumerable Env(IRandomSource random) + { + 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"; + + while (true) + { + var key = $"{Upper(random)}_{Upper(random)}"; + yield return random.Next(0, 4) switch + { + 0 => $"{key}=true\n", + 1 => $"{key}={random.Next(1, 65536)}\n", + 2 => $"{key}=https://{LoremText.Word(random)}.internal/\n", + _ => $"{key}={Hex(random, 24)}\n" + }; + } + } + + private static IEnumerable Json(IRandomSource random) + { + yield return "{\n \"name\": \"portal\",\n \"version\": \"1.4.2\",\n \"private\": true,\n \"entries\": [\n"; + + var id = 1; + while (true) + { + yield return $" {{\"id\": {id++}, \"name\": \"{LoremText.Word(random)}\", \"token\": \"{Hex(random, 16)}\", \"enabled\": {(random.Next(0, 2) == 0 ? "true" : "false")}}},\n"; + } + } + + private static IEnumerable Xml(IRandomSource random) + { + yield return "\n\n"; + + while (true) + { + var date = string.Create(CultureInfo.InvariantCulture, $"2026-{random.Next(1, 13):00}-{random.Next(1, 29):00}"); + yield return $" \n https://example.com/{Pick(random, Sections)}/{LoremText.Phrase(random, 2).Replace(' ', '-')}\n {date}\n \n"; + } + } + + private static IEnumerable Yaml(IRandomSource random) + { + yield return "version: \"3.8\"\nservices:\n"; + + while (true) + { + yield return $" {LoremText.Word(random)}:\n image: {LoremText.Word(random)}:{random.Next(1, 10)}.{random.Next(0, 20)}\n restart: unless-stopped\n environment:\n - SECRET={Hex(random, 12)}\n"; + } + } + + private static IEnumerable Sql(IRandomSource random) + { + yield return "-- MySQL dump 10.13 Distrib 8.0.36, for Linux (x86_64)\n--\n-- Host: localhost Database: app\n-- ------------------------------------------------------\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"; + + var id = 1; + while (true) + { + yield return $"INSERT INTO `users` VALUES ({id++},'{LoremText.Word(random)}','{Hex(random, 32)}');\n"; + } + } + + private static IEnumerable GitConfig(IRandomSource random) + { + 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"; + + while (true) + { + var branch = $"{LoremText.Word(random)}-{LoremText.Word(random)}"; + yield return $"[branch \"{branch}\"]\n\tremote = origin\n\tmerge = refs/heads/{branch}\n"; + } + } + + private static IEnumerable Robots(IRandomSource random) + { + yield return "User-agent: *\nCrawl-delay: 2\nSitemap: https://example.com/sitemap.xml\n"; + + while (true) + { + yield return $"Disallow: /{Pick(random, Sections)}/{LoremText.Word(random)}/\n"; + } + } + + private static string Hex(IRandomSource random, int length) + { + var chars = new char[length]; + for (var i = 0; i < length; i++) + { + chars[i] = "0123456789abcdef"[random.Next(0, 16)]; + } + + return new string(chars); + } + + private static string Upper(IRandomSource random) => LoremText.Word(random).ToUpperInvariant(); + + private static string Pick(IRandomSource random, string[] values) => values[random.Next(0, values.Length)]; +} diff --git a/src/Flypaper.Core/Strategies/FileDripStrategy.cs b/src/Flypaper.Core/Strategies/FileDripStrategy.cs new file mode 100644 index 0000000..0da7caf --- /dev/null +++ b/src/Flypaper.Core/Strategies/FileDripStrategy.cs @@ -0,0 +1,17 @@ +using Flypaper.Core.Abstractions; +using Microsoft.Extensions.Options; + +namespace Flypaper.Core.Strategies; + +public sealed class FileDripStrategy( + FileProfile profile, + IOptionsMonitor options, + IRandomSource random, + TimeProvider timeProvider) : DripStrategy(options, random, timeProvider) +{ + public override string Name => profile.Name; + + public override string MediaType => profile.MediaType; + + protected override IEnumerable Content(IRandomSource random) => profile.Generate(random); +} diff --git a/src/Flypaper.Http/Middleware/FlypaperMiddleware.cs b/src/Flypaper.Http/Middleware/FlypaperMiddleware.cs index 41117af..82f6d27 100644 --- a/src/Flypaper.Http/Middleware/FlypaperMiddleware.cs +++ b/src/Flypaper.Http/Middleware/FlypaperMiddleware.cs @@ -35,7 +35,8 @@ internal sealed class FlypaperMiddleware( var trapContext = new TrapContext( session, $"{request.Method} {StoredHost(request.Host)}{request.Path}{request.QueryString}", - request.Headers.UserAgent.ToString()); + request.Headers.UserAgent.ToString(), + request.Path.Value); var outcome = await runner.RunAsync( trapContext, diff --git a/src/Flypaper.Web/Components/Pages/Settings/HoldMethodModel.cs b/src/Flypaper.Web/Components/Pages/Settings/HoldMethodModel.cs index fe4d99b..7add2b5 100644 --- a/src/Flypaper.Web/Components/Pages/Settings/HoldMethodModel.cs +++ b/src/Flypaper.Web/Components/Pages/Settings/HoldMethodModel.cs @@ -14,5 +14,7 @@ public sealed class HoldMethodModel public string? HeadStartSize { get; set; } + public bool MatchPath { get; set; } + public string? MaxHoldDuration { get; set; } } diff --git a/src/Flypaper.Web/Components/Pages/Settings/HoldMethodSection.razor b/src/Flypaper.Web/Components/Pages/Settings/HoldMethodSection.razor index 7d5bf31..7048e6e 100644 --- a/src/Flypaper.Web/Components/Pages/Settings/HoldMethodSection.razor +++ b/src/Flypaper.Web/Components/Pages/Settings/HoldMethodSection.razor @@ -64,6 +64,14 @@ + +
Ø @Bandwidth Bytes/s pro gefangener Verbindung, berechnet aus Pausen und Paketgrößen @@ -129,6 +137,7 @@ Model.MinChunkSize, Model.MaxChunkSize, Model.HeadStartSize, + Model.MatchPath, Model.MaxHoldDuration)); if (result.Settings is null) @@ -158,6 +167,7 @@ MinChunkSize = drip.MinChunkSize.ToString(CultureInfo.InvariantCulture), MaxChunkSize = drip.MaxChunkSize.ToString(CultureInfo.InvariantCulture), HeadStartSize = drip.HeadStartSize.ToString(CultureInfo.InvariantCulture), + MatchPath = drip.MatchPath, MaxHoldDuration = Core.CurrentValue.MaxHoldDuration.ToString("c", CultureInfo.InvariantCulture) }; } diff --git a/test/Flypaper.Tests/Core/FileContentTests.cs b/test/Flypaper.Tests/Core/FileContentTests.cs new file mode 100644 index 0000000..7ade7fb --- /dev/null +++ b/test/Flypaper.Tests/Core/FileContentTests.cs @@ -0,0 +1,92 @@ +using System.Net; +using System.Text; +using Flypaper.Core.Models; +using Flypaper.Core.Runtime; +using Flypaper.Core.Strategies; +using Flypaper.Tests.Fakes; +using Shouldly; + +namespace Flypaper.Tests.Core; + +public sealed class FileContentTests +{ + [Theory] + [InlineData("/.env", "env-drip")] + [InlineData("/app/.ENV.production", "env-drip")] + [InlineData("/config.json", "json-drip")] + [InlineData("/sitemap.xml", "xml-drip")] + [InlineData("/docker-compose.yml", "yaml-drip")] + [InlineData("/backup/db.sql", "sql-drip")] + [InlineData("/.git/config", "git-drip")] + [InlineData("/robots.txt", "robots-drip")] + public void Matches_known_paths(string path, string expected) => + FileContent.Match(path).ShouldNotBeNull().Name.ShouldBe(expected); + + [Theory] + [InlineData("/")] + [InlineData("/index.php")] + [InlineData("/wp-login.php")] + [InlineData("/environment")] + [InlineData("")] + [InlineData(null)] + public void Ignores_other_paths(string? path) => FileContent.Match(path).ShouldBeNull(); + + [Theory] + [InlineData("/.env", "APP_NAME=")] + [InlineData("/config.json", "{")] + [InlineData("/sitemap.xml", "(() => strategy.RunAsync(channel, cts.Token)); + + Encoding.UTF8.GetString(channel.Writes.First()).ShouldStartWith("APP_NAME="); + channel.Writes.First().Length.ShouldBeGreaterThanOrEqualTo(300); + strategy.Describe().ShouldBe("env-drip 30000-30000ms 1-64B head 300B"); + strategy.MediaType.ShouldStartWith("text/plain"); + } + + private static ConfiguredStrategySelector Selector(bool matchPath) + { + var options = TestOptions.Monitor(new DripOptions { MatchPath = matchPath }); + var random = new SeededRandomSource(11); + return new ConfiguredStrategySelector( + [ + new HtmlDripStrategy(options, random, TimeProvider.System), + new TextDripStrategy(options, random, TimeProvider.System), + .. FileContent.Profiles.Select(profile => new FileDripStrategy(profile, options, random, TimeProvider.System)) + ], + options, + random); + } +} diff --git a/test/Flypaper.Tests/Core/HoldMethodParserTests.cs b/test/Flypaper.Tests/Core/HoldMethodParserTests.cs index 7f7158a..bbe8714 100644 --- a/test/Flypaper.Tests/Core/HoldMethodParserTests.cs +++ b/test/Flypaper.Tests/Core/HoldMethodParserTests.cs @@ -6,7 +6,7 @@ namespace Flypaper.Tests.Core; public sealed class HoldMethodParserTests { - private static readonly HoldMethodInput Valid = new("Alternating", "50", "1000", "1", "64", "2048", "01:00:00"); + private static readonly HoldMethodInput Valid = new("Alternating", "50", "1000", "1", "64", "2048", true, "01:00:00"); [Fact] public void Parses_valid_input() @@ -19,6 +19,7 @@ public sealed class HoldMethodParserTests settings.MinChunkSize.ShouldBe(1); settings.MaxChunkSize.ShouldBe(64); settings.HeadStartSize.ShouldBe(2048); + settings.MatchPath.ShouldBeTrue(); settings.MaxHoldDuration.ShouldBe(TimeSpan.FromHours(1)); settings.ToConfiguration().Keys.ShouldBe(SettingKeys.HoldMethod, ignoreOrder: true); } diff --git a/test/Flypaper.Tests/Http/ContentTypeTests.cs b/test/Flypaper.Tests/Http/ContentTypeTests.cs index 06d3774..206fe6c 100644 --- a/test/Flypaper.Tests/Http/ContentTypeTests.cs +++ b/test/Flypaper.Tests/Http/ContentTypeTests.cs @@ -14,9 +14,12 @@ namespace Flypaper.Tests.Http; public sealed class ContentTypeTests { [Theory] - [InlineData("Html", "text/html; charset=utf-8")] - [InlineData("Text", "text/plain; charset=utf-8")] - public async Task Trap_answers_with_the_media_type_of_the_selected_strategy(string content, string expected) + [InlineData("Html", "/", "text/html; charset=utf-8")] + [InlineData("Text", "/", "text/plain; charset=utf-8")] + [InlineData("Html", "/config.json", "application/json")] + [InlineData("Html", "/.env", "text/plain; charset=utf-8")] + [InlineData("Html", "/sitemap.xml", "application/xml")] + public async Task Trap_answers_with_the_media_type_of_the_selected_strategy(string content, string path, string expected) { var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary @@ -39,7 +42,7 @@ public sealed class ContentTypeTests var context = new DefaultHttpContext { RequestServices = services }; context.Connection.RemoteIpAddress = IPAddress.Parse("203.0.113.9"); context.Connection.LocalPort = 8080; - context.Request.Path = "/"; + context.Request.Path = path; await app.Build()(context); diff --git a/test/Flypaper.Tests/Storage/SettingsOverrideTests.cs b/test/Flypaper.Tests/Storage/SettingsOverrideTests.cs index 87e66e3..4ce7aea 100644 --- a/test/Flypaper.Tests/Storage/SettingsOverrideTests.cs +++ b/test/Flypaper.Tests/Storage/SettingsOverrideTests.cs @@ -89,13 +89,14 @@ public sealed class SettingsOverrideTests : IDisposable var store = host.Services.GetRequiredService(); string[] holdKeys = [.. SettingKeys.HoldMethod]; - await store.SaveAsync(new HoldMethodSettings(DripContent.Text, TimeSpan.FromMilliseconds(200), TimeSpan.FromSeconds(2), 8, 16, 256, TimeSpan.FromMinutes(5))); + await store.SaveAsync(new HoldMethodSettings(DripContent.Text, TimeSpan.FromMilliseconds(200), TimeSpan.FromSeconds(2), 8, 16, 256, false, TimeSpan.FromMinutes(5))); await store.SaveAsync(new RuntimeSettings(50, 4, 90, true)); drip.CurrentValue.Content.ShouldBe(DripContent.Text); drip.CurrentValue.MinDelay.ShouldBe(TimeSpan.FromMilliseconds(200)); drip.CurrentValue.MaxChunkSize.ShouldBe(16); drip.CurrentValue.HeadStartSize.ShouldBe(256); + drip.CurrentValue.MatchPath.ShouldBeFalse(); core.CurrentValue.MaxHoldDuration.ShouldBe(TimeSpan.FromMinutes(5)); core.CurrentValue.MaxConnections.ShouldBe(50); (await store.HasOverridesAsync(holdKeys)).ShouldBeTrue();