Skip to content

Commit 309dcf5

Browse files
committed
Address test failures on Windows and Linux
1 parent 3f990f5 commit 309dcf5

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCertificateStoreProviderShould.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,9 @@ public void TestValidCertificatePaths(string certificateStoreNameAndLocation, ob
397397
}
398398
else
399399
{
400-
certificateStoreLocation = StoreLocation.CurrentUser;
400+
certificateStoreLocation = Environment.OSVersion.Platform == PlatformID.Win32NT
401+
? StoreLocation.LocalMachine
402+
: StoreLocation.CurrentUser;
401403
}
402404

403405
// Fetch the newly created cert.

src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Fixtures/CertificateFixtureBase.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected static X509Certificate2 CreateCertificate(string subjectName, IEnumera
5151

5252
rnd.NextBytes(passwordBytes);
5353
password = Convert.ToBase64String(passwordBytes);
54-
#if NET9_0_OR_GREATER
54+
#if NET
5555
X500DistinguishedNameBuilder subjectBuilder = new X500DistinguishedNameBuilder();
5656
SubjectAlternativeNameBuilder sanBuilder = new SubjectAlternativeNameBuilder();
5757
RSA rsaKey = RSA.Create(2048);
@@ -84,8 +84,22 @@ protected static X509Certificate2 CreateCertificate(string subjectName, IEnumera
8484
// This is to ensure that it's imported into the certificate stores with its private key.
8585
using (X509Certificate2 ephemeral = request.CreateSelfSigned(notBefore, notAfter))
8686
{
87-
return X509CertificateLoader.LoadPkcs12(ephemeral.Export(X509ContentType.Pkcs12, password), password,
87+
#if NET9_0_OR_GREATER
88+
return X509CertificateLoader.LoadPkcs12(
89+
ephemeral.Export(X509ContentType.Pkcs12, password),
90+
password,
91+
X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable,
92+
new Pkcs12LoaderLimits(Pkcs12LoaderLimits.Defaults)
93+
{
94+
PreserveStorageProvider = true,
95+
PreserveKeyName = true
96+
});
97+
#else
98+
return new X509Certificate2(
99+
ephemeral.Export(X509ContentType.Pkcs12, password),
100+
password,
88101
X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
102+
#endif
89103
}
90104
#else
91105
// The CertificateRequest API is available in .NET Core, but was only added to .NET Framework 4.7.2; it thus can't be used in the test projects.

0 commit comments

Comments
 (0)