Add filters to the dashboard catch list and filter by clicking top 10 rows
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8eeb7894a3
commit
9f07d41cb0
11 files changed
+771
-83
No files matched your search
@@ -0,0 +1,67 @@
|
||||
using Flypaper.Core.Models;
|
||||
using Flypaper.Storage.Dashboard;
|
||||
using Flypaper.Web.Components.Pages.Dashboard;
|
||||
using Shouldly;
|
||||
|
||||
namespace Flypaper.Tests.Web;
|
||||
|
||||
public sealed class DashboardFilterTests
|
||||
{
|
||||
[Fact]
|
||||
public void Parses_all_parameters()
|
||||
{
|
||||
var filter = DashboardFilter.Parse("24h", "Abgelehnt", "hk", "as4134", " 203.0.113.9 ", "GET /.env", " wp ", "100");
|
||||
|
||||
filter.ShouldBe(new DashboardFilter("24h", "abgelehnt", "HK", "AS4134", "203.0.113.9", "GET /.env", "wp", 100));
|
||||
filter.ToRecentFilter().ShouldBe(new RecentFilter(TimeSpan.FromHours(24), TrapOutcome.Rejected, "HK", 4134, "203.0.113.9", "GET /.env", "wp", 100));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("aufgegeben", TrapOutcome.ClientAborted)]
|
||||
[InlineData("zeitlimit", TrapOutcome.Timeout)]
|
||||
[InlineData("abgelehnt", TrapOutcome.Rejected)]
|
||||
public void Maps_outcomes(string value, TrapOutcome expected) =>
|
||||
DashboardFilter.Parse(null, value, null, null, null, null, null, null).ToRecentFilter().Outcome.ShouldBe(expected);
|
||||
|
||||
[Fact]
|
||||
public void Ignores_invalid_values()
|
||||
{
|
||||
var filter = DashboardFilter.Parse("gestern", "kaputt", "Hongkong", "Chinanet", "not-an-ip", " ", "", "viele");
|
||||
|
||||
filter.ShouldBe(new DashboardFilter());
|
||||
filter.IsEmpty.ShouldBeTrue();
|
||||
filter.ToRecentFilter().ShouldBe(new RecentFilter());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("0", 1)]
|
||||
[InlineData("100000", RecentFilter.MaxLimit)]
|
||||
[InlineData(null, RecentFilter.DefaultLimit)]
|
||||
public void Clamps_the_limit(string? limit, int expected) =>
|
||||
DashboardFilter.Parse(null, null, null, null, null, null, null, limit).Limit.ShouldBe(expected);
|
||||
|
||||
[Fact]
|
||||
public void Builds_links_without_defaults_and_with_escaping()
|
||||
{
|
||||
new DashboardFilter().Href().ShouldBe("/#faenge");
|
||||
new DashboardFilter(Land: "CN", Ziel: "GET example.com/a&b", Limit: 100).Href("f50")
|
||||
.ShouldBe("/?land=CN&ziel=GET%20example.com%2Fa%26b&limit=100#f50");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Links_round_trip()
|
||||
{
|
||||
var filter = new DashboardFilter("7d", "zeitlimit", "TW", "AS3462", "2001:db8::1", "POST /xmlrpc.php", "curl", 200);
|
||||
var query = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(new Uri("http://x" + filter.Href()).Query);
|
||||
|
||||
DashboardFilter.Parse(query["zeit"], query["ausgang"], query["land"], query["provider"], query["ip"], query["ziel"], query["q"], query["limit"])
|
||||
.ShouldBe(filter);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Doubles_the_limit_up_to_the_maximum()
|
||||
{
|
||||
new DashboardFilter().NextLimit.ShouldBe(100);
|
||||
new DashboardFilter(Limit: 400).NextLimit.ShouldBe(RecentFilter.MaxLimit);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user