## Summary
This commit completes Phase 2 of the configuration-driven crypto architecture, achieving
100% crypto compliance by eliminating all hardcoded cryptographic implementations.
## Key Changes
### Phase 1: Plugin Loader Infrastructure
- **Plugin Discovery System**: Created StellaOps.Cryptography.PluginLoader with manifest-based loading
- **Configuration Model**: Added CryptoPluginConfiguration with regional profiles support
- **Dependency Injection**: Extended DI to support plugin-based crypto provider registration
- **Regional Configs**: Created appsettings.crypto.{international,russia,eu,china}.yaml
- **CI Workflow**: Added .gitea/workflows/crypto-compliance.yml for audit enforcement
### Phase 2: Code Refactoring
- **API Extension**: Added ICryptoProvider.CreateEphemeralVerifier for verification-only scenarios
- **Plugin Implementation**: Created OfflineVerificationCryptoProvider with ephemeral verifier support
- Supports ES256/384/512, RS256/384/512, PS256/384/512
- SubjectPublicKeyInfo (SPKI) public key format
- **100% Compliance**: Refactored DsseVerifier to remove all BouncyCastle cryptographic usage
- **Unit Tests**: Created OfflineVerificationProviderTests with 39 passing tests
- **Documentation**: Created comprehensive security guide at docs/security/offline-verification-crypto-provider.md
- **Audit Infrastructure**: Created scripts/audit-crypto-usage.ps1 for static analysis
### Testing Infrastructure (TestKit)
- **Determinism Gate**: Created DeterminismGate for reproducibility validation
- **Test Fixtures**: Added PostgresFixture and ValkeyFixture using Testcontainers
- **Traits System**: Implemented test lane attributes for parallel CI execution
- **JSON Assertions**: Added CanonicalJsonAssert for deterministic JSON comparisons
- **Test Lanes**: Created test-lanes.yml workflow for parallel test execution
### Documentation
- **Architecture**: Created CRYPTO_CONFIGURATION_DRIVEN_ARCHITECTURE.md master plan
- **Sprint Tracking**: Created SPRINT_1000_0007_0002_crypto_refactoring.md (COMPLETE)
- **API Documentation**: Updated docs2/cli/crypto-plugins.md and crypto.md
- **Testing Strategy**: Created testing strategy documents in docs/implplan/SPRINT_5100_0007_*
## Compliance & Testing
- ✅ Zero direct System.Security.Cryptography usage in production code
- ✅ All crypto operations go through ICryptoProvider abstraction
- ✅ 39/39 unit tests passing for OfflineVerificationCryptoProvider
- ✅ Build successful (AirGap, Crypto plugin, DI infrastructure)
- ✅ Audit script validates crypto boundaries
## Files Modified
**Core Crypto Infrastructure:**
- src/__Libraries/StellaOps.Cryptography/CryptoProvider.cs (API extension)
- src/__Libraries/StellaOps.Cryptography/CryptoSigningKey.cs (verification-only constructor)
- src/__Libraries/StellaOps.Cryptography/EcdsaSigner.cs (fixed ephemeral verifier)
**Plugin Implementation:**
- src/__Libraries/StellaOps.Cryptography.Plugin.OfflineVerification/ (new)
- src/__Libraries/StellaOps.Cryptography.PluginLoader/ (new)
**Production Code Refactoring:**
- src/AirGap/StellaOps.AirGap.Importer/Validation/DsseVerifier.cs (100% compliant)
**Tests:**
- src/__Libraries/__Tests/StellaOps.Cryptography.Plugin.OfflineVerification.Tests/ (new, 39 tests)
- src/__Libraries/__Tests/StellaOps.Cryptography.PluginLoader.Tests/ (new)
**Configuration:**
- etc/crypto-plugins-manifest.json (plugin registry)
- etc/appsettings.crypto.*.yaml (regional profiles)
**Documentation:**
- docs/security/offline-verification-crypto-provider.md (600+ lines)
- docs/implplan/CRYPTO_CONFIGURATION_DRIVEN_ARCHITECTURE.md (master plan)
- docs/implplan/SPRINT_1000_0007_0002_crypto_refactoring.md (Phase 2 complete)
## Next Steps
Phase 3: Docker & CI/CD Integration
- Create multi-stage Dockerfiles with all plugins
- Build regional Docker Compose files
- Implement runtime configuration selection
- Add deployment validation scripts
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
114 lines
3.3 KiB
Markdown
114 lines
3.3 KiB
Markdown
# Better Testing Strategy - Code Samples
|
|
|
|
Source advisory: `docs/product-advisories/22-Dec-2026 - Better testing strategy.md`
|
|
Note: These samples are carried over verbatim for reference and should remain offline-friendly and deterministic.
|
|
|
|
## Minimal primitives to standardize immediately
|
|
```csharp
|
|
public static class TestCategories
|
|
{
|
|
public const string Unit = "Unit";
|
|
public const string Property = "Property";
|
|
public const string Snapshot = "Snapshot";
|
|
public const string Integration = "Integration";
|
|
public const string Contract = "Contract";
|
|
public const string Security = "Security";
|
|
public const string Performance = "Performance";
|
|
public const string Live = "Live"; // opt-in only
|
|
}
|
|
```
|
|
|
|
## Property test example (FsCheck-style)
|
|
```csharp
|
|
using Xunit;
|
|
using FsCheck;
|
|
using FsCheck.Xunit;
|
|
|
|
public sealed class VersionComparisonProperties
|
|
{
|
|
[Property(Arbitrary = new[] { typeof(Generators) })]
|
|
[Trait("Category", "Unit")]
|
|
[Trait("Category", "Property")]
|
|
public void Compare_is_antisymmetric(SemVer a, SemVer b)
|
|
{
|
|
var ab = VersionComparer.Compare(a, b);
|
|
var ba = VersionComparer.Compare(b, a);
|
|
|
|
Assert.Equal(Math.Sign(ab), -Math.Sign(ba));
|
|
}
|
|
|
|
private static class Generators
|
|
{
|
|
public static Arbitrary<SemVer> SemVer() =>
|
|
Arb.From(Gen.Elements(
|
|
new SemVer(0,0,0),
|
|
new SemVer(1,0,0),
|
|
new SemVer(1,2,3),
|
|
new SemVer(10,20,30)
|
|
));
|
|
}
|
|
}
|
|
```
|
|
|
|
## Canonical JSON determinism assertion
|
|
```csharp
|
|
public static class DeterminismAssert
|
|
{
|
|
public static void CanonicalJsonStable<T>(T value, string expectedSha256)
|
|
{
|
|
byte[] canonical = CanonicalJson.SerializeToUtf8Bytes(value); // your library
|
|
string actual = Convert.ToHexString(SHA256.HashData(canonical)).ToLowerInvariant();
|
|
Assert.Equal(expectedSha256, actual);
|
|
}
|
|
}
|
|
```
|
|
|
|
## Postgres fixture skeleton (Testcontainers)
|
|
```csharp
|
|
public sealed class PostgresFixture : IAsyncLifetime
|
|
{
|
|
public string ConnectionString => _container.GetConnectionString();
|
|
|
|
private readonly PostgreSqlContainer _container =
|
|
new PostgreSqlBuilder().WithImage("postgres:16").Build();
|
|
|
|
public async Task InitializeAsync()
|
|
{
|
|
await _container.StartAsync();
|
|
await ApplyMigrationsAsync(ConnectionString);
|
|
}
|
|
|
|
public async Task DisposeAsync() => await _container.DisposeAsync();
|
|
|
|
private static async Task ApplyMigrationsAsync(string cs)
|
|
{
|
|
// call your migration runner for the module under test
|
|
}
|
|
}
|
|
```
|
|
|
|
## OTel trace capture assertion
|
|
```csharp
|
|
public sealed class OtelCapture : IDisposable
|
|
{
|
|
private readonly List<Activity> _activities = new();
|
|
private readonly ActivityListener _listener;
|
|
|
|
public OtelCapture()
|
|
{
|
|
_listener = new ActivityListener
|
|
{
|
|
ShouldListenTo = _ => true,
|
|
Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllData,
|
|
ActivityStopped = a => _activities.Add(a)
|
|
};
|
|
ActivitySource.AddActivityListener(_listener);
|
|
}
|
|
|
|
public void AssertHasSpan(string name) =>
|
|
Assert.Contains(_activities, a => a.DisplayName == name);
|
|
|
|
public void Dispose() => _listener.Dispose();
|
|
}
|
|
```
|