Files
Flypaper/test/Flypaper.Tests/Web/StrategyNamesTests.cs
T
TomandClaude Sonnet 5.5 4b946453fb
Build and deploy / build (push) Successful in 1m33s
Build and deploy / deploy (push) Successful in 20s
Answer first visits to / and favicon with an instant WordPress lure
Unknown IPs get a small WordPress-looking page or icon and are not held;
later requests are trapped as before. Switch: Flypaper__Drip__Lure.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 12:57:29 +01:00

109 lines
4.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Flypaper.Core.Strategies;
using Flypaper.Storage.Dashboard;
using Flypaper.Web.Components.Shared;
using Shouldly;
namespace Flypaper.Tests.Web;
public sealed class StrategyNamesTests
{
[Fact]
public void Describes_the_maze_with_all_suffixes()
{
var info = StrategyNames.Describe("maze-drip 50-500ms 1-1024B head 1024B link 160B repeat");
info.DisplayName.ShouldBe("Link-Labyrinth");
info.Explanation.ShouldNotBeNull();
info.Details.ShouldBe([
"tröpfelt 1–1.024 Byte alle 50–500 ms",
"schneller Start: die ersten 1.024 Byte sofort",
"alle 160 Byte ein Link",
"Wiederholer: darf länger festgehalten werden"
]);
info.Raw.ShouldBe("maze-drip 50-500ms 1-1024B head 1024B link 160B repeat");
info.Tooltip.ShouldContain("Technisch: maze-drip 50-500ms");
}
[Fact]
public void Shows_unknown_names_and_tokens_unchanged()
{
var info = StrategyNames.Describe("ufo-drip 5-9ms 1-2B odd");
info.DisplayName.ShouldBe("ufo-drip");
info.Explanation.ShouldBeNull();
info.Details.ShouldBe(["tröpfelt 1–2 Byte alle 5–9 ms", "odd"]);
}
[Theory]
[InlineData("robots-static")]
[InlineData("robots-bait 10-20ms 1-8B link 160B")]
public void Covers_robots_strategies(string strategy) =>
StrategyNames.Describe(strategy).Explanation.ShouldNotBeNull();
[Fact]
public void Covers_every_strategy_name_of_the_core()
{
string[] names =
[
MazeDripStrategy.PageName, MazeDripStrategy.ListingName, MazeDripStrategy.BaitName,
HtmlDripStrategy.StrategyName, TextDripStrategy.StrategyName, RobotsStaticStrategy.StrategyName,
LureStrategy.PageName, LureStrategy.IconName,
.. FileContent.Profiles.Select(profile => profile.Name)
];
foreach (var name in names)
{
StrategyNames.Describe(name).Explanation.ShouldNotBeNull(name);
}
}
[Fact]
public void Finds_base_names_by_display_name()
{
StrategyNames.Matching(" gefälschtes git ").ShouldBe(["git-drip"]);
StrategyNames.Matching("zugangsdaten").ShouldBe(["env-drip"]);
StrategyNames.Matching("").ShouldBeEmpty();
StrategyNames.Matching("nichts").ShouldBeEmpty();
}
[Fact]
public void Groups_variants_by_base_type_and_shows_only_content_differences_as_badges()
{
StrategyNames.Describe("html-drip 50-500ms 1-1024B").GroupKey.ShouldBe("html-drip");
StrategyNames.Describe("html-drip 50-500ms 1-640B").GroupKey.ShouldBe("html-drip");
var variant = StrategyNames.Describe("html-drip 5-20ms 1-64B head 1024B repeat");
variant.GroupKey.ShouldBe("html-drip head repeat");
variant.Badges.ShouldBe(["Schnellstart", "Wiederholer"]);
StrategyNames.Describe("maze-drip 50-500ms 1-1024B head 1024B link 160B").Badges.ShouldBe(["Schnellstart"]);
}
[Fact]
public void Treats_drip_as_the_old_name_of_the_endless_page()
{
var info = StrategyNames.Describe("drip");
info.DisplayName.ShouldBe("Endlose Webseite");
info.GroupKey.ShouldBe("html-drip");
StrategyNames.Matching("endlose webseite").ShouldBe(["html-drip", "drip"]);
}
[Fact]
public void Ranks_groups_by_median_and_sinks_groups_with_few_catches()
{
var samples = new List<StrategySample>();
samples.AddRange(Enumerable.Repeat(new StrategySample("html-drip 50-500ms 1-1024B", 10_000), 3));
samples.AddRange(Enumerable.Repeat(new StrategySample("html-drip 50-500ms 1-640B", 20_000), 2));
samples.Add(new StrategySample("drip", 1_000_000));
samples.AddRange(Enumerable.Repeat(new StrategySample("env-drip 50-500ms 1-1024B", 30_000), 5));
samples.Add(new StrategySample("text-drip", 500_000_000));
var ranked = StrategyNames.Rank(samples, 10);
ranked.Select(r => r.Key).ShouldBe(["env-drip", "html-drip", "text-drip"]);
ranked[0].MedianHold.ShouldBe(TimeSpan.FromSeconds(30));
ranked[1].Count.ShouldBe(6);
ranked[1].MedianHold.ShouldBe(TimeSpan.FromSeconds(15));
ranked[1].HoldTime.ShouldBe(TimeSpan.FromMilliseconds(1_070_000));
}
}