Refactor code structure and optimize performance across multiple modules

This commit is contained in:
StellaOps Bot
2025-12-26 20:03:22 +02:00
parent c786faae84
commit b4fc66feb6
3353 changed files with 88254 additions and 1590657 deletions

View File

@@ -17,6 +17,8 @@ using Microsoft.Extensions.Options;
using StellaOps.IssuerDirectory.Client;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.IssuerDirectory.Core.Tests;
public class IssuerDirectoryClientTests
@@ -56,7 +58,8 @@ public class IssuerDirectoryClientTests
};
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task SetIssuerTrustAsync_SendsAuditMetadataAndInvalidatesCache()
{
var handler = new RecordingHandler(
@@ -99,7 +102,8 @@ public class IssuerDirectoryClientTests
handler.Requests[2].Method.Should().Be(HttpMethod.Get);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task DeleteIssuerTrustAsync_UsesDeleteVerbAndReasonHeaderWhenProvided()
{
var handler = new RecordingHandler(
@@ -131,7 +135,8 @@ public class IssuerDirectoryClientTests
handler.Requests[2].Method.Should().Be(HttpMethod.Get);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task SetIssuerTrustAsync_PropagatesFailureAndDoesNotEvictCache()
{
var handler = new RecordingHandler(

View File

@@ -13,5 +13,6 @@
<ItemGroup>
<ProjectReference Include="..\StellaOps.IssuerDirectory.Core\StellaOps.IssuerDirectory.Core.csproj" />
<ProjectReference Include="..\..\..\__Libraries\StellaOps.IssuerDirectory.Client\StellaOps.IssuerDirectory.Client.csproj" />
<ProjectReference Include="../../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
</ItemGroup>
</Project>

View File

@@ -7,6 +7,8 @@ using StellaOps.IssuerDirectory.Core.Domain;
using StellaOps.IssuerDirectory.Storage.Postgres.Repositories;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.IssuerDirectory.Storage.Postgres.Tests;
[Collection(IssuerDirectoryPostgresCollection.Name)]
@@ -41,7 +43,8 @@ public sealed class IssuerAuditSinkTests : IAsyncLifetime
public Task DisposeAsync() => Task.CompletedTask;
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task WriteAsync_PersistsAuditEntry()
{
var entry = CreateAuditEntry("issuer.created", "Issuer was created");
@@ -55,7 +58,8 @@ public sealed class IssuerAuditSinkTests : IAsyncLifetime
persisted.Actor.Should().Be("test@test.com");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task WriteAsync_PersistsMetadata()
{
var metadata = new Dictionary<string, string>
@@ -75,7 +79,8 @@ public sealed class IssuerAuditSinkTests : IAsyncLifetime
persisted.Details["newSlug"].Should().Be("new-issuer");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task WriteAsync_PersistsEmptyMetadata()
{
var entry = CreateAuditEntry("issuer.deleted", "Issuer removed");
@@ -88,7 +93,8 @@ public sealed class IssuerAuditSinkTests : IAsyncLifetime
persisted.Details.Should().BeEmpty();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task WriteAsync_PersistsNullReason()
{
var entry = CreateAuditEntry("issuer.updated", null);
@@ -100,7 +106,8 @@ public sealed class IssuerAuditSinkTests : IAsyncLifetime
persisted!.Reason.Should().BeNull();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task WriteAsync_PersistsTimestampCorrectly()
{
var now = DateTimeOffset.UtcNow;
@@ -113,7 +120,8 @@ public sealed class IssuerAuditSinkTests : IAsyncLifetime
persisted!.OccurredAt.Should().BeCloseTo(now.UtcDateTime, TimeSpan.FromSeconds(1));
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task WriteAsync_PersistsMultipleEntriesForSameIssuer()
{
var entry1 = CreateAuditEntry("issuer.created", "Created");
@@ -128,7 +136,8 @@ public sealed class IssuerAuditSinkTests : IAsyncLifetime
count.Should().Be(3);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task WriteAsync_PersistsActorCorrectly()
{
var entry = new IssuerAuditEntry(

View File

@@ -5,6 +5,7 @@ using StellaOps.IssuerDirectory.Core.Domain;
using StellaOps.IssuerDirectory.Storage.Postgres.Repositories;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.IssuerDirectory.Storage.Postgres.Tests;
[Collection(IssuerDirectoryPostgresCollection.Name)]
@@ -38,7 +39,8 @@ public sealed class IssuerKeyRepositoryTests : IAsyncLifetime
public Task DisposeAsync() => Task.CompletedTask;
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_CreatesNewKey()
{
var keyRecord = CreateKeyRecord("key-001", IssuerKeyType.Ed25519PublicKey);
@@ -52,7 +54,8 @@ public sealed class IssuerKeyRepositoryTests : IAsyncLifetime
fetched.Status.Should().Be(IssuerKeyStatus.Active);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_UpdatesExistingKey()
{
var keyRecord = CreateKeyRecord("key-update", IssuerKeyType.Ed25519PublicKey);
@@ -74,7 +77,8 @@ public sealed class IssuerKeyRepositoryTests : IAsyncLifetime
fetched.RetiredAtUtc.Should().NotBeNull();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task GetAsync_ReturnsNullForNonExistentKey()
{
var result = await _keyRepository.GetAsync(_tenantId, _issuerId, "nonexistent", CancellationToken.None);
@@ -82,7 +86,8 @@ public sealed class IssuerKeyRepositoryTests : IAsyncLifetime
result.Should().BeNull();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task GetByFingerprintAsync_ReturnsKey()
{
var fingerprint = $"fp_{Guid.NewGuid():N}";
@@ -95,7 +100,8 @@ public sealed class IssuerKeyRepositoryTests : IAsyncLifetime
fetched!.Fingerprint.Should().Be(fingerprint);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task ListAsync_ReturnsAllKeysForIssuer()
{
var key1 = CreateKeyRecord("key-list-1", IssuerKeyType.Ed25519PublicKey);
@@ -110,7 +116,8 @@ public sealed class IssuerKeyRepositoryTests : IAsyncLifetime
results.Select(k => k.Id).Should().BeEquivalentTo(["key-list-1", "key-list-2"]);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task ListGlobalAsync_ReturnsGlobalKeys()
{
var globalIssuerId = await SeedGlobalIssuerAsync();
@@ -122,7 +129,8 @@ public sealed class IssuerKeyRepositoryTests : IAsyncLifetime
results.Should().Contain(k => k.Id == "global-key");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsKeyTypeEd25519()
{
var keyRecord = CreateKeyRecord("key-ed25519", IssuerKeyType.Ed25519PublicKey);
@@ -134,7 +142,8 @@ public sealed class IssuerKeyRepositoryTests : IAsyncLifetime
fetched!.Type.Should().Be(IssuerKeyType.Ed25519PublicKey);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsKeyTypeX509()
{
var keyRecord = CreateKeyRecord("key-x509", IssuerKeyType.X509Certificate);
@@ -146,7 +155,8 @@ public sealed class IssuerKeyRepositoryTests : IAsyncLifetime
fetched!.Type.Should().Be(IssuerKeyType.X509Certificate);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsKeyTypeDsse()
{
var keyRecord = CreateKeyRecord("key-dsse", IssuerKeyType.DssePublicKey);
@@ -158,7 +168,8 @@ public sealed class IssuerKeyRepositoryTests : IAsyncLifetime
fetched!.Type.Should().Be(IssuerKeyType.DssePublicKey);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsRevokedStatus()
{
var keyRecord = CreateKeyRecord("key-revoked", IssuerKeyType.Ed25519PublicKey) with
@@ -175,7 +186,8 @@ public sealed class IssuerKeyRepositoryTests : IAsyncLifetime
fetched.RevokedAtUtc.Should().NotBeNull();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsReplacesKeyId()
{
var oldKey = CreateKeyRecord("old-key", IssuerKeyType.Ed25519PublicKey) with
@@ -197,7 +209,8 @@ public sealed class IssuerKeyRepositoryTests : IAsyncLifetime
fetched!.ReplacesKeyId.Should().Be("old-key");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsExpirationDate()
{
var expiresAt = DateTimeOffset.UtcNow.AddYears(1);

View File

@@ -5,6 +5,7 @@ using StellaOps.IssuerDirectory.Core.Domain;
using StellaOps.IssuerDirectory.Storage.Postgres.Repositories;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.IssuerDirectory.Storage.Postgres.Tests;
[Collection(IssuerDirectoryPostgresCollection.Name)]
@@ -34,7 +35,8 @@ public sealed class IssuerRepositoryTests : IAsyncLifetime
public Task DisposeAsync() => Task.CompletedTask;
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_CreatesNewIssuer()
{
var record = CreateIssuerRecord("test-issuer", "Test Issuer");
@@ -49,7 +51,8 @@ public sealed class IssuerRepositoryTests : IAsyncLifetime
fetched.TenantId.Should().Be(_tenantId);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_UpdatesExistingIssuer()
{
var record = CreateIssuerRecord("update-test", "Original Name");
@@ -71,7 +74,8 @@ public sealed class IssuerRepositoryTests : IAsyncLifetime
fetched.Description.Should().Be("Updated description");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task GetAsync_ReturnsNullForNonExistentIssuer()
{
var result = await _repository.GetAsync(_tenantId, Guid.NewGuid().ToString(), CancellationToken.None);
@@ -79,7 +83,8 @@ public sealed class IssuerRepositoryTests : IAsyncLifetime
result.Should().BeNull();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task ListAsync_ReturnsAllIssuersForTenant()
{
var issuer1 = CreateIssuerRecord("issuer-a", "Issuer A");
@@ -94,7 +99,8 @@ public sealed class IssuerRepositoryTests : IAsyncLifetime
results.Select(i => i.Slug).Should().BeEquivalentTo(["issuer-a", "issuer-b"]);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task ListGlobalAsync_ReturnsGlobalIssuers()
{
var globalIssuer = CreateIssuerRecord("global-issuer", "Global Issuer", IssuerTenants.Global);
@@ -105,7 +111,8 @@ public sealed class IssuerRepositoryTests : IAsyncLifetime
results.Should().Contain(i => i.Slug == "global-issuer");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task DeleteAsync_RemovesIssuer()
{
var record = CreateIssuerRecord("to-delete", "To Delete");
@@ -117,7 +124,8 @@ public sealed class IssuerRepositoryTests : IAsyncLifetime
fetched.Should().BeNull();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsContactInformation()
{
var contact = new IssuerContact(
@@ -138,7 +146,8 @@ public sealed class IssuerRepositoryTests : IAsyncLifetime
fetched.Contact.Timezone.Should().Be("UTC");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsEndpoints()
{
var endpoints = new List<IssuerEndpoint>
@@ -158,7 +167,8 @@ public sealed class IssuerRepositoryTests : IAsyncLifetime
fetched.Endpoints.Should().Contain(e => e.Kind == "oidc" && e.RequiresAuthentication);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsMetadata()
{
var metadata = new IssuerMetadata(
@@ -181,7 +191,8 @@ public sealed class IssuerRepositoryTests : IAsyncLifetime
fetched.Metadata.Attributes.Should().ContainKey("custom");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsTags()
{
var record = CreateIssuerRecord("tags-test", "Tags Test") with

View File

@@ -5,6 +5,7 @@ using StellaOps.IssuerDirectory.Core.Domain;
using StellaOps.IssuerDirectory.Storage.Postgres.Repositories;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.IssuerDirectory.Storage.Postgres.Tests;
[Collection(IssuerDirectoryPostgresCollection.Name)]
@@ -38,7 +39,8 @@ public sealed class IssuerTrustRepositoryTests : IAsyncLifetime
public Task DisposeAsync() => Task.CompletedTask;
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_CreatesNewTrustOverride()
{
var record = CreateTrustRecord(5.5m, "Trusted vendor");
@@ -51,7 +53,8 @@ public sealed class IssuerTrustRepositoryTests : IAsyncLifetime
fetched.Reason.Should().Be("Trusted vendor");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_UpdatesExistingTrustOverride()
{
var record = CreateTrustRecord(3.0m, "Initial trust");
@@ -68,7 +71,8 @@ public sealed class IssuerTrustRepositoryTests : IAsyncLifetime
fetched.UpdatedBy.Should().Be("admin@test.com");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task GetAsync_ReturnsNullForNonExistentOverride()
{
var result = await _trustRepository.GetAsync(_tenantId, Guid.NewGuid().ToString(), CancellationToken.None);
@@ -76,7 +80,8 @@ public sealed class IssuerTrustRepositoryTests : IAsyncLifetime
result.Should().BeNull();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task DeleteAsync_RemovesTrustOverride()
{
var record = CreateTrustRecord(2.0m, "To be deleted");
@@ -88,7 +93,8 @@ public sealed class IssuerTrustRepositoryTests : IAsyncLifetime
fetched.Should().BeNull();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsPositiveWeight()
{
var record = CreateTrustRecord(10.0m, "Maximum trust");
@@ -100,7 +106,8 @@ public sealed class IssuerTrustRepositoryTests : IAsyncLifetime
fetched!.Weight.Should().Be(10.0m);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsNegativeWeight()
{
var record = CreateTrustRecord(-5.0m, "Distrust override");
@@ -112,7 +119,8 @@ public sealed class IssuerTrustRepositoryTests : IAsyncLifetime
fetched!.Weight.Should().Be(-5.0m);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsZeroWeight()
{
var record = CreateTrustRecord(0m, "Neutral trust");
@@ -124,7 +132,8 @@ public sealed class IssuerTrustRepositoryTests : IAsyncLifetime
fetched!.Weight.Should().Be(0m);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsNullReason()
{
var record = CreateTrustRecord(5.0m, null);
@@ -136,7 +145,8 @@ public sealed class IssuerTrustRepositoryTests : IAsyncLifetime
fetched!.Reason.Should().BeNull();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAsync_PersistsTimestamps()
{
var now = DateTimeOffset.UtcNow;

View File

@@ -32,6 +32,7 @@
<ProjectReference Include="..\..\StellaOps.IssuerDirectory.Storage.Postgres\StellaOps.IssuerDirectory.Storage.Postgres.csproj" />
<ProjectReference Include="..\..\StellaOps.IssuerDirectory.Core\StellaOps.IssuerDirectory.Core.csproj" />
<ProjectReference Include="..\..\..\..\__Tests\__Libraries\StellaOps.Infrastructure.Postgres.Testing\StellaOps.Infrastructure.Postgres.Testing.csproj" />
<ProjectReference Include="../../../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
</ItemGroup>
</Project>

View File

@@ -5,6 +5,7 @@ using StellaOps.IssuerDirectory.Storage.Postgres;
using StellaOps.IssuerDirectory.Storage.Postgres.Repositories;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.IssuerDirectory.Storage.Postgres.Tests;
public class IssuerKeyRepositoryTests : IClassFixture<IssuerDirectoryPostgresFixture>
@@ -24,7 +25,8 @@ public class IssuerKeyRepositoryTests : IClassFixture<IssuerDirectoryPostgresFix
new(new IssuerDirectoryDataSource(_fixture.Fixture.Options, NullLogger<IssuerDirectoryDataSource>.Instance),
NullLogger<PostgresIssuerKeyRepository>.Instance);
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task AddKey_And_List_Works()
{
var tenant = Guid.NewGuid().ToString();

View File

@@ -5,6 +5,7 @@ using StellaOps.IssuerDirectory.Storage.Postgres;
using StellaOps.IssuerDirectory.Storage.Postgres.Repositories;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.IssuerDirectory.Storage.Postgres.Tests;
public class IssuerRepositoryTests : IClassFixture<IssuerDirectoryPostgresFixture>
@@ -24,7 +25,8 @@ public class IssuerRepositoryTests : IClassFixture<IssuerDirectoryPostgresFixtur
return new PostgresIssuerRepository(dataSource, NullLogger<PostgresIssuerRepository>.Instance);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertAndGet_Works_For_Tenant()
{
var repo = CreateRepository();

View File

@@ -24,5 +24,6 @@
<ProjectReference Include="..\\..\\StellaOps.IssuerDirectory\\StellaOps.IssuerDirectory.Storage.Postgres\\StellaOps.IssuerDirectory.Storage.Postgres.csproj" />
<ProjectReference Include="..\\..\\..\\__Tests\\__Libraries\\StellaOps.Infrastructure.Postgres.Testing\\StellaOps.Infrastructure.Postgres.Testing.csproj" />
<ProjectReference Include="..\\..\\StellaOps.IssuerDirectory\\StellaOps.IssuerDirectory.Core\\StellaOps.IssuerDirectory.Core.csproj" />
<ProjectReference Include="../../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
</ItemGroup>
</Project>

View File

@@ -5,6 +5,7 @@ using StellaOps.IssuerDirectory.Storage.Postgres;
using StellaOps.IssuerDirectory.Storage.Postgres.Repositories;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.IssuerDirectory.Storage.Postgres.Tests;
public class TrustRepositoryTests : IClassFixture<IssuerDirectoryPostgresFixture>
@@ -24,7 +25,8 @@ public class TrustRepositoryTests : IClassFixture<IssuerDirectoryPostgresFixture
new(new IssuerDirectoryDataSource(_fixture.Fixture.Options, NullLogger<IssuerDirectoryDataSource>.Instance),
NullLogger<PostgresIssuerTrustRepository>.Instance);
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task UpsertTrustOverride_Works()
{
var tenant = Guid.NewGuid().ToString();