Skip to content

Commit 329cf2a

Browse files
ViveliDuChCopilot
andcommitted
Make TestKeyRing.CreateECDsa resilient to transient macOS OSStatus -50 failures
Backport of #125909 to release/8.0-staging. The automated backport failed because TestKeyRing.cs (introduced by a later refactor) does not exist on this branch; the CreateECDsa helper still lives in CoseTestHelpers.cs here. This applies the same fix (retry ECDsa.Create up to 3 times on macOS when it transiently fails with OSStatus -50 / CryptographicException HResult -50) to that location instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent de61314 commit 329cf2a

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎src/libraries/System.Security.Cryptography.Cose/tests/CoseTestHelpers.cs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Formats.Cbor;
77
using System.IO;
88
using System.Linq;
9+
using System.Runtime.InteropServices;
910
using Microsoft.IdentityModel.Tokens;
1011
using Test.Cryptography;
1112
using Xunit;
@@ -391,7 +392,14 @@ private static ECDsa CreateECDsa(ECParameters parameters, bool includePrivateKey
391392
parametersLocalCopy.D = null;
392393
}
393394

394-
return ECDsa.Create(parametersLocalCopy);
395+
// The Apple Security framework intermittently fails with OSStatus error -50 when creating
396+
// EC keys. Retry a few times to make the test robust against this transient failure.
397+
ECDsa? result = null;
398+
RetryHelper.Execute(
399+
() => result = ECDsa.Create(parametersLocalCopy),
400+
maxAttempts: 3,
401+
retryWhen: e => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && e is CryptographicException { HResult: -50 });
402+
return result!;
395403
}
396404

397405
private static RSA CreateRSA(bool includePrivateKey)

0 commit comments

Comments
 (0)