using System.Linq; using System.Net; using System.Net.Http.Json; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using StellaOps.Notifier.Tests.Support; using StellaOps.Notifier.WebService.Contracts; using StellaOps.Notify.Queue; using Xunit; using StellaOps.TestKit; namespace StellaOps.Notifier.Tests; public sealed class AttestationEventEndpointTests : IClassFixture { private readonly NotifierApplicationFactory _factory; public AttestationEventEndpointTests(NotifierApplicationFactory factory) { _factory = factory; } [Trait("Category", TestCategories.Unit)] [Fact(Skip = "Disabled under in-memory compatibility mode")] public async Task Attestation_event_is_published_to_queue() { var recordingQueue = new RecordingNotifyEventQueue(); var client = _factory.WithWebHostBuilder(builder => { builder.ConfigureServices(services => { services.RemoveAll(); services.AddSingleton(recordingQueue); }); }).CreateClient(); var request = new AttestationEventRequest { EventId = Guid.NewGuid(), Kind = "authority.keys.rotated", Actor = "authority", Timestamp = DateTimeOffset.Parse("2025-11-24T00:00:00Z"), Payload = new System.Text.Json.Nodes.JsonObject { ["rotation"] = new System.Text.Json.Nodes.JsonObject { ["batchId"] = "batch-42", ["executedAt"] = "2025-11-24T00:00:00Z" } } }; var message = new HttpRequestMessage(HttpMethod.Post, "/api/v1/notify/attestation-events") { Content = JsonContent.Create(request) }; message.Headers.Add("X-StellaOps-Tenant", "tenant-sample"); var response = await client.SendAsync(message, TestContext.Current.CancellationToken); Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); Assert.Single(recordingQueue.Published); var published = recordingQueue.Published.Single(); Assert.Equal("authority.keys.rotated", published.Event.Kind); Assert.Equal("tenant-sample", published.Event.Tenant); Assert.Equal("notify:events", published.Stream); } }