Skip to content

Commit 313e6e7

Browse files
committed
Initial work to enable Unix support.
* Only allow the use of the CurrentUser location for certificates. * Changed the PublishTestResults@2 step to ensure that failed tests are also published.
1 parent d53b7ad commit 313e6e7

File tree

6 files changed

+63
-16
lines changed

6 files changed

+63
-16
lines changed

eng/pipelines/common/templates/steps/publish-test-results-step.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ steps:
3838
TestResults/*.trx
3939
TestResults/**/*.coverage
4040
testRunTitle: 'Linux Tests'
41+
condition: succeededOrFailed()
4142

4243
- powershell: |
4344
cd TestResults

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCertificateStoreProvider.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ private void ValidateCertificatePathLength(string masterKeyPath, bool isSystemOp
324324
/// </summary>
325325
private string[] GetValidCertificateLocations()
326326
{
327-
return new string[2] { CertLocationLocalMachine, CertLocationCurrentUser };
327+
return Environment.OSVersion.Platform == PlatformID.Win32NT
328+
? new string[2] { CertLocationLocalMachine, CertLocationCurrentUser }
329+
: new string[1] { CertLocationCurrentUser };
328330
}
329331

330332
/// <summary>
@@ -372,7 +374,8 @@ private X509Certificate2 GetCertificateByPath(string keyPath, bool isSystemOp)
372374
// Extract the store location where the cert is stored
373375
if (certParts.Length > 2)
374376
{
375-
if (string.Equals(certParts[0], CertLocationLocalMachine, StringComparison.OrdinalIgnoreCase) == true)
377+
if (string.Equals(certParts[0], CertLocationLocalMachine, StringComparison.OrdinalIgnoreCase) == true
378+
&& Environment.OSVersion.Platform == PlatformID.Win32NT)
376379
{
377380
storeLocation = StoreLocation.LocalMachine;
378381
}

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlUtil.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,17 +1854,27 @@ internal static Exception InvalidCngKey(string masterKeyPath, string cngProvider
18541854

18551855
internal static Exception InvalidCertificateLocation(string certificateLocation, string certificatePath, string[] validLocations, bool isSystemOp)
18561856
{
1857-
1858-
#if NETFRAMEWORK
1859-
Debug.Assert(2 == validLocations.Length);
1860-
#endif
1861-
if (isSystemOp)
1857+
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
18621858
{
1863-
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificateLocationSysErr, certificateLocation, certificatePath, validLocations[0], validLocations[1], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
1859+
if (isSystemOp)
1860+
{
1861+
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificateLocationSysErr, certificateLocation, certificatePath, validLocations[0], validLocations[1], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
1862+
}
1863+
else
1864+
{
1865+
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificateLocation, certificateLocation, certificatePath, validLocations[0], validLocations[1], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
1866+
}
18641867
}
18651868
else
18661869
{
1867-
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificateLocation, certificateLocation, certificatePath, validLocations[0], validLocations[1], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
1870+
if (isSystemOp)
1871+
{
1872+
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificateLocationSysErr_Unix, certificateLocation, certificatePath, validLocations[0], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
1873+
}
1874+
else
1875+
{
1876+
return ADP.Argument(StringsHelper.GetString(Strings.TCE_InvalidCertificateLocation_Unix, certificateLocation, certificatePath, validLocations[0], @"/"), TdsEnums.TCE_PARAM_MASTERKEY_PATH);
1877+
}
18681878
}
18691879
}
18701880

src/Microsoft.Data.SqlClient/src/Resources/Strings.Designer.cs

Lines changed: 24 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.Data.SqlClient/src/Resources/Strings.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4071,9 +4071,15 @@
40714071
<data name="TCE_InvalidCertificateLocation" xml:space="preserve">
40724072
<value>Invalid certificate location '{0}' in certificate path '{1}'. Use the following format: &lt;certificate location&gt;{4}&lt;certificate store&gt;{4}&lt;certificate thumbprint&gt;, where &lt;certificate location&gt; is either '{2}' or '{3}'.</value>
40734073
</data>
4074+
<data name="TCE_InvalidCertificateLocation_Unix" xml:space="preserve">
4075+
<value>Invalid certificate location '{0}' in certificate path '{1}'. Use the following format: &lt;certificate location&gt;{3}&lt;certificate store&gt;{3}&lt;certificate thumbprint&gt;, where &lt;certificate location&gt; is '{2}'.</value>
4076+
</data>
40744077
<data name="TCE_InvalidCertificateLocationSysErr" xml:space="preserve">
40754078
<value>Internal error. Invalid certificate location '{0}' in certificate path '{1}'. Use the following format: &lt;certificate location&gt;{4}&lt;certificate store&gt;{4}&lt;certificate thumbprint&gt;, where &lt;certificate location&gt; is either '{2}' or '{3}'.</value>
40764079
</data>
4080+
<data name="TCE_InvalidCertificateLocationSysErr_Unix" xml:space="preserve">
4081+
<value>Internal error. Invalid certificate location '{0}' in certificate path '{1}'. Use the following format: &lt;certificate location&gt;{3}&lt;certificate store&gt;{3}&lt;certificate thumbprint&gt;, where &lt;certificate location&gt; is '{2}'.</value>
4082+
</data>
40774083
<data name="TCE_InvalidCertificateStore" xml:space="preserve">
40784084
<value>Invalid certificate store '{0}' specified in certificate path '{1}'. Expected value: '{2}'.</value>
40794085
</data>

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,12 +495,17 @@ public class ValidCertificatePathsParameters : DataAttribute
495495
public override IEnumerable<Object[]> GetData(MethodInfo testMethod)
496496
{
497497
yield return new object[2] { CurrentUserMyPathPrefix, StoreLocation.CurrentUser };
498-
yield return new object[2] { MyPathPrefix, null };
499-
yield return new object[2] { @"", null };
500-
// use localmachine cert path only when current user is Admin.
501-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && CertificateFixture.IsAdmin)
498+
499+
// use localmachine cert path (or a location in the cert path which defaults to localmachine) only when current user is Admin.
500+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
502501
{
503-
yield return new object[2] { LocalMachineMyPathPrefix, StoreLocation.LocalMachine };
502+
yield return new object[2] { @"", null };
503+
yield return new object[2] { MyPathPrefix, null };
504+
505+
if (CertificateFixture.IsAdmin)
506+
{
507+
yield return new object[2] { LocalMachineMyPathPrefix, StoreLocation.LocalMachine };
508+
}
504509
}
505510
}
506511
}

0 commit comments

Comments
 (0)