Record request headers and bodies and show them per catch
Build and deploy / build (push) Successful in 1m29s
Release / image (push) Successful in 1m53s
Build and deploy / deploy (push) Successful in 30s
Release / release (push) Successful in 6s

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>
This commit is contained in:
TomandClaude Sonnet 5.5 committed 2026-11-26 21:47:28 +01:00
1 parent a46727bab3
commit b559f83550
35 files changed
+1012 -18

No files matched your search

@@ -0,0 +1,54 @@
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();
}