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.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,
                        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.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);
                }
        }
Пример #3
0
        public async Task NtlmAuthenticationTest(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, ApplicationType applicationType, string applicationBaseUrl)
        {
            using (_logger.BeginScope("NtlmAuthenticationTest"))
            {
                var musicStoreDbName = DbUtils.GetUniqueName();

                var deploymentParameters = new DeploymentParameters(Helpers.GetApplicationPath(applicationType), serverType, runtimeFlavor, architecture)
                {
                    PublishApplicationBeforeDeployment = true,
                    PublishTargetFramework             = runtimeFlavor == RuntimeFlavor.Clr ? "net451" : "netcoreapp1.0",
                    ApplicationType             = applicationType,
                    ApplicationBaseUriHint      = applicationBaseUrl,
                    EnvironmentName             = "NtlmAuthentication", //Will pick the Start class named 'StartupNtlmAuthentication'
                    ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("NtlmAuthentation.config") : null,
                    SiteName = "MusicStoreNtlmAuthentication",          //This is configured in the NtlmAuthentication.config
                    UserAdditionalCleanup = parameters =>
                    {
                        DbUtils.DropDatabase(musicStoreDbName, _logger);
                    }
                };

                // Override the connection strings using environment based configuration
                deploymentParameters.EnvironmentVariables
                .Add(new KeyValuePair <string, string>(
                         MusicStore.StoreConfig.ConnectionStringKey,
                         DbUtils.CreateConnectionString(musicStoreDbName)));

                using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, _logger))
                {
                    var deploymentResult  = deployer.Deploy();
                    var httpClientHandler = new HttpClientHandler()
                    {
                        UseDefaultCredentials = true
                    };
                    var httpClient = new HttpClient(httpClientHandler)
                    {
                        BaseAddress = new Uri(deploymentResult.ApplicationBaseUri)
                    };

                    // Request to base address and check if various parts of the body are rendered & measure the cold startup time.
                    var response = await RetryHelper.RetryRequest(async() =>
                    {
                        return(await httpClient.GetAsync(string.Empty));
                    }, logger : _logger, cancellationToken : deploymentResult.HostShutdownToken);

                    Assert.False(response == null, "Response object is null because the client could not " +
                                 "connect to the server after multiple retries");

                    var validator = new Validator(httpClient, httpClientHandler, _logger, deploymentResult);

                    Console.WriteLine("Verifying home page");
                    await validator.VerifyNtlmHomePage(response);

                    Console.WriteLine("Verifying access to store with permissions");
                    await validator.AccessStoreWithPermissions();

                    _logger.LogInformation("Variation completed successfully.");
                }
            }
        }
        // TODO: temporarily disabling x86 tests as dotnet xunit test runner currently does not support 32-bit

        //[ConditionalTheory(Skip = "https://github.com/aspnet/MusicStore/issues/565"), Trait("E2Etests", "E2Etests")]
        //[OSSkipCondition(OperatingSystems.Windows)]
        //[InlineData(ServerType.Kestrel, RuntimeFlavor.Clr, RuntimeArchitecture.x86, ApplicationType.Portable, "http://localhost:5045/")]
        //public async Task OpenIdConnect_OnMono(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, ApplicationType applicationType, string applicationBaseUrl)
        //{
        //    await OpenIdConnectTestSuite(serverType, runtimeFlavor, architecture, applicationBaseUrl);
        //}

        private async Task OpenIdConnectTestSuite(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, ApplicationType applicationType, string applicationBaseUrl)
        {
            using (_logger.BeginScope("OpenIdConnectTestSuite"))
            {
                var musicStoreDbName = DbUtils.GetUniqueName();

                var deploymentParameters = new DeploymentParameters(Helpers.GetApplicationPath(applicationType), serverType, runtimeFlavor, architecture)
                {
                    PublishApplicationBeforeDeployment       = true,
                    PreservePublishedApplicationForDebugging = Helpers.PreservePublishedApplicationForDebugging,
                    TargetFramework        = runtimeFlavor == RuntimeFlavor.Clr ? "net451" : "netcoreapp1.0",
                    Configuration          = Helpers.GetCurrentBuildConfiguration(),
                    ApplicationType        = applicationType,
                    ApplicationBaseUriHint = applicationBaseUrl,
                    EnvironmentName        = "OpenIdConnectTesting",
                    UserAdditionalCleanup  = parameters =>
                    {
                        DbUtils.DropDatabase(musicStoreDbName, _logger);
                    }
                };

                // Override the connection strings using environment based configuration
                deploymentParameters.EnvironmentVariables
                .Add(new KeyValuePair <string, string>(
                         MusicStoreConfig.ConnectionStringKey,
                         DbUtils.CreateConnectionString(musicStoreDbName)));

                using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, _logger))
                {
                    var deploymentResult  = deployer.Deploy();
                    var httpClientHandler = new HttpClientHandler();
                    var httpClient        = new HttpClient(httpClientHandler)
                    {
                        BaseAddress = new Uri(deploymentResult.ApplicationBaseUri)
                    };

                    // Request to base address and check if various parts of the body are rendered & measure the cold startup time.
                    var response = await RetryHelper.RetryRequest(async() =>
                    {
                        return(await httpClient.GetAsync(string.Empty));
                    }, logger : _logger, cancellationToken : deploymentResult.HostShutdownToken);

                    Assert.False(response == null, "Response object is null because the client could not " +
                                 "connect to the server after multiple retries");

                    var validator = new Validator(httpClient, httpClientHandler, _logger, deploymentResult);

                    Console.WriteLine("Verifying home page");
                    await validator.VerifyHomePage(response);

                    Console.WriteLine("Verifying login by OpenIdConnect");
                    await validator.LoginWithOpenIdConnect();

                    _logger.LogInformation("Variation completed successfully.");
                }
            }
        }
Пример #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.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.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);
                    }
        }
Пример #6
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);
                    }
        }