sln build fix (again), tests fixes, audit work and doctors work
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using StellaOps.Doctor.Models;
|
||||
using StellaOps.Doctor.Plugins;
|
||||
using StellaOps.Doctor.Plugins.Cryptography.Checks;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Doctor.Plugins.Cryptography.Tests.Checks;
|
||||
|
||||
[Trait("Category", "Unit")]
|
||||
public class CryptoProviderAvailabilityCheckTests
|
||||
{
|
||||
[Fact]
|
||||
public void CheckId_ReturnsExpectedValue()
|
||||
{
|
||||
var check = new CryptoProviderAvailabilityCheck();
|
||||
|
||||
Assert.Equal("check.crypto.provider", check.CheckId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Name_ReturnsExpectedValue()
|
||||
{
|
||||
var check = new CryptoProviderAvailabilityCheck();
|
||||
|
||||
Assert.Equal("Crypto Provider Availability", check.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DefaultSeverity_IsWarn()
|
||||
{
|
||||
var check = new CryptoProviderAvailabilityCheck();
|
||||
|
||||
Assert.Equal(DoctorSeverity.Warn, check.DefaultSeverity);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Tags_ContainsCryptography()
|
||||
{
|
||||
var check = new CryptoProviderAvailabilityCheck();
|
||||
|
||||
Assert.Contains("cryptography", check.Tags);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanRun_ReturnsTrue()
|
||||
{
|
||||
var check = new CryptoProviderAvailabilityCheck();
|
||||
var context = CreateTestContext();
|
||||
|
||||
Assert.True(check.CanRun(context));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RunAsync_ReturnsPassResult_WhenProvidersAvailable()
|
||||
{
|
||||
var check = new CryptoProviderAvailabilityCheck();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var result = await check.RunAsync(context, CancellationToken.None);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("check.crypto.provider", result.CheckId);
|
||||
// Should pass because ECDSA, RSA, AES are typically available
|
||||
Assert.Equal(DoctorSeverity.Pass, result.Severity);
|
||||
}
|
||||
|
||||
private static DoctorPluginContext CreateTestContext(IConfiguration? configuration = null)
|
||||
{
|
||||
var services = new ServiceCollection().BuildServiceProvider();
|
||||
configuration ??= new ConfigurationBuilder().Build();
|
||||
|
||||
return new DoctorPluginContext
|
||||
{
|
||||
Services = services,
|
||||
Configuration = configuration,
|
||||
TimeProvider = TimeProvider.System,
|
||||
Logger = NullLogger.Instance,
|
||||
EnvironmentName = "Test",
|
||||
PluginConfig = configuration.GetSection("Doctor:Plugins:Cryptography")
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using StellaOps.Doctor.Models;
|
||||
using StellaOps.Doctor.Plugins;
|
||||
using StellaOps.Doctor.Plugins.Cryptography;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Doctor.Plugins.Cryptography.Tests;
|
||||
|
||||
[Trait("Category", "Unit")]
|
||||
public class CryptographyPluginTests
|
||||
{
|
||||
[Fact]
|
||||
public void PluginId_ReturnsExpectedValue()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
|
||||
Assert.Equal("stellaops.doctor.cryptography", plugin.PluginId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DisplayName_ReturnsExpectedValue()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
|
||||
Assert.Equal("Cryptography", plugin.DisplayName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Category_ReturnsCryptography()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
|
||||
Assert.Equal(DoctorCategory.Cryptography, plugin.Category);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Version_ReturnsValidVersion()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
|
||||
Assert.NotNull(plugin.Version);
|
||||
Assert.True(plugin.Version >= new Version(1, 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MinEngineVersion_ReturnsValidVersion()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
|
||||
Assert.NotNull(plugin.MinEngineVersion);
|
||||
Assert.True(plugin.MinEngineVersion >= new Version(1, 0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsAvailable_ReturnsTrue()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
var services = new ServiceCollection().BuildServiceProvider();
|
||||
|
||||
Assert.True(plugin.IsAvailable(services));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ReturnsEightChecks()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Equal(8, checks.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ContainsCryptoProviderAvailabilityCheck()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Contains(checks, c => c.CheckId == "check.crypto.provider");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ContainsFipsComplianceCheck()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Contains(checks, c => c.CheckId == "check.crypto.fips");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ContainsGostProviderCheck()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Contains(checks, c => c.CheckId == "check.crypto.gost");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ContainsSmProviderCheck()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Contains(checks, c => c.CheckId == "check.crypto.sm");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ContainsEidasProviderCheck()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Contains(checks, c => c.CheckId == "check.crypto.eidas");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ContainsHsmConnectivityCheck()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Contains(checks, c => c.CheckId == "check.crypto.hsm");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ContainsCryptoLicenseCheck()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Contains(checks, c => c.CheckId == "check.crypto.license");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetChecks_ContainsCryptoProCheck()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
var checks = plugin.GetChecks(context);
|
||||
|
||||
Assert.Contains(checks, c => c.CheckId == "check.crypto.cryptopro");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InitializeAsync_CompletesSuccessfully()
|
||||
{
|
||||
var plugin = new CryptographyPlugin();
|
||||
var context = CreateTestContext();
|
||||
|
||||
await plugin.InitializeAsync(context, CancellationToken.None);
|
||||
|
||||
// Should complete without throwing
|
||||
}
|
||||
|
||||
private static DoctorPluginContext CreateTestContext(IConfiguration? configuration = null)
|
||||
{
|
||||
var services = new ServiceCollection().BuildServiceProvider();
|
||||
configuration ??= new ConfigurationBuilder().Build();
|
||||
|
||||
return new DoctorPluginContext
|
||||
{
|
||||
Services = services,
|
||||
Configuration = configuration,
|
||||
TimeProvider = TimeProvider.System,
|
||||
Logger = NullLogger.Instance,
|
||||
EnvironmentName = "Test",
|
||||
PluginConfig = configuration.GetSection("Doctor:Plugins:Cryptography")
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" />
|
||||
<PackageReference Include="Moq" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\StellaOps.Doctor\StellaOps.Doctor.csproj" />
|
||||
<ProjectReference Include="..\..\StellaOps.Doctor.Plugins.Cryptography\StellaOps.Doctor.Plugins.Cryptography.csproj" />
|
||||
<ProjectReference Include="..\..\StellaOps.TestKit\StellaOps.TestKit.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user