tests fixes and sprints work
This commit is contained in:
@@ -5,6 +5,9 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using StellaOps.Cryptography;
|
||||
using StellaOps.Cryptography.Plugin.EIDAS;
|
||||
using StellaOps.Cryptography.Plugin.EIDAS.Configuration;
|
||||
@@ -15,13 +18,16 @@ using Xunit;
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Cryptography.Plugin.EIDAS.Tests;
|
||||
|
||||
public class EidasCryptoProviderTests
|
||||
public class EidasCryptoProviderTests : IDisposable
|
||||
{
|
||||
private readonly ServiceProvider _serviceProvider;
|
||||
private readonly EidasCryptoProvider _provider;
|
||||
private readonly string _keystorePath;
|
||||
private const string KeystorePassword = "test-password";
|
||||
|
||||
public EidasCryptoProviderTests()
|
||||
{
|
||||
_keystorePath = CreateTestKeystore();
|
||||
var services = new ServiceCollection();
|
||||
|
||||
// Configure eIDAS options
|
||||
@@ -49,8 +55,8 @@ public class EidasCryptoProviderTests
|
||||
options.Local = new LocalSigningOptions
|
||||
{
|
||||
Type = "PKCS12",
|
||||
Path = "/tmp/test-keystore.p12",
|
||||
Password = "test-password"
|
||||
Path = _keystorePath,
|
||||
Password = KeystorePassword
|
||||
};
|
||||
|
||||
// Configure TSP (stub)
|
||||
@@ -71,6 +77,36 @@ public class EidasCryptoProviderTests
|
||||
?? throw new InvalidOperationException("Failed to resolve EidasCryptoProvider");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_serviceProvider.Dispose();
|
||||
|
||||
if (File.Exists(_keystorePath))
|
||||
{
|
||||
File.Delete(_keystorePath);
|
||||
}
|
||||
}
|
||||
|
||||
private static string CreateTestKeystore()
|
||||
{
|
||||
var path = Path.Combine(Path.GetTempPath(), $"eidas-test-{Guid.NewGuid():N}.p12");
|
||||
|
||||
using var ecdsa = ECDsa.Create(ECCurve.NamedCurves.nistP256);
|
||||
var request = new CertificateRequest(
|
||||
"CN=StellaOps Test",
|
||||
ecdsa,
|
||||
HashAlgorithmName.SHA256);
|
||||
|
||||
var notBefore = DateTimeOffset.UtcNow.AddDays(-1);
|
||||
var notAfter = DateTimeOffset.UtcNow.AddDays(7);
|
||||
using var certificate = request.CreateSelfSigned(notBefore, notAfter);
|
||||
|
||||
var pfxBytes = certificate.Export(X509ContentType.Pfx, KeystorePassword);
|
||||
File.WriteAllBytes(path, pfxBytes);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Provider_Name_IsEidas()
|
||||
@@ -249,7 +285,9 @@ public class EidasDependencyInjectionTests
|
||||
{
|
||||
["StellaOps:Crypto:Profiles:eidas:SignatureLevel"] = "AdES",
|
||||
["StellaOps:Crypto:Profiles:eidas:SignatureFormat"] = "CAdES",
|
||||
["StellaOps:Crypto:Profiles:eidas:DefaultAlgorithm"] = "ECDSA-P256"
|
||||
["StellaOps:Crypto:Profiles:eidas:DefaultAlgorithm"] = "ECDSA-P256",
|
||||
["StellaOps:Crypto:Profiles:eidas:Tsp:Endpoint"] = "https://tsp.example.com",
|
||||
["StellaOps:Crypto:Profiles:eidas:Tsp:ApiKey"] = "test-api-key"
|
||||
})
|
||||
.Build();
|
||||
|
||||
@@ -275,6 +313,11 @@ public class EidasDependencyInjectionTests
|
||||
options.SignatureLevel = SignatureLevel.QES;
|
||||
options.SignatureFormat = SignatureFormat.XAdES;
|
||||
options.DefaultAlgorithm = "RSA-PSS-4096";
|
||||
options.Tsp = new TspOptions
|
||||
{
|
||||
Endpoint = "https://tsp.example.com",
|
||||
ApiKey = "test-api-key"
|
||||
};
|
||||
});
|
||||
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
Reference in New Issue
Block a user