From c4d5c53a84a41facf7fbec1a6a4b9c690b29a4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Thu, 30 Jan 2020 01:21:00 +0000 Subject: [PATCH 1/4] get TimestampTests working again Fixes: https://github.com/NuGet/Home/issues/8935 --- .../SigningTests/TimestampTests.cs | 15 ++++++--------- .../Test.Utility/Signing/SigningTestUtility.cs | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 12 deletions(-) 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.")); } From 4b300d4130f80ec86711822d0a13504c422863ba Mon Sep 17 00:00:00 2001 From: Heng Liu Date: Tue, 16 Jun 2020 19:55:44 -0700 Subject: [PATCH 2/4] address comments --- .../SigningTests/TimestampTests.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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 1605aa3dd95..1e89890be89 100644 --- a/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/TimestampTests.cs +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/TimestampTests.cs @@ -82,13 +82,17 @@ public async Task Timestamp_Verify_WithOfflineRevocation_ReturnsCorrectFlagsAndL var errors = logs.Where(l => l.Level == LogLevel.Error); - errors.Count().Should().Be(RuntimeEnvironmentHelper.IsMacOSX ? 1 : 2); - SigningTestUtility.AssertRevocationStatusUnknown(errors, LogLevel.Error, NuGetLogCode.NU3028); - - if (!RuntimeEnvironmentHelper.IsMacOSX) + if (RuntimeEnvironmentHelper.IsMacOSX) + { + errors.Count().Should().Be(1); + } + else { - SigningTestUtility.AssertOfflineRevocationOnlineMode(errors, LogLevel.Error, NuGetLogCode.NU3028); - } + errors.Count().Should().Be(2); + SigningTestUtility.AssertRevocationStatusUnknown(errors, LogLevel.Error, NuGetLogCode.NU3028); + } + + SigningTestUtility.AssertOfflineRevocationOnlineMode(errors, LogLevel.Error, NuGetLogCode.NU3028); } } } From 543b6e77deb163f9fc582018c25aa2f78f9f84c1 Mon Sep 17 00:00:00 2001 From: Heng Liu Date: Wed, 17 Jun 2020 13:48:03 -0700 Subject: [PATCH 3/4] address feedback2 --- src/NuGet.Core/NuGet.Packaging/Properties/AssemblyInfo.cs | 2 ++ test/TestUtilities/Test.Utility/Signing/SigningTestUtility.cs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/NuGet.Core/NuGet.Packaging/Properties/AssemblyInfo.cs b/src/NuGet.Core/NuGet.Packaging/Properties/AssemblyInfo.cs index b87cf8c32bf..aae643165c3 100644 --- a/src/NuGet.Core/NuGet.Packaging/Properties/AssemblyInfo.cs +++ b/src/NuGet.Core/NuGet.Packaging/Properties/AssemblyInfo.cs @@ -11,9 +11,11 @@ [assembly: InternalsVisibleTo("NuGet.Packaging.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: InternalsVisibleTo("NuGet.Commands.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] +[assembly: InternalsVisibleTo("Test.Utility, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] #else [assembly: InternalsVisibleTo("NuGet.Packaging.Test")] [assembly: InternalsVisibleTo("NuGet.Packaging.FuncTest")] [assembly: InternalsVisibleTo("NuGet.Commands.Test")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] +[assembly: InternalsVisibleTo("Test.Utility")] #endif diff --git a/test/TestUtilities/Test.Utility/Signing/SigningTestUtility.cs b/test/TestUtilities/Test.Utility/Signing/SigningTestUtility.cs index 624da3731de..2e6a23fb268 100644 --- a/test/TestUtilities/Test.Utility/Signing/SigningTestUtility.cs +++ b/test/TestUtilities/Test.Utility/Signing/SigningTestUtility.cs @@ -687,7 +687,7 @@ public static void AssertOfflineRevocationOnlineMode(IEnumerable i Assert.Contains(issues, issue => 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.")); + issue.Message.Contains(NuGet.Packaging.Strings.VerifyCertTrustOfflineWhileRevocationModeOnline)); } public static void AssertOfflineRevocationOfflineMode(IEnumerable issues) @@ -700,7 +700,7 @@ public static void AssertOfflineRevocationOfflineMode(IEnumerable Assert.Contains(issues, issue => 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.")); + issue.Message.Contains(NuGet.Packaging.Strings.VerifyCertTrustOfflineWhileRevocationModeOffline)); } public static void AssertRevocationStatusUnknown(IEnumerable issues, LogLevel logLevel) From 461c35dbb2ba1be6bece97d39b81c5080a3f6e24 Mon Sep 17 00:00:00 2001 From: Heng Liu Date: Wed, 17 Jun 2020 16:32:35 -0700 Subject: [PATCH 4/4] fix --- .../NuGet.Packaging.FuncTest/SigningTests/TimestampTests.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 1e89890be89..d4ce0a98981 100644 --- a/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/TimestampTests.cs +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/TimestampTests.cs @@ -89,10 +89,9 @@ public async Task Timestamp_Verify_WithOfflineRevocation_ReturnsCorrectFlagsAndL else { errors.Count().Should().Be(2); - SigningTestUtility.AssertRevocationStatusUnknown(errors, LogLevel.Error, NuGetLogCode.NU3028); + SigningTestUtility.AssertOfflineRevocationOnlineMode(errors, LogLevel.Error, NuGetLogCode.NU3028); } - - SigningTestUtility.AssertOfflineRevocationOnlineMode(errors, LogLevel.Error, NuGetLogCode.NU3028); + SigningTestUtility.AssertRevocationStatusUnknown(errors, LogLevel.Error, NuGetLogCode.NU3028); } } }