archive audit attempts

This commit is contained in:
master
2026-02-19 22:00:31 +02:00
parent c2f13fe588
commit b5829dce5c
19638 changed files with 6366 additions and 7 deletions

View File

@@ -0,0 +1,103 @@
using System.Net;
using System.Net.Http.Json;
using StellaOps.Platform.WebService.Contracts;
using StellaOps.TestKit;
using Xunit;
namespace StellaOps.Platform.WebService.Tests;
public sealed class FederationTelemetryEndpointsTests : IClassFixture<PlatformWebApplicationFactory>
{
private readonly PlatformWebApplicationFactory _factory;
public FederationTelemetryEndpointsTests(PlatformWebApplicationFactory factory)
{
_factory = factory;
}
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task ConsentGrantAndRevokeLifecycle_Works()
{
var tenantId = Guid.NewGuid().ToString("D");
using var client = CreateTenantClient(tenantId);
var before = await client.GetFromJsonAsync<FederationConsentStateResponse>(
"/api/v1/telemetry/federation/consent",
TestContext.Current.CancellationToken);
Assert.NotNull(before);
Assert.False(before!.Granted);
var grantResponse = await client.PostAsJsonAsync(
"/api/v1/telemetry/federation/consent/grant",
new FederationGrantConsentRequest("qa-admin", 12),
TestContext.Current.CancellationToken);
grantResponse.EnsureSuccessStatusCode();
var proof = await grantResponse.Content.ReadFromJsonAsync<FederationConsentProofResponse>(
TestContext.Current.CancellationToken);
Assert.NotNull(proof);
Assert.Equal(tenantId, proof!.TenantId);
Assert.Equal("qa-admin", proof.GrantedBy);
Assert.StartsWith("sha256:", proof.DsseDigest, StringComparison.Ordinal);
var afterGrant = await client.GetFromJsonAsync<FederationConsentStateResponse>(
"/api/v1/telemetry/federation/consent",
TestContext.Current.CancellationToken);
Assert.NotNull(afterGrant);
Assert.True(afterGrant!.Granted);
Assert.Equal("qa-admin", afterGrant.GrantedBy);
var revokeResponse = await client.PostAsJsonAsync(
"/api/v1/telemetry/federation/consent/revoke",
new FederationRevokeConsentRequest("qa-admin"),
TestContext.Current.CancellationToken);
Assert.Equal(HttpStatusCode.OK, revokeResponse.StatusCode);
var afterRevoke = await client.GetFromJsonAsync<FederationConsentStateResponse>(
"/api/v1/telemetry/federation/consent",
TestContext.Current.CancellationToken);
Assert.NotNull(afterRevoke);
Assert.False(afterRevoke!.Granted);
}
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task ListBundles_ReturnsDeterministicEmptyCollection_WhenNoBundlesExist()
{
var tenantId = Guid.NewGuid().ToString("D");
using var client = CreateTenantClient(tenantId);
var bundles = await client.GetFromJsonAsync<IReadOnlyList<FederationBundleSummary>>(
"/api/v1/telemetry/federation/bundles",
TestContext.Current.CancellationToken);
Assert.NotNull(bundles);
Assert.Empty(bundles!);
}
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task PrivacyBudgetSnapshot_ReturnsExpectedShape()
{
var tenantId = Guid.NewGuid().ToString("D");
using var client = CreateTenantClient(tenantId);
var snapshot = await client.GetFromJsonAsync<FederationPrivacyBudgetResponse>(
"/api/v1/telemetry/federation/privacy-budget",
TestContext.Current.CancellationToken);
Assert.NotNull(snapshot);
Assert.True(snapshot!.Total > 0);
Assert.True(snapshot.Remaining <= snapshot.Total);
Assert.True(snapshot.NextReset >= snapshot.PeriodStart);
}
private HttpClient CreateTenantClient(string tenantId)
{
var client = _factory.CreateClient();
client.DefaultRequestHeaders.Add("X-StellaOps-Tenant", tenantId);
client.DefaultRequestHeaders.Add("X-StellaOps-Actor", "federation-test");
return client;
}
}