Esempio n. 1
0
        [PlatformFact(Platform.Windows, Platform.Linux)] // https://github.com/NuGet/Home/issues/8047
        public void Verify_WhenChainBuildingFails_Throws()
        {
            using (var certificate = _fixture.GetExpiredCertificate())
                using (var request = CreateRequest(certificate))
                {
                    var logger = new TestLogger();

                    var exception = Assert.Throws <SignatureException>(
                        () => SigningUtility.Verify(request, logger));

                    Assert.Equal(NuGetLogCode.NU3018, exception.Code);
                    Assert.Equal("Certificate chain validation failed.", exception.Message);

                    Assert.Equal(1, logger.Errors);

                    if (RuntimeEnvironmentHelper.IsLinux)
                    {
                        Assert.Equal(2, logger.Warnings);
                        SigningTestUtility.AssertRevocationStatusUnknown(logger.LogMessages, LogLevel.Warning);
                    }
                    else
                    {
                        Assert.Equal(1, logger.Warnings);
                    }

                    SigningTestUtility.AssertNotTimeValid(logger.LogMessages, LogLevel.Error);
                    SigningTestUtility.AssertUntrustedRoot(logger.LogMessages, LogLevel.Warning);
                }
        }
        public async Task SignAsync_WhenChainBuildingFails_ThrowsAsync()
        {
            var package = new SimpleTestPackageContext();

            using (var packageStream = await package.CreateAsStreamAsync())
                using (var test = SignTest.Create(
                           _fixture.GetExpiredCertificate(),
                           HashAlgorithmName.SHA256,
                           packageStream.ToArray(),
                           new X509SignatureProvider(timestampProvider: null)))
                {
                    var exception = await Assert.ThrowsAsync <SignatureException>(
                        () => SigningUtility.SignAsync(test.Options, test.Request, CancellationToken.None));

                    Assert.Equal(NuGetLogCode.NU3018, exception.Code);
                    Assert.Equal("Certificate chain validation failed.", exception.Message);

                    Assert.Equal(1, test.Logger.Errors);
                    Assert.Equal(1, test.Logger.Warnings);
                    SigningTestUtility.AssertNotTimeValid(test.Logger.LogMessages, LogLevel.Error);
                    SigningTestUtility.AssertUntrustedRoot(test.Logger.LogMessages, LogLevel.Warning);
                }
        }