Files
Flypaper/test/Flypaper.Tests/TrapMatcherTests.cs
T

42 lines
1.4 KiB
C#

using Flypaper.Http;
using Microsoft.Extensions.Options;
using Shouldly;
namespace Flypaper.Tests;
public sealed class TrapMatcherTests
{
private readonly TrapMatcher _matcher = new(Options.Create(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);
}