SubjectValidator validates for supported attributes and OID

This commit is contained in:
2025-10-22 20:14:50 +02:00
parent 5da328208c
commit cc7fe89330
11 changed files with 302 additions and 34 deletions

View File

@@ -0,0 +1,21 @@
using CertMgr.CertGen.Utils;
using CertMgr.Core.Validation;
using NUnit.Framework;
namespace certmgrTest;
public class SubjectValidatorTest
{
[TestCase("CN=www.example.com, O=Example Corp, OU=IT Department, L=Prague, ST=Czech Republic, C=CZ", true)]
[TestCase("CN=John Doe + OU=Engineering", true)]
[TestCase("1.2.3.4=John Doe", true)]
[TestCase("OID.1.2.3.4=John Doe", true)]
[TestCase("OID.1.2=John Doe", false)]
public async Task First(string subj, bool expectedSuccess)
{
SubjectValidator validator = new SubjectValidator("TestSetting");
ValidationResult result = await validator.ValidateAsync(subj, CancellationToken.None);
Assert.That(result.IsValid, Is.EqualTo(expectedSuccess), result.Justification);
}
}

View File

@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\certmgr\certmgr.csproj" />
</ItemGroup>
</Project>