public async Task DowngradeSignedToUnsignedVersionFromPMCForPR_SucceedAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            // This test is not considered an ideal behavior of the product but states the current behavior.
            // A package that is already installed as signed should be specailly treated and a user should not be
            // able to downgrade to an unsigned version. This test needs to be updated once this behavior gets
            // corrected in the product.

            var packageVersion09 = "0.9.0";
            var signedPackage    = _fixture.AuthorSignedTestPackage;

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
            {
                await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, signedPackage.Id, packageVersion09);

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

                var nugetConsole = GetConsole(testContext.Project);

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

                nugetConsole.UpdatePackageFromPMC(signedPackage.Id, packageVersion09);
                testContext.SolutionService.Build();
                testContext.NuGetApexTestService.WaitForAutoRestore();

                CommonUtility.AssertPackageReferenceExists(VisualStudio, testContext.Project, signedPackage.Id, packageVersion09, XunitLogger);
            }
        }
        public async Task WithExpiredCertificate_InstallFromPMCForPR_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);
                    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);
                }
        }
        public async Task DowngradePackageFromPMCForPRAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();
            var packageName     = "TestPackage";
            var packageVersion1 = "1.0.0";
            var packageVersion2 = "2.0.0";

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
            {
                await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, packageName, packageVersion1);

                await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, packageName, packageVersion2);

                var nugetConsole = GetConsole(testContext.Project);

                nugetConsole.InstallPackageFromPMC(packageName, packageVersion2);
                testContext.Project.Build();
                testContext.NuGetApexTestService.WaitForAutoRestore();

                nugetConsole.UpdatePackageFromPMC(packageName, packageVersion1);
                testContext.Project.Build();

                CommonUtility.AssertPackageReferenceExists(VisualStudio, testContext.Project, packageName, packageVersion1, XunitLogger);
                CommonUtility.AssertPackageInAssetsFile(VisualStudio, testContext.Project, packageName, packageVersion1, XunitLogger);
            }
        }
        public async Task UpdateUnsignedToSignedVersionFromPMCForPR_SucceedAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            var packageVersion09 = "0.9.0";
            var signedPackage    = _fixture.AuthorSignedTestPackage;

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
            {
                await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, signedPackage.Id, packageVersion09);

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

                var nugetConsole = GetConsole(testContext.Project);

                nugetConsole.InstallPackageFromPMC(signedPackage.Id, packageVersion09);
                testContext.SolutionService.Build();
                testContext.NuGetApexTestService.WaitForAutoRestore();

                nugetConsole.UpdatePackageFromPMC(signedPackage.Id, signedPackage.Version);
                testContext.SolutionService.Build();
                testContext.NuGetApexTestService.WaitForAutoRestore();

                CommonUtility.AssertPackageReferenceExists(VisualStudio, testContext.Project, signedPackage.Id, signedPackage.Version, XunitLogger);
            }
        }
Example #5
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.GenerateTrustedTestCertificateThatExpiresIn5Seconds())
                    {
                        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);
                    }
        }
Example #6
0
        public async Task InstallPackageFromPMCWithNoAutoRestoreVerifyAssetsFileAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger, noAutoRestore: true))
            {
                var packageName    = "TestPackage";
                var packageVersion = "1.0.0";
                await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, packageName, packageVersion);

                var nugetConsole = GetConsole(testContext.Project);

                nugetConsole.InstallPackageFromPMC(packageName, packageVersion);

                CommonUtility.AssertPackageReferenceExists(VisualStudio, testContext.Project, packageName, packageVersion, XunitLogger);
                CommonUtility.AssertPackageInAssetsFile(VisualStudio, testContext.Project, packageName, packageVersion, XunitLogger);
            }
        }
Example #7
0
        public async Task InstallFromPMCForPR_SucceedAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            var signedPackage = _fixture.RepositoryCountersignedTestPackage;

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
            {
                await SimpleTestPackageUtility.CreatePackagesAsync(testContext.PackageSource, signedPackage);

                var nugetConsole = GetConsole(testContext.Project);

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

                testContext.Project.Build();
                testContext.NuGetApexTestService.WaitForAutoRestore();

                CommonUtility.AssertPackageReferenceExists(VisualStudio, testContext.Project, signedPackage.Id, signedPackage.Version, XunitLogger);
            }
        }
