Remove the unused content choice and the plain-text hold method
The link labyrinth held every catch that mattered, text-drip was never used. Flypaper__Drip__Content now only triggers the removed-settings warning. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4b946453fb
commit
c5167262b9
21 files changed
+26
-187
No files matched your search
@@ -126,7 +126,6 @@ public sealed class FileContentTests
|
||||
new HtmlDripStrategy(options, random, TimeProvider.System),
|
||||
new MazeDripStrategy(MazeKind.Page, options, random, TimeProvider.System),
|
||||
new MazeDripStrategy(MazeKind.Listing, options, random, TimeProvider.System),
|
||||
new TextDripStrategy(options, random, TimeProvider.System),
|
||||
new RobotsStaticStrategy(options),
|
||||
new MazeDripStrategy(MazeKind.Bait, options, random, TimeProvider.System),
|
||||
.. FileContent.Profiles.Select(profile => new FileDripStrategy(profile, options, random, TimeProvider.System))
|
||||
|
||||
@@ -6,14 +6,13 @@ namespace Flypaper.Tests.Core;
|
||||
|
||||
public sealed class HoldMethodParserTests
|
||||
{
|
||||
private static readonly HoldMethodInput Valid = new("Alternating", "50", "1000", "1", "64", "2048", true, "80", "/Backup-2024, /admin-old/x", "01:00:00", "7", "1.00:00:00");
|
||||
private static readonly HoldMethodInput Valid = new("50", "1000", "1", "64", "2048", true, "80", "/Backup-2024, /admin-old/x", "01:00:00", "7", "1.00:00:00");
|
||||
|
||||
[Fact]
|
||||
public void Parses_valid_input()
|
||||
{
|
||||
var settings = RuntimeSettingsParser.ParseHoldMethod(Valid).Settings.ShouldNotBeNull();
|
||||
|
||||
settings.Content.ShouldBe(DripContent.Alternating);
|
||||
settings.MinDelay.ShouldBe(TimeSpan.FromMilliseconds(50));
|
||||
settings.MaxDelay.ShouldBe(TimeSpan.FromSeconds(1));
|
||||
settings.MinChunkSize.ShouldBe(1);
|
||||
@@ -26,19 +25,6 @@ public sealed class HoldMethodParserTests
|
||||
settings.ToConfiguration().Keys.ShouldBe(SettingKeys.HoldMethod, ignoreOrder: true);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("html", DripContent.Html)]
|
||||
[InlineData("Text", DripContent.Text)]
|
||||
public void Accepts_content_case_insensitively(string value, DripContent expected) =>
|
||||
RuntimeSettingsParser.ParseHoldMethod(Valid with { Content = value }).Settings.ShouldNotBeNull().Content.ShouldBe(expected);
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData("fake-env")]
|
||||
[InlineData("7")]
|
||||
public void Rejects_unknown_content(string value) =>
|
||||
RuntimeSettingsParser.ParseHoldMethod(Valid with { Content = value }).Errors.Keys.ShouldBe([nameof(HoldMethodInput.Content)]);
|
||||
|
||||
[Theory]
|
||||
[InlineData("9", "1000")]
|
||||
[InlineData("50", "30001")]
|
||||
|
||||
@@ -14,65 +14,34 @@ public sealed class StrategySelectionTests
|
||||
private static readonly TrapContext Http =
|
||||
new(new TrapSession(Guid.NewGuid(), TrapProtocol.Http, IPAddress.Parse("203.0.113.9"), DateTimeOffset.UtcNow));
|
||||
|
||||
[Theory]
|
||||
[InlineData(DripContent.Html, "html-drip")]
|
||||
[InlineData(DripContent.Text, "text-drip")]
|
||||
public void Selects_the_configured_content(DripContent content, string expected) =>
|
||||
Selector(content).Select(Http).ShouldNotBeNull().Name.ShouldBe(expected);
|
||||
|
||||
[Fact]
|
||||
public void Alternating_picks_both_strategies()
|
||||
{
|
||||
var selector = Selector(DripContent.Alternating);
|
||||
|
||||
var names = Enumerable.Range(0, 50).Select(_ => selector.Select(Http)!.Name).Distinct().ToList();
|
||||
|
||||
names.ShouldBe(["html-drip", "text-drip"], ignoreOrder: true);
|
||||
}
|
||||
public void Selects_the_html_page() =>
|
||||
Selector().Select(Http).ShouldNotBeNull().Name.ShouldBe("html-drip");
|
||||
|
||||
[Fact]
|
||||
public void Returns_nothing_for_unsupported_protocols()
|
||||
{
|
||||
var ssh = Http with { Session = Http.Session with { Protocol = TrapProtocol.Ssh } };
|
||||
|
||||
Selector(DripContent.Html).Select(ssh).ShouldBeNull();
|
||||
Selector().Select(ssh).ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Strategies_describe_themselves_with_their_parameters()
|
||||
{
|
||||
var options = TestOptions.Monitor(new DripOptions { MinDelay = TimeSpan.FromMilliseconds(100), MaxDelay = TimeSpan.FromMilliseconds(250), MinChunkSize = 2, MaxChunkSize = 8 });
|
||||
var text = new TextDripStrategy(options, new SeededRandomSource(1), TimeProvider.System);
|
||||
var html = new HtmlDripStrategy(options, new SeededRandomSource(1), TimeProvider.System);
|
||||
|
||||
text.Describe().ShouldBe("text-drip 100-250ms 2-8B head 1024B");
|
||||
text.MediaType.ShouldStartWith("text/plain");
|
||||
new HtmlDripStrategy(options, new SeededRandomSource(1), TimeProvider.System).MediaType.ShouldStartWith("text/html");
|
||||
html.Describe().ShouldBe("html-drip 100-250ms 2-8B head 1024B");
|
||||
html.MediaType.ShouldStartWith("text/html");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Text_strategy_drips_plain_text()
|
||||
private static ConfiguredStrategySelector Selector()
|
||||
{
|
||||
var strategy = new TextDripStrategy(
|
||||
TestOptions.Monitor(new DripOptions { MinDelay = TimeSpan.FromMilliseconds(1), MaxDelay = TimeSpan.FromMilliseconds(2), MinChunkSize = 32, MaxChunkSize = 64 }),
|
||||
new SeededRandomSource(3),
|
||||
TimeProvider.System);
|
||||
var channel = new FakeTrapChannel();
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(200));
|
||||
|
||||
await Should.ThrowAsync<OperationCanceledException>(() => strategy.RunAsync(channel, cts.Token));
|
||||
|
||||
var text = Encoding.UTF8.GetString(channel.Writes.SelectMany(w => w).ToArray());
|
||||
text.Length.ShouldBeGreaterThan(200);
|
||||
text.ShouldNotContain("<");
|
||||
text.ShouldContain("\n");
|
||||
}
|
||||
|
||||
private static ConfiguredStrategySelector Selector(DripContent content)
|
||||
{
|
||||
var options = TestOptions.Monitor(new DripOptions { Content = content });
|
||||
var options = TestOptions.Monitor(new DripOptions());
|
||||
var random = new SeededRandomSource(11);
|
||||
return new ConfiguredStrategySelector(
|
||||
[new HtmlDripStrategy(options, random, TimeProvider.System), new TextDripStrategy(options, random, TimeProvider.System)],
|
||||
[new HtmlDripStrategy(options, random, TimeProvider.System)],
|
||||
options,
|
||||
random);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user