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,79 @@
|
||||
using Flypaper.Core.Models;
|
||||
using Flypaper.Storage.Dashboard;
|
||||
using Flypaper.Tests.Fakes;
|
||||
using Flypaper.Tests.Mcp;
|
||||
using Shouldly;
|
||||
|
||||
namespace Flypaper.Tests.Storage;
|
||||
|
||||
public sealed class RecentCatchesTests : IDisposable
|
||||
{
|
||||
private readonly McpTestData _data = new();
|
||||
private readonly DashboardQueries _queries;
|
||||
|
||||
public RecentCatchesTests() => _queries = new DashboardQueries(_data.Factory, new FixedTimeProvider(McpTestData.Now));
|
||||
|
||||
[Fact]
|
||||
public async Task Without_filters_returns_all_events_newest_first()
|
||||
{
|
||||
var recent = await _queries.GetRecentAsync(new RecentFilter());
|
||||
|
||||
recent.Total.ShouldBe(6);
|
||||
recent.Items.Select(e => e.StartedAt).ShouldBeInOrder(SortDirection.Descending);
|
||||
recent.Countries.Select(c => c.Code).ShouldBe(["CN", "TW", "US"], ignoreOrder: true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Combines_filters()
|
||||
{
|
||||
var recent = await _queries.GetRecentAsync(new RecentFilter(Window: TimeSpan.FromHours(24), CountryCode: "TW", Outcome: TrapOutcome.Rejected));
|
||||
|
||||
recent.Total.ShouldBe(1);
|
||||
recent.Items.ShouldHaveSingleItem().RemoteIp.ShouldBe("198.51.100.7");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(4134L, null, null, 2)]
|
||||
[InlineData(null, "203.0.113.9", null, 2)]
|
||||
[InlineData(null, null, "GET /.env", 2)]
|
||||
[InlineData(4134L, null, "GET /.env", 1)]
|
||||
public async Task Matches_provider_ip_and_target_exactly(long? asn, string? ip, string? target, int expected)
|
||||
{
|
||||
var recent = await _queries.GetRecentAsync(new RecentFilter(Asn: asn, Ip: ip, Target: target));
|
||||
|
||||
recent.Total.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("chinanet", 2)]
|
||||
[InlineData("CURL", 2)]
|
||||
[InlineData("198.51", 2)]
|
||||
[InlineData("wp-login", 1)]
|
||||
[InlineData("100%", 0)]
|
||||
public async Task Search_is_case_insensitive_over_ip_provider_target_and_user_agent(string search, int expected)
|
||||
{
|
||||
var recent = await _queries.GetRecentAsync(new RecentFilter(Search: search));
|
||||
|
||||
recent.Total.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Returns_an_empty_result_when_nothing_matches()
|
||||
{
|
||||
var recent = await _queries.GetRecentAsync(new RecentFilter(CountryCode: "US", Outcome: TrapOutcome.Rejected));
|
||||
|
||||
recent.Total.ShouldBe(0);
|
||||
recent.Items.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Limits_the_items_but_counts_all_matches()
|
||||
{
|
||||
var recent = await _queries.GetRecentAsync(new RecentFilter(Limit: 2));
|
||||
|
||||
recent.Items.Count.ShouldBe(2);
|
||||
recent.Total.ShouldBe(6);
|
||||
}
|
||||
|
||||
public void Dispose() => _data.Dispose();
|
||||
}
|
||||
@@ -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