diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/TimestampTests.cs b/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/TimestampTests.cs index 4f525a002bf..1605aa3dd95 100644 --- a/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/TimestampTests.cs +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/TimestampTests.cs @@ -81,17 +81,14 @@ public async Task Timestamp_Verify_WithOfflineRevocation_ReturnsCorrectFlagsAndL result.HasFlag(SignatureVerificationStatusFlags.UnknownRevocation).Should().BeTrue(); var errors = logs.Where(l => l.Level == LogLevel.Error); - errors.Count().Should().Be(RuntimeEnvironmentHelper.IsWindows ? 2 : 1); - if (RuntimeEnvironmentHelper.IsWindows) - { - errors.Should().Contain(w => w.Code == NuGetLogCode.NU3028 && w.Message.Contains("The revocation function was unable to check revocation because the revocation server could not be reached.")); - errors.Should().Contain(w => w.Code == NuGetLogCode.NU3028 && w.Message.Contains("The revocation function was unable to check revocation for the certificate.")); - } - else + errors.Count().Should().Be(RuntimeEnvironmentHelper.IsMacOSX ? 1 : 2); + SigningTestUtility.AssertRevocationStatusUnknown(errors, LogLevel.Error, NuGetLogCode.NU3028); + + if (!RuntimeEnvironmentHelper.IsMacOSX) { - errors.Should().Contain(w => w.Code == NuGetLogCode.NU3028 && w.Message.Contains("unable to get certificate CRL")); - } + SigningTestUtility.AssertOfflineRevocationOnlineMode(errors, LogLevel.Error, NuGetLogCode.NU3028); + } } } } diff --git a/test/TestUtilities/Test.Utility/Signing/SigningTestUtility.cs b/test/TestUtilities/Test.Utility/Signing/SigningTestUtility.cs index 7f5aeaa0b7c..624da3731de 100644 --- a/test/TestUtilities/Test.Utility/Signing/SigningTestUtility.cs +++ b/test/TestUtilities/Test.Utility/Signing/SigningTestUtility.cs @@ -678,18 +678,28 @@ public static void AssertOfflineRevocation(IEnumerable issues, LogL //We will change the original X509ChainStatus.StatusInformation of OfflineRevocation to VerifyCertTrustOfflineWhileRevocationModeOffline or VerifyCertTrustOfflineWhileRevocationModeOnline in Signature.cs and Timestamp.cs //So if we use APIs above to verify the results of chain.build, we should use assert AssertOfflineRevocationOnlineMode and AssertOfflineRevocationOfflineMode public static void AssertOfflineRevocationOnlineMode(IEnumerable issues, LogLevel logLevel) + { + AssertOfflineRevocationOnlineMode(issues, logLevel, NuGetLogCode.NU3018); + } + + public static void AssertOfflineRevocationOnlineMode(IEnumerable issues, LogLevel logLevel, NuGetLogCode code) { Assert.Contains(issues, issue => - issue.Code == NuGetLogCode.NU3018 && + issue.Code == code && issue.Level == logLevel && issue.Message.Contains("The revocation function was unable to check revocation because the revocation server could not be reached. For more information, visit https://aka.ms/certificateRevocationMode.")); } public static void AssertOfflineRevocationOfflineMode(IEnumerable issues) + { + AssertOfflineRevocationOfflineMode(issues, LogLevel.Information, NuGetLogCode.Undefined); + } + + public static void AssertOfflineRevocationOfflineMode(IEnumerable issues, LogLevel logLevel, NuGetLogCode code) { Assert.Contains(issues, issue => - issue.Code == NuGetLogCode.Undefined && - issue.Level == LogLevel.Information && + issue.Code == code && + issue.Level == logLevel && issue.Message.Contains("The revocation function was unable to check revocation because the certificate is not available in the cached certificate revocation list and NUGET_CERT_REVOCATION_MODE environment variable has been set to offline. For more information, visit https://aka.ms/certificateRevocationMode.")); }