Skip to content

Commit b58ece5

Browse files
committed
Fix failing CertificateValidationRemoteServer.ConnectWithRevocation_WithCallback test (dotnet#99915)
* Don't add empty Organization to Subject string * Make sure testName is populated when creating test PKI * Minor changes
1 parent cf1182c commit b58ece5

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/libraries/Common/tests/System/Security/Cryptography/X509Certificates/CertificateAuthority.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ internal X509Certificate2 CreateOcspSigner(string subject, RSA publicKey)
179179
subject,
180180
publicKey,
181181
TimeSpan.FromSeconds(1),
182-
new X509ExtensionCollection() { s_eeConstraints, s_eeKeyUsage, s_ocspResponderEku},
182+
new X509ExtensionCollection() { s_eeConstraints, s_eeKeyUsage, s_ocspResponderEku },
183183
ocspResponder: true);
184184
}
185185

@@ -950,12 +950,10 @@ private static string BuildSubject(
950950
PkiOptions pkiOptions,
951951
bool includePkiOptions)
952952
{
953-
if (includePkiOptions)
954-
{
955-
return $"CN=\"{cn}\", O=\"{testName}\", OU=\"{pkiOptions}\"";
956-
}
953+
string testNamePart = !string.IsNullOrWhiteSpace(testName) ? $", O=\"{testName}\"" : "";
954+
string pkiOptionsPart = includePkiOptions ? $", OU=\"{pkiOptions}\"" : "";
957955

958-
return $"CN=\"{cn}\", O=\"{testName}\"";
956+
return $"CN=\"{cn}\"" + testNamePart + pkiOptionsPart;
959957
}
960958
}
961959
}

src/libraries/System.Net.Security/tests/FunctionalTests/CertificateValidationRemoteServer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Net.Sockets;
88
using System.Net.Test.Common;
99
using System.Reflection;
10+
using System.Runtime.CompilerServices;
1011
using System.Runtime.InteropServices;
1112
using System.Security.Cryptography.X509Certificates;
1213
using System.Security.Cryptography.X509Certificates.Tests.Common;
@@ -188,7 +189,8 @@ static bool CertificateValidationCallback(
188189
private async Task ConnectWithRevocation_WithCallback_Core(
189190
X509RevocationMode revocationMode,
190191
bool? offlineContext = false,
191-
bool noIntermediates = false)
192+
bool noIntermediates = false,
193+
[CallerMemberName] string testName = null)
192194
{
193195
string offlinePart = offlineContext.HasValue ? offlineContext.GetValueOrDefault().ToString().ToLower() : "null";
194196
string serverName = $"{revocationMode.ToString().ToLower()}.{offlinePart}.server.example";
@@ -201,6 +203,7 @@ private async Task ConnectWithRevocation_WithCallback_Core(
201203
out CertificateAuthority rootAuthority,
202204
out CertificateAuthority[] intermediateAuthorities,
203205
out X509Certificate2 serverCert,
206+
testName: testName,
204207
intermediateAuthorityCount: noIntermediates ? 0 : 1,
205208
subjectName: serverName,
206209
keySize: 2048,

src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamCertificateContextTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static async Task Create_OcspDoesNotReturnOrCacheInvalidStapleData()
2424
out CertificateAuthority rootAuthority,
2525
out CertificateAuthority[] intermediateAuthorities,
2626
out X509Certificate2 serverCert,
27+
testName: nameof(Create_OcspDoesNotReturnOrCacheInvalidStapleData),
2728
intermediateAuthorityCount: 1,
2829
subjectName: serverName,
2930
keySize: 2048,

0 commit comments

Comments
 (0)