Headers and the first 8 KB of the body are stored unmasked for 30 days, read alongside the response so the trap answers as before. MCP get_request and the expanded catch row show them. Changelog prepared for 0.10.0. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using System.Net;
|
|
using Flypaper.Core.Models;
|
|
using Flypaper.Storage.Entities;
|
|
using Flypaper.Storage.Maintenance;
|
|
using Flypaper.Storage.Queries;
|
|
using Flypaper.Tests.Mcp;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Shouldly;
|
|
|
|
namespace Flypaper.Tests.Storage;
|
|
|
|
public sealed class TrapRequestStorageTests : IDisposable
|
|
{
|
|
private readonly McpTestData _data = new();
|
|
|
|
[Fact]
|
|
public async Task Request_details_are_returned_expire_early_and_go_with_their_catch()
|
|
{
|
|
long oldId, newId;
|
|
using (var db = _data.Factory.CreateDbContext())
|
|
{
|
|
var old = Entity(daysAgo: 40);
|
|
var recent = Entity(daysAgo: 1);
|
|
db.TrapEvents.AddRange(old, recent);
|
|
db.SaveChanges();
|
|
(oldId, newId) = (old.Id, recent.Id);
|
|
}
|
|
|
|
var queries = new CatchQueries(_data.Factory);
|
|
var maintenance = new TrapDataMaintenance(_data.Factory);
|
|
(await queries.GetRequestAsync(newId)).Request.ShouldNotBeNull().Body.ShouldBe("pwd=1");
|
|
|
|
(await maintenance.DeleteRequestsOlderThanAsync(McpTestData.Now.UtcDateTime.AddDays(-30))).ShouldBe(1);
|
|
|
|
var expired = await queries.GetRequestAsync(oldId);
|
|
expired.Found.ShouldBeTrue();
|
|
expired.Request.ShouldBeNull();
|
|
(await queries.GetRequestAsync(999_999)).Found.ShouldBeFalse();
|
|
|
|
await maintenance.DeleteAllAsync();
|
|
using var check = _data.Factory.CreateDbContext();
|
|
(await check.TrapRequests.CountAsync()).ShouldBe(0);
|
|
}
|
|
|
|
private static TrapEventEntity Entity(int daysAgo)
|
|
{
|
|
var started = McpTestData.Now.AddDays(-daysAgo);
|
|
return TrapEventEntity.From(new TrapEvent(
|
|
Guid.NewGuid(), TrapProtocol.Http, IPAddress.Parse("203.0.113.60"), "maze-drip", started, started.AddSeconds(5), 10,
|
|
TrapOutcome.ClientAborted, "POST /", null, new RequestDetails("Host: x\n", "pwd=1", 5, false)));
|
|
}
|
|
|
|
public void Dispose() => _data.Dispose();
|
|
}
|