Fix X509ChainElementCollection_CopyTo_NonZeroLowerBound_ThrowsIndexOutOfRangeExceptio...
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Wed, 1 Sep 2021 15:45:42 +0000 (17:45 +0200)
committerGitHub <noreply@github.com>
Wed, 1 Sep 2021 15:45:42 +0000 (17:45 +0200)
It started to fail because the validity of the MicrosoftDotComSslCertBytes expired on 2021-08-29 22:17:02.
Since this test doesn't need to validate a specific expiration time we can just set the VerificationTime on the chain like we do in other tests.

Fixes https://github.com/dotnet/runtime/issues/58416

Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
src/libraries/System.Security.Cryptography.X509Certificates/tests/CollectionTests.cs

index e31f2c3..a519f7a 100644 (file)
@@ -899,7 +899,13 @@ namespace System.Security.Cryptography.X509Certificates.Tests
                 chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
                 chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
 
-                chain.Build(microsoftDotCom);
+                // Halfway between microsoftDotCom's NotBefore and NotAfter
+                // This isn't a boundary condition test.
+                chain.ChainPolicy.VerificationTime = new DateTime(2021, 02, 26, 12, 01, 01, DateTimeKind.Local);
+
+                bool valid = chain.Build(microsoftDotCom);
+                Assert.True(valid, "Precondition: Chain built validly");
+
                 ICollection collection = chain.ChainElements;
                 Array array = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
                 Assert.Throws<IndexOutOfRangeException>(() => collection.CopyTo(array, 0));