Skip to content

Commit

Permalink
Fix failing CertificateValidationRemoteServer.ConnectWithRevocation_W…
Browse files Browse the repository at this point in the history
…ithCallback test (dotnet#99915)

* Don't add empty Organization to Subject string

* Make sure testName is populated when creating test PKI

* Minor changes
  • Loading branch information
rzikm committed Mar 19, 2024
1 parent cf1182c commit b58ece5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ internal X509Certificate2 CreateOcspSigner(string subject, RSA publicKey)
subject,
publicKey,
TimeSpan.FromSeconds(1),
new X509ExtensionCollection() { s_eeConstraints, s_eeKeyUsage, s_ocspResponderEku},
new X509ExtensionCollection() { s_eeConstraints, s_eeKeyUsage, s_ocspResponderEku },
ocspResponder: true);
}

Expand Down Expand Up @@ -950,12 +950,10 @@ private static string BuildSubject(
PkiOptions pkiOptions,
bool includePkiOptions)
{
if (includePkiOptions)
{
return $"CN=\"{cn}\", O=\"{testName}\", OU=\"{pkiOptions}\"";
}
string testNamePart = !string.IsNullOrWhiteSpace(testName) ? $", O=\"{testName}\"" : "";
string pkiOptionsPart = includePkiOptions ? $", OU=\"{pkiOptions}\"" : "";

return $"CN=\"{cn}\", O=\"{testName}\"";
return $"CN=\"{cn}\"" + testNamePart + pkiOptionsPart;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net.Sockets;
using System.Net.Test.Common;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.X509Certificates.Tests.Common;
Expand Down Expand Up @@ -188,7 +189,8 @@ static bool CertificateValidationCallback(
private async Task ConnectWithRevocation_WithCallback_Core(
X509RevocationMode revocationMode,
bool? offlineContext = false,
bool noIntermediates = false)
bool noIntermediates = false,
[CallerMemberName] string testName = null)
{
string offlinePart = offlineContext.HasValue ? offlineContext.GetValueOrDefault().ToString().ToLower() : "null";
string serverName = $"{revocationMode.ToString().ToLower()}.{offlinePart}.server.example";
Expand All @@ -201,6 +203,7 @@ private async Task ConnectWithRevocation_WithCallback_Core(
out CertificateAuthority rootAuthority,
out CertificateAuthority[] intermediateAuthorities,
out X509Certificate2 serverCert,
testName: testName,
intermediateAuthorityCount: noIntermediates ? 0 : 1,
subjectName: serverName,
keySize: 2048,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static async Task Create_OcspDoesNotReturnOrCacheInvalidStapleData()
out CertificateAuthority rootAuthority,
out CertificateAuthority[] intermediateAuthorities,
out X509Certificate2 serverCert,
testName: nameof(Create_OcspDoesNotReturnOrCacheInvalidStapleData),
intermediateAuthorityCount: 1,
subjectName: serverName,
keySize: 2048,
Expand Down

0 comments on commit b58ece5

Please sign in to comment.