Fix precondition on OSX 10.15 mutable store tests
authorJeremy Barton <jbarton@microsoft.com>
Fri, 10 Jul 2020 21:28:58 +0000 (14:28 -0700)
committerGitHub <noreply@github.com>
Fri, 10 Jul 2020 21:28:58 +0000 (14:28 -0700)
src/libraries/System.Security.Cryptography.X509Certificates/tests/X509StoreMutableTests.OSX.cs

index 227e409..422c71a 100644 (file)
@@ -21,17 +21,25 @@ namespace System.Security.Cryptography.X509Certificates.Tests
             {
                 const int errSecWrPerm = -61;
                 const int errSecInteractionNotAllowed = -25308;
+                const int kPOSIXErrorBase = 100000;
 
-                if (e.HResult == errSecInteractionNotAllowed)
+                switch (e.HResult)
                 {
-                    Console.WriteLine("Run 'security unlock-keychain' to make tests runable.");
-                    return false;
+                    case errSecInteractionNotAllowed:
+                        Console.WriteLine("Run 'security unlock-keychain' to make tests runable.");
+                        return false;
+                    case kPOSIXErrorBase:
+                        // kPOSIXErrorBase is returned for "unknown error from a subsystem",
+                        // which seems to happen on writes from SSH sessions even if the keychain
+                        // was unlocked.
+                        Console.WriteLine("Writing precondition failed with kPOSIXErrorBase, skipping tests.");
+                        return false;
+                    case errSecWrPerm:
+                        Console.WriteLine("Writing precondition failed with permission denied, skipping tests.");
+                        return false;
                 }
 
-                if (e.HResult == errSecWrPerm)
-                {
-                    return false;
-                }
+                Console.WriteLine($"Precondition test failed with unknown code {e.HResult}, running anyways.");
             }
             catch
             {