using Flypaper.Http; using Flypaper.Http.Matching; using Flypaper.Tests.Fakes; using Shouldly; namespace Flypaper.Tests.Http; public sealed class TrapMatcherTests { private readonly TrapMatcher _matcher = new(TestOptions.Monitor(new HttpTrapOptions { KnownHosts = ["example.com", "*.example.org"], TrapPaths = ["/.env", "/.git/*", "/wp-login.php"] })); [Theory] [InlineData("example.com", "/")] [InlineData("EXAMPLE.com", "/index.html")] [InlineData("app.example.org", "/api/items")] [InlineData("example.com", "/.envelope")] [InlineData("example.com", "/.git")] public void Lets_normal_requests_pass(string host, string path) => _matcher.Match(host, path).ShouldBe(TrapMatch.None); [Theory] [InlineData("example.com", "/.env")] [InlineData("example.com", "/.ENV")] [InlineData("example.com", "/.env/")] [InlineData("example.com", "/.git/config")] [InlineData("app.example.org", "/wp-login.php")] public void Traps_configured_paths(string host, string path) => _matcher.Match(host, path).ShouldBe(TrapMatch.TrapPath); [Theory] [InlineData("unknown.net", "/")] [InlineData("203.0.113.7", "/")] [InlineData("example.org", "/")] [InlineData("", "/")] [InlineData(null, "/")] public void Traps_unknown_hosts(string? host, string path) => _matcher.Match(host, path).ShouldBe(TrapMatch.UnknownHost); }