コード例 #1
0
        public async Task WithExpiredCertificate_InstallFromPMCForPC_WarnAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
                using (var trustedExpiringTestCert = SigningTestUtility.GenerateTrustedTestCertificateThatExpiresIn10Seconds())
                {
                    XunitLogger.LogInformation("Creating package");
                    var package = CommonUtility.CreatePackage("ExpiredTestPackage", "1.0.0");

                    XunitLogger.LogInformation("Signing package");
                    var expiredTestPackage = CommonUtility.AuthorSignPackage(package, trustedExpiringTestCert.Source.Cert);
                    await SimpleTestPackageUtility.CreatePackagesAsync(testContext.PackageSource, expiredTestPackage);

                    XunitLogger.LogInformation("Waiting for package to expire");
                    SigningUtility.WaitForCertificateToExpire(trustedExpiringTestCert.Source.Cert);

                    var nugetConsole = GetConsole(testContext.Project);

                    nugetConsole.InstallPackageFromPMC(expiredTestPackage.Id, expiredTestPackage.Version);

                    // TODO: Fix bug where no warnings are shown when package is untrusted but still installed
                    //nugetConsole.IsMessageFoundInPMC("expired certificate").Should().BeTrue("expired certificate warning");
                    CommonUtility.AssetPackageInPackagesConfig(VisualStudio, testContext.Project, expiredTestPackage.Id, expiredTestPackage.Version, XunitLogger);
                }
        }
コード例 #2
0
        public async Task WithExpiredAuthorCertificate_ExpiredRepoCertificate_InstallFromPMCForPC_WarnAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
                using (var trustedExpiringTestCert = SigningTestUtility.GenerateTrustedTestCertificateThatExpiresIn10Seconds())
                {
                    XunitLogger.LogInformation("Creating package");
                    var package = CommonUtility.CreatePackage("ExpiredTestPackage", "1.0.0");

                    XunitLogger.LogInformation("Signing and countersigning package");
                    var expiredTestPackage   = CommonUtility.AuthorSignPackage(package, trustedExpiringTestCert.Source.Cert);
                    var countersignedPackage = CommonUtility.RepositoryCountersignPackage(
                        expiredTestPackage,
                        trustedExpiringTestCert.Source.Cert,
                        new Uri("https://v3serviceIndexUrl.test/api/index.json"));

                    await SimpleTestPackageUtility.CreatePackagesAsync(testContext.PackageSource, expiredTestPackage);

                    XunitLogger.LogInformation("Waiting for package to expire");
                    SigningUtility.WaitForCertificateToExpire(trustedExpiringTestCert.Source.Cert);

                    var nugetConsole = GetConsole(testContext.Project);

                    nugetConsole.InstallPackageFromPMC(expiredTestPackage.Id, expiredTestPackage.Version);
                    testContext.SolutionService.Build();
                    testContext.NuGetApexTestService.WaitForAutoRestore();

                    // TODO: Fix bug where no warnings are shown when package is untrusted but still installed
                    //nugetConsole.IsMessageFoundInPMC("expired certificate").Should().BeTrue("expired certificate warning");
                    CommonUtility.AssertPackageReferenceExists(VisualStudio, testContext.Project, expiredTestPackage.Id, expiredTestPackage.Version, XunitLogger);
                }
        }
コード例 #3
0
        public async Task WithExpiredAuthorCertificateAtCountersigning_InstallFromPMCForPR_WarnAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            var timestampService = await _fixture.GetDefaultTrustedTimestampServiceAsync();

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
                using (var trustedCert = _fixture.TrustedRepositoryTestCertificate)
                    using (var trustedExpiringTestCert = SigningTestUtility.GenerateTrustedTestCertificateThatExpiresIn10Seconds())
                    {
                        XunitLogger.LogInformation("Creating package");
                        var package = CommonUtility.CreatePackage("ExpiredTestPackage", "1.0.0");

                        XunitLogger.LogInformation("Signing package");
                        var expiredTestPackage = CommonUtility.AuthorSignPackage(package, trustedExpiringTestCert.Source.Cert);
                        await SimpleTestPackageUtility.CreatePackagesAsync(testContext.PackageSource, expiredTestPackage);

                        var packageFullName = Path.Combine(testContext.PackageSource, expiredTestPackage.PackageName);

                        XunitLogger.LogInformation("Waiting for package to expire");
                        SigningUtility.WaitForCertificateToExpire(trustedExpiringTestCert.Source.Cert);

                        XunitLogger.LogInformation("Countersigning package");
                        var countersignedPackage = await SignedArchiveTestUtility.RepositorySignPackageAsync(
                            new X509Certificate2(trustedCert.Source.Cert),
                            packageFullName,
                            testContext.PackageSource,
                            new Uri("https://v3serviceIndexUrl.test/api/index.json"),
                            timestampService.Url);

                        File.Copy(countersignedPackage, packageFullName, overwrite: true);
                        File.Delete(countersignedPackage);

                        var nugetConsole = GetConsole(testContext.Project);

                        nugetConsole.InstallPackageFromPMC(expiredTestPackage.Id, expiredTestPackage.Version);
                        testContext.Project.Build();
                        testContext.NuGetApexTestService.WaitForAutoRestore();

                        // TODO: Fix bug where no warnings are shown when package is untrusted but still installed
                        //nugetConsole.IsMessageFoundInPMC("expired certificate").Should().BeTrue("expired certificate warning");
                        CommonUtility.AssertPackageReferenceExists(VisualStudio, testContext.Project, expiredTestPackage.Id, expiredTestPackage.Version, XunitLogger);
                    }
        }
コード例 #4
0
        public async Task WithExpiredAuthorCertificateAfterCountersigning_InstallFromPMCForPC_SucceedAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            var timestampService = await _fixture.GetDefaultTrustedTimestampServiceAsync();

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
                using (var trustedCert = _fixture.TrustedRepositoryTestCertificate)
                    using (var trustedExpiringTestCert = SigningTestUtility.GenerateTrustedTestCertificateThatExpiresIn10Seconds())
                    {
                        XunitLogger.LogInformation("Creating package");
                        var package = CommonUtility.CreatePackage("ExpiredTestPackage", "1.0.0");

                        XunitLogger.LogInformation("Signing and countersigning package");
                        var expiredTestPackage   = CommonUtility.AuthorSignPackage(package, trustedExpiringTestCert.Source.Cert);
                        var countersignedPackage = CommonUtility.RepositoryCountersignPackage(
                            expiredTestPackage,
                            trustedCert.Source.Cert,
                            new Uri("https://v3serviceIndexUrl.test/api/index.json"),
                            packageOwners: null,
                            timestampProviderUrl: timestampService.Url);

                        await SimpleTestPackageUtility.CreatePackagesAsync(testContext.PackageSource, expiredTestPackage);

                        XunitLogger.LogInformation("Waiting for package to expire");
                        SigningUtility.WaitForCertificateToExpire(trustedExpiringTestCert.Source.Cert);

                        var nugetConsole = GetConsole(testContext.Project);

                        nugetConsole.InstallPackageFromPMC(expiredTestPackage.Id, expiredTestPackage.Version);
                        testContext.SolutionService.Build();
                        testContext.NuGetApexTestService.WaitForAutoRestore();

                        CommonUtility.AssertPackageReferenceExists(VisualStudio, testContext.Project, expiredTestPackage.Id, expiredTestPackage.Version, XunitLogger);
                    }
        }