Example #8
0
        public async Task UpdatePackageFromPMCForPRAsync(ProjectTemplate projectTemplate, string flag, string expectedVersion)
        {
            // Arrange
            EnsureVisualStudioHost();

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
            {
                var packageName     = "TestPackage";
                var packageVersion1 = "1.0.0";
                var packageVersion2 = "2.0.0";
                var packageVersion3 = "1.0.1";
                var packageVersion4 = "1.1.0";
                await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, packageName, packageVersion1);

                await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, packageName, packageVersion2);

                await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, packageName, packageVersion3);

                await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, packageName, packageVersion4);

                var nugetConsole = GetConsole(testContext.Project);

                nugetConsole.InstallPackageFromPMC(packageName, packageVersion1);
                testContext.Project.Build();
                testContext.NuGetApexTestService.WaitForAutoRestore();

                if (flag == null)
                {
                    nugetConsole.UpdatePackageFromPMC(packageName, packageVersion2);
                }
                else
                {
                    nugetConsole.UpdatePackageFromPMCWithConstraints(packageName, flag);
                }
                testContext.Project.Build();

                CommonUtility.AssertPackageReferenceExists(VisualStudio, testContext.Project, packageName, expectedVersion, XunitLogger);
                CommonUtility.AssertPackageInAssetsFile(VisualStudio, testContext.Project, packageName, expectedVersion, XunitLogger);
            }
        }
        public async Task InstallPackageFromPMCVerifyInstallForPRAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
            {
                var packageName    = "TestPackage";
                var packageVersion = "1.0.0";
                await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, packageName, packageVersion);

                var nugetConsole = GetConsole(testContext.Project);

                nugetConsole.InstallPackageFromPMC(packageName, packageVersion);

                // Build before the install check to ensure that everything is up to date.
                testContext.Project.Build();

                CommonUtility.AssertPackageReferenceExists(VisualStudio, testContext.Project, packageName, packageVersion, XunitLogger);
                CommonUtility.AssertPackageInAssetsFile(VisualStudio, testContext.Project, packageName, packageVersion, XunitLogger);
            }
        }
Example #10
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.GenerateTrustedTestCertificateThatExpiresIn5Seconds())
                    {
                        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.Project.Build();
                        testContext.NuGetApexTestService.WaitForAutoRestore();

                        CommonUtility.AssertPackageReferenceExists(VisualStudio, testContext.Project, expiredTestPackage.Id, expiredTestPackage.Version, XunitLogger);
                    }
        }
        public async Task WithSourceMappingEnabled_InstallPackageFromPMUIFromExpectedSource_Succeeds(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            using (var simpleTestPathContext = new SimpleTestPathContext())
            {
                string solutionDirectory     = simpleTestPathContext.SolutionRoot;
                var    privateRepositoryPath = Path.Combine(solutionDirectory, "PrivateRepository");
                Directory.CreateDirectory(privateRepositoryPath);
                var externalRepositoryPath = Path.Combine(solutionDirectory, "ExternalRepository");
                Directory.CreateDirectory(externalRepositoryPath);

                var packageName    = "Contoso.a";
                var packageVersion = "1.0.0";

                await CommonUtility.CreatePackageInSourceAsync(privateRepositoryPath, packageName, packageVersion);

                await CommonUtility.CreatePackageInSourceAsync(externalRepositoryPath, packageName, packageVersion);


                // Create nuget.config with Package source mapping filtering rules before project is created.
                CommonUtility.CreateConfigurationFile(Path.Combine(solutionDirectory, "NuGet.Config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <packageSources>
        <add key=""ExternalRepository"" value=""{externalRepositoryPath}"" />
        <add key=""PrivateRepository"" value=""{privateRepositoryPath}"" />
    </packageSources>
    <packageSourceMapping>
        <packageSource key=""externalRepository"">
            <package pattern=""External.*"" />
            <package pattern=""Others.*"" />
        </packageSource>
        <packageSource key=""PrivateRepository"">
            <package pattern=""contoso.*"" />
            <package pattern=""Test.*"" />
        </packageSource>
        <packageSource key=""nuget"">
            <package pattern=""Microsoft.*"" />
            <package pattern=""NetStandard*"" />
        </packageSource>
    </packageSourceMapping>
</configuration>");

                using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger, addNetStandardFeeds: true, simpleTestPathContext: simpleTestPathContext))
                {
                    VisualStudio.AssertNoErrors();

                    // Act
                    CommonUtility.OpenNuGetPackageManagerWithDte(VisualStudio, XunitLogger);
                    var nugetTestService = GetNuGetTestService();
                    var uiwindow         = nugetTestService.GetUIWindowfromProject(testContext.SolutionService.Projects[0]);
                    uiwindow.InstallPackageFromUI(packageName, packageVersion);

                    // Assert
                    VisualStudio.AssertNuGetOutputDoesNotHaveErrors();
                    CommonUtility.AssertPackageReferenceExists(VisualStudio, testContext.SolutionService.Projects[0], packageName, packageVersion, XunitLogger);
                    Assert.Contains($"Installed {packageName} {packageVersion} from {privateRepositoryPath}", GetPackageManagerOutputWindowPaneText());
                }
            }
        }