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>
68 lines
2.6 KiB
C#
68 lines
2.6 KiB
C#
using System.Net;
|
|
using Flypaper.Core.Abstractions;
|
|
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 LureTests
|
|
{
|
|
private static readonly TrapSession Session = new(Guid.NewGuid(), TrapProtocol.Http, IPAddress.Parse("203.0.113.9"), DateTimeOffset.UtcNow);
|
|
|
|
[Theory]
|
|
[InlineData("/", true, "lure-page")]
|
|
[InlineData("/favicon.ico", true, "lure-icon")]
|
|
[InlineData("/", false, "html-drip")]
|
|
[InlineData("/.env", true, "env-drip")]
|
|
[InlineData("/wp-login.php", true, "wordpress-drip")]
|
|
public void Lures_only_new_ips_on_start_page_and_favicon(string path, bool isNewIp, string expected) =>
|
|
Selector(new DripOptions { LinkSpacing = 0 }).Select(new TrapContext(Session, "GET " + path, null, path, isNewIp)).ShouldNotBeNull().Name.ShouldBe(expected);
|
|
|
|
[Fact]
|
|
public void Switch_turns_the_lure_off() =>
|
|
Selector(new DripOptions { LinkSpacing = 0, Lure = false })
|
|
.Select(new TrapContext(Session, "GET /", null, "/", true)).ShouldNotBeNull().Name.ShouldBe("html-drip");
|
|
|
|
[Fact]
|
|
public async Task Lure_page_is_one_consistent_wordpress_response()
|
|
{
|
|
var channel = new FakeTrapChannel();
|
|
var strategy = LureStrategy.Page();
|
|
|
|
await strategy.RunAsync(channel, default);
|
|
|
|
System.Text.Encoding.UTF8.GetString(channel.Writes.SelectMany(w => w).ToArray()).ShouldContain("WordPress 6.4.3");
|
|
strategy.MediaType.ShouldStartWith("text/html");
|
|
strategy.Headers["X-Powered-By"].ShouldStartWith("PHP/");
|
|
}
|
|
|
|
[Fact]
|
|
public void Lure_icon_is_a_valid_ico_file()
|
|
{
|
|
var icon = LureContent.Icon();
|
|
|
|
icon[..4].ShouldBe([0, 0, 1, 0]);
|
|
BitConverter.ToInt32(icon, 14).ShouldBe(icon.Length - 22);
|
|
LureStrategy.Icon().MediaType.ShouldBe("image/x-icon");
|
|
}
|
|
|
|
private static ConfiguredStrategySelector Selector(DripOptions dripOptions)
|
|
{
|
|
var options = TestOptions.Monitor(dripOptions);
|
|
var random = new SeededRandomSource(5);
|
|
return new ConfiguredStrategySelector(
|
|
[
|
|
new HtmlDripStrategy(options, random, TimeProvider.System),
|
|
new FileDripStrategy(FileContent.Profiles.First(p => p.Name == "env-drip"), options, random, TimeProvider.System),
|
|
new FileDripStrategy(FileContent.Profiles.First(p => p.Name == "wordpress-drip"), options, random, TimeProvider.System),
|
|
LureStrategy.Page(),
|
|
LureStrategy.Icon()
|
|
],
|
|
options,
|
|
random);
|
|
}
|
|
}
|