Exemplo n.º 1
0
        public async Task GetTrustResultAsync_WithInvalidSignature_Throws()
        {
            var package          = new SimpleTestPackageContext();
            var timestampService = await _testFixture.GetDefaultTrustedTimestampServiceAsync();

            using (var directory = TestDirectory.Create())
                using (var testCertificate = new X509Certificate2(_trustedTestCert.Source.Cert))
                {
                    var packageFilePath = await SignedArchiveTestUtility.AuthorSignPackageAsync(
                        testCertificate,
                        package,
                        directory,
                        timestampService.Url);

                    using (var packageReader = new PackageArchiveReader(packageFilePath))
                    {
                        var signature = await packageReader.GetPrimarySignatureAsync(CancellationToken.None);

                        var invalidSignature = SignatureTestUtility.GenerateInvalidPrimarySignature(signature);
                        var provider         = new SignatureTrustAndValidityVerificationProvider();

                        var result = await provider.GetTrustResultAsync(
                            packageReader,
                            invalidSignature,
                            _defaultSettings,
                            CancellationToken.None);

                        var issue = result.Issues.FirstOrDefault(log => log.Code == NuGetLogCode.NU3012);

                        Assert.NotNull(issue);
                        Assert.Contains("validation failed.", issue.Message);
                    }
                }
        }