22// The .NET Foundation licenses this file to you under the MIT license.
33
44using System . Runtime . CompilerServices ;
5+ using Microsoft . DotNet . XUnitExtensions ;
56using Xunit ;
67
78namespace System . Security . Cryptography . X509Certificates . Tests
89{
910 public abstract partial class X509CertificateLoaderPkcs12Tests
1011 {
11- [ Theory ]
12+ [ ConditionalTheory ]
1213 [ InlineData ( true , true ) ]
1314 [ InlineData ( true , false ) ]
1415 [ InlineData ( false , true ) ]
1516 [ InlineData ( false , false ) ]
1617 public void VerifyPreserveKeyName ( bool preserveName , bool machineKey )
1718 {
19+ if ( machineKey && ! PlatformDetection . IsPrivilegedProcess )
20+ {
21+ throw new SkipTestException ( "Test requires administrator privileges." ) ;
22+ }
23+
1824 Pkcs12LoaderLimits loaderLimits = new Pkcs12LoaderLimits
1925 {
2026 PreserveKeyName = preserveName ,
@@ -51,13 +57,18 @@ public void VerifyPreserveKeyName(bool preserveName, bool machineKey)
5157 }
5258 }
5359
54- [ Theory ]
60+ [ ConditionalTheory ]
5561 [ InlineData ( true , true ) ]
5662 [ InlineData ( true , false ) ]
5763 [ InlineData ( false , true ) ]
5864 [ InlineData ( false , false ) ]
5965 public void VerifyPreserveAlias ( bool preserveAlias , bool machineKey )
6066 {
67+ if ( machineKey && ! PlatformDetection . IsPrivilegedProcess )
68+ {
69+ throw new SkipTestException ( "Test requires administrator privileges." ) ;
70+ }
71+
6172 Pkcs12LoaderLimits loaderLimits = new Pkcs12LoaderLimits
6273 {
6374 PreserveCertificateAlias = preserveAlias ,
@@ -95,7 +106,7 @@ public void VerifyPreserveAlias(bool preserveAlias, bool machineKey)
95106 }
96107 }
97108
98- [ Theory ]
109+ [ ConditionalTheory ]
99110 [ InlineData ( true , true , true ) ]
100111 [ InlineData ( true , true , false ) ]
101112 [ InlineData ( true , false , true ) ]
@@ -106,6 +117,11 @@ public void VerifyPreserveAlias(bool preserveAlias, bool machineKey)
106117 [ InlineData ( false , false , false ) ]
107118 public void VerifyPreserveProvider ( bool preserveProvider , bool preserveName , bool machineKey )
108119 {
120+ if ( machineKey && ! PlatformDetection . IsPrivilegedProcess )
121+ {
122+ throw new SkipTestException ( "Test requires administrator privileges." ) ;
123+ }
124+
109125 // This test forces a key creation with CAPI, and verifies that
110126 // PreserveStorageProvider keeps the key in CAPI. Additionally,
111127 // it shows that PreserveKeyName and PreserveStorageProvider are independent.
@@ -158,11 +174,16 @@ public void VerifyPreserveProvider(bool preserveProvider, bool preserveName, boo
158174 }
159175 }
160176
161- [ Theory ]
177+ [ ConditionalTheory ]
162178 [ InlineData ( false ) ]
163179 [ InlineData ( true ) ]
164180 public void VerifyNamesWithDuplicateAttributes ( bool noLimits )
165181 {
182+ if ( ! PlatformDetection . IsPrivilegedProcess )
183+ {
184+ throw new SkipTestException ( "Test requires administrator privileges." ) ;
185+ }
186+
166187 // This test mainly shows that when duplicate attributes are present contents
167188 // processed by our filter and processed directly by PFXImportCertStore come up
168189 // with the same answer.
0 commit comments