Skip to content

Commit 7fb8c48

Browse files
committed
Fix unit test on Mac.
1 parent a765197 commit 7fb8c48

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Authentication/Authentication.Test/Helpers/AuthenticationHelpersTests.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,19 @@ private void CreateSelfSignedCert(string certName)
9797
CertificateRequest certificateRequest = new CertificateRequest(certName, ecdsaKey, HashAlgorithmName.SHA256);
9898
// We have to export cert to dummy cert since `CreateSelfSigned` creates a cert without a private key.
9999
X509Certificate2 cert = certificateRequest.CreateSelfSigned(DateTimeOffset.Now, DateTimeOffset.Now.AddYears(5));
100-
X509Certificate2 dummyCert = new X509Certificate2(cert.Export(X509ContentType.Pfx, "P@55w0rd"), "P@55w0rd", X509KeyStorageFlags.PersistKeySet);
100+
101+
X509Certificate2 dummyCert = null;
102+
if (PowerShell.Authentication.Helpers.OperatingSystem.IsMacOS())
103+
{
104+
dummyCert = new X509Certificate2(cert.Export(X509ContentType.Pfx, "P@55w0rd"), "P@55w0rd", X509KeyStorageFlags.Exportable);
105+
}
106+
else
107+
{
108+
dummyCert = new X509Certificate2(cert.Export(X509ContentType.Pfx, "P@55w0rd"), "P@55w0rd", X509KeyStorageFlags.PersistKeySet);
109+
}
101110
using (X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser))
102111
{
103112
store.Open(OpenFlags.ReadWrite);
104-
105113
store.Add(dummyCert);
106114
}
107115
}

0 commit comments

Comments
 (0)